Skip to content

Commit 1a31897

Browse files
committed
does this work
1 parent 76d4f73 commit 1a31897

File tree

3 files changed

+48
-78
lines changed

3 files changed

+48
-78
lines changed

src/bin/miri.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,10 @@ impl rustc_driver::Callbacks for MiriCompilerCalls {
191191

192192
todo!("GenMC mode not yet implemented");
193193
};
194-
#[cfg(target_os = "linux")]
195-
if config.native_lib.is_some() {
196-
let _ = miri::Supervisor::init();
197-
}
194+
//#[cfg(target_os = "linux")]
195+
//if config.native_lib.is_some() {
196+
// let _ = miri::Supervisor::init();
197+
//}
198198
if let Some(many_seeds) = self.many_seeds.take() {
199199
assert!(config.seed.is_none());
200200
let exit_code = sync::IntoDynSyncSend(AtomicI32::new(rustc_driver::EXIT_SUCCESS));

src/shims/native_lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,9 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
210210
if super::trace::Supervisor::init().is_ok() {
211211
this.prepare_exposed_for_native_call(false)?;
212212
} else {
213-
this.prepare_exposed_for_native_call(true)?;
214-
//eprintln!("Oh noes!")
215-
//panic!("No ptrace!");
213+
//this.prepare_exposed_for_native_call(true)?;
214+
//eprintln!("Oh noes!");
215+
panic!("No ptrace!");
216216
}
217217
#[cfg(not(target_os = "linux"))]
218218
this.prepare_exposed_for_native_call(true)?;

src/shims/trace.rs

Lines changed: 41 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ impl Supervisor {
118118
/// supervisor process could not be created successfully; else, the caller
119119
/// is now the child process and can communicate via `start_ffi`/`end_ffi`,
120120
/// receiving back events through `get_events`.
121-
#[expect(unreachable_code)]
121+
//#[expect(unreachable_code)]
122122
pub fn init() -> Result<(), SvInitError> {
123-
return Err(SvInitError);
123+
//return Err(SvInitError);
124124
let ptrace_status = std::fs::read_to_string("/proc/sys/kernel/yama/ptrace_scope");
125125
if let Ok(stat) = ptrace_status {
126126
if let Some(stat) = stat.chars().next() {
@@ -147,7 +147,7 @@ impl Supervisor {
147147
let listener = ChildListener {
148148
rx: r_message,
149149
pid: child,
150-
last_ret: 0,
150+
//last_ret: 0,
151151
attached: false,
152152
};
153153
sv_loop(listener, t_event, page_size)
@@ -164,12 +164,12 @@ impl Supervisor {
164164
Ok(())
165165
}
166166

167-
pub fn kill(code: i32) {
167+
/*pub fn kill(code: i32) {
168168
let mut sv_guard = SUPERVISOR.lock().unwrap();
169169
if let Some(sv) = sv_guard.take() {
170170
sv.t_message.send(TraceRequest::MainProcessDied(code)).unwrap();
171171
}
172-
}
172+
}*/
173173

174174
/// Begins preparations for doing an FFI call. This should be called at
175175
/// the last possible moment before entering said call. `id` is the value
@@ -224,7 +224,7 @@ impl Supervisor {
224224
// On the off-chance something really weird happens, don't block forever
225225
let (ret, ptr) = sv
226226
.r_event
227-
.try_recv_timeout(std::time::Duration::from_secs(10))
227+
.try_recv_timeout(std::time::Duration::from_secs(5))
228228
.map_err(|e| {
229229
match e {
230230
ipc::TryRecvError::IpcError(e) => ipc::TryRecvError::IpcError(e),
@@ -256,7 +256,7 @@ impl Supervisor {
256256
enum TraceRequest {
257257
BeginFfi(BeginFfiInfo),
258258
EndFfi,
259-
MainProcessDied(i32),
259+
//MainProcessDied(i32),
260260
}
261261

262262
/// Information needed to begin tracing.
@@ -319,8 +319,8 @@ struct ChildListener {
319319
rx: ipc::IpcReceiver<TraceRequest>,
320320
/// The main child process' pid.
321321
pid: unistd::Pid,
322-
/// The last code returned by a child process.
323-
last_ret: i32,
322+
// /// The last code returned by a child process.
323+
//last_ret: i32,
324324
/// Whether an FFI call is currently ongoing.
325325
attached: bool,
326326
}
@@ -331,7 +331,7 @@ struct ChildListener {
331331
enum ExecEvent {
332332
Status(wait::WaitStatus),
333333
Request(TraceRequest),
334-
//Died(i32),
334+
Died(i32),
335335
}
336336

337337
impl Iterator for ChildListener {
@@ -347,7 +347,6 @@ impl Iterator for ChildListener {
347347
| wait::WaitPidFlag::WUNTRACED
348348
| wait::WaitPidFlag::WEXITED;
349349
loop {
350-
//let pid = unistd::Pid::from_raw(0);
351350
/*match wait::waitid(wait::Id::All, opts) {
352351
Ok(stat) =>
353352
match stat {
@@ -368,44 +367,15 @@ impl Iterator for ChildListener {
368367
}
369368
}*/
370369

371-
//let opts = opts | wait::WaitPidFlag::WNOWAIT;
372-
/*if self.attached {
373-
match wait::waitpid(self.thread_pid, Some(opts)) {
374-
Ok(stat) =>
375-
match stat {
376-
wait::WaitStatus::Exited(_pid, code) => {
377-
eprintln!("Thread code: {code}");
378-
return Some(ExecEvent::Request(TraceRequest::MainProcessDied(
379-
code,
380-
)));
381-
}
382-
wait::WaitStatus::StillAlive => (),
383-
_ =>
384-
if self.attached {
385-
return Some(ExecEvent::Status(stat));
386-
},
387-
},
388-
#[allow(clippy::as_conversions)]
389-
Err(errno) => {
390-
eprintln!("Thread errno: {errno} ({})", errno as i32);
391-
return Some(ExecEvent::Request(TraceRequest::MainProcessDied(
392-
errno as i32,
393-
)));
394-
}
395-
}
396-
}*/
397-
398-
match wait::waitid(wait::Id::Pid(self.pid), opts) {
370+
match wait::waitid(wait::Id::All, opts) {
399371
Ok(stat) =>
400372
match stat {
401373
wait::WaitStatus::Exited(pid, code) => {
402-
if code != 0 {
403-
self.last_ret = code;
404-
}
374+
//if code != 0 {
375+
// self.last_ret = code;
376+
//}
405377
if pid == self.pid {
406-
return Some(ExecEvent::Request(TraceRequest::MainProcessDied(
407-
self.last_ret,
408-
)));
378+
return Some(ExecEvent::Died(code));
409379
}
410380
}
411381
wait::WaitStatus::StillAlive => (),
@@ -417,7 +387,7 @@ impl Iterator for ChildListener {
417387
#[allow(clippy::as_conversions)]
418388
Err(errno) => {
419389
if errno == nix::errno::Errno::ECHILD {
420-
return Some(ExecEvent::Request(TraceRequest::MainProcessDied(1)));
390+
return Some(ExecEvent::Died(1));
421391
}
422392
//eprintln!("Errno: {errno} ({})", errno as i32);
423393
}
@@ -434,7 +404,6 @@ impl Iterator for ChildListener {
434404
self.attached = true;
435405
},
436406
TraceRequest::EndFfi => self.attached = false,
437-
_ => (),
438407
}
439408
return Some(ExecEvent::Request(msg));
440409
}
@@ -556,7 +525,7 @@ fn sv_loop(
556525
// Stopped, probably by a segfault or SIGTRAP
557526
wait::WaitStatus::Stopped(pid, signal) => {
558527
match signal {
559-
signal::SIGSEGV => {
528+
/*signal::SIGSEGV => {
560529
if let Err(ret) = handle_segfault(
561530
pid,
562531
&ch_pages,
@@ -575,11 +544,13 @@ fn sv_loop(
575544
retcode = ret;
576545
break 'listen;
577546
}
578-
}
547+
}*/
548+
signal::SIGSTOP =>
549+
if ptrace::syscall(pid, None).is_err() {
550+
signal::kill(pid, signal::SIGCONT).unwrap();
551+
},
579552
_ => {
580-
eprintln!(
581-
"Process unexpectedly stopped at {signal}; continuing..."
582-
);
553+
eprintln!("Process unexpectedly stopped at {signal}; continuing...");
583554
// In case we're not tracing
584555
if ptrace::syscall(pid, None).is_err() {
585556
signal::kill(pid, signal::SIGCONT).unwrap();
@@ -722,23 +693,22 @@ fn sv_loop(
722693
ptrace::detach(main_pid, None).unwrap();
723694
signal::kill(main_pid, signal::SIGCONT).unwrap();
724695
}
725-
TraceRequest::MainProcessDied(code) => {
726-
retcode = code;
727-
break 'listen;
728-
}
729696
},
730-
//ExecEvent::Died(child_code) => {
731-
//retcode = child_code;
732-
//break 'listen;
733-
// Break if there are no child processes alive at all
734-
//let mut children = std::fs::read_dir("/proc/self/task/").unwrap();
735-
//eprintln!("children: {children:?}");
736-
// One will always be us
737-
//children.next();
738-
//if children.next().is_none() {
739-
// break 'listen;
740-
//}
741-
//} //ExecEvent::EveryoneIsDead => break 'listen,
697+
ExecEvent::Died(code) => {
698+
retcode = code;
699+
break 'listen;
700+
} //ExecEvent::Died(child_code) => {
701+
//retcode = child_code;
702+
//break 'listen;
703+
// Break if there are no child processes alive at all
704+
//let mut children = std::fs::read_dir("/proc/self/task/").unwrap();
705+
//eprintln!("children: {children:?}");
706+
// One will always be us
707+
//children.next();
708+
//if children.next().is_none() {
709+
// break 'listen;
710+
//}
711+
//} //ExecEvent::EveryoneIsDead => break 'listen,
742712
}
743713
}
744714
//eprintln!("Final code: {retcode}");
@@ -975,7 +945,7 @@ fn handle_segfault(
975945
Ok(())
976946
}
977947

978-
let siginfo = ptrace::getsiginfo(pid).unwrap();
948+
let siginfo = ptrace::getsiginfo(pid).map_err(|_| 1)?;
979949
let addr = unsafe { siginfo.si_addr().addr().to_u64() };
980950
//eprintln!("Segfault addr: {addr:#0x?}");
981951
//eprintln!("Owned pages: {ch_pages:#0x?}");
@@ -1055,7 +1025,7 @@ fn handle_segfault(
10551025
eprintln!("Expected access on pages: {ch_pages:#018x?}");
10561026
eprintln!("Register dump: {regs:#x?}");
10571027
ptrace::kill(pid).unwrap();
1058-
Err(-1)
1028+
Err(1)
10591029
}
10601030
}
10611031

@@ -1067,7 +1037,7 @@ fn handle_sigtrap(
10671037
libc_events: &mut Vec<LibcEvent>,
10681038
libc_vals: MagicLibcValues,
10691039
) -> Result<(), i32> {
1070-
let regs = ptrace::getregs(pid).unwrap();
1040+
let regs = ptrace::getregs(pid).map_err(|_| 1)?;
10711041
match regs.ip().strict_sub(1) {
10721042
// malloc
10731043
a if a == libc_vals.malloc_addr => {

0 commit comments

Comments
 (0)