You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Disallow non-portable and signal values as exit statuses. (#235)
* Disallow non-portable and signal values as exit statuses.
Exit codes of at least 256 aren't portable to [POSIX exit], so
programs expecting to return full 32-bit [Windows System Error Codes]
aren't practically portable.
And on POSIX, error codes of at least 128 are reserved for reporting
program exits via signals, and 127 and 126 are reserved for POSIX-style
shells. While it's theoretically possible for POSIX applications to
return these explicitly, this is very rare, not often useful,
particularly in programs intended to be portable, and could potentially
be confusing to users.
If a need arrises for programs to return values in [126,256), or to
provide other kinds of information upon program exit, we can look at
relaxing these restrictions or adding new APIs to WASI for program
termination, but for now it makes sense to start with something simple.
With that, this PR proposes:
- The WASI `exit` function takes a `u8`, but if the value is at
least 126, it traps. Otherwise it is provided to the environment.
- WASI libc's `exit` will map from `int` to `u8` by applying the mask
as specified in [POSIX exit].
No other WASI syscalls trap right now, but `exit` has no other way to
indicate errors.
[POSIX exit]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/_Exit.html
[Windows System Error Codes]: https://docs.microsoft.com/en-us/windows/win32/debug/system-error-codes?redirectedfrom=MSDN#system-error-codes
* Update the docs.
* Say "or greater" instead of "at least".
Co-authored-by: Dan Gohman <[email protected]>
0 commit comments