-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Return value from wasm module via WASI #32093
Comments
those functions don't have a return value. |
Oh, I somehow thought they did. Could there be an alternative way? |
what are you trying to achieve? |
I'm trying to use this simple C program that detects if a number is even: #include <stdlib.h>
#define WASM_EXPORT __attribute__((visibility("default")))
WASM_EXPORT
int main(int argc, char *argv[]) {
char *rest;
long i = strtol(argv[1], &rest, 10);
return i % 2;
} I compiled it with wasi-sdk. It works fine when running with wasmtime and I get the intended return value. I expected it to be usable with node. Or have I misunderstood something? |
also this is basically what _start does:
|
Yeah this definitely seems odd - can start just not return the code directly? |
_start is doing the correct thing. The odd thing is that we don't scope __wasi_proc_exit to the WASI instance. |
|
Right, but there is no reason |
I agree, and that would be preferable. But that's not currently in our control. |
Can you clarify why that is the case? |
@cjihrig indeed... i'm just saying it should not exit the node process. for the moment we can throw an exception, since wasm can't catch them yet. @guybedford __wasi_proc_exit can happen at any point, we should probably represent it as some sort of event, not a return value. |
@guybedford I think the proper fix would need to happen in the wasi-libc. We could also try @devsnek's suggestion of throwing an exception (by overwriting the |
There is no need for a return value from |
Thinking of these WASI apps as nanoprocesses (I think that's what the WASI folks are calling them), I think having an exit code would be useful for the same reasons real processes have exit codes. I think that could be discussed separately from this issue though. IMO, the real problem here is that |
It's worth noting, __wasi_proc_exit is in an odd place atm, and how it works will likely change in the future (or it will be removed). For the moment, just making it not exit the entire process is enough. |
@devsnek I'll look into this tonight. |
This commit adds a WASI option allowing the __wasi_proc_exit() function to return an exit code instead of forcefully terminating the process. PR-URL: #32101 Fixes: #32093 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
This commit adds a WASI option allowing the __wasi_proc_exit() function to return an exit code instead of forcefully terminating the process. PR-URL: nodejs#32101 Fixes: nodejs#32093 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
This commit adds a WASI option allowing the __wasi_proc_exit() function to return an exit code instead of forcefully terminating the process. PR-URL: #32101 Fixes: #32093 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Is your feature request related to a problem? Please describe.
I have a WebAssembly file compiled from a simple C++ program. I would like to get the return value from main. I am calling the function via
wasm.start()
Describe the solution you'd like
start()
should return the value from_start()
and/or__wasi_unstable_reactor_start
.Describe alternatives you've considered
The WASI object could also store the return value and make it available via a getter function, but I think the solution via the return value cleaner.
The text was updated successfully, but these errors were encountered: