Skip to content

Commit d314f5a

Browse files
committed
various minor cleanups
1 parent 36695e3 commit d314f5a

File tree

4 files changed

+21
-33
lines changed

4 files changed

+21
-33
lines changed

src/bin/miri.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ impl rustc_driver::Callbacks for MiriBeRustCompilerCalls {
335335
fn exit(exit_code: i32) -> ! {
336336
// Drop the tracing guard before exiting, so tracing calls are flushed correctly.
337337
deinit_loggers();
338-
//eprintln!("Called exit!");
338+
// Make sure the supervisor knows about the code code.
339339
#[cfg(target_os = "linux")]
340340
miri::native_lib::register_retcode_sv(exit_code);
341341
std::process::exit(exit_code);
@@ -357,7 +357,8 @@ fn run_compiler_and_exit(
357357
callbacks: &mut (dyn rustc_driver::Callbacks + Send),
358358
) -> ! {
359359
// Install the ctrlc handler that sets `rustc_const_eval::CTRL_C_RECEIVED`, even if
360-
// MIRI_BE_RUSTC is set.
360+
// MIRI_BE_RUSTC is set. We do this late so that when `native_lib::init_sv` is called,
361+
// there are no other threads.
361362
rustc_driver::install_ctrlc_handler();
362363

363364
// Invoke compiler, catch any unwinding panics and handle return code.

src/shims/native_lib/mod.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,12 @@ pub mod trace;
2222
use crate::*;
2323

2424
/// The final results of an FFI trace, containing every relevant event detected
25-
/// by the tracer. Sent by the supervisor after receiving a `SIGUSR1` signal.
26-
///
27-
/// The sender for this channel should live on the parent process.
25+
/// by the tracer.
2826
#[allow(dead_code)]
2927
#[cfg_attr(target_os = "linux", derive(serde::Serialize, serde::Deserialize))]
3028
#[derive(Debug)]
3129
pub struct MemEvents {
32-
/// An ordered list of memory accesses that occurred. These should be assumed
33-
/// to be overcautious; that is, if the size of an access is uncertain it is
34-
/// pessimistically rounded up, and if the type (read/write/both) is uncertain
35-
/// it is reported as whatever would be safest to assume; i.e. a read + maybe-write
36-
/// becomes a read + write, etc.
30+
/// An list of memory accesses that occurred, in the order they occurred in.
3731
pub acc_events: Vec<AccessEvent>,
3832
}
3933

@@ -76,9 +70,9 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
7670
// Placeholder value.
7771
let alloc = ();
7872

79-
// Call the function (`ptr`) with arguments `libffi_args`, and obtain the return value
80-
// as the specified primitive integer type
81-
let ffi_fn = || {
73+
trace::Supervisor::do_ffi(alloc, || {
74+
// Call the function (`ptr`) with arguments `libffi_args`, and obtain the return value
75+
// as the specified primitive integer type
8276
let scalar = match dest.layout.ty.kind() {
8377
// ints
8478
ty::Int(IntTy::I8) => {
@@ -144,9 +138,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
144138
.into(),
145139
};
146140
interp_ok(ImmTy::from_scalar(scalar, dest.layout))
147-
};
148-
149-
trace::Supervisor::do_ffi(alloc, ffi_fn)
141+
})
150142
}
151143

152144
/// Get the pointer to the function of the specified name in the shared object file,

src/shims/native_lib/trace/messages.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
//! the child process's POV is as follows:
99
//! ```
1010
//! message_tx.send(TraceRequest::StartFfi);
11-
//! confirm_rx.recv();
11+
//! confirm_rx.recv(); // receives a `Confirmation`
1212
//! raise(SIGSTOP);
1313
//! /* do ffi call */
1414
//! raise(SIGUSR1); // morally equivalent to some kind of "TraceRequest::EndFfi"
15-
//! let events = event_rx.recv();
15+
//! let events = event_rx.recv(); // receives a `MemEvents`
1616
//! ```
1717
//! `TraceRequest::OverrideRetcode` can be sent at any point in the above, including
1818
//! before or after all of them. `confirm_rx.recv()` is to be called after, to ensure

src/shims/native_lib/trace/parent.rs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const WAIT_FLAGS: wait::WaitPidFlag =
1515
/// The default word size on a given platform, in bytes.
1616
#[cfg(target_arch = "x86")]
1717
const ARCH_WORD_SIZE: usize = 4;
18-
#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))]
18+
#[cfg(target_arch = "x86_64")]
1919
const ARCH_WORD_SIZE: usize = 8;
2020

2121
/// The address of the page set to be edited, initialised to a sentinel null
@@ -65,17 +65,6 @@ impl ArchIndependentRegs for libc::user_regs_struct {
6565
fn set_sp(&mut self, sp: usize) { self.esp = sp.try_into().unwrap() }
6666
}
6767

68-
#[cfg(target_arch = "aarch64")]
69-
#[rustfmt::skip]
70-
impl ArchIndependentRegs for libc::user_regs_struct {
71-
#[inline]
72-
fn ip(&self) -> usize { self.pc.try_into().unwrap() }
73-
#[inline]
74-
fn set_ip(&mut self, ip: usize) { self.pc = ip.try_into().unwrap() }
75-
#[inline]
76-
fn set_sp(&mut self, sp: usize) { self.sp = sp.try_into().unwrap() }
77-
}
78-
7968
/// A unified event representing something happening on the child process. Wraps
8069
/// `nix`'s `WaitStatus` and our custom signals so it can all be done with one
8170
/// `match` statement.
@@ -324,8 +313,6 @@ fn get_disasm() -> capstone::Capstone {
324313
{cs_pre.x86().mode(arch::x86::ArchMode::Mode64)}
325314
#[cfg(target_arch = "x86")]
326315
{cs_pre.x86().mode(arch::x86::ArchMode::Mode32)}
327-
#[cfg(target_arch = "aarch64")]
328-
{cs_pre.arm64().mode(arch::arm64::ArchMode::Arm)}
329316
}
330317
.detail(true)
331318
.build()
@@ -401,13 +388,21 @@ fn handle_segfault(
401388
let ins_detail = cs.insn_detail(&insns[0])?;
402389
let arch_detail = ins_detail.arch_detail();
403390

391+
let mut found_mem_op = false;
392+
404393
for op in arch_detail.operands() {
405394
match op {
406395
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
407396
arch::ArchOperand::X86Operand(x86_operand) => {
408397
match x86_operand.op_type {
409398
// We only care about memory accesses
410399
arch::x86::X86OperandType::Mem(_) => {
400+
if found_mem_op {
401+
panic!(
402+
"more than one memory operand in a single operation is not supported"
403+
);
404+
}
405+
411406
let push = AccessRange { addr, size: x86_operand.size.into() };
412407
// It's called a "RegAccessType" but it also applies to memory
413408
let acc_ty = x86_operand.access.unwrap();
@@ -418,7 +413,7 @@ fn handle_segfault(
418413
acc_events.push(AccessEvent::Write(push));
419414
}
420415

421-
return Ok(());
416+
found_mem_op = true;
422417
}
423418
_ => (),
424419
}

0 commit comments

Comments
 (0)