feat(libSceFreeType): implement the legacy memory allocators #12004

Merged
santhoshkumar-dev merged 12 commits from upstream-pr/12004 into main 2026-11-09 16:07:33 +00:00
santhoshkumar-dev commented 2026-10-27 16:37:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by santhoshkumar-dev on 2026-10-27T16:37:28Z.


What

Add the legacy allocator family FT_Alloc (Uw+BZJpflxk), FT_QAlloc (hz-J3hohXW8) and FT_Free (fHMsRluEMfI) to the physical libSceFreeType adapter. The functions operate on the guest GuestMemoryRec callback record already used by FT_List_Finalize. An independently authored implementation follows the allocator family retained for old internals in FreeType 2.4.12 ftutil.c; the bundled 2.13.3 build no longer contains these names, so nothing is forwarded to it.

The contract: allocation calls the guest alloc callback for positive sizes only, clears the guest output when the callback returns null and reports FT_Err_Out_Of_Memory, FT_Alloc zeroes successful blocks while FT_QAlloc leaves callback contents intact, zero sizes produce a null block without error, negative sizes report FT_Err_Invalid_Argument with a cleared output and no callback traffic, and FT_Free releases through the guest free callback and nulls the output only when a block was freed. The negative-size rejection follows the reference implementation's explicit else if ( size < 0 ) check in ft_mem_qalloc; the originally published head returned success there and is corrected in 02896e7445. Null records or outputs make the allocating helpers throw; the reference implementation dereferences them. FT_Free ignores null memory records, output pointers and blocks; this divergence is explicitly recorded in debt and covered by the fixture. The names/NIDs are in the PS5 3.20 inventory and match the PS4 tables. Console ABI is unverified and recorded in debt.

The matching OT inventory helper for FT_QAlloc is named sceFreeTypeOtQAlloc_nid_no_patch and declared once in libSceFreeTypeOt/include/MemoryAllocation.hpp, reachable through the Ot umbrella included by its export implementation; its no-parameter placeholder, explicit NID alias and throwing behavior remain. The Ol-provider stubs that current main added for FT_Alloc and FT_Free are named sceFreeTypeOlAlloc_nid_no_patch and sceFreeTypeOlFree_nid_no_patch and declared through the Ol umbrella header; their placeholders, explicit NID aliases and throwing behavior remain unchanged.

Ordering: submitted head 6b7a1c9446fb4baa14531190e0b62e0e273ad116 merges cleanly with main aaccd0ba39b7d40fdbf19664575a7e567d8542f7. The allocator debt entry was moved below the existing reference-face entry to avoid #12680's new top-of-section insertion; the whole-branch combination with #12680 head cf9b7c6b392164b03f0479afbf109023513e1e41 is clean. Registration remains outside the neighbouring arithmetic additions. #12373 is a stacked follow-up and depends on this PR; no other allocator implementation is claimed.

Tested

Current submitted head 6b7a1c9446fb4baa14531190e0b62e0e273ad116 adds review fixes to previously tested head 74276c468329afcb9a6054e94a0195bebde8cd48. The 70/70 full-library/focused-CTest results below refer to that earlier head, including main c02d287bd0; they were not rerun as a full product build for this header/debt/test-only follow-up.

Fresh October 29 follow-up checks on Windows 11 / WinLibs GCC 15.2.0 and Ubuntu under WSL / GCC 13.3.0: the public-header audit passes (368 libraries, 13,054 exports); standalone allocator/Ot umbrella headers compile together and twice; the Ot export translation unit compiles on Windows and compiles on Linux. Each platform freshly compiles the production MemoryAllocation.cpp and revised in-tree fixture as isolated artifacts, then passes three runs in each normal and repository-NID-patched export mode. Windows links the existing product libc import library for its custom unwind support; this is not a fresh complete libs build. The new checks verify that freeing with a null record preserves a live block and contents, null output pointers make no callback, and the retained block can subsequently be freed normally. Conventions and whitespace pass.

Windows 11 x64 / WinLibs GCC 15.2.0 r7 and local Ubuntu 24.04.1 x86-64 under WSL2 / GCC 13.3.0 / glibc 2.39: Ninja Release, bundled dependencies, BUILD_TESTING=ON, ANYPS5_ENABLE_SPIRV_TOOLS=OFF, in fresh build trees on each platform. On each platform the complete libs target (including all packaged-NID .prx patching) and selected test executables build, and 70/70 CTests pass: public-header audit, all 64 header compilation batches, both allocator export modes (unpatched names and packaged NIDs Uw+BZJpflxk/hz-J3hohXW8/fHMsRluEMfI), charmap checks and the packaged-library loader.

The fixture registers real guest callbacks in-process. Each mode verifies: FT_Alloc zeroing a callback-prepared dirty block; FT_QAlloc preserving the dirty pattern; the Out_Of_Memory error and cleared output when the callback returns null; FT_Free nulling the output after releasing, skipping null blocks and leaving the free counter unchanged; zero sizes producing null outputs without error or callback traffic; and negative sizes -1, -8 and INT64_MIN producing Invalid_Argument (6) with a cleared output and zero callback traffic. A standalone regression outside the repository compiled the revised fixture against the previously published allocator implementation (fails its negative-size assertion, exit 1) and against this head (passes, exit 0) on Linux.

