wasm-minimal-protocol icon indicating copy to clipboard operation
wasm-minimal-protocol copied to clipboard

Change the default stubbing value to 0

Open arnaudgolfouse opened this issue 2 years ago • 1 comments

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 ?

arnaudgolfouse avatar Nov 06 '23 21:11 arnaudgolfouse

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.

peng1999 avatar Nov 27 '23 08:11 peng1999