feat(libfontconfig): implement font and object set lifecycles #15283
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15283"
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 hyvvs on 2026-11-02T22:41:28Z.
What
Implement five typed guest-ABI libfontconfig exports
FcFontSetCreate,FcFontSetAdd,FcFontSetDestroy,FcObjectSetBuildandFcObjectSetDestroy, now matching firmware 13.42libfontconfig.sprxdisassembly rather than generic desktop Fontconfig's ownership and allocation rules. Module SHA-25674d7414445f8687c1d22a92fa3c994d2e5fa304e6699dc84dcc5459af7da8472was supplied in BunnyFl's review.FcFontSetAddduplicates the pattern through a correctly typedFcPatternDuplicate(const FcPattern*), leaving caller ownership intact; the set owns that duplicate andFcFontSetDestroydestroys each duplicate. Capacity is stored in bytes, growing by 128 (16 pattern pointers), capped at 8,192 bytes / 1,024 entries. The 1,025th insertion returns false.FcObjectSetBuildcounts sentinel-terminated names, allocates theFcObjectSetheader and its pointer array in one allocation, storesobjects=(set+1), setssobject=8*n, and duplicates strings in original argument order, including repeated names. Linux and MinGW Windows both read guest SysV variadic arguments. Destruction releases each name and the one header/array allocation.Dependencies: Nonempty
FcFontSetAddandFcFontSetDestroyrequireFcPatternDuplicateandFcPatternDestroyfrom #14435, which itself depends on #14392. The pattern duplicate/destroy symbols still throw in this branch until that PR is merged or rebased in. Do not claim populated font sets work on unmodified main. Test code supplies typed pattern duplicate/destroy mocks. This PR contributes exactly 5 newly callable export definitions on its branch, conditional on dependent pattern support, not to upstream main yet.Tested
g++ -std=c++20 -O2 -DNDEBUG -Wall -Wextra -Werror -pedantic -Icore/libs core/libs/tests/GuestFontconfigSets.cpp core/libs/prx/libfontconfig/Sets.cpp, linked executable ran with exit 0; Release assertions forced active. Verifies 1,024 successful adds, one refused extra, duplicate ownership and independent caller destruction; exact byte capacities 128 through 8192; System V variadics; preserved object-name order and inline pointer array.-fsanitize=address,undefinedandASAN_OPTIONS=detect_leaks=1:halt_on_error=1 UBSAN_OPTIONS=halt_on_error=1, exit 0, no sanitizer reports.git diff --checkclean. Conventions and remote CI rechecked on new commit. No console or firmware-runtime execution or full integrated CMake/CTest run performed. No claim of native Fontconfig 2.15.0 matching since firmware semantics intentionally differ.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 BunnyFl on 2026-11-03T02:58:53Z.
Review: CHANGES_REQUESTED
The PR follows Fontconfig 2.15.0, but firmware 13.42's own
system_ex/common_ex/lib/libfontconfig.sprx(sha25674d7414445f8687c1d22a92fa3c994d2e5fa304e6699dc84dcc5459af7da8472) implements these sets differently. It's a C++ implementation, not upstreamfcfs.c/fclist.c. Everything below is from disassembly only, with each body read to its return, and is not measured on a console. The exports are 5-bytejmps to the bodies at0x65d0(FcFontSetCreate),0x6650(FcFontSetAdd) and0x65f0(FcFontSetDestroy). Call names are resolved through the module's PLT/GOT and the public NID database.1.
FcFontSetAddstores a duplicate, not the caller's pattern. This is the blocking point.On the console the caller keeps ownership of its pattern. Code written for it may destroy the pattern after adding it. With this PR, the set then holds a freed pointer, and
FcFontSetDestroydestroys it a second time.2.
sfontis a byte count, the set grows by 16 entries, and it stops at 1024.So a guest reading
sfontsees 8 × the capacity. Growth is 0x80 bytes (16 entries), not 32 entries, and the 1025th add returns 0.3.
FcObjectSetBuild(0x35f0) keeps argument order in one allocation. It collectsfirstand the varargs up to NULL into a temporary list. It then makes a singlemalloc(16 + 8*n)block withnobject = nat +0,sobject = 8*nat +4, andobjectspointing at the inline array at +16. Each name isstrduped in argument order:The PR sorts
objectsby pointer address and grows in steps of 4 (core/libs/prx/libfontconfig/Sets.cpp:26-45on this head), so a guest walkingobjectssees a different order.firstis stored without a null check (at0x369b,mov %r15,0x10(%rax)), soFcObjectSetBuild(NULL)presumably reachesstrdup(NULL). I didn't follow that path past0x3794.4. Null handling.
FcFontSetDestroy(65fa: mov 0x8(%rdi),%rdi) andFcObjectSetDestroy(382b: movslq (%rdi),%r14) dereference their argument with no null check. The PR returns early instead. That's fine as a host-safety choice ifdocs/dev/debt/libfontconfig.mdsays so.FcFontSetCreatematches the PR's layout:operator new(16)zeroed (65d4–65e2), so{nfont, sfont, fonts}at 0/4/8.Could you rebuild these from the module's contract: duplicate on add, byte-sized
sfont/sobject, 16-entry growth and the 1024 cap, argument order? Tests should usemainas the negative control. Point 1 also affects #14435: the firmware's patterns are 0x48-byte objects (FcPatternDuplicate,93b: mov $0x48,%edibeforeoperator new), andFcPatternReferenceislock incl (%rdi)(0x9f0), a reference count at offset 0.Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-04T03:48:25Z.
Review: APPROVED
@hyvvs thanks, all four points from my review are addressed at
d7685faff1. Compared with the firmware 13.42 reading I posted:FcFontSetAddstoresFcPatternDuplicate(pattern), andFcFontSetDestroydestroys the copies the set owns.sfontis a byte count that grows by 128 (16 entries). Adds stop once it reaches 8192, i.e. 1024 entries. That is the module's(sfont & 0x1ff8) + 0x80growth with itscmp $0x1fff/jacap.FcObjectSetBuild: onemalloc(16 + 8n)withnobject = n,sobject = 8n, the objects inline, and copied names in argument order.What I ran: head
d7685faff1merged ontomain1c8c0efc8c, Windows 11, WinLibs GCC, Release:guest_fontconfig_setsandpublic_headerspass (2 of 2);patterninstead of the duplicate:guest_fontconfig_setsfails atGuestFontconfigSets.cpp:44(set->fonts[j] != pattern);GuestFontconfigSets.cpp:43(set->sfont == ((j / 16) + 1) * 128);tools/check_conventions.py --base upstream/mainon the head: all checks passed.Two things to know, not blocking:
d848a0885c), this head conflicts incore/libs/prx/libfontconfig/CMakeLists.txt(add/add),Export.cpp,include/InventoryExports.hppanddocs/dev/debt/libfontconfig.md. So it needs a rebase once #14435 lands, and I couldn't run the two together.tools/pr_overlap.py --branchalso lists #14392, #15294 and #15363 as touching the same files.FcObjectSetBuild(NULL). It returns an empty set here, where the module storesfirstwithout a null check (0x369b) and presumably reachesstrdup(NULL). If you want the debt entry complete, that's a third host-safety case next to null add and null destroy.Approving.