feat(libkernel): accept MADV_PROTECT advisory hint in madvise #4154
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4154"
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-12T00:06:45Z.
What
Accept
MADV_PROTECT(10) as a valid advice parameter inmadvise:MADV_PROTECTinforms the kernel to protect the process from being killed when memory is exhausted (OOM protection hint).core/libs/tests/GuestMemory.cppto verify advice up to 10 (MADV_PROTECT) returns success, while values > 10 returnEINVAL.docs/dev/TechnicalDebt.md.Tested
python tools/check_conventions.py --base origin/mainpassed with 0 violations.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-12T00:19:13Z.
Progress report (
bca7a29→e6bf54d)📈 System libraries: 86.5% (+0.03%, +1 implemented functions)
✅ 1 implemented
madvise_nid_postfixImported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-12T00:37:05Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/libs/prx/libkernel/DirectMemory/PosixMemory.cppL228docs/dev/TechnicalDebt.mdL23-24Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-12T01:29:19Z.
#4053: the fix applies a pattern that's already working elsewhere in this file rather than inventing new logic —
close_nid_postfix,sceKernelRead, andsceKernelWritealready route guest-socket-range descriptors toGuestSockets::Closethe same way this adds forsceKernelClose, and a closed or unknown socket still returns the sameEBADFbefore and after, so there's no behavior change for anything that already worked.The conflict with open #3764 is real but lower-severity than it might read: #3764 does add
EqueueDescriptorClosed(d)as the very first line, at the same position this PR's socket check would occupy, so the two will textually conflict on merge. But tracing whatEqueueDescriptorClosedactually does, calling it twice (once from #3764's line, once again insideGuestSockets::Close) is harmless — it's an idempotent erase-if over the equeue's event list, not a refcount decrement or a free. So whichever lands second just needs the socket check to run before the redundant equeue call, which is a one-line reordering, not a functional fix.#4154: the no-op treatment is safe, and it's consistent with how this function already treats every other advisory-only hint in range —
MADV_DONTNEEDis already accepted as a pure no-op, andMADV_PROTECT's real FreeBSD semantics (don't kill this process under swap pressure) is exactly the kind of hint a host can't grant anyway, so ignoring it only forgoes a hint, not a requirement. The value 10 matches FreeBSD's own ordering forMADV_PROTECT. One cosmetic note: removing this throw leaves theGuestAdviceCoreconstant with no remaining reference — dead but harmless, since nothing in this build is-Werror=unused.Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-12T08:28:22Z.
Closing: no title is shown to call
madvisewithMADV_PROTECT, and FreeBSD passes it toPROC_SPROTECT, which fails withEPERMwithoutPRIV_VM_MADV_PROTECT(see #3795), so returning 0 isn't shown to be what the console does. Reopen with the title ID and the log line where it stops on main.Pull request closed