fix(libc): implement mspace heap emptiness query #10397
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10397"
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 MarcZX10 on 2026-10-23T21:08:03Z.
What
Implement
sceLibcMspaceIsHeapEmptyby checking the arena's tracked live-allocation bytes, and route the PAF variant through the same query. The PS4 Developer Wiki confirms that both symbols exist, but does not document their signatures or behavior. fpPS4's cited lines are generic allocator bitmap helpers and do not implement either export. The valid-handle behavior here is inferred from the function name and remains unverified against PS5; unknown handles seterrnotoEINVALand throw because their console behavior is unknown.Tested
Mspacetest, compiled with GCC using C++20,-Wall -Wextra -Werror, passed after the follow-up and rebase. It covers empty, active, partially freed, fully freed, null-handle and unknown-handle cases.python3 tools/check_conventions.py --base upstream/mainandgit diff --check upstream/main...HEADpassed on the rebased head.python3 tools/pr_overlap.py --branch codex/fix-mspace-empty-invalid-handlereports the shared mspace debt paragraph with #10236; this PR depends on #10236 to retain both debt updates. Its uncomparable-file entries for #1060 and #4847 are unrelated AGC changes; neither changes the mspace source, test, or debt files.Checklist
main; no other open PR implements the same functionNotImplemented_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 harisibrar1 on 2026-10-24T01:10:31Z.
Review: COMMENTED
Checked against main
11d6efa06cand red-prig/fpPS4src/libcinternal/ps4_mspace_internal.pas:_sceLibcMspaceIsHeapEmpty(around lines 3509-3526, registered as$A7351AECA128C9DCinps4_libscelibcinternal.pas). For a user heap it returnscurrentInuseSize = 1440, and_sceLibcMspaceCreatesets 1440 as the starting value, so "empty" means no live user allocations. That's whatinUse == 0gives here, since main doesn't count its 64-byte header. It could be cited in the description and the debt entry as the source for the valid-handle behaviour.errnotoEINVALbefore the throw, and the test's== 22check, encode a value nothing supports. Maybe drop the errno write and that assertion, and have the debt entry note the PS4 result instead.tests/Mspace.cppdeclaressceLibcMspaceIsHeapEmpty_nid_postfixandsceLibcPafMspaceIsHeapEmpty_nid_postfixtwice.(libc) -the other entries have.int0/1, matching fpPS4'sIntegerand orbital'sint (void* msp)).Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-02T04:57:18Z.
Review: COMMENTED
Reviewed — two test expectations still open, current test matches production
The two requests on
Mspace.cppare still in head f3b8323, and the production code behaves as the test currently expects in both places.What I ran
Head
f3b832397ae390282cdd107ccba38bdcc9f6370b(live, OPEN). Read-only:gh pr view,gh apiGET on comments,git showandgit grepat the head. Nothing was built or run.Results
core/libs/tests/Mspace.cpp:135-140core/libs/tests/Mspace.cpp:148-150Mspace.cpp:291Mspace.cpp:208Findings
Mspace.cpp:291. Removing the test assertion leaves that production behavior unchanged. Your call whether to keep it.secondwithsceLibcMspaceFree_nid_postfixinstead ofsceLibcMspaceRealloc_nid_postfix(arena, second, 0). At head the realloc with size 0 on a used chunk callsReleaseand returns nullptr (Mspace.cpp:208), so the current test matches the current implementation. The firmware 13.42 measurement the reviewer cites is not in the repository, and I did not verify it.Sources
github.com/boykopovar/AnyPS5@f3b832397a/core/libs/tests/Mspace.cpp (L135-L150)github.com/boykopovar/AnyPS5@f3b832397a/core/libs/prx/libc/src/Mspace.cpp (L202-L210)github.com/boykopovar/AnyPS5@f3b832397a/core/libs/prx/libc/src/Mspace.cpp (L288-L292)Not verified
malloc(0)alternative the reviewer suggests (not run).Pull request closed