Skip to content

stdio: skip empty iovec when buffering is disabled (upstream fde29c04) - #14

Open
tombl wants to merge 1 commit into
masterfrom
ryan/stdio-empty-iovec
Open

tombl wants to merge 1 commit into
masterfrom
ryan/stdio-empty-iovec

Conversation

@tombl

@tombl tombl commented Oct 25, 2026

Copy link
Copy Markdown
Owner

A cherry-pick (-x) of upstream musl fde29c0 by Casey Connolly, which our fork's base (61399d4, 2024-09) predates.

An unbuffered stream's buffer is always empty. __stdio_write() still sent it as the first iovec, and files whose kernel handler is a plain .write get a zero-length write first, because do_loop_readv_writev() calls the handler once per segment. /proc/<pid>/oom_score_adj fails such a write with EINVAL, so writing it through an unbuffered stream failed. systemd's OOMScoreAdjust= is one example. That kernel behaviour matches upstream Linux, so this replaces tombl/linux#63, which skipped empty segments in the VFS.

Test (basic-init stdio-unbuffered-proc, in distro#206): fopen /proc/self/oom_score_adj, setvbuf(_IONBF), fputs "100\n", then read it back. Before (main's pins): fputs /proc/self/oom_score_adj: Invalid argument. After: pass.

Found through ryanrasti/linux@657d4881 by Ryan Rasti, which patched the kernel instead.

When buffering on a FILE is disabled we still send both iovecs, even
though the first one is always empty. Clean things up by skipping the
empty iovec instead.

(cherry picked from commit fde29c0)
tombl added a commit to tombl/distro that referenced this pull request Oct 25, 2026
The kernel moves to tombl/linux@365cc111 (ryan-fixes), which is wasm
with tombl/linux#64 and #65: an empty ramfs file grows sparsely on wasm
instead of contiguously, ramfs gains fallocate without an MMU, and the
unused THREAD_SHIFT is dropped. It also brings in tombl/linux#58, the
clone failure cleanup that wasm already has. The UAPI headers are
unchanged.

musl moves to tombl/musl@dbbe5cbb (ryan-fixes), which is master with
tombl/musl#14, #12 and #13: stdio skips an empty buffer in writev, as
upstream musl does, the pointer-sized limits get long's type, syscall
numbers 451 to 471 are added, swapon and swapoff are provided, and
pthread_getattr_np reports the main thread's stack.
tombl added a commit to tombl/distro that referenced this pull request Oct 25, 2026
The kernel moves to tombl/linux@3902e778 (ryan-fixes), which is wasm
at 89fefa07 with tombl/linux#64 and #65: an empty ramfs file grows
sparsely on wasm instead of contiguously, ramfs gains fallocate without
an MMU, and the unused THREAD_SHIFT is dropped. The UAPI headers are
unchanged.

musl moves to tombl/musl@38da5853 (ryan-fixes), which is master with
tombl/musl#14, #12 and #13: stdio skips an empty buffer in writev, as
upstream musl does, the pointer-sized limits get long's type, syscall
numbers 451 to 471 and map_shadow_stack are added and counted, swapon
and swapoff are provided, and pthread_getattr_np reports the main
thread's stack.
tombl added a commit to tombl/distro that referenced this pull request Oct 25, 2026
The kernel moves to tombl/linux@84c7c188 (ryan-fixes), which is wasm
at d1911fdd with tombl/linux#64 and #65: an empty ramfs file grows
sparsely on wasm instead of contiguously, ramfs gains fallocate without
an MMU, and the unused THREAD_SHIFT is dropped. The UAPI headers are
unchanged.

musl moves to tombl/musl@38da5853 (ryan-fixes), which is master with
tombl/musl#14, #12 and #13: stdio skips an empty buffer in writev, as
upstream musl does, the pointer-sized limits get long's type, syscall
numbers 451 to 471 and map_shadow_stack are added and counted, swapon
and swapoff are provided, and pthread_getattr_np reports the main
thread's stack.
tombl added a commit to tombl/distro that referenced this pull request Oct 27, 2026
The kernel moves to tombl/linux@84c7c188 (ryan-fixes), which is wasm
at d1911fdd with tombl/linux#64 and #65: an empty ramfs file grows
sparsely on wasm instead of contiguously, ramfs gains fallocate without
an MMU, and the unused THREAD_SHIFT is dropped. The UAPI headers are
unchanged.

musl moves to tombl/musl@38da5853 (ryan-fixes), which is master with
tombl/musl#14, #12 and #13: stdio skips an empty buffer in writev, as
upstream musl does, the pointer-sized limits get long's type, syscall
numbers 451 to 471 and map_shadow_stack are added and counted, swapon
and swapoff are provided, and pthread_getattr_np reports the main
thread's stack.
tombl added a commit to tombl/distro that referenced this pull request Oct 27, 2026
The kernel moves to tombl/linux@84c7c188 (ryan-fixes), which is wasm
at d1911fdd with tombl/linux#64 and #65: an empty ramfs file grows
sparsely on wasm instead of contiguously, ramfs gains fallocate without
an MMU, and the unused THREAD_SHIFT is dropped. The UAPI headers are
unchanged.

musl moves to tombl/musl@38da5853 (ryan-fixes), which is master with
tombl/musl#14, #12 and #13: stdio skips an empty buffer in writev, as
upstream musl does, the pointer-sized limits get long's type, syscall
numbers 451 to 471 and map_shadow_stack are added and counted, swapon
and swapoff are provided, and pthread_getattr_np reports the main
thread's stack.
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.

1 participant