rename intptrcast -> alloc_addresses, and make a folder for it
This commit is contained in:
parent
16e869a678
commit
092bd53c1e
@ -1,3 +1,6 @@
|
||||
//! This module is responsible for managing the absolute addresses that allocations are located at,
|
||||
//! and for casting between pointers and integers based on those addresses.
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::cmp::max;
|
||||
use std::collections::hash_map::Entry;
|
||||
@ -96,7 +99,7 @@ trait EvalContextExtPriv<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
|
||||
// or `None` if the addr is out of bounds
|
||||
fn alloc_id_from_addr(&self, addr: u64) -> Option<AllocId> {
|
||||
let ecx = self.eval_context_ref();
|
||||
let global_state = ecx.machine.intptrcast.borrow();
|
||||
let global_state = ecx.machine.alloc_addresses.borrow();
|
||||
assert!(global_state.provenance_mode != ProvenanceMode::Strict);
|
||||
|
||||
let pos = global_state.int_to_ptr_map.binary_search_by_key(&addr, |(addr, _)| *addr);
|
||||
@ -133,7 +136,7 @@ fn alloc_id_from_addr(&self, addr: u64) -> Option<AllocId> {
|
||||
|
||||
fn addr_from_alloc_id(&self, alloc_id: AllocId) -> InterpResult<'tcx, u64> {
|
||||
let ecx = self.eval_context_ref();
|
||||
let mut global_state = ecx.machine.intptrcast.borrow_mut();
|
||||
let mut global_state = ecx.machine.alloc_addresses.borrow_mut();
|
||||
let global_state = &mut *global_state;
|
||||
|
||||
Ok(match global_state.base_addr.entry(alloc_id) {
|
||||
@ -196,7 +199,7 @@ impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriInterpCx<'mir,
|
||||
pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
|
||||
fn expose_ptr(&mut self, alloc_id: AllocId, tag: BorTag) -> InterpResult<'tcx> {
|
||||
let ecx = self.eval_context_mut();
|
||||
let global_state = ecx.machine.intptrcast.get_mut();
|
||||
let global_state = ecx.machine.alloc_addresses.get_mut();
|
||||
// In strict mode, we don't need this, so we can save some cycles by not tracking it.
|
||||
if global_state.provenance_mode == ProvenanceMode::Strict {
|
||||
return Ok(());
|
||||
@ -207,7 +210,7 @@ fn expose_ptr(&mut self, alloc_id: AllocId, tag: BorTag) -> InterpResult<'tcx> {
|
||||
return Ok(());
|
||||
}
|
||||
trace!("Exposing allocation id {alloc_id:?}");
|
||||
let global_state = ecx.machine.intptrcast.get_mut();
|
||||
let global_state = ecx.machine.alloc_addresses.get_mut();
|
||||
global_state.exposed.insert(alloc_id);
|
||||
if ecx.machine.borrow_tracker.is_some() {
|
||||
ecx.expose_tag(alloc_id, tag)?;
|
||||
@ -219,7 +222,7 @@ fn ptr_from_addr_cast(&self, addr: u64) -> InterpResult<'tcx, Pointer<Option<Pro
|
||||
trace!("Casting {:#x} to a pointer", addr);
|
||||
|
||||
let ecx = self.eval_context_ref();
|
||||
let global_state = ecx.machine.intptrcast.borrow();
|
||||
let global_state = ecx.machine.alloc_addresses.borrow();
|
||||
|
||||
// Potentially emit a warning.
|
||||
match global_state.provenance_mode {
|
@ -71,13 +71,13 @@
|
||||
#[allow(unused_extern_crates)]
|
||||
extern crate rustc_driver;
|
||||
|
||||
mod alloc_addresses;
|
||||
mod borrow_tracker;
|
||||
mod clock;
|
||||
mod concurrency;
|
||||
mod diagnostics;
|
||||
mod eval;
|
||||
mod helpers;
|
||||
mod intptrcast;
|
||||
mod machine;
|
||||
mod mono_hash_map;
|
||||
mod operator;
|
||||
@ -100,6 +100,7 @@
|
||||
pub use crate::shims::time::EvalContextExt as _;
|
||||
pub use crate::shims::tls::TlsData;
|
||||
|
||||
pub use crate::alloc_addresses::{EvalContextExt as _, ProvenanceMode};
|
||||
pub use crate::borrow_tracker::stacked_borrows::{
|
||||
EvalContextExt as _, Item, Permission, Stack, Stacks,
|
||||
};
|
||||
@ -121,7 +122,6 @@
|
||||
create_ecx, eval_entry, AlignmentCheck, BacktraceStyle, IsolatedOp, MiriConfig, RejectOpWith,
|
||||
};
|
||||
pub use crate::helpers::{AccessKind, EvalContextExt as _};
|
||||
pub use crate::intptrcast::{EvalContextExt as _, ProvenanceMode};
|
||||
pub use crate::machine::{
|
||||
AllocExtra, FrameExtra, MiriInterpCx, MiriInterpCxExt, MiriMachine, MiriMemoryKind,
|
||||
PrimitiveLayouts, Provenance, ProvenanceExtra,
|
||||
|
@ -436,7 +436,7 @@ pub struct MiriMachine<'mir, 'tcx> {
|
||||
pub data_race: Option<data_race::GlobalState>,
|
||||
|
||||
/// Ptr-int-cast module global data.
|
||||
pub intptrcast: intptrcast::GlobalState,
|
||||
pub alloc_addresses: alloc_addresses::GlobalState,
|
||||
|
||||
/// Environment variables set by `setenv`.
|
||||
/// Miri does not expose env vars from the host to the emulated program.
|
||||
@ -634,7 +634,7 @@ pub(crate) fn new(config: &MiriConfig, layout_cx: LayoutCx<'tcx, TyCtxt<'tcx>>)
|
||||
tcx,
|
||||
borrow_tracker,
|
||||
data_race,
|
||||
intptrcast: RefCell::new(intptrcast::GlobalStateInner::new(config, stack_addr)),
|
||||
alloc_addresses: RefCell::new(alloc_addresses::GlobalStateInner::new(config, stack_addr)),
|
||||
// `env_vars` depends on a full interpreter so we cannot properly initialize it yet.
|
||||
env_vars: EnvVars::default(),
|
||||
main_fn_ret_place: None,
|
||||
@ -782,7 +782,7 @@ fn visit_provenance(&self, visit: &mut VisitWith<'_>) {
|
||||
dir_handler,
|
||||
borrow_tracker,
|
||||
data_race,
|
||||
intptrcast,
|
||||
alloc_addresses,
|
||||
file_handler,
|
||||
tcx: _,
|
||||
isolated_op: _,
|
||||
@ -827,7 +827,7 @@ fn visit_provenance(&self, visit: &mut VisitWith<'_>) {
|
||||
file_handler.visit_provenance(visit);
|
||||
data_race.visit_provenance(visit);
|
||||
borrow_tracker.visit_provenance(visit);
|
||||
intptrcast.visit_provenance(visit);
|
||||
alloc_addresses.visit_provenance(visit);
|
||||
main_fn_ret_place.visit_provenance(visit);
|
||||
argc.visit_provenance(visit);
|
||||
argv.visit_provenance(visit);
|
||||
@ -1304,7 +1304,7 @@ fn before_memory_deallocation(
|
||||
{
|
||||
*deallocated_at = Some(machine.current_span());
|
||||
}
|
||||
machine.intptrcast.get_mut().free_alloc_id(alloc_id);
|
||||
machine.alloc_addresses.get_mut().free_alloc_id(alloc_id);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -197,7 +197,7 @@ fn remove_unreachable_allocs(&mut self, allocs: FxHashSet<AllocId>) {
|
||||
let allocs = LiveAllocs { ecx: this, collected: allocs };
|
||||
this.machine.allocation_spans.borrow_mut().retain(|id, _| allocs.is_live(*id));
|
||||
this.machine.symbolic_alignment.borrow_mut().retain(|id, _| allocs.is_live(*id));
|
||||
this.machine.intptrcast.borrow_mut().remove_unreachable_allocs(&allocs);
|
||||
this.machine.alloc_addresses.borrow_mut().remove_unreachable_allocs(&allocs);
|
||||
if let Some(borrow_tracker) = &this.machine.borrow_tracker {
|
||||
borrow_tracker.borrow_mut().remove_unreachable_allocs(&allocs);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user