Skip to content

wasm: long-typed pointer limits and syscall numbers 451–471 - #12

Open
tombl wants to merge 3 commits into
masterfrom
ryan/wasm-headers
Open

tombl wants to merge 3 commits into
masterfrom
ryan/wasm-headers

Conversation

@tombl

@tombl tombl commented Oct 25, 2026 •

Copy link
Copy Markdown
Owner

Both changes are wasm32 port fixes in arch/wasm32.

  • Give the pointer-sized limits long's type. This follows from a port choice. _Addr is long on wasm32, matching clang's wasm32 ABI, where size_t is unsigned long; wasm32 is the only 32-bit musl arch with _Addr long. The generic bits/stdint.h gives 32-bit long targets INT32_*/UINT32_MAX, which have int's types, so SIZE_MAX was unsigned int. Expressions that check their operands' types failed to compile, for example systemd's CONST_MIN((size_t)INT_MAX, SIZE_MAX / 4). The fix is an arch override, arch/wasm32/bits/stdint.h.
  • Add syscall numbers 451 to 471. The arch table was stale against the kernel's asm-generic/unistd.h, which has all of them. Upstream musl adds new numbers per arch the same way. Note one behaviour change: with SYS_fchmodat2 defined, fchmodat() with any nonzero flags (AT_SYMLINK_NOFOLLOW, AT_EMPTY_PATH) now tries the kernel's fchmodat2 first. Only ENOSYS falls back to the old path, and other errors propagate. Zero flags still use fchmodat.
  • Count every syscall number and add map_shadow_stack (a separate commit by Tom, after review). __NR_syscalls was still 451, below the new numbers. It is now 472, matching the kernel. map_shadow_stack (453) is added, as upstream musl's other arch tables have it, and arm64 and RISC-V implement it as well as x86. The wasm kernel returns ENOSYS.

Test (basic-init stdint-limits, in distro#206): _Static_asserts that each limit has its type's type. Before (main's pins), it fails to compile with six errors, for example __builtin_types_compatible_p(unsigned int, unsigned long): SIZE_MAX is not a size_t. After: pass.

The first two commits are byte-identical diffs of Ryan Rasti's ryanrasti/tombl-musl@658e061c and @5c158631. The syscall commit was re-picked after review, because the previous version had moved two entries. So he remains their author, and only the messages were rewritten. The third commit is Tom's.

ryanrasti and others added 3 commits October 25, 2026 23:58
size_t, intptr_t and ptrdiff_t are long and unsigned long on wasm32,
since _Addr is long, but the generic bits/stdint.h gives their limits the
types of int32_t and uint32_t. An expression that mixes them, such as
systemd's CONST_MIN((size_t)INT_MAX, SIZE_MAX / 4), then fails to compile
because the operand types differ. Define the limits as long constants, as
clang's own __SIZE_MAX__ and friends are.

Ported from ryanrasti/tombl-musl@658e061c.
Add the numbers that the kernel's asm-generic/unistd.h has gained since
the table was generated, such as fchmodat2, setxattrat, removexattrat and
open_tree_attr, which systemd calls by number.

Cherry-picked from ryanrasti/tombl-musl@5c158631.
__NR_syscalls was still 451 after numbers up to 471 were added, so it
no longer covered the table. It is 472 in the kernel's
asm-generic/unistd.h. Also add map_shadow_stack (453), which the other
arches' tables carry and which arm64 and RISC-V now implement as well as
x86. The wasm kernel answers it with ENOSYS.
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.

2 participants