wasm-minimal-protocol
wasm-minimal-protocol copied to clipboard
Change the default stubbing value to 0
We currently use 71 as the default return value for functions stubbed by wasi-stub. This was done to call attention to a somewhat weird value, so that someone might realize they called a stubbed function.
However, people probably want the stubbed calls to succeed anyways, because they can’t avoid it (e.g. the call happen in a library). Recently it was brought up that the default hasher of HashMap suffers from this…
Was someone actually helped by the 71 value ?
Was someone actually helped by the 71 value ?
I'm currently working on https://github.com/peng1999/typst-pyrunner and to make the random work I need to make the filesystem API to return 76 and the random API to return 0.
Currently I apply a patch to this project:
--- a/wasi-stub/src/lib.rs
+++ b/wasi-stub/src/lib.rs
@@ -19,9 +19,7 @@ pub struct ShouldStub {
impl Default for ShouldStub {
fn default() -> Self {
Self {
- modules: [(String::from("wasi_snapshot_preview1"), FunctionsToStub::All)]
- .into_iter()
- .collect(),
+ modules: Default::default(),
}
}
}
And then set the return value of functions separately.
In my point of view, it is not good to return 0 instead of 76 in most cases, because if a successful value is returned from a failed function, it will almost certainly lead to an bug. What we do know, is that some functions (like get_random and maybe get_environ) is safe to be return 0. We should enable user to set these in a case-by-case manner.