No full application/test-suite, macOS, title or physical-console run is claimed.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5037607939 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12004). Originally posted by [santhoshkumar-dev](https://github.com/santhoshkumar-dev) on 2026-10-27T16:37:28Z. --- ### What Add the legacy allocator family `FT_Alloc` (`Uw+BZJpflxk`), `FT_QAlloc` (`hz-J3hohXW8`) and `FT_Free` (`fHMsRluEMfI`) to the physical `libSceFreeType` adapter. The functions operate on the guest `GuestMemoryRec` callback record already used by `FT_List_Finalize`. An independently authored implementation follows the allocator family retained for old internals in [FreeType 2.4.12 ftutil.c](https://github.com/freetype/freetype/blob/cecf93ef90c660a8b0b45e5adbbfb5ea443fb6b9/src/base/ftutil.c#L435-L500); the bundled 2.13.3 build no longer contains these names, so nothing is forwarded to it. The contract: allocation calls the guest `alloc` callback for positive sizes only, clears the guest output when the callback returns null and reports `FT_Err_Out_Of_Memory`, `FT_Alloc` zeroes successful blocks while `FT_QAlloc` leaves callback contents intact, zero sizes produce a null block without error, **negative sizes report `FT_Err_Invalid_Argument` with a cleared output and no callback traffic**, and `FT_Free` releases through the guest `free` callback and nulls the output only when a block was freed. The negative-size rejection follows the reference implementation's explicit [`else if ( size < 0 )` check in `ft_mem_qalloc`](https://github.com/freetype/freetype/blob/cecf93ef90c660a8b0b45e5adbbfb5ea443fb6b9/src/base/ftutil.c#L73-L89); the originally published head returned success there and is corrected in `02896e7445`. Null records or outputs make the allocating helpers throw; the reference implementation dereferences them. `FT_Free` ignores null memory records, output pointers and blocks; this divergence is explicitly recorded in debt and covered by the fixture. The names/NIDs are in the [PS5 3.20 inventory](https://github.com/DNNDHH/PS5-3.20_Libs/blob/b2a77c09cd71c01f34c790cfbe98c751a13262ad/libSceFreeTypeOt.c) and match the PS4 tables. Console ABI is unverified and recorded in debt. The matching OT inventory helper for `FT_QAlloc` is named `sceFreeTypeOtQAlloc_nid_no_patch` and declared once in `libSceFreeTypeOt/include/MemoryAllocation.hpp`, reachable through the Ot umbrella included by its export implementation; its no-parameter placeholder, explicit NID alias and throwing behavior remain. The Ol-provider stubs that current `main` added for `FT_Alloc` and `FT_Free` are named `sceFreeTypeOlAlloc_nid_no_patch` and `sceFreeTypeOlFree_nid_no_patch` and declared through the Ol umbrella header; their placeholders, explicit NID aliases and throwing behavior remain unchanged. Ordering: submitted head `6b7a1c9446fb4baa14531190e0b62e0e273ad116` merges cleanly with main `aaccd0ba39b7d40fdbf19664575a7e567d8542f7`. The allocator debt entry was moved below the existing reference-face entry to avoid #12680's new top-of-section insertion; the whole-branch combination with #12680 head `cf9b7c6b392164b03f0479afbf109023513e1e41` is clean. Registration remains outside the neighbouring arithmetic additions. #12373 is a stacked follow-up and depends on this PR; no other allocator implementation is claimed. ### Tested Current submitted head `6b7a1c9446fb4baa14531190e0b62e0e273ad116` adds review fixes to previously tested head `74276c468329afcb9a6054e94a0195bebde8cd48`. The 70/70 full-library/focused-CTest results below refer to that earlier head, including main `c02d287bd0`; they were not rerun as a full product build for this header/debt/test-only follow-up. Fresh October 29 follow-up checks on Windows 11 / WinLibs GCC 15.2.0 and Ubuntu under WSL / GCC 13.3.0: the public-header audit passes (368 libraries, 13,054 exports); standalone allocator/Ot umbrella headers compile together and twice; the Ot export translation unit compiles on Windows and compiles on Linux. Each platform freshly compiles the production `MemoryAllocation.cpp` and revised in-tree fixture as isolated artifacts, then passes three runs in each normal and repository-NID-patched export mode. Windows links the existing product libc import library for its custom unwind support; this is not a fresh complete `libs` build. The new checks verify that freeing with a null record preserves a live block and contents, null output pointers make no callback, and the retained block can subsequently be freed normally. Conventions and whitespace pass. Windows 11 x64 / WinLibs GCC 15.2.0 r7 and local Ubuntu 24.04.1 x86-64 under WSL2 / GCC 13.3.0 / glibc 2.39: Ninja Release, bundled dependencies, `BUILD_TESTING=ON`, `ANYPS5_ENABLE_SPIRV_TOOLS=OFF`, in fresh build trees on each platform. On each platform the complete `libs` target (including all packaged-NID `.prx` patching) and selected test executables build, and **70/70 CTests pass**: public-header audit, all 64 header compilation batches, both allocator export modes (unpatched names and packaged NIDs `Uw+BZJpflxk`/`hz-J3hohXW8`/`fHMsRluEMfI`), charmap checks and the packaged-library loader. The fixture registers real guest callbacks in-process. Each mode verifies: `FT_Alloc` zeroing a callback-prepared dirty block; `FT_QAlloc` preserving the dirty pattern; the `Out_Of_Memory` error and cleared output when the callback returns null; `FT_Free` nulling the output after releasing, skipping null blocks and leaving the free counter unchanged; zero sizes producing null outputs without error or callback traffic; and negative sizes `-1`, `-8` and `INT64_MIN` producing `Invalid_Argument` (6) with a cleared output and zero callback traffic. A standalone regression outside the repository compiled the revised fixture against the previously published allocator implementation (fails its negative-size assertion, exit 1) and against this head (passes, exit 0) on Linux. No full application/test-suite, macOS, title or physical-console run is claimed. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none <!-- #PR, or none --> - [x] Fixes: none <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: none <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: n/a <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes <!-- yes / no -->
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!12004
No description provided.