mirror of
https://github.com/RhapsodiOS/RhapsodiOS.git
synced 2026-11-03 22:01:40 -07:00
[GH-ISSUE #86] kernel: mmap and map_fd of an active swap file now fail instead of mapping a null pager #80
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#80
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 30, 2026).
Original GitHub issue: https://github.com/RhapsodiOS/RhapsodiOS/issues/86
Side effect of #84 (
eba20b6c5).vnode_pager_setup(vm/vnode_pager.c~657-665) returnsvm_pager_nullfor a vnode in use as a pager file (swap file) on thepager_fileslist. That was always true. Before #84, the callers didn't check:mmap(bsd/kern/kern_mman.c~342) andmap_fd(~791) went on and mapped the file with a null pager.Since #84 they treat a null pager as "reclaimed":
mmapreturns EBADF;map_fdreturns KERN_INVALID_ARGUMENT.Two things to decide:
vnode_pager_setup's callers.vnode_pager_setupskipsunix_release(), unlike the other returns. It leaves the unix master lock held.Check who maps swap files in practice (dynamic_pager / macx_swapon,
vm_stat-style tools) so nothing that worked before breaks.@raynorpat commented on GitHub (Oct 31, 2026):
Fixed by
1d3cb1f80, merged into ffs-perf in23c1dd5f6.Who maps swap files.
/etc/startup/0500_VirtualMemoryrunsmach_swapon -avfrom/etc/swaptab(/private/var/vm/swapfile).cp:file_cmds/cp/utils.c:152 mmaps any file of 8 MB or less.cpof a small swap file silently copied zero-fill pages.read().Telling the cases apart.
vnode_pager_setupreturns NULL in both cases, so callers checkv_vm_info. The function comment now says so.v_vm_infoset): mmap → ETXTBSY, map_fd → KERN_PROTECTION_FAILURE. ETXTBSY because the kernel is using the file as backing store, which is whatvn_writechkalready uses ETXTBSY for (vfs_vnops.c:226). The condition is temporary and applies to root too. EACCES would wrongly point at permissions.v_vm_infoNULL): unchanged from #84, EBADF / KERN_INVALID_ARGUMENT.exec of a swap file: EACCES at mode 1600, otherwise ENOEXEC (not Mach-O).
unix_release: the pager-file early return invnode_pager_setup(:663) now releases the unix master. The other returns ofvnode_pager_setupandvnode_pager_createwere already balanced. On these NCPUS 1 buildsunix_masteris a no-op, so the missing call only mattered for a multi-CPU kernel.Verified (kernel cksum 151843857):
mach_swapon. Ordinary files still map.stress-vm pressure(swap growing to about 420 MB) works.Left open:
map_vnode(mapfs.c:499) still carries on with a NULL pager for an active swap file. This is old behaviour, andread()of the swap file works.