-
Notifications
You must be signed in to change notification settings - Fork 730
Add wasm_runtime_get_wasi_exit_code #1748
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
Conversation
|
i plan to use this for WebAssembly/wasi-testsuite#16 |
| char **argv_list; | ||
| char *env_buf; | ||
| char **env_list; | ||
| uint32_t exit_code; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see where we initialize exit_code; is there something like memset(ctx, 0, sizeof(WASIContext)) in the startup code to set the value of exit_code to 0? Otherwise it'll contain garbage if the module doesn't call proc_exit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's allocated with runtime_malloc, which does memset.
| typedef struct WASIContext { | ||
| uvwasi_t uvwasi; | ||
| uint32_t exit_code; | ||
| } WASIContext; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's probably out of scope of this PR as it needs a bit larger refactoring, but I think we should strive to have one declaration per context, instead of duplicating it. I've opened an issue to track it: #1749
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i tend to agree. but it's how this code base is currently structured.
| WASM_RUNTIME_API_EXTERN WASMFunctionInstanceCommon * | ||
| wasm_runtime_lookup_wasi_start_function(WASMModuleInstanceCommon *module_inst); | ||
|
|
||
| /* See wasm_export.h for description */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add documentation for this function in wasm_export.h?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| #if WASM_ENABLE_LIBC_WASI != 0 | ||
| if (ret == 0) { | ||
| /* propagate wasi exit code. */ | ||
| ret = wasm_runtime_get_wasi_exit_code(wasm_module_inst); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had better also apply similar changes to windows main.c?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done. i haven't tested it locally at all though.
| WASM_RUNTIME_API_EXTERN wasm_function_inst_t | ||
| wasm_runtime_lookup_wasi_start_function(wasm_module_inst_t module_inst); | ||
|
|
||
| WASM_RUNTIME_API_EXTERN uint32_t |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had better add comments?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Preserve wasi exit code so that an embedder can query it.
…t code It seems like a common practice for engines with a cli. Also, use non-zero exit code on an exeception.
| } | ||
|
|
||
| ret = 0; | ||
| #if WASM_ENABLE_LIBC_WASI != 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wanted to doublecheck - won't that break any user scenario right now? I guess many scripts assumed the return code is ignored by iwasm, so with the update it's possible this breaks some of the usecases. Just want to highlight we have to definitely include it in the release notes and probably highlight as backward incompatible change - any thoughts @wenyongh @yamt ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems that it won't break any user scenarios for us - normally we only use iwasm to run spec cases and standalone cases. Agree to highlight the change in the release notes. And not sure whether it is very important to the users? iwasm just gives a sample, the host embedders can embed WAMR into their application and decide how to handle the exit code.
wenyongh
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
| } | ||
|
|
||
| ret = 0; | ||
| #if WASM_ENABLE_LIBC_WASI != 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems that it won't break any user scenarios for us - normally we only use iwasm to run spec cases and standalone cases. Agree to highlight the change in the release notes. And not sure whether it is very important to the users? iwasm just gives a sample, the host embedders can embed WAMR into their application and decide how to handle the exit code.
loganek
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
#1738