Skip to content

Commit 9bba6e8

Browse files
committed
fixups
1 parent 11c0f42 commit 9bba6e8

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

src/alloc/alloc_bytes.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ impl AllocBytes for MiriAllocBytes {
119119
let slice = slice.into();
120120
let size = slice.len();
121121
let align = align.bytes();
122+
// We need to clone here, since one copy goes into the alloc_fn and
123+
// another is stored in the actual MiriAllocBytes
122124
let p_clone = params.clone();
123125
// SAFETY: `alloc_fn` will only be used with `size != 0`.
124126
let alloc_fn = |layout| unsafe {

src/alloc/isolated_alloc.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ impl IsolatedAlloc {
4242
assert_ne!(page_size, 0);
4343

4444
let page_layout = unsafe { Layout::from_size_align_unchecked(page_size, page_size) };
45-
// We don't overwrite the bytes we hand out so make sure they're zeroed by default!
4645
let page_ptr = unsafe { alloc::alloc(page_layout) };
4746
// `page_infos` has to have one-eighth as many bits as a page has bytes
4847
// (or one-64th as many bytes)
@@ -140,7 +139,7 @@ impl IsolatedAlloc {
140139

141140
/// Allocates in multiples of one page on the host system.
142141
///
143-
/// SAFETY: Same as `alloc_inner()`.
142+
/// SAFETY: Same as `alloc()`.
144143
unsafe fn alloc_multi_page(&mut self, layout: Layout, zeroed: bool) -> *mut u8 {
145144
let ret =
146145
unsafe { if zeroed { alloc::alloc_zeroed(layout) } else { alloc::alloc(layout) } };

src/machine.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ pub struct MiriMachine<'tcx> {
534534

535535
/// The allocator used for the machine's `AllocBytes` in native-libs mode.
536536
#[cfg(target_os = "linux")]
537-
pub(crate) allocator: Rc<RefCell<crate::alloc::isolated_alloc::IsolatedAlloc>>,
537+
pub(crate) allocator: Option<Rc<RefCell<crate::alloc::isolated_alloc::IsolatedAlloc>>>,
538538

539539
/// The allocation IDs to report when they are being allocated
540540
/// (helps for debugging memory leaks and use after free bugs).
@@ -642,8 +642,7 @@ impl<'tcx> MiriMachine<'tcx> {
642642
let path = Path::new(out).join(filename);
643643
measureme::Profiler::new(path).expect("Couldn't create `measureme` profiler")
644644
});
645-
let seed = config.seed.unwrap_or(0);
646-
let rng = StdRng::seed_from_u64(seed);
645+
let rng = StdRng::seed_from_u64(config.seed.unwrap_or(0));
647646
let borrow_tracker = config.borrow_tracker.map(|bt| bt.instantiate_global_state(config));
648647
let data_race = if config.genmc_mode {
649648
// `genmc_ctx` persists across executions, so we don't create a new one here.
@@ -721,7 +720,9 @@ impl<'tcx> MiriMachine<'tcx> {
721720
extern_statics: FxHashMap::default(),
722721
rng: RefCell::new(rng),
723722
#[cfg(target_os = "linux")]
724-
allocator: Rc::new(RefCell::new(crate::alloc::isolated_alloc::IsolatedAlloc::new())),
723+
allocator: if config.native_lib.is_some() {
724+
Some(Rc::new(RefCell::new(crate::alloc::isolated_alloc::IsolatedAlloc::new())))
725+
} else { None },
725726
tracked_alloc_ids: config.tracked_alloc_ids.clone(),
726727
track_alloc_accesses: config.track_alloc_accesses,
727728
check_alignment: config.check_alignment,
@@ -1817,10 +1818,9 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
18171818
use crate::alloc::MiriAllocParams;
18181819

18191820
#[cfg(target_os = "linux")]
1820-
if self.native_lib.is_some() {
1821-
MiriAllocParams::Isolated(self.allocator.clone())
1822-
} else {
1823-
MiriAllocParams::Global
1821+
match &self.allocator {
1822+
Some(alloc) => MiriAllocParams::Isolated(alloc.clone()),
1823+
None => MiriAllocParams::Global,
18241824
}
18251825
#[cfg(not(target_os = "linux"))]
18261826
MiriAllocParams::Global

0 commit comments

Comments
 (0)