feat(libSceNKWebKit): implement bmalloc iso heap and TLS layout bookkeeping #22561
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/22561"
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 RiverWhy on 2026-11-17T20:50:50Z.
What
Implements 13 bmalloc Iso heap bookkeeping exports that all throw on
maintoday:Mutex&constructor,D0,didCommit,didDecommit,isNowFreeable,isNoLongerFreeableandaddToAllIsoHeaps.addandhead.size_tconstructor,D0andextent.add.This fills in the construction and destruction that the existing bmalloc class allocation operators debt entry leaves open. It uses the field layout that
FieldGetters.cppalready reads:footprintat 0x20,freeableMemoryat 0x28, andIsoTLSEntryoffset and size at 0x10 and 0x14.Source: pinned IsoHeapImpl.h/.cpp, IsoHeapImplInlines.h, IsoTLSEntry.h/.cpp, IsoTLSLayout.cpp and AllIsoHeaps.cpp (PS5 11.x). The pinned tree defaults to libpas on PlayStation, but the module exports these non-libpas symbols, so this follows the
!BUSE(LIBPAS)code, as the existing bmalloc entries do.Layouts were measured by compiling those files with libpas off:
lock, then zeroesm_next, the slow-path time, both counters and the eight 6-byte packed shared cells. It setsm_availableShared = 0xFF, the allocation mode toInitand the inline-directory flag to true, as the measured constructor does. The vtable is[D1, D0, scavenge].m_next = nullptr,m_offset = UINT_MAXandm_sizeto the low 32 bits of the size.extentadds the twounsignedfields before widening, so it wraps as upstream does. The vtable is[D1, D0, construct, move, destruct, scavenge].std::logic_error.D0frees through the classes'MAKE_BMALLOCEDoperator deleteexports already onmain.Other details:
IsoTLSLayout::addplaces each entry at its tail's extent rounded up to 8 bytes. ItsRELEASE_BASSERTs (entry already linked, offset reachingUINT_MAX, head without tail or tail without head) throwstd::logic_errorinstead of crashing.addToAllIsoHeapsadds to a hostAllIsoHeaps, because the module's per-process storage isn't exported. Theadd/headlocks and theIsoTLSLayoutadding lock are host mutexes.scavengeNowandfinishScavengingdecommit guest pages throughmadviseand call intoIsoDirectory, so they still throw.Debt: a fragment,
docs/dev/debt/changes/feat-nkwebkit-bmalloc-iso-heap-bookkeeping.md, adds the entry and removes the 13 inventory rows.Overlap:
pr_overlap.pyfinds no open PR with these exports. It couldn't compare 19 NKWebKit PRs that conflict withmain(#13515, #14138, #14164, #14259, #14860, #15184, #16510, #17695, #17771, #17793, #17805, #17922, #17927, #17929, #17933, #18395, #20319, #21957, #21958); I checked their diffs by hand and none mention these classes. The only reported conflict is the shared last include line oflibSceNKWebKit.hpp(#18797, #18805, #20327, #21422, #21432, #21979, #22449–#22456, #22480–#22482, #22555–#22557).Tested
Linux Mint 22.3. A shared driver runs random sequences on 4 heaps and up to 96 entries:
AllIsoHeapsand walking the chain;IsoTLSLayout, and reading offsets and extents.It hashes the constructed objects' bytes (outside the vtable and lock pointer), every counter, offset, extent and list order. The hash is compared with the one from the real 11.x
IsoHeapImpl/IsoTLSEntry/IsoTLSLayout/AllIsoHeapscode, compiled with libpas off and running the same driver.nkwebkit_bmallocisoheaptest: 16 sequences of 1,000 operations match. As a one-off, 300 sequences of 10,000 also matched.IsoTLSLayout::addassertion;addToAllIsoHeapson the host list;footprint,freeableMemory,sizeandoffsetgetters reading the constructed objects.extentfails the transcript check.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 PrivacyOnion on 2026-11-17T20:54:30Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
e333f6f4ea:tools/check_conventions.pypassed.nkwebkit_bmallocisoheap_testsbuilt cleanly.nkwebkit_bmallocisoheap):core/libs/prx/libSceNKWebKit/Export.cpp,core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp,core/libs/prx/libSceNKWebKit/libSceNKWebKit.hpp,core/libs/prx/libSceNKWebKit/src/BmallocIsoHeap.cppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-17T23:55:26Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
4dc35bba30:tools/check_conventions.pypassed.nkwebkit_bmallocisoheap_testsbuilt cleanly.nkwebkit_bmallocisoheap):core/libs/prx/libSceNKWebKit/Export.cpp,core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp,core/libs/prx/libSceNKWebKit/libSceNKWebKit.hpp,core/libs/prx/libSceNKWebKit/src/BmallocIsoHeap.cppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.Looks Good To Me