Change proc_exit to unwind the stack rather than exiting the host process. (#1646)
* Remove Cranelift's OutOfBounds trap, which is no longer used. * Change proc_exit to unwind instead of exit the host process. This implements the semantics in https://github.com/WebAssembly/WASI/pull/235. Fixes #783. Fixes #993. * Fix exit-status tests on Windows. * Revert the wiggle changes and re-introduce the wasi-common implementations. * Move `wasi_proc_exit` into the wasmtime-wasi crate. * Revert the spec_testsuite change. * Remove the old proc_exit implementations. * Make `TrapReason` an implementation detail. * Allow exit status 2 on Windows too. * Fix a documentation link. * Really fix a documentation link.
This commit is contained in:
@@ -142,13 +142,24 @@ impl RunCommand {
|
||||
{
|
||||
Ok(()) => (),
|
||||
Err(e) => {
|
||||
// If the program exited because of a trap, return an error code
|
||||
// to the outside environment indicating a more severe problem
|
||||
// than a simple failure.
|
||||
if e.is::<Trap>() {
|
||||
// If the program exited because of a non-zero exit status, print
|
||||
// a message and exit.
|
||||
if let Some(trap) = e.downcast_ref::<Trap>() {
|
||||
// Print the error message in the usual way.
|
||||
eprintln!("Error: {:?}", e);
|
||||
|
||||
if let Some(status) = trap.i32_exit_status() {
|
||||
// On Windows, exit status 3 indicates an abort (see below),
|
||||
// so return 1 indicating a non-zero status to avoid ambiguity.
|
||||
if cfg!(windows) && status >= 3 {
|
||||
process::exit(1);
|
||||
}
|
||||
process::exit(status);
|
||||
}
|
||||
|
||||
// If the program exited because of a trap, return an error code
|
||||
// to the outside environment indicating a more severe problem
|
||||
// than a simple failure.
|
||||
if cfg!(unix) {
|
||||
// On Unix, return the error code of an abort.
|
||||
process::exit(128 + libc::SIGABRT);
|
||||
|
||||
Reference in New Issue
Block a user