Skip to content
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

Disallow non-portable and signal values as exit statuses. #235

Merged
merged 3 commits into from
Mar 9, 2021

Commits on Mar 9, 2021

  1. 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
    sunfishcode committed Mar 9, 2021
    Configuration menu
    Copy the full SHA
    62c0f4d View commit details
    Browse the repository at this point in the history
  2. Update the docs.

    sunfishcode committed Mar 9, 2021
    Configuration menu
    Copy the full SHA
    e1f207d View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    17a25e7 View commit details
    Browse the repository at this point in the history