|
3 | 3 | use std::cell::RefCell; |
4 | 4 | use std::collections::hash_map::Entry; |
5 | 5 | use std::num::TryFromIntError; |
6 | | -use std::sync::atomic::{AtomicBool, Ordering::Relaxed}; |
| 6 | +use std::sync::atomic::Ordering::Relaxed; |
7 | 7 | use std::task::Poll; |
8 | 8 | use std::time::{Duration, SystemTime}; |
9 | 9 |
|
10 | 10 | use log::trace; |
11 | 11 |
|
12 | 12 | use rustc_data_structures::fx::FxHashMap; |
| 13 | +use rustc_data_structures::CTRL_C_RECEIVED; |
13 | 14 | use rustc_hir::def_id::DefId; |
14 | 15 | use rustc_index::{Idx, IndexVec}; |
15 | 16 | use rustc_middle::mir::Mutability; |
@@ -1020,21 +1021,22 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> { |
1020 | 1021 | /// Run the core interpreter loop. Returns only when an interrupt occurs (an error or program |
1021 | 1022 | /// termination). |
1022 | 1023 | fn run_threads(&mut self) -> InterpResult<'tcx, !> { |
1023 | | - static SIGNALED: AtomicBool = AtomicBool::new(false); |
| 1024 | + // In normal rustc, rustc_driver::main installs this handler. But we don't use that |
| 1025 | + // function, see src/bin/miri.rs. |
1024 | 1026 | ctrlc::set_handler(move || { |
1025 | | - // Indicate that we have ben signaled to stop. If we were already signaled, exit |
| 1027 | + // Indicate that we have been signaled to stop. If we were already signaled, exit |
1026 | 1028 | // immediately. In our interpreter loop we try to consult this value often, but if for |
1027 | 1029 | // whatever reason we don't get to that check or the cleanup we do upon finding that |
1028 | 1030 | // this bool has become true takes a long time, the exit here will promptly exit the |
1029 | 1031 | // process on the second Ctrl-C. |
1030 | | - if SIGNALED.swap(true, Relaxed) { |
| 1032 | + if CTRL_C_RECEIVED.swap(true, Relaxed) { |
1031 | 1033 | std::process::exit(1); |
1032 | 1034 | } |
1033 | 1035 | }) |
1034 | | - .unwrap(); |
| 1036 | + .expect("Unable to install ctrlc handler"); |
1035 | 1037 | let this = self.eval_context_mut(); |
1036 | 1038 | loop { |
1037 | | - if SIGNALED.load(Relaxed) { |
| 1039 | + if CTRL_C_RECEIVED.load(Relaxed) { |
1038 | 1040 | this.machine.handle_abnormal_termination(); |
1039 | 1041 | std::process::exit(1); |
1040 | 1042 | } |
|
0 commit comments