fix(libkernel): return error codes for failed fixed virtual range reservations #10192
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10192"
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 Mohabbadi11 on 2026-10-23T12:37:15Z.
What
When
sceKernelReserveVirtualRangeis called with a fixed address that cannot be mapped because it lies outside the guest address space arena, conflicts with an existing reservation under no-overwrite, or overlaps an occupied guest arena range, returnSCE_KERNEL_ERROR_EINVALorSCE_KERNEL_ERROR_ENOMEMinstead of terminating the process with an unhandled C++ exception.Tested
guest_memory_lifetime: Passedguest_memory: Passedguest_mmap_fixed_anonymous: Passed5095176cctools/check_conventions.py --base origin/mainpassed (0 errors, 0 warnings).9db8310b48by contributors; it has not been rerun locally on this head.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T12:40:26Z.
Review: CHANGES_REQUESTED
Reviewed exact head
7ca63e1899e7b667f6def659a3e4c6fe5d975cf4. The error conversion is directionally consistent with #10143, but this head adds no runtime regression test: the reported 898tools/testsPython tests and conventions check do not exerciseDoReserveVirtualorsceKernelReserveVirtualRange, and the hosted checks so far are intake/conventions/labels only. Please add a focused C++ regression that forces a fixed reservation placement failure, asserts a documented guest error and unchanged output/guest mapping state, and run the relevant memory tests on Linux and Windows. The issue discussion also records the handoff to babyhuey for this wrapper/test and title runs; please confirm coordination with them in #10143 so this remains one contribution. I have not approved until the runtime behavior and overlap/ownership are clear.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T12:57:15Z.
Review: CHANGES_REQUESTED
Re-review of exact head
6dbe5125ac22c671bbd549a1686609e1c3ce8264: the new outside-arena case now exercises the public API and checks the returned guest error, unchanged input pointer, and absent guest mapping. One claimed path is not actually protected by a regression yet. InCheckFixedVirtualReservation, the existing0x90conflict check still setsrefused = trueboth when the API returns an error and when it throws;Require(refused)therefore passes under the old exception behavior. Please make this assertion require a nonzero return without accepting an exception (a thrown exception should fail the test), and verify the reservation/output state is unchanged. The issue response says this case returns an error instead of throwing, so pinning that behavior will cover the no-overwrite branch separately from the outside-arena test. Current hosted checks are conventions and labels only; they pass, but the focused C++ test has not yet run in hosted CI.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T14:38:46Z.
Review: CHANGES_REQUESTED
Re-review of exact head
03f74c5eaff27cc57c768884f7190e3d402847d6. The newCheckFixedVirtualReservationnow requires a nonzero conflict result without accepting an exception, checks the caller's pointer is unchanged, and verifies the existing direct mapping remains queryable. The outside-arena case also checks an error result, unchanged pointer, and no guest mapping. That resolves my prior assertion blocker.The remaining blocker is runtime validation of the new C++ test. The only hosted checks currently reported for this head are conventions and labels; they do not build or execute
GuestMemory.cpp. The PR body reports 898 Python tool tests, which do not exercise this API. I attempted a local full Linux configure from this exact checkout, but it cannot proceed because the pinned3rdparty/SDL2checkout has no source/CMakeLists and the host lacks XRandR development support. Please run the focused guest-memory test on Linux and Windows (and, if available, the PS5X360 regression from #10143) on this exact head or its refreshed combined head, and report the commands/results. Current main also changed the touched files since the merge base, so please refresh before the final rerun.I have not approved this head pending that runtime evidence. No request to close either contribution.
Imported from boykopovar/AnyPS5. Originally posted by ahmadmuj on 2026-10-25T12:37:45Z.
Review: COMMENTED
Checked head
0ec885c89973merged onto main29ce6d87eb5b(clean merge). Linux, GCC 13.3, Release.What I ran:
guest_memory_tests;ctest -R '^guest_(memory|mmap_fixed_anonymous)$'is 2/2 green, 3 runs. So the:1073failure from the earlier run is gone with the0x4000addressGuestMemory.cppaborts withunhandled exception 'St13runtime_error' ... fixed mapping 0x200104000+0x8000 overlaps a registered guest allocation, so the0x90check really pins the new return0x3000, fixed at0x4000all go from a throw toEINVAL; fixed0x10on a free arena range still returns 0 on bothThings to change:
A fixed
0x10reserve (no0x80) that only partly overlaps a live mapping now returnsENOMEM. Probe: direct map 2 pages at0x200000000, then reserve 2 pages fixed at0x200004000. Main throwsoverlaps a registered guest allocation; this PR returns0x8002000cand leaves the old mapping in place. A full overlap still replaces (the existing test case). FreeBSD 11.4vm_map_fixeddeletes the old range whenMAP_CHECK_EXCLisn't set (vm_map.c#L1457-L1458, already cited inlibkernel.md), andDoMapDirect,DoMapAnonand the file-backed map do that throughReplaceFixedOverlap(DirectMemory.cpp:997). So that's an emulator gap, and thecatchatDirectMemory.cpp:1440turns it into a silent error. I'd catch only the no-overwrite case there, or replace likeReplaceFixedOverlapdoes.The debt entry doesn't match the code anymore:
EINVAL... when the host refuses the placement": the Windows case from #10143 (fixed guest mapping 0x10000+0x150000 overlaps a host region) is astd::runtime_errorfromKernelArena::MarkUsed, so it hits the lastcatch (const std::exception&)(DirectMemory.cpp:1454) and returnsENOMEM. Read only, I didn't run Windows.0x10000now, and0x40000000/0x50000000are inside it. Outside the arena only means below0x10000(or below0x200000000on macOS).The catch-alls hide more than placement failures. In
Export.cpp:343the null-outputstd::invalid_argumentfromValidateOutputbecomesEINVAL, and so do internal ones like a failedmutation.Add. A null output is a caller bug, and the console's answer for it isn't sourced, so per the throw-on-unknown rule I'd let those throw and only catch whatDoReserveVirtualmaps itself. (Guarded()inMemoryPoolExport.cppdoes the same thing, so this one is your call.) The emptycatch (...)around_releaseFlexible(Export.cpp:349) can only seebad_allocor a mutex error, and the sibling exports atExport.cpp:263-281call it bare. I'd drop it.Not checked: Windows, macOS, PS5X360 (no dump here), what the console returns for a partial fixed overlap.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T21:36:54Z.
Review: COMMENTED
Re-reviewed exact head
969089d9393c63a9fd9f7ff19c06bd83a6f08335. This update addresses the earlier behavior concerns I can verify in the diff: partial overlaps without the no-overwrite flag now retain the existingRequireAvailableexception path, the broad wrapper catch and_releaseFlexiblecatch are removed, and the debt entry now distinguishes outside-arenaEINVALfrom placementENOMEM.The current hosted checks are conventions and labels only. The Linux
guest_memory_tests/ctestresults in the discussion were run on parent head0ec885c89973915275cf218afb6285e31899985b, before these changes; the PR body’s Python suite does not exercise this C++ API. Please rerun the focused guest-memory test on this exact head and include the command/result, especially the fixed partial-overlap behavior and the0x90no-overwrite error case. I did not have a configured local build available for this revision, so this is a comment-only follow-up, not an approval.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-26T15:31:50Z.
Review: DISMISSED
Thanks for the update; the
0x90and0x4000cases are pinned well. Remaining points:core/libs/prx/libkernel/DirectMemory/DirectMemory.cpp:1450:catch (const std::exception&)(and thestd::bad_allocone above it) turns any failure ofMapAlignedintoENOMEM, for non-fixed reservations too, which previously threw. Please scope the conversion to the fixed case and the exceptionsMapAlignedis known to throw for a placement failure; anything else should keep throwing.DirectMemory.cpp:1447: astd::system_erroron a fixed reservation returnsEINVAL, but thedocs/dev/debt/libkernel.mdentry says host placement failure returnsENOMEM. Make code and entry agree and say which reference the errno follows (FreeBSDvm_map_findfailure on a fixed range isENOMEM).Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T08:05:27Z.
Review: CHANGES_REQUESTED
Rechecked exact head
7960d91da67ba02f30ae3af0d7fc4e7a82693ec1against currentmain4c7d275bef89.Findings
Blocking — the native placement-error conversion is untested. The new
hostOccupiedcase does not reach thestd::system_errorcatch aroundMapAligned: the implementation detects the occupied guest-arena range first withGuestArenaNextUsed_nid_no_patchand returnsSCE_KERNEL_ERROR_ENOMEMbefore callingMapAligned. The author’s 10/28 note confirms that this is the path the test exercises. Thus the regression proves the preflight collision response, but not that an actual host placement failure is translated correctly. Please either add a deterministic test that reaches theMapAlignedstd::system_errorcatch, or remove that conversion if it cannot be exercised and supported. Keep the separate preflight collision test.The earlier review concerns about limiting conversion to fixed reservations, letting unrelated runtime errors propagate, the
0x90result, and the FreeBSD-derivedENOMEMdocumentation are addressed in this head. The current-main merge preview is clean andgit diff --checkpasses.Validation
The author reports the focused Linux memory tests passing 3/3 on this head. Windows has not been rerun after the latest change. I did not build or run these tests locally, and I did not test console behavior.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-10T19:31:44Z.
Review: APPROVED
Reviewed — looks good
Reviewed exact head
5095176ccd95c0feacf66663a81ed264e2e5b3ccagainst currentmain56c80b0917c40b08248be1a0e172e56690678df5; the earlier behavior, regression-test, and validation concerns are addressed.What I ran
Environment: Linux 6.1, Python 3.11.2, GCC-compatible
c++12.2.0. The exact head merges cleanly in a preview against the currentmaintip.Results
main.conventionsandlabelschecks pass; no required checks are configured for this branch.Full no-build precheck results and evidence
GuestMemory.cppinguest_memory_testsand CTest'sguest_memory.The author reports Linux WSL Ubuntu 22.04 / GCC 11.4 Release runs on this head:
guest_memory_lifetime,guest_memory, andguest_mmap_fixed_anonymouseach passed 3/3. B-Howell and JJenkx report Windows runs on this head:guest_memoryandguest_mmap_fixed_anonymouseach passed 3/3. These are contributor-reported, not runs I performed. B-Howell's Windows control kept the test but restoredDirectMemory.cppto the main implementation;guest_memorythen aborted while the fixed-anonymous test passed. The same failure split is reported on Linux.Negative control
Contributor reports on exact head
5095176ccd95c0feacf66663a81ed264e2e5b3ccsay the test fails when the oldDirectMemory.cppimplementation is restored, so the regression detects the original failure. I did not execute this control locally.Findings
Blocking
None in the reviewed three-file diff.
Non-blocking
None.
Sources
Not verified
I did not compile or run the C++ tests locally, and no PS5/title behavior was tested. Contributor test runs were on the exact head but their merge previews used earlier
maintips than this review's current-base preview.