diff --git a/src/tools/miri/src/intptrcast.rs b/src/tools/miri/src/alloc_addresses/mod.rs similarity index 96% rename from src/tools/miri/src/intptrcast.rs rename to src/tools/miri/src/alloc_addresses/mod.rs index 3fe127f9732..3177a1297c8 100644 --- a/src/tools/miri/src/intptrcast.rs +++ b/src/tools/miri/src/alloc_addresses/mod.rs @@ -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 { 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 { 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 { pub data_race: Option, /// 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(()) } diff --git a/src/tools/miri/src/provenance_gc.rs b/src/tools/miri/src/provenance_gc.rs index 347951ce372..f23d7dfd52d 100644 --- a/src/tools/miri/src/provenance_gc.rs +++ b/src/tools/miri/src/provenance_gc.rs @@ -197,7 +197,7 @@ fn remove_unreachable_allocs(&mut self, allocs: FxHashSet) { 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); }