Skip to content

libs/libc, syscall: Let user programs of protected and kernel builds link msg*() and posix_madvise(). - #21105

Merged
acassis merged 2 commits into
apache:masterfrom
casaroli:grp-d-up
Oct 29, 2026
Merged

acassis merged 2 commits into
apache:masterfrom
casaroli:grp-d-up

Conversation

@casaroli

Copy link
Copy Markdown
Contributor

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() and msgrcv() 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.csv and include/sys/syscall_lookup.h, with the condition of their code (CONFIG_DISABLE_MQUEUE_SYSV not set).

libc-posix-madvise

posix_madvise() is 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.

This PR moves the function to libs/libc/misc as it is (Make and CMake), and adds it to libc.csv. Flat builds link the same function from the C library instead of fs/.

Impact

  • msg-syscalls: Protected and kernel builds: user programs can use System V message queues. The system call numbers after the new entries change (they are not a stable ABI). Flat builds: no change. Documentation: no change (Documentation/standards/posix.rst already lists the four functions as supported).
  • libc-posix-madvise: User programs of protected and kernel builds can call posix_madvise() and madvise(). The behavior does not change: the advice is ignored and 0 is returned. No new system call. Documentation: no change (Documentation/standards/posix.rst lists posix_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 on qemu-armv8a:knsh and qemu-armv8a:nsh.

msg-syscalls

Test program msgsys.c: msgget(IPC_PRIVATE), msgsnd() of one message, msgctl(IPC_STAT) gives msg_qnum 1, msgrcv() gives the message, msgrcv(IPC_NOWAIT) of the empty queue gives -1, msgctl(IPC_RMID), then IPC_STAT gives EINVAL.

master this PR
msgsys.c on qemu-armv8a:knsh (kernel, arm64, QEMU with HVF) does not link: msgctl, msgget, msgrcv, msgsnd undefined all PASS
ostest, qemu-armv8a:knsh and qemu-armv8a:nsh status 0 status 0

Build, 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:knsh with CONFIG_DISABLE_MQUEUE and CONFIG_DISABLE_MQUEUE_SYSV, and qemu-armv8a:knsh with only CONFIG_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 each POSIX_MADV_xxx gives 0; madvise() with MADV_DONTNEED and MADV_HUGEPAGE gives 0.

master this PR
madvise.c on qemu-armv8a:knsh (kernel, arm64, QEMU with HVF) does not link: posix_madvise undefined all PASS
ostest, qemu-armv8a:knsh and qemu-armv8a:nsh status 0 status 0

Build, each OK (master aeab6fb with this change and other small independent fixes): rv-virt:pnsh64 (protected, rv64: the user libc.a and the kernel libkc.a define posix_madvise), rv-virt:knsh64 (kernel, rv64), mps2-an500:nsh (flat, armv7-m), mps2-an500:knsh (protected, armv7-m), qemu-armv8a:nsh_smp, and qemu-armv8a:nsh with CMake (only libc.a defines posix_madvise).

tools/checkpatch.sh -c -u -m -g passes.

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]>
@github-actions github-actions Bot added Area: File System File System issues Size: S The size of the change in this PR is small labels Oct 29, 2026
@github-actions

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

No memory changes detected for:


Catch memory regressions in CI with MemBrowse. Free for open source.

@acassis
acassis merged commit 01d8ee3 into apache:master Oct 29, 2026
53 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: File System File System issues Size: S The size of the change in this PR is small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants