Skip to content

Fix recvmsg msghdr outputs - #27399

Merged
sbc100 merged 3 commits into
emscripten-core:mainfrom
guybedford:recvmsg-msghdr-fix
Jul 22, 2026
Merged

Fix recvmsg msghdr outputs#27399
sbc100 merged 3 commits into
emscripten-core:mainfrom
guybedford:recvmsg-msghdr-fix

Conversation

@guybedford

Copy link
Copy Markdown
Collaborator

This fixes three issues in the recvmsg syscall implementation for sockets, split out separately from #27395 per review feedback.

The bugs:

  • Datagram data was written at the wrong offsets when scattered across multiple iovecs — HEAPU8.set(buf, iovbase + bytesRead) skipped ahead by the bytes already read into previous iovecs, corrupting all iovecs after the first.
  • msg_namelen was not updated to reflect the actual source address size.
  • msg_controllen and msg_flags were left untouched rather than zeroed, leaving callers reading uninitialized values as control data / flags.

Adds sockets.test_noderawsockets_udp_recvmsg covering a datagram scattered across two iovecs along with the msghdr output fields, verified failing before the fix.

Made with AI assistance under my review

Comment thread ChangeLog.md Outdated
@sbc100
sbc100 enabled auto-merge (squash) July 21, 2026 22:45
recvmsg was writing iovecs after the first at incorrect offsets, and was
not updating msg_namelen, msg_controllen or msg_flags in the caller's
struct msghdr.
@guybedford
guybedford force-pushed the recvmsg-msghdr-fix branch from 18500ff to ccb89c8 Compare July 22, 2026 00:11
@sbc100
sbc100 merged commit 6d8b2c1 into emscripten-core:main Jul 22, 2026
38 of 40 checks passed
@guybedford
guybedford deleted the recvmsg-msghdr-fix branch July 22, 2026 01:08
sbc100 pushed a commit that referenced this pull request Jul 22, 2026
This implements `recvmmsg` and `sendmmsg`, which were previously
`ENOSYS` stubs.

Per review feedback, the implementations now live in musl's `sendmmsg.c`
and `recvmmsg.c` rather than the syscall stubs: `sendmmsg.c` already
contained the emulation loop (previously gated behind `LONG_MAX >
INT_MAX`), which is now also enabled under `__EMSCRIPTEN__`, and
`recvmmsg.c` gains an equivalent `recvmsg` loop supporting
`MSG_WAITFORONE` (timeouts report `ENOSYS`).

Since nothing references the syscalls anymore, the
`__syscall_recvmmsg`/`__syscall_sendmmsg` surface is removed entirely:
the `UNIMPLEMENTED` stubs, the `SYS_` mappings in
`arch/emscripten/bits/syscall.h`, the declarations in
`emscripten/syscalls.h`, and their `native_sigs.py` entries.

The `recvmsg` msghdr output fixes previously bundled here were split out
into #27399.

Adds `sockets.test_noderawsockets_mmsg` batching two datagrams out via
`sendmmsg` and receiving them back in a single `recvmmsg` call.

_Made with AI assistance under my review_
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