Skip to content

fix(wasi): remap exit codes to prevent proc_exit traps - #16600

Open
eduardomourar wants to merge 1 commit into
uutils:mainfrom
eduardomourar:fix/wasi-remap-exit-codes
Open

eduardomourar wants to merge 1 commit into
uutils:mainfrom
eduardomourar:fix/wasi-remap-exit-codes

Conversation

@eduardomourar

@eduardomourar eduardomourar commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor
  • Add wasi_safe_exit_code() function to remap codes outside [0, 126) to 125
  • Remap exit codes in main() before exit paths for WASI targets
  • Add explicit exit() call for WASI preview 2 to ensure code reaches host
  • Add comprehensive test coverage for wasi_safe_exit_code() with edge cases
  • Prevents module traps from shell-reserved exit codes (126, 127, 128+signal)
  • Maintains non-zero exit status while keeping module execution safe

Fixes #16594

@sylvestre

Copy link
Copy Markdown
Contributor

thanks for the work on this!
The wasip2 lint failure comes from the unreachable return after exit(code); (see the inline comment). Please also add a test that runs under wasmtime.

@eduardomourar
eduardomourar force-pushed the fix/wasi-remap-exit-codes branch from 20cc16c to 871631e Compare November 17, 2026 14:00
@eduardomourar

Copy link
Copy Markdown
Contributor Author

Linting fixed. For the test under wasmtime, I had to move the logic to uucore so that we can run the unit tests and added a new test_exec_failure_remaps_exit_code_under_wasi to nice integration tests file.

Comment thread src/uucore/src/lib/mods/error.rs Resolved
Comment thread src/bin/coreutils.rs Resolved
Comment thread src/uucore/src/lib/mods/error.rs Resolved
@github-actions

Copy link
Copy Markdown

Binary size comparison:

Individual binary size comparison VS main (threshold: >=5% AND >=4 KB).

Total size of compared binaries: 155.49 MB (+108 KB, +0.07%)

Significant per-binary changes:
  env     1.20 MB ->    1.28 MB  (+80 KB, +6.51%)

@eduardomourar
eduardomourar force-pushed the fix/wasi-remap-exit-codes branch from 9e84fcb to 9c1be1f Compare November 21, 2026 19:08
@codspeed

codspeed Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

1 warning, 1 note

⚠️ 122 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

ℹ️ 1 benchmark has no flamegraph

The flamegraph wasn't generated: most of the time was spent in runtime internals, which would leave nothing useful to analyze.

See affected benchmarks

✅ 215 untouched benchmarks
⏩ 268 skipped benchmarks1


Comparing eduardomourar:fix/wasi-remap-exit-codes (39ab4a0) with main (8b16a3d)

Open in CodSpeed

Footnotes

  1. 268 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@eduardomourar
eduardomourar force-pushed the fix/wasi-remap-exit-codes branch from 9c1be1f to 39ab4a0 Compare November 23, 2026 00:07
@eduardomourar
eduardomourar force-pushed the fix/wasi-remap-exit-codes branch from 39ab4a0 to cf443f1 Compare November 27, 2026 22:15

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Exit codes >= 126 crash the WASI build instead of exiting cleanly

2 participants