feat(libkernel): implement madvise #1633
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1633"
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 babyhuey on 2026-10-08T15:20:31Z.
What
Implements
madvise(Jahsnh4KKkg) in libkernel. Part of #1578: PPSA99039 and PPSA99001 import it.Follows FreeBSD 11
kern_madvise(sys/vm/vm_mmap.c) andvm_map_madvise(sys/vm/vm_map.c):behavoutsideMADV_NORMAL..MADV_CORE(0..9) fails withEINVAL.VM_MAXUSER_ADDRESS(0x800000000000on amd64) fails withEINVAL. Unmapped holes are not an error.MADV_DONTNEEDonly lowers page priority andMADV_FREElets the kernel discard pages, so keeping the contents is valid for both; the call returns 0 without touching memory.MADV_PROTECT(10) goes throughprocctl(PROC_SPROTECT)and its privilege check on FreeBSD, so it callsNotImplemented_nid_no_patch.Tested
Linux (Ubuntu 24.04, GCC 13, Release):
guest_memorypasses with--repeat until-fail:3. It now checks all ten values on anmmaprange with its contents intact afterwards, a zero length, an unmapped range, invalid values (also with zero length), a wrapping range, a start at0x800000000000and a range ending exactly there. The test fails when the range check is removed.check_conventions.pypasses. Windows:PosixMemory.cppcompiles with MinGW-w64 GCC 13 (-Wall -Wextra -fsyntax-only); not run on Windows. No title run.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 klosixgaming-arch on 2026-10-08T15:33:07Z.
Review: APPROVED
LGTM. Clean implementation of madvise following FreeBSD semantics with proper validation (advice range 0-9, address bounds) and correct handling of MADV_PROTECT as unimplemented. The test coverage is excellent - testing all valid advice values, edge cases (zero length, invalid values, wrapping ranges), boundary conditions at the user address limit, and verifying contents remain intact after advisory calls. Good addition to support PPSA99039 and PPSA99001's import requirements.
Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-08T17:37:07Z.
Fork CI while the upstream run waits for approval: Build run, all jobs green on d5a4ac17 (Linux 466/466, Windows 457/457, relinker on Linux, macOS and Windows). It builds the branch head, not the merge with
main.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-08T21:25:39Z.
Progress report (
c9da0f9→d7e52cb)📉 System libraries: 85.67% (-0.03%, +1 declared functions)
🆕 1 declared as stubs
madvise_nid_postfixImported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-08T22:57:42Z.
Titles that stop on
madviseon currentmain. Linux, Ubuntu 24.04 container, GCC 13, Release,maind64134f0(relinkerandlibs); titles from the homebrew catalog, relinked for Linux and run from the title folder.mainapp.elf: symbol lookup error: app.elf: undefined symbol: Jahsnh4KKkg(madvise)JZKw5+Wrnaw(pthread_sigmask)app.elf: symbol lookup error: app.elf: undefined symbol: Jahsnh4KKkg(madvise)JZKw5+Wrnaw(pthread_sigmask)The "with this branch" build also had my other open PRs merged; only this branch exports
Jahsnh4KKkg.Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-09T01:34:47Z.
Windows follow-up. The two
madvisetitles above don't relink with--windowsonmain(LSDA check, fixed in #1944). With #1944 and this branch merged (Windows 11, WinLibs GCC 15.2.0 r7,mainf1451396), both get pastmadvise:FAIL: unresolved ELF import JZKw5+Wrnaw from libkernel.prx(pthread_sigmask)FAIL: unresolved ELF import JZKw5+Wrnaw from libkernel.prx(pthread_sigmask)Imported from boykopovar/AnyPS5. Originally posted by popcoder565 on 2026-10-09T10:00:51Z.
First Windows run, since the description says it was only compiled with MinGW. Setup: Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. #1624, #1628, #1633 and #1634 merged together onto
mainb7218b3c.guest_memory, which carries this PR'smadvisecases, passes.🤖 Addressed by Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-10T04:17:58Z.
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)madvise_nid_postfix