Skip to content

Commit f3c00a4

Browse files
committed
use new MachineStop error variant
1 parent cde718f commit f3c00a4

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4007d4ef26eab44bdabc2b7574d032152264d3ad
1+
f5c81e0a986e4285d3d0fd781a1bd475753eb12c

src/eval.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ pub struct MiriConfig {
2424
pub seed: Option<u64>,
2525
}
2626

27+
/// Details of premature program termination.
28+
pub enum TerminationInfo {
29+
Exit(i64),
30+
Abort,
31+
}
32+
2733
/// Returns a freshly created `InterpCx`, along with an `MPlaceTy` representing
2834
/// the location where the return value of the `start` lang item will be
2935
/// written to.
@@ -200,7 +206,15 @@ pub fn eval_main<'tcx>(tcx: TyCtxt<'tcx>, main_id: DefId, config: MiriConfig) ->
200206
Err(mut e) => {
201207
// Special treatment for some error kinds
202208
let msg = match e.kind {
203-
InterpError::Exit(code) => return Some(code.into()),
209+
InterpError::MachineStop(ref info) => {
210+
let info = info.downcast_ref::<TerminationInfo>()
211+
.expect("invalid MachineStop payload");
212+
match info {
213+
TerminationInfo::Exit(code) => return Some(*code),
214+
TerminationInfo::Abort =>
215+
format!("The program aborted execution")
216+
}
217+
}
204218
err_unsup!(NoMirFor(..)) =>
205219
format!("{}. Did you set `MIRI_SYSROOT` to a Miri-enabled sysroot? You can prepare one with `cargo miri setup`.", e),
206220
_ => e.to_string()

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub use crate::machine::{
4747
PAGE_SIZE, STACK_ADDR, STACK_SIZE, NUM_CPUS,
4848
MemoryExtra, AllocExtra, MiriMemoryKind, Evaluator, MiriEvalContext, MiriEvalContextExt,
4949
};
50-
pub use crate::eval::{eval_main, create_ecx, MiriConfig};
50+
pub use crate::eval::{eval_main, create_ecx, MiriConfig, TerminationInfo};
5151

5252
/// Insert rustc arguments at the beginning of the argument list that Miri wants to be
5353
/// set per default, for maximal validation power.

src/shims/foreign_items.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
152152
}
153153

154154
"exit" | "ExitProcess" => {
155-
// it's really u32 for ExitProcess, but we have to put it into the `Exit` error variant anyway
155+
// it's really u32 for ExitProcess, but we have to put it into the `Exit` variant anyway
156156
let code = this.read_scalar(args[0])?.to_i32()?;
157-
return Err(InterpError::Exit(code).into());
157+
let ti = Box::new(TerminationInfo::Exit(code.into()));
158+
return Err(InterpError::MachineStop(ti).into());
158159
}
159160
_ => {
160161
if let Some(p) = ret {

0 commit comments

Comments
 (0)