From d61a8bb6d2a95a4ec45f996e222e0c86cde56cf0 Mon Sep 17 00:00:00 2001 From: losfair Date: Sat, 10 Aug 2019 03:10:12 +0800 Subject: [PATCH] Prevent continueing execution on unreliable stack. (LLVM register save area information is missing) --- lib/runtime-core/src/tiering.rs | 4 ++-- src/bin/wasmer.rs | 36 +++++++++------------------------ 2 files changed, 12 insertions(+), 28 deletions(-) diff --git a/lib/runtime-core/src/tiering.rs b/lib/runtime-core/src/tiering.rs index 75688bab4..36ec19a1a 100644 --- a/lib/runtime-core/src/tiering.rs +++ b/lib/runtime-core/src/tiering.rs @@ -28,6 +28,7 @@ pub enum ShellExitOperation { pub struct InteractiveShellContext { pub image: Option, + pub patched: bool, } struct OptimizationState { @@ -178,8 +179,6 @@ pub fn run_tiering ShellExitOperation>( .as_ptr() as usize, }); n_versions.set(n_versions.get() + 1); - - eprintln!("Patched"); } // TODO: Fix this for optimized version. let breakpoints = baseline.module.runnable_module.get_breakpoints(); @@ -215,6 +214,7 @@ pub fn run_tiering ShellExitOperation>( } let op = interactive_shell(InteractiveShellContext { image: Some(new_image.clone()), + patched: n_versions.get() > 1, }); match op { ShellExitOperation::ContinueWith(new_image) => { diff --git a/src/bin/wasmer.rs b/src/bin/wasmer.rs index 07bf68d5c..a68ef2190 100644 --- a/src/bin/wasmer.rs +++ b/src/bin/wasmer.rs @@ -635,37 +635,21 @@ fn interactive_shell(mut ctx: InteractiveShellContext) -> ShellExitOperation { } } "continue" | "c" => { - if let Some(image) = ctx.image.take() { - return ShellExitOperation::ContinueWith(image); + if ctx.patched { + println!("Error: Continueing execution is not yet supported on patched code."); } else { - println!("Program state not available, cannot continue execution"); - } - } - // Disabled due to unsafety. - /* - "switch_backend" => { - let backend_name = parts.next(); - if backend_name.is_none() { - println!("Usage: switch_backend [backend_name]"); - continue; - } - let backend_name = backend_name.unwrap(); - let backend = match backend_name { - "singlepass" => Backend::Singlepass, - "llvm" => Backend::LLVM, - _ => { - println!("unknown backend"); - continue; + if let Some(image) = ctx.image.take() { + return ShellExitOperation::ContinueWith(image); + } else { + println!("Program state not available, cannot continue execution"); } - }; - if let Some(image) = ctx.image.take() { - return ShellExitOperation::ContinueWith(image, Some(backend)); - } else { - println!("Program state not available, cannot continue execution"); } } - */ "backtrace" | "bt" => { + if ctx.patched { + println!("Warning: Backtrace on patched code might be inaccurate."); + } + if let Some(ref image) = ctx.image { println!("{}", image.execution_state.colored_output()); } else {