Repository navigation
libs/libc, syscall: Let user programs of protected and kernel builds link msg*() and posix_madvise(). - #21105
Merged
Merged
Conversation
msgget(), msgctl(), msgsnd() and msgrcv() are in the kernel (sched/mqueue) but were not system calls: in a protected or a kernel build a program that uses them did not link (undefined references), so System V message queues were only for kernel code. Add them to syscall.csv and syscall_lookup.h, with the condition of their code (CONFIG_DISABLE_MQUEUE_SYSV not set). Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]>
posix_madvise() was defined in fs/mmap/fs_mmisc.c and has no system call, so in protected and kernel builds a user program that calls it (or madvise(), which <sys/mman.h> maps to it) does not link. The function ignores the advice and touches no kernel state, so it does not need a system call. Move it to libs/libc/misc as it is, and add it to libc.csv. Flat builds link the same function from the C library instead of fs/. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]>
casaroli
requested review from
Donny9,
jerpelea,
pussuw,
xiaoxiang781216 and
yamt
as code owners
October 29, 2026 07:06
|
xiaoxiang781216
approved these changes
Oct 29, 2026
acassis
approved these changes
Oct 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two functions that programs of protected and kernel builds could not link, one commit each: the System V message queue calls had no system call, and posix_madvise() was in the kernel only.
msg-syscalls
msgget(),msgctl(),msgsnd()andmsgrcv()are kernel code (sched/mqueue), but they are not system calls. In a protected or a kernel build, a user program that calls them does not link.This PR adds them to
syscall/syscall.csvandinclude/sys/syscall_lookup.h, with the condition of their code (CONFIG_DISABLE_MQUEUE_SYSVnot set).libc-posix-madvise
posix_madvise()is defined infs/mmap/fs_mmisc.cand has no system call. So in protected and kernel builds, a user program that calls it (ormadvise(), which<sys/mman.h>maps to it) does not link. The function ignores the advice and touches no kernel state, so it does not need a system call.This PR moves the function to
libs/libc/miscas it is (Make and CMake), and adds it tolibc.csv. Flat builds link the same function from the C library instead offs/.Impact
Documentation/standards/posix.rstalready lists the four functions as supported).posix_madvise()andmadvise(). The behavior does not change: the advice is ignored and 0 is returned. No new system call. Documentation: no change (Documentation/standards/posix.rstlistsposix_madvise()as "Empty", which stays true).Testing
The branches were first tested one by one (below). Then all commits of this PR together, on master b79dc18: msgsys.c, madvise.c on
qemu-armv8a:knsh(QEMU with HVF) all PASS, and ostest exits with status 0 onqemu-armv8a:knshandqemu-armv8a:nsh.msg-syscalls
Test program
msgsys.c:msgget(IPC_PRIVATE),msgsnd()of one message,msgctl(IPC_STAT)givesmsg_qnum1,msgrcv()gives the message,msgrcv(IPC_NOWAIT)of the empty queue gives -1,msgctl(IPC_RMID), thenIPC_STATgivesEINVAL.msgsys.conqemu-armv8a:knsh(kernel, arm64, QEMU with HVF)msgctl,msgget,msgrcv,msgsndundefinedqemu-armv8a:knshandqemu-armv8a:nshBuild, each OK (master aeab6fb with this change and other small independent fixes):
rv-virt:pnsh64(protected, rv64),rv-virt:knsh64(kernel, rv64),mps2-an500:knsh(protected, armv7-m),qemu-armv8a:knshwithCONFIG_DISABLE_MQUEUEandCONFIG_DISABLE_MQUEUE_SYSV, andqemu-armv8a:knshwith onlyCONFIG_DISABLE_MQUEUE.No test in nuttx-apps covers System V message queues.
libc-posix-madvise
Test program
madvise.c:posix_madvise()of a heap buffer with eachPOSIX_MADV_xxxgives 0;madvise()withMADV_DONTNEEDandMADV_HUGEPAGEgives 0.madvise.conqemu-armv8a:knsh(kernel, arm64, QEMU with HVF)posix_madviseundefinedqemu-armv8a:knshandqemu-armv8a:nshBuild, each OK (master aeab6fb with this change and other small independent fixes):
rv-virt:pnsh64(protected, rv64: the userlibc.aand the kernellibkc.adefineposix_madvise),rv-virt:knsh64(kernel, rv64),mps2-an500:nsh(flat, armv7-m),mps2-an500:knsh(protected, armv7-m),qemu-armv8a:nsh_smp, andqemu-armv8a:nshwith CMake (onlylibc.adefinesposix_madvise).tools/checkpatch.sh -c -u -m -gpasses.