feat(libkernel): accept MADV_PROTECT advisory hint in madvise #4582
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4582"
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?
Imported from boykopovar/AnyPS5. Originally posted by jagrat04 on 2026-10-12T16:09:36Z.
What
Accepts MADV_PROTECT (10) as a valid advisory hint in madvise in libkernel. In FreeBSD, MADV_PROTECT protects the process from OOM termination. Like the other madvise hints (0-9), user-mode emulation accepts it as a no-op hint without terminating the process via NotImplemented_nid_no_patch. Updates unit tests in GuestMemory.cpp and documents Technical Debt.
Tested
Guest unit tests in core/libs/tests/GuestMemory.cpp
Checklist
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-12T16:10:38Z.
Progress report (
43e3a70→59bd0c1)📈 System libraries: 87.89% (+0.02%, +1 implemented functions)
✅ 1 implemented
madvise_nid_postfixImported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-12T21:02:38Z.
Review: CHANGES_REQUESTED
Thanks for the PR. Before this can go in:
madvisewithMADV_PROTECTis not an address-range hint in FreeBSD:kern_madvise(sys/vm/vm_mmap.c) handles it before the address check, ignoresaddr/len, and callskern_procctl(..., PROC_SPROTECT, PPROT_SET)on the calling process. HerePosixMemory.cpp:229still validates the range for advice 10, somadvise(0, 0xFFFFFFFFFFFFF000, 10)returnsEINVALwhere FreeBSD does not look at it. Please make advice 10 skip the range check, or keep throwing.PROC_SPROTECTneeds privilege (PRIV_VM_MADV_PROTECT) and fails otherwise, so returning 0 unconditionally is a guess, not the exact result. If you keep it as a stub, say which result it follows and why in the TechnicalDebt line (docs/dev/debt/libkernel.md:146), and citevm_mmap.c.core/libs/tests/GuestMemory.cpp:1969only adds advice 10 with a valid range. Add a row with an invalid range for advice 10, so the test pins the behaviour chosen above.madvise(MADV_PROTECT). Without one, the previous explicit throw is the exact-or-throw choice; please add the title/PPSA (or log) that hits it.Feel free to push the changes and ping me.
Imported from boykopovar/AnyPS5. Originally posted by jagrat04 on 2026-10-12T22:54:02Z.
Updated as requested:
Imported from boykopovar/AnyPS5. Originally posted by nicolasfalesy on 2026-10-13T07:36:14Z.
Linux test (Arch, GCC 16.2.1, glibc, Release), this PR merged onto
main7e181fcc3together with #4725, #4719, #4585 and #4582 (no conflicts):guest_memorypasses. With this PR's source change reverted (test kept), it fails on Linux, so the check guards the change on Linux too.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T07:44:15Z.
Review: APPROVED
Checked against FreeBSD
kern_madvise: advice 10 now returns before the range validation, the debt entry documents the privilege assumption, and the newguest_memoryrows fail with the source change reverted. Build and ctest green locally (also confirmed on Linux by @nicolasfalesy); merging.