wasi-libc
wasi-libc copied to clipboard
Implementing errno with WASI modularization
With WASI modularization, each proposal will be moving to having its own error code, rather than a single unified errno across all WASI APIs:
- https://github.com/WebAssembly/wasi-filesystem/issues/29
- https://github.com/WebAssembly/wasi-clocks/issues/5
- https://github.com/WebAssembly/wasi-random/issues/8
- https://github.com/WebAssembly/wasi-poll/issues/2
- https://github.com/WebAssembly/wasi-classic-command/issues/6
- https://github.com/WebAssembly/wasi-handle-index/issues/2
WASI libc will need to repack these into a single integer space in order to implement a C-compatible errno
.
Some WASI proposals are not listed here, such as wasi-nn and wasi-crypto, as they aren't expected to use the C errno
variable to report their errors at the C source level. WASI libc's errno
doesn't need to be aware of them.
My rough idea for how to combine these errors is to assign ranges to proposals that need them, so that the C errno
value is computed by taking the raw WASI error code and adding the base value of the appropriate range.
Won't wasi-libc ever want to combine errno values from different proposal into a single value? i.e. will proposal not share error codes at the libc level?
Ah, yes, I forgot about that. Yes, there are a few, such as EINVAL
and EACCES
, which will be shared across eg. wasi-filesystem and an expected future wasi-sockets. One option would be to special-case those in libc to map them to shared errno values.
Another option would be to simply coordinate a set of constants between the different proposals. The constants don't change very often, so maybe this would be fine.