@@ -118,9 +118,9 @@ impl Supervisor {
118
118
/// supervisor process could not be created successfully; else, the caller
119
119
/// is now the child process and can communicate via `start_ffi`/`end_ffi`,
120
120
/// receiving back events through `get_events`.
121
- #[ expect( unreachable_code) ]
121
+ // #[expect(unreachable_code)]
122
122
pub fn init ( ) -> Result < ( ) , SvInitError > {
123
- return Err ( SvInitError ) ;
123
+ // return Err(SvInitError);
124
124
let ptrace_status = std:: fs:: read_to_string ( "/proc/sys/kernel/yama/ptrace_scope" ) ;
125
125
if let Ok ( stat) = ptrace_status {
126
126
if let Some ( stat) = stat. chars ( ) . next ( ) {
@@ -147,7 +147,7 @@ impl Supervisor {
147
147
let listener = ChildListener {
148
148
rx : r_message,
149
149
pid : child,
150
- last_ret : 0 ,
150
+ // last_ret: 0,
151
151
attached : false ,
152
152
} ;
153
153
sv_loop ( listener, t_event, page_size)
@@ -164,12 +164,12 @@ impl Supervisor {
164
164
Ok ( ( ) )
165
165
}
166
166
167
- pub fn kill ( code : i32 ) {
167
+ /* pub fn kill(code: i32) {
168
168
let mut sv_guard = SUPERVISOR.lock().unwrap();
169
169
if let Some(sv) = sv_guard.take() {
170
170
sv.t_message.send(TraceRequest::MainProcessDied(code)).unwrap();
171
171
}
172
- }
172
+ }*/
173
173
174
174
/// Begins preparations for doing an FFI call. This should be called at
175
175
/// the last possible moment before entering said call. `id` is the value
@@ -224,7 +224,7 @@ impl Supervisor {
224
224
// On the off-chance something really weird happens, don't block forever
225
225
let ( ret, ptr) = sv
226
226
. r_event
227
- . try_recv_timeout ( std:: time:: Duration :: from_secs ( 10 ) )
227
+ . try_recv_timeout ( std:: time:: Duration :: from_secs ( 5 ) )
228
228
. map_err ( |e| {
229
229
match e {
230
230
ipc:: TryRecvError :: IpcError ( e) => ipc:: TryRecvError :: IpcError ( e) ,
@@ -256,7 +256,7 @@ impl Supervisor {
256
256
enum TraceRequest {
257
257
BeginFfi ( BeginFfiInfo ) ,
258
258
EndFfi ,
259
- MainProcessDied ( i32 ) ,
259
+ // MainProcessDied(i32),
260
260
}
261
261
262
262
/// Information needed to begin tracing.
@@ -319,8 +319,8 @@ struct ChildListener {
319
319
rx : ipc:: IpcReceiver < TraceRequest > ,
320
320
/// The main child process' pid.
321
321
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,
324
324
/// Whether an FFI call is currently ongoing.
325
325
attached : bool ,
326
326
}
@@ -331,7 +331,7 @@ struct ChildListener {
331
331
enum ExecEvent {
332
332
Status ( wait:: WaitStatus ) ,
333
333
Request ( TraceRequest ) ,
334
- // Died(i32),
334
+ Died ( i32 ) ,
335
335
}
336
336
337
337
impl Iterator for ChildListener {
@@ -347,7 +347,6 @@ impl Iterator for ChildListener {
347
347
| wait:: WaitPidFlag :: WUNTRACED
348
348
| wait:: WaitPidFlag :: WEXITED ;
349
349
loop {
350
- //let pid = unistd::Pid::from_raw(0);
351
350
/*match wait::waitid(wait::Id::All, opts) {
352
351
Ok(stat) =>
353
352
match stat {
@@ -368,44 +367,15 @@ impl Iterator for ChildListener {
368
367
}
369
368
}*/
370
369
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) {
399
371
Ok ( stat) =>
400
372
match stat {
401
373
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
+ // }
405
377
if pid == self . pid {
406
- return Some ( ExecEvent :: Request ( TraceRequest :: MainProcessDied (
407
- self . last_ret ,
408
- ) ) ) ;
378
+ return Some ( ExecEvent :: Died ( code) ) ;
409
379
}
410
380
}
411
381
wait:: WaitStatus :: StillAlive => ( ) ,
@@ -417,7 +387,7 @@ impl Iterator for ChildListener {
417
387
#[ allow( clippy:: as_conversions) ]
418
388
Err ( errno) => {
419
389
if errno == nix:: errno:: Errno :: ECHILD {
420
- return Some ( ExecEvent :: Request ( TraceRequest :: MainProcessDied ( 1 ) ) ) ;
390
+ return Some ( ExecEvent :: Died ( 1 ) ) ;
421
391
}
422
392
//eprintln!("Errno: {errno} ({})", errno as i32);
423
393
}
@@ -434,7 +404,6 @@ impl Iterator for ChildListener {
434
404
self . attached = true ;
435
405
} ,
436
406
TraceRequest :: EndFfi => self . attached = false ,
437
- _ => ( ) ,
438
407
}
439
408
return Some ( ExecEvent :: Request ( msg) ) ;
440
409
}
@@ -556,7 +525,7 @@ fn sv_loop(
556
525
// Stopped, probably by a segfault or SIGTRAP
557
526
wait:: WaitStatus :: Stopped ( pid, signal) => {
558
527
match signal {
559
- signal:: SIGSEGV => {
528
+ /* signal::SIGSEGV => {
560
529
if let Err(ret) = handle_segfault(
561
530
pid,
562
531
&ch_pages,
@@ -575,11 +544,13 @@ fn sv_loop(
575
544
retcode = ret;
576
545
break 'listen;
577
546
}
578
- }
547
+ }*/
548
+ signal:: SIGSTOP =>
549
+ if ptrace:: syscall ( pid, None ) . is_err ( ) {
550
+ signal:: kill ( pid, signal:: SIGCONT ) . unwrap ( ) ;
551
+ } ,
579
552
_ => {
580
- eprintln ! (
581
- "Process unexpectedly stopped at {signal}; continuing..."
582
- ) ;
553
+ eprintln ! ( "Process unexpectedly stopped at {signal}; continuing..." ) ;
583
554
// In case we're not tracing
584
555
if ptrace:: syscall ( pid, None ) . is_err ( ) {
585
556
signal:: kill ( pid, signal:: SIGCONT ) . unwrap ( ) ;
@@ -722,23 +693,22 @@ fn sv_loop(
722
693
ptrace:: detach ( main_pid, None ) . unwrap ( ) ;
723
694
signal:: kill ( main_pid, signal:: SIGCONT ) . unwrap ( ) ;
724
695
}
725
- TraceRequest :: MainProcessDied ( code) => {
726
- retcode = code;
727
- break ' listen;
728
- }
729
696
} ,
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,
742
712
}
743
713
}
744
714
//eprintln!("Final code: {retcode}");
@@ -975,7 +945,7 @@ fn handle_segfault(
975
945
Ok ( ( ) )
976
946
}
977
947
978
- let siginfo = ptrace:: getsiginfo ( pid) . unwrap ( ) ;
948
+ let siginfo = ptrace:: getsiginfo ( pid) . map_err ( |_| 1 ) ? ;
979
949
let addr = unsafe { siginfo. si_addr ( ) . addr ( ) . to_u64 ( ) } ;
980
950
//eprintln!("Segfault addr: {addr:#0x?}");
981
951
//eprintln!("Owned pages: {ch_pages:#0x?}");
@@ -1055,7 +1025,7 @@ fn handle_segfault(
1055
1025
eprintln ! ( "Expected access on pages: {ch_pages:#018x?}" ) ;
1056
1026
eprintln ! ( "Register dump: {regs:#x?}" ) ;
1057
1027
ptrace:: kill ( pid) . unwrap ( ) ;
1058
- Err ( - 1 )
1028
+ Err ( 1 )
1059
1029
}
1060
1030
}
1061
1031
@@ -1067,7 +1037,7 @@ fn handle_sigtrap(
1067
1037
libc_events : & mut Vec < LibcEvent > ,
1068
1038
libc_vals : MagicLibcValues ,
1069
1039
) -> Result < ( ) , i32 > {
1070
- let regs = ptrace:: getregs ( pid) . unwrap ( ) ;
1040
+ let regs = ptrace:: getregs ( pid) . map_err ( |_| 1 ) ? ;
1071
1041
match regs. ip ( ) . strict_sub ( 1 ) {
1072
1042
// malloc
1073
1043
a if a == libc_vals. malloc_addr => {
0 commit comments