Skip to content

Commit 08a1c93

Browse files
committed
manual death signal
1 parent 4db90d6 commit 08a1c93

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

src/bin/miri.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,13 @@ fn entry_fn(tcx: TyCtxt<'_>) -> (DefId, MiriEntryFnType) {
130130
}
131131
}
132132

133+
/// If for whatever reason the supervisor process exists but can't see that
134+
/// we died, inform it manually.
135+
fn exit(return_code: i32) -> ! {
136+
miri::kill_sv(return_code);
137+
std::process::exit(return_code)
138+
}
139+
133140
impl rustc_driver::Callbacks for MiriCompilerCalls {
134141
fn config(&mut self, config: &mut Config) {
135142
config.override_queries = Some(|_, providers| {
@@ -213,7 +220,7 @@ impl rustc_driver::Callbacks for MiriCompilerCalls {
213220
if !many_seeds.keep_going {
214221
// `abort_if_errors` would actually not stop, since `par_for_each` waits for the
215222
// rest of the to finish, so we just exit immediately.
216-
std::process::exit(return_code);
223+
exit(return_code);
217224
}
218225
exit_code.store(return_code, Ordering::Relaxed);
219226
num_failed.fetch_add(1, Ordering::Relaxed);
@@ -223,15 +230,15 @@ impl rustc_driver::Callbacks for MiriCompilerCalls {
223230
if num_failed > 0 {
224231
eprintln!("{num_failed}/{total} SEEDS FAILED", total = many_seeds.seeds.count());
225232
}
226-
std::process::exit(exit_code.0.into_inner());
233+
exit(exit_code.0.into_inner());
227234
} else {
228235
let return_code = miri::eval_entry(tcx, entry_def_id, entry_type, &config, None)
229236
.unwrap_or_else(|| {
230237
tcx.dcx().abort_if_errors();
231238
rustc_driver::EXIT_FAILURE
232239
});
233240

234-
std::process::exit(return_code);
241+
exit(return_code);
235242
}
236243

237244
// Unreachable.
@@ -326,7 +333,7 @@ impl rustc_driver::Callbacks for MiriBeRustCompilerCalls {
326333

327334
fn show_error(msg: &impl std::fmt::Display) -> ! {
328335
eprintln!("fatal error: {msg}");
329-
std::process::exit(1)
336+
exit(1)
330337
}
331338

332339
macro_rules! show_error {
@@ -400,7 +407,7 @@ fn run_compiler_and_exit(
400407
// Invoke compiler, and handle return code.
401408
let exit_code =
402409
rustc_driver::catch_with_exit_code(move || rustc_driver::run_compiler(args, callbacks));
403-
std::process::exit(exit_code)
410+
exit(exit_code)
404411
}
405412

406413
/// Parses a comma separated list of `T` from the given string:
@@ -479,7 +486,7 @@ fn main() {
479486
let env_snapshot = env::vars_os().collect::<Vec<_>>();
480487

481488
let args = rustc_driver::catch_fatal_errors(|| rustc_driver::args::raw_args(&early_dcx))
482-
.unwrap_or_else(|_| std::process::exit(rustc_driver::EXIT_FAILURE));
489+
.unwrap_or_else(|_| exit(rustc_driver::EXIT_FAILURE));
483490

484491
// Install the ctrlc handler that sets `rustc_const_eval::CTRL_C_RECEIVED`, even if
485492
// MIRI_BE_RUSTC is set.

src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ pub use rustc_const_eval::interpret::{self, AllocMap, Provenance as _};
9999
use rustc_middle::{bug, span_bug};
100100
use tracing::{info, trace};
101101

102+
// Let bin/miri.rs kill the supervisor process.
103+
pub use crate::shims::trace::kill_sv;
104+
102105
// Type aliases that set the provenance parameter.
103106
pub type Pointer = interpret::Pointer<Option<machine::Provenance>>;
104107
pub type StrictPointer = interpret::Pointer<machine::Provenance>;

src/shims/trace.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@ pub struct Supervisor {
8282
r_event: ipc::IpcReceiver<MemEvents>,
8383
}
8484

85+
pub fn kill_sv(code: i32) {
86+
if let Ok(mut sv_guard) = SUPERVISOR.lock() {
87+
if let Some(sv) = sv_guard.take() {
88+
let _ = sv.t_message.send(TraceRequest::Die(code));
89+
*sv_guard = Some(sv);
90+
}
91+
}
92+
}
93+
8594
impl Supervisor {
8695
pub fn init() -> Result<(), ()> {
8796
let ptrace_status = std::fs::read_to_string("/proc/sys/kernel/yama/ptrace_scope");
@@ -185,7 +194,7 @@ impl Supervisor {
185194
pub enum TraceRequest {
186195
BeginFfi(Vec<u64>),
187196
EndFfi,
188-
Die,
197+
Die(i32),
189198
}
190199

191200
#[derive(serde::Serialize, serde::Deserialize, Debug)]
@@ -427,7 +436,10 @@ fn sv_loop(listener: ChildListener, t_event: ipc::IpcSender<MemEvents>) -> ! {
427436
signal::kill(main_pid, signal::SIGCONT).unwrap();
428437
}
429438

430-
TraceRequest::Die => break 'listen,
439+
TraceRequest::Die(child_code) => {
440+
retcode = child_code;
441+
break 'listen;
442+
}
431443
},
432444
ExecEvent::Died(child_code) => {
433445
if child_code != 0 {

0 commit comments

Comments
 (0)