wasi-common: port to use wiggle::Trap

This commit is contained in:
Pat Hickey
2021-01-05 18:21:01 -08:00
parent 1c7c18b026
commit 4a574c14eb
5 changed files with 12 additions and 37 deletions

View File

@@ -1,5 +1,3 @@
use wasmtime::Trap;
pub mod old;
pub use wasi_common::virtfs;
@@ -26,12 +24,7 @@ modules. This structure exports all that various fields of the wasi instance
as fields which can be used to implement your own instantiation logic, if
necessary. Additionally [`Wasi::get_export`] can be used to do name-based
resolution.",
// Don't use the wiggle generated code to implement proc_exit, we need
// to hook directly into the runtime there:
function_override: {
proc_exit => wasi_proc_exit
}
},
}
},
});
@@ -41,17 +34,3 @@ pub fn is_wasi_module(name: &str) -> bool {
// trick.
name.starts_with("wasi")
}
/// Implement the WASI `proc_exit` function. This function is implemented here
/// instead of in wasi-common so that we can use the runtime to perform an
/// unwind rather than exiting the host process.
fn wasi_proc_exit(status: i32) -> Result<(), Trap> {
// Check that the status is within WASI's range.
if status >= 0 && status < 126 {
Err(Trap::i32_exit(status))
} else {
Err(Trap::new(
"exit with invalid exit status outside of [0..126)",
))
}
}

View File

@@ -1,8 +1,6 @@
pub use wasi_common::virtfs;
pub use wasi_common::{WasiCtx, WasiCtxBuilder};
use crate::wasi_proc_exit;
// Defines a `struct Wasi` with member fields and appropriate APIs for dealing
// with all the various WASI exports.
wasmtime_wiggle::wasmtime_integration!({
@@ -25,12 +23,7 @@ modules. This structure exports all that various fields of the wasi instance
as fields which can be used to implement your own instantiation logic, if
necessary. Additionally [`Wasi::get_export`] can be used to do name-based
resolution.",
// Don't use the wiggle generated code to implement proc_exit, we need
// to hook directly into the runtime there:
function_override: {
proc_exit => wasi_proc_exit
}
},
}
},
});