mirror of
https://github.com/RhapsodiOS/RhapsodiOS.git
synced 2026-11-03 22:01:40 -07:00
[GH-ISSUE #43] kernel: mlock/munlock, MAP_ANON (and msync/madvise/mincore) are unimplemented #35
Labels
No labels
bug
documentation
enhancement
enhancement
good first issue
help wanted
help wanted
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github-starred/RhapsodiOS#35
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @raynorpat on GitHub (Oct 14, 2026).
Original GitHub issue: https://github.com/RhapsodiOS/RhapsodiOS/issues/43
Summary
Several standard BSD memory calls are unimplemented in kernel-7. The new stress suite (
src/Commands/stress, ffs-perf branch) reports them as UNSUP:mlockbsd/kern/kern_mman.c:575-582/* Not yet implemented */, returnsEOPNOTSUPPmunlockbsd/kern/kern_mman.c:589-596mmap(..., MAP_ANON, ...)bsd/kern/kern_mman.c:224-228EINVALRelated stubs in the same file, worth fixing alongside:
msync(kern_mman.c:442-449), also disabled ininit_sysent.c(#warning stubbed out msync).madvise(kern_mman.c:545-552) andmincore(kern_mman.c:561-568).sbrkandsstk(kern_mman.c:100-124).User space: the v2 image's installed Libc had no
mlock/munlockentry points, so the suite binds them through dyld at runtime.src/Libc-1/sys.subproj/SYSCALL-LISTlists them, but there are nomlock.s/munlock.sstubs next tomprotect.s/msync.sini386.subprojandppc.subproj.What the stress suite sees
stress-vm wire:UNSUP reason="mlock: ENOSYS", because Libc has no symbol, and the kernel call returnsEOPNOTSUPPanyway. Nothing can wire user memory.stress-mmap anon:UNSUPbecauseMAP_ANONreturnsEINVAL. Programs that expect anonymousmmapfail or need a/dev/zeroorvm_allocatefallback. Note that/dev/zeromapping support is its own question.stress-mmap sync:UNSUP reason="msync: ENOSYS".Proposed work
MAP_ANON: back it withvm_allocate/vm_mapof anonymous memory honouringprot,MAP_SHARED/MAP_PRIVATEandMAP_FIXED. The Mach VM already does this forvm_allocate, so this is mostly plumbing inmmap().mlock/munlock: implement withvm_map_pageable()(wire/unwire the range,KERN_RESOURCE_SHORTAGE→EAGAIN). Also enforceRLIMIT_MEMLOCKand allow it for root only, or within the limit. Add Libc syscall stubs for i386 and ppc.msync: flush dirty pages of the range to the pager (vm_object_sync/memory_object_lock_request, depending on what kernel-7 exposes), then re-enable the syscall entry.madvise/mincore: low priority.madvisecan return 0 as a hint, andmincorecan report residency from the pmap.Once each lands, the matching stress tests (
vm wire,mmap anon,mmap sync) switch from UNSUP to PASS/FAIL automatically and become regression tests for it.Related: #41 (mapped-file truncation), also from the stress suite.
@raynorpat commented on GitHub (Oct 15, 2026):
Fixed on the ffs-perf branch (merge
b148fd5beof issue-43):87848c750kernel: MAP_ANON (zero-fill, honours prot, MAP_SHARED shared across fork); mlock/munlock as new syscalls 177/178 (root only, ENOMEM for unmapped or unreadable ranges, EAGAIN past a third of memory wired); msync re-enabled at syscall 65 via vm_synchronize; madvise accepts the standard hints; mincore reports pages entered in the pmap. Also fixes vm_synchronize leaving pagerless pages busy forever (msync of a private or anonymous mapping would hang) and its share-map range translation.12607a01bLibc: mlock/munlock stubs for i386 and ppc.mlock/munlock numbers: Mac OS X Server 1.2 never had these calls, and 4.4BSD's 203 is NeXT's getdtablesize here, so they use the unused slots 177/178.
Tested on a snapshot v2 guest with the new kernel: a direct-syscall test passes for every call (anon private/shared/PROT_READ/PROT_NONE, mincore, madvise, mlock/munlock incl. exit while locked, msync of shared, private and anonymous mappings). stress-mmap anon PASS; with syscall shims for the missing Libc symbols, stress-vm wire and stress-mmap sync PASS. No panics. On installed systems wire/sync stay UNSUP until a Libc with the new stubs is installed.
sbrk/sstk stay unimplemented, as in 4.4BSD. It reaches master when ffs-perf is merged.