Skip to content

Commit 3b1584e

Browse files
committed
address review
1 parent bbe0635 commit 3b1584e

File tree

11 files changed

+76
-56
lines changed

11 files changed

+76
-56
lines changed

build.rs

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/alloc/alloc_bytes.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
use std::alloc::Layout;
22
use std::borrow::Cow;
33
use std::{alloc, slice};
4-
#[cfg(trace)]
4+
#[cfg(target_os = "linux")]
55
use std::{cell::RefCell, rc::Rc};
66

77
use rustc_abi::{Align, Size};
88
use rustc_middle::mir::interpret::AllocBytes;
99

10-
#[cfg(trace)]
10+
#[cfg(target_os = "linux")]
1111
use crate::alloc::isolated_alloc::IsolatedAlloc;
1212
use crate::helpers::ToU64 as _;
1313

1414
#[derive(Clone, Debug)]
1515
pub enum MiriAllocParams {
1616
Global,
17-
#[cfg(trace)]
17+
#[cfg(target_os = "linux")]
1818
Isolated(Rc<RefCell<IsolatedAlloc>>),
1919
}
2020

@@ -56,7 +56,7 @@ impl Drop for MiriAllocBytes {
5656
unsafe {
5757
match self.params.clone() {
5858
MiriAllocParams::Global => alloc::dealloc(self.ptr, alloc_layout),
59-
#[cfg(trace)]
59+
#[cfg(target_os = "linux")]
6060
MiriAllocParams::Isolated(alloc) =>
6161
alloc.borrow_mut().dealloc(self.ptr, alloc_layout),
6262
}
@@ -123,7 +123,7 @@ impl AllocBytes for MiriAllocBytes {
123123
let alloc_fn = |layout, params: &MiriAllocParams| unsafe {
124124
match params {
125125
MiriAllocParams::Global => alloc::alloc(layout),
126-
#[cfg(trace)]
126+
#[cfg(target_os = "linux")]
127127
MiriAllocParams::Isolated(alloc) => alloc.borrow_mut().alloc(layout),
128128
}
129129
};
@@ -144,7 +144,7 @@ impl AllocBytes for MiriAllocBytes {
144144
let alloc_fn = |layout, params: &MiriAllocParams| unsafe {
145145
match params {
146146
MiriAllocParams::Global => alloc::alloc_zeroed(layout),
147-
#[cfg(trace)]
147+
#[cfg(target_os = "linux")]
148148
MiriAllocParams::Isolated(alloc) => alloc.borrow_mut().alloc_zeroed(layout),
149149
}
150150
};

src/alloc/isolated_alloc.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -304,14 +304,13 @@ impl IsolatedAlloc {
304304

305305
/// Returns a vector of page addresses managed by the allocator.
306306
pub fn pages(&self) -> Vec<usize> {
307-
let mut pages: Vec<usize> =
308-
self.page_ptrs.iter().map(|p| p.expose_provenance().get()).collect();
309-
for (ptr, size) in self.huge_ptrs.iter() {
310-
for i in 0..size / self.page_size {
311-
pages.push(ptr.expose_provenance().get().strict_add(i * self.page_size));
312-
}
313-
}
314-
pages
307+
let pages = self.page_ptrs.iter().map(|p| p.expose_provenance().get());
308+
let pages = pages.chain(self.huge_ptrs.iter().flat_map(|(ptr, size)| {
309+
(0..size / self.page_size)
310+
.map(|i| ptr.expose_provenance().get().strict_add(i * self.page_size))
311+
}));
312+
313+
pages.collect()
315314
}
316315

317316
/// Protects all owned memory as `PROT_NONE`, preventing accesses.

src/alloc/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
mod alloc_bytes;
2-
#[cfg(trace)]
2+
#[cfg(target_os = "linux")]
33
pub mod isolated_alloc;
44

55
pub use self::alloc_bytes::{MiriAllocBytes, MiriAllocParams};

src/bin/miri.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ impl rustc_driver::Callbacks for MiriCompilerCalls {
233233
} else {
234234
let return_code = miri::eval_entry(tcx, entry_def_id, entry_type, &config, None)
235235
.unwrap_or_else(|| {
236-
#[cfg(trace)]
236+
// abort_if_errors may exit without calling the exit function.
237237
miri::native_lib::register_retcode_sv(rustc_driver::EXIT_FAILURE);
238238
tcx.dcx().abort_if_errors();
239239
rustc_driver::EXIT_FAILURE
@@ -750,9 +750,8 @@ fn main() {
750750

751751
debug!("rustc arguments: {:?}", rustc_args);
752752
debug!("crate arguments: {:?}", miri_config.args);
753-
#[cfg(trace)]
754753
if !miri_config.native_lib.is_empty() && miri_config.native_lib_enable_tracing {
755-
// FIXME: This should display a diagnostic / warning on error
754+
// FIXME(ptrace): This should display a diagnostic / warning on error
756755
// SAFETY: If any other threads exist at this point (namely for the ctrlc
757756
// handler), they will not interact with anything on the main rustc/Miri
758757
// thread in an async-signal-unsafe way such as by accessing shared

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ pub use rustc_const_eval::interpret::{self, AllocMap, Provenance as _};
9797
use rustc_middle::{bug, span_bug};
9898
use tracing::{info, trace};
9999

100-
#[cfg(trace)]
101100
pub mod native_lib {
102101
pub use crate::shims::{init_sv, register_retcode_sv};
103102
}

src/machine.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ pub struct MiriMachine<'tcx> {
530530
pub(crate) rng: RefCell<StdRng>,
531531

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

536536
/// The allocation IDs to report when they are being allocated
@@ -718,7 +718,7 @@ impl<'tcx> MiriMachine<'tcx> {
718718
local_crates,
719719
extern_statics: FxHashMap::default(),
720720
rng: RefCell::new(rng),
721-
#[cfg(trace)]
721+
#[cfg(target_os = "linux")]
722722
allocator: if !config.native_lib.is_empty() {
723723
Some(Rc::new(RefCell::new(crate::alloc::isolated_alloc::IsolatedAlloc::new())))
724724
} else { None },
@@ -924,7 +924,7 @@ impl VisitProvenance for MiriMachine<'_> {
924924
backtrace_style: _,
925925
local_crates: _,
926926
rng: _,
927-
#[cfg(trace)]
927+
#[cfg(target_os = "linux")]
928928
allocator: _,
929929
tracked_alloc_ids: _,
930930
track_alloc_accesses: _,
@@ -1819,12 +1819,12 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
18191819
fn get_default_alloc_params(&self) -> <Self::Bytes as AllocBytes>::AllocParams {
18201820
use crate::alloc::MiriAllocParams;
18211821

1822-
#[cfg(trace)]
1822+
#[cfg(target_os = "linux")]
18231823
match &self.allocator {
18241824
Some(alloc) => MiriAllocParams::Isolated(alloc.clone()),
18251825
None => MiriAllocParams::Global,
18261826
}
1827-
#[cfg(not(trace))]
1827+
#[cfg(not(target_os = "linux"))]
18281828
MiriAllocParams::Global
18291829
}
18301830
}

src/shims/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ pub mod time;
2121
pub mod tls;
2222

2323
pub use self::files::FdTable;
24-
#[cfg(trace)]
2524
pub use self::native_lib::trace::{init_sv, register_retcode_sv};
2625
pub use self::unix::{DirTable, EpollInterestTable};
2726

src/shims/native_lib/mod.rs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
//! Implements calling functions from a native library.
22
3-
#[cfg(trace)]
4-
pub mod trace;
5-
63
use std::ops::Deref;
74

85
use libffi::high::call as ffi;
@@ -12,15 +9,27 @@ use rustc_middle::mir::interpret::Pointer;
129
use rustc_middle::ty::{self as ty, IntTy, UintTy};
1310
use rustc_span::Symbol;
1411

15-
#[cfg(trace)]
12+
#[cfg_attr(
13+
all(
14+
target_os = "linux",
15+
target_env = "gnu",
16+
any(target_arch = "x86", target_arch = "x86_64", target_arch = "aarch64")
17+
),
18+
path = "trace/mod.rs"
19+
)]
20+
#[cfg_attr(
21+
not(all(
22+
target_os = "linux",
23+
target_env = "gnu",
24+
any(target_arch = "x86", target_arch = "x86_64", target_arch = "aarch64")
25+
)),
26+
path = "trace_stub.rs"
27+
)]
28+
pub mod trace;
29+
1630
use self::trace::Supervisor;
1731
use crate::*;
1832

19-
#[cfg(trace)]
20-
type CallResult<'tcx> = InterpResult<'tcx, (ImmTy<'tcx>, Option<self::trace::messages::MemEvents>)>;
21-
#[cfg(not(trace))]
22-
type CallResult<'tcx> = InterpResult<'tcx, (ImmTy<'tcx>, Option<!>)>;
23-
2433
impl<'tcx> EvalContextExtPriv<'tcx> for crate::MiriInterpCx<'tcx> {}
2534
trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
2635
/// Call native host function and return the output as an immediate.
@@ -30,13 +39,11 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
3039
dest: &MPlaceTy<'tcx>,
3140
ptr: CodePtr,
3241
libffi_args: Vec<libffi::high::Arg<'a>>,
33-
) -> CallResult<'tcx> {
42+
) -> trace::CallResult<'tcx> {
3443
let this = self.eval_context_mut();
35-
#[cfg(trace)]
3644
let alloc = this.machine.allocator.as_ref().unwrap();
3745

3846
// SAFETY: We don't touch the machine memory past this point.
39-
#[cfg(trace)]
4047
let (guard, stack_ptr) = unsafe { Supervisor::start_ffi(alloc) };
4148

4249
// Call the function (`ptr`) with arguments `libffi_args`, and obtain the return value
@@ -111,10 +118,8 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
111118

112119
// SAFETY: We got the guard and stack pointer from start_ffi, and
113120
// the allocator is the same
114-
#[cfg(trace)]
115121
let events = unsafe { Supervisor::end_ffi(alloc, guard, stack_ptr) };
116-
#[cfg(not(trace))]
117-
let events = None;
122+
//let events = None;
118123

119124
interp_ok((res?, events))
120125
}
@@ -213,10 +218,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
213218
if !this.machine.native_call_mem_warned.replace(true) {
214219
// Newly set, so first time we get here.
215220
this.emit_diagnostic(NonHaltingDiagnostic::NativeCallSharedMem {
216-
#[cfg(trace)]
217221
tracing: self::trace::Supervisor::is_enabled(),
218-
#[cfg(not(trace))]
219-
tracing: false,
220222
});
221223
}
222224

src/shims/native_lib/trace/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,8 @@ pub use self::child::{Supervisor, init_sv, register_retcode_sv};
66

77
/// The size of the temporary stack we use for callbacks that the server executes in the client.
88
const CALLBACK_STACK_SIZE: usize = 1024;
9+
10+
pub(super) type CallResult<'tcx> = rustc_const_eval::interpret::InterpResult<
11+
'tcx,
12+
(crate::ImmTy<'tcx>, Option<messages::MemEvents>),
13+
>;

src/shims/native_lib/trace_stub.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
pub type CallResult<'tcx> =
2+
rustc_const_eval::interpret::InterpResult<'tcx, (crate::ImmTy<'tcx>, Option<!>)>;
3+
4+
pub struct Supervisor;
5+
6+
impl Supervisor {
7+
#[inline(always)]
8+
pub fn is_enabled() -> bool {
9+
false
10+
}
11+
12+
#[inline(always)]
13+
pub unsafe fn start_ffi<T>(_: T) -> ((), ()) {
14+
((), ())
15+
}
16+
17+
#[inline(always)]
18+
pub unsafe fn end_ffi<T, U, V>(_: T, _: U, _: V) -> Option<!> {
19+
None
20+
}
21+
}
22+
23+
#[expect(clippy::missing_safety_doc)]
24+
#[inline(always)]
25+
pub unsafe fn init_sv() -> Result<(), !> {
26+
Ok(())
27+
}
28+
29+
#[inline(always)]
30+
pub fn register_retcode_sv<T>(_: T) {}

0 commit comments

Comments
 (0)