forked from bytecodealliance/wasmtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change proc_exit to unwind instead of exit the host process.
This implements the semantics in WebAssembly/WASI#235. Fixes bytecodealliance#783. Fixes bytecodealliance#993.
- Loading branch information
1 parent
f295cc6
commit 55cf462
Showing
29 changed files
with
378 additions
and
141 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use crate::frame_info::FRAME_INFO; | ||
use crate::{Exit, Trap}; | ||
use anyhow::Error; | ||
use wasmtime_environ::ir::TrapCode; | ||
|
||
/// Convert from an internal unwinding code into an `Error`. | ||
pub(crate) fn from_runtime(jit: wasmtime_runtime::Trap) -> Error { | ||
let info = FRAME_INFO.read().unwrap(); | ||
match jit { | ||
wasmtime_runtime::Trap::User(error) => error, | ||
wasmtime_runtime::Trap::Jit { | ||
pc, | ||
backtrace, | ||
maybe_interrupted, | ||
} => { | ||
let mut code = info | ||
.lookup_trap_info(pc) | ||
.map(|info| info.trap_code) | ||
.unwrap_or(TrapCode::StackOverflow); | ||
if maybe_interrupted && code == TrapCode::StackOverflow { | ||
code = TrapCode::Interrupt; | ||
} | ||
Error::new(Trap::new_wasm(&info, Some(pc), code, backtrace)) | ||
} | ||
wasmtime_runtime::Trap::Wasm { | ||
trap_code, | ||
backtrace, | ||
} => Error::new(Trap::new_wasm(&info, None, trap_code, backtrace)), | ||
wasmtime_runtime::Trap::OOM { backtrace } => Error::new(Trap::new_with_trace( | ||
&info, | ||
None, | ||
"out of memory".to_string(), | ||
backtrace, | ||
)), | ||
wasmtime_runtime::Trap::Exit { status } => Error::new(Exit::new(status)), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use std::fmt; | ||
use std::num::NonZeroI32; | ||
|
||
/// A struct representing an explicit program exit, with a code | ||
/// indicating the status. | ||
#[derive(Clone, Debug)] | ||
pub struct Exit { | ||
status: NonZeroI32, | ||
} | ||
|
||
impl Exit { | ||
/// Creates a new `Exit` with `status`. The status value must be in the range [1..126]. | ||
/// # Example | ||
/// ``` | ||
/// let exit = wasmtime::Exit::new(std::num::NonZeroI32::new(1).unwrap()); | ||
/// assert_eq!(1, exit.status().get()); | ||
/// ``` | ||
pub fn new(status: NonZeroI32) -> Self { | ||
assert!(status.get() > 0 && status.get() < 126); | ||
Self { status } | ||
} | ||
|
||
/// Returns a reference the `status` stored in `Exit`. | ||
pub fn status(&self) -> NonZeroI32 { | ||
self.status | ||
} | ||
} | ||
|
||
impl fmt::Display for Exit { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
// Error codes used by WASI libc. | ||
match self.status.get() { | ||
70 => write!(f, "internal software error"), | ||
71 => write!(f, "system error"), | ||
_ => write!(f, "non-zero status {}", self.status), | ||
} | ||
} | ||
} | ||
|
||
impl std::error::Error for Exit {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.