wasi-common: port to use wiggle::Trap
This commit is contained in:
@@ -714,10 +714,13 @@ impl<'a> WasiSnapshotPreview1 for WasiCtx {
|
|||||||
Ok(nevents)
|
Ok(nevents)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn proc_exit(&self, _rval: types::Exitcode) -> std::result::Result<(), ()> {
|
fn proc_exit(&self, status: types::Exitcode) -> wiggle::Trap {
|
||||||
// proc_exit is special in that it's expected to unwind the stack, which
|
// Check that the status is within WASI's range.
|
||||||
// typically requires runtime-specific logic.
|
if status < 126 {
|
||||||
unimplemented!("runtimes are expected to override this implementation")
|
wiggle::Trap::I32(status as i32)
|
||||||
|
} else {
|
||||||
|
wiggle::Trap::String("exit with invalid exit status outside of [0..126)".to_owned())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn proc_raise(&self, _sig: types::Signal) -> Result<()> {
|
fn proc_raise(&self, _sig: types::Signal) -> Result<()> {
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ impl types::GuestErrorConversion for WasiCtx {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl types::UserErrorConversion for WasiCtx {
|
impl types::UserErrorConversion for WasiCtx {
|
||||||
fn errno_from_error(&self, e: Error) -> Result<Errno, String> {
|
fn errno_from_error(&self, e: Error) -> Result<Errno, wiggle::Trap> {
|
||||||
tracing::debug!("Error: {:?}", e);
|
tracing::debug!("Error: {:?}", e);
|
||||||
Ok(e.into())
|
Ok(e.into())
|
||||||
}
|
}
|
||||||
@@ -346,7 +346,7 @@ impl wasi_unstable::WasiUnstable for WasiCtx {
|
|||||||
Ok(nevents)
|
Ok(nevents)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn proc_exit(&self, rval: Exitcode) -> Result<(), ()> {
|
fn proc_exit(&self, rval: Exitcode) -> wiggle::Trap {
|
||||||
WasiSnapshotPreview1::proc_exit(self, rval)
|
WasiSnapshotPreview1::proc_exit(self, rval)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ impl types::GuestErrorConversion for WasiCtx {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl types::UserErrorConversion for WasiCtx {
|
impl types::UserErrorConversion for WasiCtx {
|
||||||
fn errno_from_error(&self, e: Error) -> Result<Errno, String> {
|
fn errno_from_error(&self, e: Error) -> Result<Errno, wiggle::Trap> {
|
||||||
debug!("Error: {:?}", e);
|
debug!("Error: {:?}", e);
|
||||||
Ok(e.into())
|
Ok(e.into())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
use wasmtime::Trap;
|
|
||||||
|
|
||||||
pub mod old;
|
pub mod old;
|
||||||
|
|
||||||
pub use wasi_common::virtfs;
|
pub use wasi_common::virtfs;
|
||||||
@@ -26,13 +24,8 @@ 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
|
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
|
necessary. Additionally [`Wasi::get_export`] can be used to do name-based
|
||||||
resolution.",
|
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
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
pub fn is_wasi_module(name: &str) -> bool {
|
pub fn is_wasi_module(name: &str) -> bool {
|
||||||
@@ -41,17 +34,3 @@ pub fn is_wasi_module(name: &str) -> bool {
|
|||||||
// trick.
|
// trick.
|
||||||
name.starts_with("wasi")
|
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)",
|
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
pub use wasi_common::virtfs;
|
pub use wasi_common::virtfs;
|
||||||
pub use wasi_common::{WasiCtx, WasiCtxBuilder};
|
pub use wasi_common::{WasiCtx, WasiCtxBuilder};
|
||||||
|
|
||||||
use crate::wasi_proc_exit;
|
|
||||||
|
|
||||||
// Defines a `struct Wasi` with member fields and appropriate APIs for dealing
|
// Defines a `struct Wasi` with member fields and appropriate APIs for dealing
|
||||||
// with all the various WASI exports.
|
// with all the various WASI exports.
|
||||||
wasmtime_wiggle::wasmtime_integration!({
|
wasmtime_wiggle::wasmtime_integration!({
|
||||||
@@ -25,13 +23,8 @@ 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
|
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
|
necessary. Additionally [`Wasi::get_export`] can be used to do name-based
|
||||||
resolution.",
|
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
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
pub fn is_wasi_module(name: &str) -> bool {
|
pub fn is_wasi_module(name: &str) -> bool {
|
||||||
|
|||||||
Reference in New Issue
Block a user