wiggle traps

This commit is contained in:
Pat Hickey
2021-01-07 14:43:56 -08:00
parent 13cd7a4a8e
commit c2a715ca54
2 changed files with 2 additions and 21 deletions

View File

@@ -30,7 +30,7 @@ impl types::GuestErrorConversion for WasiCtx {
} }
impl types::UserErrorConversion for WasiCtx { impl types::UserErrorConversion for WasiCtx {
fn errno_from_error(&self, e: Error) -> Result<types::Errno, String> { fn errno_from_error(&self, e: Error) -> Result<types::Errno, wiggle::Trap> {
debug!("Error: {:?}", e); debug!("Error: {:?}", e);
Ok(e.into()) Ok(e.into())
} }
@@ -885,7 +885,7 @@ impl<'a> wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
unimplemented!() unimplemented!()
} }
fn proc_exit(&self, _rval: types::Exitcode) -> Result<(), ()> { fn proc_exit(&self, _rval: types::Exitcode) -> wiggle::Trap {
unimplemented!() unimplemented!()
} }

View File

@@ -1,5 +1,4 @@
pub use wasi_c2::WasiCtx; pub use wasi_c2::WasiCtx;
use wasmtime::Trap;
// 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.
@@ -22,24 +21,6 @@ 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
}
}, },
}, },
// Error to return when caller module is missing memory export:
missing_memory: { wasi_c2::snapshots::preview_1::types::Errno::Inval },
}); });
fn wasi_proc_exit(status: i32) -> Result<(), Trap> {
if status >= 0 && status < 126 {
Err(Trap::i32_exit(status))
} else {
Err(Trap::new(format!(
"exit with invalid exit status outside of [0..126): {}",
status,
)))
}
}