Skip to content

Implement recvmmsg and sendmmsg - #27395

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

Implement recvmmsg and sendmmsg#27395
sbc100 merged 3 commits into
emscripten-core:mainfrom
guybedford:mmsg

Conversation

@guybedford

@guybedford guybedford commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

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

Comment thread system/lib/libc/emscripten_syscall_stubs.c Outdated

@sbc100 sbc100 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm although I would still expect the stubs for these syscalls to be removed (and also the syscalls themselves the syscalls.h, etc).

Ideally I would love to see the bugfix land first/separately, but its also not a big deal if testing in isolation is too difficult.

@guybedford

Copy link
Copy Markdown
Collaborator Author

Sure, I've gone ahead and split out the bugfixes into #27399.

@guybedford guybedford changed the title Implement recvmmsg and sendmmsg, fix recvmsg msghdr outputs Implement recvmmsg and sendmmsg Jul 21, 2026
sbc100 pushed a commit that referenced this pull request Jul 22, 2026
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.

@carlaarchuleta707-lgtm carlaarchuleta707-lgtm left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gh pr checkout 27395

@carlaarchuleta707-lgtm

Copy link
Copy Markdown

gh pr checkout 27395

#27395 (review)

Comment thread ChangeLog.md Outdated
Implements recvmmsg and sendmmsg in musl in terms of recvmsg and
sendmsg, removing the now-unreferenced __syscall_recvmmsg and
__syscall_sendmmsg stubs and syscall definitions.
@sbc100
sbc100 enabled auto-merge (squash) July 22, 2026 23:00
@sbc100
sbc100 merged commit 4e8579a into emscripten-core:main Jul 22, 2026
44 checks passed
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.

3 participants