Skip to content

Commit 5e14d0f

Browse files
committed
move all the message types into one place
1 parent cde1012 commit 5e14d0f

File tree

4 files changed

+31
-31
lines changed

4 files changed

+31
-31
lines changed

src/tools/miri/src/shims/native_lib/trace/child.rs

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

8-
use super::messages::{Confirmation, MemEvents, TraceRequest};
8+
use super::CALLBACK_STACK_SIZE;
9+
use super::messages::{Confirmation, MemEvents, StartFfiInfo, TraceRequest};
910
use super::parent::{ChildListener, sv_loop};
10-
use super::{CALLBACK_STACK_SIZE, StartFfiInfo};
1111
use crate::alloc::isolated_alloc::IsolatedAlloc;
1212

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

src/tools/miri/src/shims/native_lib/trace/messages.rs

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,42 @@
1818
//! in `super::child` (namely `start_ffi()` and `end_ffi()`) to handle this. It is
1919
//! trivially easy to cause a deadlock or crash by messing this up!
2020
21+
use std::ops::Range;
22+
2123
/// An IPC request sent by the child process to the parent.
2224
///
2325
/// The sender for this channel should live on the child process.
2426
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
25-
pub(super) enum TraceRequest {
27+
pub enum TraceRequest {
2628
/// Requests that tracing begins. Following this being sent, the child must
2729
/// wait to receive a `Confirmation` on the respective channel and then
2830
/// `raise(SIGSTOP)`.
2931
///
3032
/// To avoid possible issues while allocating memory for IPC channels, ending
3133
/// the tracing is instead done via `raise(SIGUSR1)`.
32-
StartFfi(super::StartFfiInfo),
34+
StartFfi(StartFfiInfo),
3335
/// Manually overrides the code that the supervisor will return upon exiting.
3436
/// Once set, it is permanent. This can be called again to change the value.
3537
OverrideRetcode(i32),
3638
}
3739

40+
/// Information needed to begin tracing.
41+
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
42+
pub struct StartFfiInfo {
43+
/// A vector of page addresses. These should have been automatically obtained
44+
/// with `IsolatedAlloc::pages` and prepared with `IsolatedAlloc::prepare_ffi`.
45+
pub page_ptrs: Vec<usize>,
46+
/// The address of an allocation that can serve as a temporary stack.
47+
/// This should be a leaked `Box<[u8; CALLBACK_STACK_SIZE]>` cast to an int.
48+
pub stack_ptr: usize,
49+
}
50+
3851
/// A marker type confirming that the supervisor has received the request to begin
3952
/// tracing and is now waiting for a `SIGSTOP`.
4053
///
4154
/// The sender for this channel should live on the parent process.
4255
#[derive(serde::Serialize, serde::Deserialize, Debug)]
43-
pub(super) struct Confirmation;
56+
pub struct Confirmation;
4457

4558
/// The final results of an FFI trace, containing every relevant event detected
4659
/// by the tracer. Sent by the supervisor after receiving a `SIGUSR1` signal.
@@ -53,5 +66,15 @@ pub struct MemEvents {
5366
/// pessimistically rounded up, and if the type (read/write/both) is uncertain
5467
/// it is reported as whatever would be safest to assume; i.e. a read + maybe-write
5568
/// becomes a read + write, etc.
56-
pub acc_events: Vec<super::AccessEvent>,
69+
pub acc_events: Vec<AccessEvent>,
70+
}
71+
72+
/// A single memory access, conservatively overestimated
73+
/// in case of ambiguity.
74+
#[derive(serde::Serialize, serde::Deserialize, Debug)]
75+
pub enum AccessEvent {
76+
/// A read may have occurred on no more than the specified address range.
77+
Read(Range<usize>),
78+
/// A write may have occurred on no more than the specified address range.
79+
Write(Range<usize>),
5780
}

src/tools/miri/src/shims/native_lib/trace/mod.rs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,7 @@ mod child;
22
pub mod messages;
33
mod parent;
44

5-
use std::ops::Range;
6-
75
pub use self::child::{Supervisor, init_sv, register_retcode_sv};
86

97
/// The size of the temporary stack we use for callbacks that the server executes in the client.
108
const CALLBACK_STACK_SIZE: usize = 1024;
11-
12-
/// Information needed to begin tracing.
13-
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
14-
struct StartFfiInfo {
15-
/// A vector of page addresses. These should have been automatically obtained
16-
/// with `IsolatedAlloc::pages` and prepared with `IsolatedAlloc::prepare_ffi`.
17-
page_ptrs: Vec<usize>,
18-
/// The address of an allocation that can serve as a temporary stack.
19-
/// This should be a leaked `Box<[u8; CALLBACK_STACK_SIZE]>` cast to an int.
20-
stack_ptr: usize,
21-
}
22-
23-
/// A single memory access, conservatively overestimated
24-
/// in case of ambiguity.
25-
#[derive(serde::Serialize, serde::Deserialize, Debug)]
26-
pub enum AccessEvent {
27-
/// A read may have occurred on no more than the specified address range.
28-
Read(Range<usize>),
29-
/// A write may have occurred on no more than the specified address range.
30-
Write(Range<usize>),
31-
}

src/tools/miri/src/shims/native_lib/trace/parent.rs

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

7-
use super::messages::{Confirmation, MemEvents, TraceRequest};
8-
use super::{AccessEvent, CALLBACK_STACK_SIZE, StartFfiInfo};
7+
use super::CALLBACK_STACK_SIZE;
8+
use super::messages::{AccessEvent, Confirmation, MemEvents, StartFfiInfo, TraceRequest};
99

1010
/// The flags to use when calling `waitid()`.
1111
/// Since bitwise or on the nix version of these flags is implemented as a trait,

0 commit comments

Comments
 (0)