]> git.lizzy.rs Git - rust.git/commitdiff
use new MachineStop error variant
authorRalf Jung <post@ralfj.de>
Mon, 2 Dec 2019 08:05:35 +0000 (09:05 +0100)
committerRalf Jung <post@ralfj.de>
Mon, 2 Dec 2019 08:05:35 +0000 (09:05 +0100)
rust-version
src/eval.rs
src/lib.rs
src/shims/foreign_items.rs

index 43425c9afc589ff6b73c1200eb90ac6c0e05f5a2..3a0cf96e132750c618127f839b3d28ac9efc6235 100644 (file)
@@ -1 +1 @@
-4007d4ef26eab44bdabc2b7574d032152264d3ad
+f5c81e0a986e4285d3d0fd781a1bd475753eb12c
index 986c6143ab4dbbb769fc9b251956207271b118b2..2c165760418f46c4f6ccd46ea1e265e8f854121f 100644 (file)
@@ -24,6 +24,12 @@ pub struct MiriConfig {
     pub seed: Option<u64>,
 }
 
+/// Details of premature program termination.
+pub enum TerminationInfo {
+    Exit(i64),
+    Abort,
+}
+
 /// Returns a freshly created `InterpCx`, along with an `MPlaceTy` representing
 /// the location where the return value of the `start` lang item will be
 /// written to.
@@ -200,7 +206,15 @@ pub fn eval_main<'tcx>(tcx: TyCtxt<'tcx>, main_id: DefId, config: MiriConfig) ->
         Err(mut e) => {
             // Special treatment for some error kinds
             let msg = match e.kind {
-                InterpError::Exit(code) => return Some(code.into()),
+                InterpError::MachineStop(ref info) => {
+                    let info = info.downcast_ref::<TerminationInfo>()
+                        .expect("invalid MachineStop payload");
+                    match info {
+                        TerminationInfo::Exit(code) => return Some(*code),
+                        TerminationInfo::Abort =>
+                            format!("The program aborted execution")
+                    }
+                }
                 err_unsup!(NoMirFor(..)) =>
                     format!("{}. Did you set `MIRI_SYSROOT` to a Miri-enabled sysroot? You can prepare one with `cargo miri setup`.", e),
                 _ => e.to_string()
index f29ec8f22bbaea993960dabde730410e4a5e052e..05234e880f58cd961685f3624b3b50bab0afcacd 100644 (file)
@@ -47,7 +47,7 @@
     PAGE_SIZE, STACK_ADDR, STACK_SIZE, NUM_CPUS,
     MemoryExtra, AllocExtra, MiriMemoryKind, Evaluator, MiriEvalContext, MiriEvalContextExt,
 };
-pub use crate::eval::{eval_main, create_ecx, MiriConfig};
+pub use crate::eval::{eval_main, create_ecx, MiriConfig, TerminationInfo};
 
 /// Insert rustc arguments at the beginning of the argument list that Miri wants to be
 /// set per default, for maximal validation power.
index b9e6734613c058ef9fdf79aa0451235384e94f57..114931e435a4c6e982fbb116b387a6117ff409b3 100644 (file)
@@ -152,9 +152,10 @@ fn emulate_foreign_item(
             }
 
             "exit" | "ExitProcess" => {
-                // it's really u32 for ExitProcess, but we have to put it into the `Exit` error variant anyway
+                // it's really u32 for ExitProcess, but we have to put it into the `Exit` variant anyway
                 let code = this.read_scalar(args[0])?.to_i32()?;
-                return Err(InterpError::Exit(code).into());
+                let ti = Box::new(TerminationInfo::Exit(code.into()));
+                return Err(InterpError::MachineStop(ti).into());
             }
             _ => {
                 if let Some(p) = ret {