Skip to content

Commit 24748b1

Browse files
committed
fix review comments
1 parent 4cf2cf4 commit 24748b1

File tree

7 files changed

+50
-68
lines changed

7 files changed

+50
-68
lines changed

no_alloc.json

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

src/alloc_addresses/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
484484
/// called before the FFI (with `paranoid` set to false) then some of the writes may be
485485
/// lost!
486486
#[cfg(target_os = "linux")]
487-
fn apply_events(&mut self, events: crate::shims::trace::MemEvents) -> InterpResult<'tcx> {
487+
fn apply_events(&mut self, events: crate::shims::trace::messages::MemEvents) -> InterpResult<'tcx> {
488488
let this = self.eval_context_mut();
489489

490490
let mut reads = vec![];

src/shims/native_lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::alloc::isolated_alloc::IsolatedAlloc;
1515
use crate::*;
1616

1717
#[cfg(target_os = "linux")]
18-
type CallResult<'tcx> = InterpResult<'tcx, (ImmTy<'tcx>, Option<shims::trace::MemEvents>)>;
18+
type CallResult<'tcx> = InterpResult<'tcx, (ImmTy<'tcx>, Option<shims::trace::messages::MemEvents>)>;
1919
#[cfg(not(target_os = "linux"))]
2020
type CallResult<'tcx> = InterpResult<'tcx, (ImmTy<'tcx>, Option<!>)>;
2121

@@ -261,7 +261,7 @@ unsafe fn do_native_call<T: libffi::high::CType>(
261261
ptr: CodePtr,
262262
args: &[ffi::Arg<'_>],
263263
alloc: Option<Rc<RefCell<IsolatedAlloc>>>,
264-
) -> (T, Option<shims::trace::MemEvents>) {
264+
) -> (T, Option<shims::trace::messages::MemEvents>) {
265265
use shims::trace::Supervisor;
266266

267267
unsafe {

src/shims/trace/child.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ use nix::sys::{ptrace, signal};
66
use nix::unistd;
77

88
use crate::alloc::isolated_alloc::IsolatedAlloc;
9+
use crate::shims::trace::messages::{Confirmation, MemEvents, TraceRequest};
910
use crate::shims::trace::parent::{ChildListener, sv_loop};
10-
use crate::shims::trace::{FAKE_STACK_SIZE, MemEvents, StartFfiInfo, TraceRequest};
11+
use crate::shims::trace::{FAKE_STACK_SIZE, StartFfiInfo};
1112

1213
static SUPERVISOR: std::sync::Mutex<Option<Supervisor>> = std::sync::Mutex::new(None);
1314

@@ -18,7 +19,7 @@ pub struct Supervisor {
1819
message_tx: ipc::IpcSender<TraceRequest>,
1920
/// Used for synchronisation, allowing us to receive confirmation that the
2021
/// parent process has handled the request from `message_tx`.
21-
confirm_rx: ipc::IpcReceiver<()>,
22+
confirm_rx: ipc::IpcReceiver<Confirmation>,
2223
/// Receiver for memory acceses that ocurred during the FFI call.
2324
event_rx: ipc::IpcReceiver<MemEvents>,
2425
}

src/shims/trace/messages.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//! Houses the types that are directly sent across the IPC channels.
2+
3+
/// An IPC request sent by the child process to the parent.
4+
///
5+
/// The sender for this channel should live on the child process.
6+
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
7+
pub(super) enum TraceRequest {
8+
/// Requests that tracing begins. Following this being sent, the child must
9+
/// wait to receive a `Confirmation` on the respective channel and then
10+
/// `raise(SIGSTOP)`.
11+
///
12+
/// To avoid possible issues while allocating memory for IPC channels, ending
13+
/// the tracing is instead done via `raise(SIGUSR1)`.
14+
StartFfi(super::StartFfiInfo),
15+
/// Manually overrides the code that the supervisor will return upon exiting.
16+
/// Once set, it is permanent. This can be called again to change the value.
17+
OverrideRetcode(i32),
18+
}
19+
20+
/// A marker type confirming that the supervisor has received the request to begin
21+
/// tracing and is now waiting for a `SIGSTOP`.
22+
///
23+
/// The sender for this channel should live on the parent process.
24+
#[derive(serde::Serialize, serde::Deserialize, Debug)]
25+
pub(super) struct Confirmation;
26+
27+
/// The final results of an FFI trace, containing every relevant event detected
28+
/// by the tracer. Sent by the supervisor.
29+
///
30+
/// The sender for this channel should live on the parent process.
31+
#[derive(serde::Serialize, serde::Deserialize, Debug)]
32+
pub struct MemEvents {
33+
/// An ordered list of memory accesses that occurred. These should be assumed
34+
/// to be overcautious; that is, if the size of an access is uncertain it is
35+
/// pessimistically rounded up, and if the type (read/write/both) is uncertain
36+
/// it is reported as whatever would be safest to assume; i.e. a read + maybe-write
37+
/// becomes a read + write, etc.
38+
pub acc_events: Vec<super::AccessEvent>,
39+
}

src/shims/trace/mod.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
mod child;
22
mod parent;
3+
pub mod messages;
34

45
use std::ops::Range;
56

@@ -19,12 +20,6 @@ struct StartFfiInfo {
1920
stack_ptr: usize,
2021
}
2122

22-
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
23-
enum TraceRequest {
24-
StartFfi(StartFfiInfo),
25-
OverrideRetcode(i32),
26-
}
27-
2823
/// A single memory access, conservatively overestimated
2924
/// in case of ambiguity.
3025
#[derive(serde::Serialize, serde::Deserialize, Debug)]
@@ -34,11 +29,3 @@ pub enum AccessEvent {
3429
/// A write may have occurred on no more than the specified address range.
3530
Write(Range<usize>),
3631
}
37-
38-
/// The final results of an FFI trace, containing every relevant event detected
39-
/// by the tracer.
40-
#[derive(serde::Serialize, serde::Deserialize, Debug)]
41-
pub struct MemEvents {
42-
/// An ordered list of memory accesses that occurred.
43-
pub acc_events: Vec<AccessEvent>,
44-
}

src/shims/trace/parent.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ use ipc_channel::ipc;
44
use nix::sys::{ptrace, signal, wait};
55
use nix::unistd;
66

7-
use crate::shims::trace::{AccessEvent, FAKE_STACK_SIZE, MemEvents, StartFfiInfo, TraceRequest};
7+
use crate::shims::trace::messages::{Confirmation, MemEvents, TraceRequest};
8+
use crate::shims::trace::{AccessEvent, FAKE_STACK_SIZE, StartFfiInfo};
89

910
/// The flags to use when calling `waitid()`.
1011
/// Since bitwise or on the nix version of these flags is implemented as a trait,
@@ -242,7 +243,7 @@ enum ExecError {
242243
pub fn sv_loop(
243244
listener: ChildListener,
244245
event_tx: ipc::IpcSender<MemEvents>,
245-
confirm_tx: ipc::IpcSender<()>,
246+
confirm_tx: ipc::IpcSender<Confirmation>,
246247
page_size: usize,
247248
) -> Result<!, Option<i32>> {
248249
// Things that we return to the child process
@@ -281,7 +282,7 @@ pub fn sv_loop(
281282
// so we can let the child move on to the end of start_ffi where it will
282283
// raise a SIGSTOP. We need it to be signal-stopped *and waited for* in
283284
// order to do most ptrace operations!
284-
confirm_tx.send(()).unwrap();
285+
confirm_tx.send(Confirmation).unwrap();
285286
wait_for_signal(main_pid, signal::SIGSTOP, false).unwrap();
286287

287288
ptrace::syscall(main_pid, None).unwrap();

0 commit comments

Comments
 (0)