feat(libSceFreeType): implement the legacy reallocation helpers #12373

Merged
santhoshkumar-dev merged 11 commits from upstream-pr/12373 into main 2026-11-09 23:45:47 +00:00
santhoshkumar-dev commented 2026-10-28 11:46:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by santhoshkumar-dev on 2026-10-28T11:46:44Z.


What

Add the legacy reallocation family FT_Realloc (HVSaZbxYi2s) and FT_QRealloc (KVbmKCGGowg) to the physical libSceFreeType adapter, completing the allocator family from #12004. Both take the guest GuestMemoryRec, a current size, a new size and a guest in-out block pointer. The names/NIDs are in the PS5 3.20 inventory and re-derive from the repository's own NID hash; open/closed/merged history has no other implementation.

The contract follows ft_mem_qrealloc with unit item size in FreeType 2.4.12: negative current or new size report Invalid_Argument and keep the guest output; a zero new size releases the block through the free callback and clears the output; sizes above INT_MAX report Array_Too_Large and keep the output; an empty current takes the zeroing allocation path (the reference's fresh path uses the zeroing allocator for both variants); a growth callback that returns null reports Out_Of_Memory while keeping the previous block in the output; and only FT_Realloc additionally clears the grown region. Null records or outputs make the helpers throw; the reference implementation dereferences them. Console ABI is unverified and recorded in debt.

The matching OT inventory helpers are named sceFreeTypeOtRealloc_nid_no_patch and sceFreeTypeOtQRealloc_nid_no_patch and declared once in libSceFreeTypeOt/include/MemoryAllocation.hpp, reachable through the Ot umbrella included by the export implementation; their no-parameter placeholders, explicit NID aliases and throwing behavior remain.

Ordering: Depends on: #12004. This branch now includes that PR's reviewed allocator fixes at 6b7a1c9446fb4baa14531190e0b62e0e273ad116. After #12004 lands, this PR will be refreshed to retain only the reallocation follow-up. Submitted head 94b05e61d0b834554672e1ddf061c41e4fecca89 merges cleanly with current main aaccd0ba39b7d40fdbf19664575a7e567d8542f7. The Ot allocator declarations are separated from the shared FreeType header, and the allocator/debt additions use distinct anchors from the other pending FreeType contributions. The acceptance side of the INT_MAX boundary (a 2 GiB allocation) is not exercised to keep CI bounded; the rejection side is covered.

Tested

Current submitted head 94b05e61d0b834554672e1ddf061c41e4fecca89 carries the allocator review corrections without changing the allocation/reallocation implementation from previously tested head 22dfb9f66b56dbb6d6b8c95f07232758f335d1db. The 70/70 full-library/focused-CTest results below refer to that earlier head, based on #12004 head 74276c4683 and main c02d287bd0; they were not rerun as a full product build for this header/debt/test-only follow-up.

Fresh October 29 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,056 exports), the canonical public headers compile independently and together, and the Ot export translation unit compiles. Each platform freshly compiles production MemoryAllocation.cpp and the revised in-tree fixture as isolated artifacts, then passes three runs in each normal and repository-NID-patched export mode. The fixture retains all allocation/reallocation cases and adds null-record/null-output FT_Free calls that preserve a live block, contents and callback counts until normal release. Windows uses the existing product libc import library/binaries for custom unwind support. This is not a fresh complete libs build. 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, the allocator fixture's both export modes (unpatched names and packaged NIDs Uw+BZJpflxk/hz-J3hohXW8/fHMsRluEMfI/HVSaZbxYi2s/KVbmKCGGowg), charmap checks and the packaged-library loader.

The fixture registers counting guest callbacks with a deterministic realloc (preserves the prefix, fills growth with a marker). Each mode verifies, for both helpers: the fresh path returning zeroed contents; growth preserving a written prefix while FT_Realloc clears the grown region and FT_QRealloc leaves the callback's marker there; -1, INT64_MIN current and size, and size 2147483648 producing Invalid_Argument/Array_Too_Large with the output pointer kept and zero callback traffic; zero size releasing through the free callback and clearing the output, with a null block producing no release; a failing growth callback producing Out_Of_Memory with the previous block kept and no free; and a failing fresh allocation producing Out_Of_Memory with a cleared output.

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: #12004
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5049933861 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12373). Originally posted by [santhoshkumar-dev](https://github.com/santhoshkumar-dev) on 2026-10-28T11:46:44Z. --- ### What Add the legacy reallocation family `FT_Realloc` (`HVSaZbxYi2s`) and `FT_QRealloc` (`KVbmKCGGowg`) to the physical `libSceFreeType` adapter, completing the allocator family from #12004. Both take the guest `GuestMemoryRec`, a current size, a new size and a guest in-out block pointer. The names/NIDs are in the [PS5 3.20 inventory](https://github.com/DNNDHH/PS5-3.20_Libs/blob/b2a77c09cd71c01f34c790cfbe98c751a13262ad/libSceFreeTypeOt.c) and re-derive from the repository's own NID hash; open/closed/merged history has no other implementation. The contract follows [`ft_mem_qrealloc` with unit item size in FreeType 2.4.12](https://github.com/freetype/freetype/blob/cecf93ef90c660a8b0b45e5adbbfb5ea443fb6b9/src/base/ftutil.c#L91-L165): negative current or new size report `Invalid_Argument` and keep the guest output; a zero new size releases the block through the free callback and clears the output; sizes above `INT_MAX` report `Array_Too_Large` and keep the output; an empty current takes the zeroing allocation path (the reference's fresh path uses the zeroing allocator for both variants); a growth callback that returns null reports `Out_Of_Memory` while keeping the previous block in the output; and only `FT_Realloc` additionally clears the grown region. Null records or outputs make the helpers throw; the reference implementation dereferences them. Console ABI is unverified and recorded in debt. The matching OT inventory helpers are named `sceFreeTypeOtRealloc_nid_no_patch` and `sceFreeTypeOtQRealloc_nid_no_patch` and declared once in `libSceFreeTypeOt/include/MemoryAllocation.hpp`, reachable through the Ot umbrella included by the export implementation; their no-parameter placeholders, explicit NID aliases and throwing behavior remain. Ordering: **Depends on: #12004.** This branch now includes that PR's reviewed allocator fixes at `6b7a1c9446fb4baa14531190e0b62e0e273ad116`. After #12004 lands, this PR will be refreshed to retain only the reallocation follow-up. Submitted head `94b05e61d0b834554672e1ddf061c41e4fecca89` merges cleanly with current main `aaccd0ba39b7d40fdbf19664575a7e567d8542f7`. The Ot allocator declarations are separated from the shared FreeType header, and the allocator/debt additions use distinct anchors from the other pending FreeType contributions. The acceptance side of the `INT_MAX` boundary (a 2 GiB allocation) is not exercised to keep CI bounded; the rejection side is covered. ### Tested Current submitted head `94b05e61d0b834554672e1ddf061c41e4fecca89` carries the allocator review corrections without changing the allocation/reallocation implementation from previously tested head `22dfb9f66b56dbb6d6b8c95f07232758f335d1db`. The 70/70 full-library/focused-CTest results below refer to that earlier head, based on #12004 head `74276c4683` and main `c02d287bd0`; they were not rerun as a full product build for this header/debt/test-only follow-up. Fresh October 29 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,056 exports), the canonical public headers compile independently and together, and the Ot export translation unit compiles. Each platform freshly compiles production `MemoryAllocation.cpp` and the revised in-tree fixture as isolated artifacts, then passes three runs in each normal and repository-NID-patched export mode. The fixture retains all allocation/reallocation cases and adds null-record/null-output `FT_Free` calls that preserve a live block, contents and callback counts until normal release. Windows uses the existing product libc import library/binaries for custom unwind support. This is not a fresh complete `libs` build. 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, the allocator fixture's both export modes (unpatched names and packaged NIDs `Uw+BZJpflxk`/`hz-J3hohXW8`/`fHMsRluEMfI`/`HVSaZbxYi2s`/`KVbmKCGGowg`), charmap checks and the packaged-library loader. The fixture registers counting guest callbacks with a deterministic realloc (preserves the prefix, fills growth with a marker). Each mode verifies, for both helpers: the fresh path returning zeroed contents; growth preserving a written prefix while `FT_Realloc` clears the grown region and `FT_QRealloc` leaves the callback's marker there; `-1`, `INT64_MIN` current and size, and size `2147483648` producing `Invalid_Argument`/`Array_Too_Large` with the output pointer kept and zero callback traffic; zero size releasing through the free callback and clearing the output, with a null block producing no release; a failing growth callback producing `Out_Of_Memory` with the previous block kept and no free; and a failing fresh allocation producing `Out_Of_Memory` with a cleared output. 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: #12004 <!-- #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 -->
MarcZX10 commented 2026-10-28 11:54:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-28T11:54:47Z.

Review: COMMENTED


Reviewed exact head 22dfb9f66b56dbb6d6b8c95f07232758f335d1db. I compared Reallocate against the linked FreeType 2.4.12 ft_mem_qrealloc contract: invalid negative sizes and over-INT_MAX requests leave the output pointer untouched; zero size frees and clears it; a fresh allocation uses the zeroed allocation path; failed growth preserves the original pointer; and only FT_Realloc zeroes the grown tail. I built MemoryAllocation.cpp and GuestFreeTypeMemoryAllocation.cpp directly with GCC on this Linux host and ran the unpatched-symbol fixture successfully. git diff --check and tools/check_conventions.py --base upstream/main also pass. The hosted Windows check is still in progress, so I have not approved.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5682172021 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12373#pullrequestreview-5682172021). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-28T11:54:47Z. **Review:** COMMENTED --- Reviewed exact head `22dfb9f66b56dbb6d6b8c95f07232758f335d1db`. I compared `Reallocate` against the linked FreeType 2.4.12 `ft_mem_qrealloc` contract: invalid negative sizes and over-`INT_MAX` requests leave the output pointer untouched; zero size frees and clears it; a fresh allocation uses the zeroed allocation path; failed growth preserves the original pointer; and only `FT_Realloc` zeroes the grown tail. I built `MemoryAllocation.cpp` and `GuestFreeTypeMemoryAllocation.cpp` directly with GCC on this Linux host and ran the unpatched-symbol fixture successfully. `git diff --check` and `tools/check_conventions.py --base upstream/main` also pass. The hosted Windows check is still in progress, so I have not approved.
MarcZX10 commented 2026-10-28 12:08:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-28T12:08:53Z.

Review: APPROVED


The exact-head review and focused allocator fixture support the documented FreeType 2.4.12 behavior, and the Windows CI check has now passed. I found no remaining correctness issue in the reviewed change.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5682329442 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12373#pullrequestreview-5682329442). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-28T12:08:53Z. **Review:** APPROVED --- The exact-head review and focused allocator fixture support the documented FreeType 2.4.12 behavior, and the Windows CI check has now passed. I found no remaining correctness issue in the reviewed change.
MarcZX10 commented 2026-10-29 08:43:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T08:43:32Z.

Review: APPROVED


Re-reviewed exact head 94b05e61d0b834554672e1ddf061c41e4fecca89. Relative to the previously reviewed head 22dfb9f66b, production allocator/reallocator source is unchanged. The follow-up moves the three Ot placeholder declarations into their library-specific header and adds FT_Free null-input coverage that verifies the block and free/allocation counters remain unchanged until a valid release. The author reports cross-platform standalone/header builds and the allocation/reallocation fixture passing three times on Windows and Ubuntu WSL, plus a clean current-main merge/conventions check. The PR keeps Depends on: #12004; it remains stacked on that open prerequisite. I inspected the new diff and git diff --check; I did not rerun the author’s builds or tests locally. Hosted checks for the new head are still queued.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5694962902 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12373#pullrequestreview-5694962902). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-29T08:43:32Z. **Review:** APPROVED --- Re-reviewed exact head `94b05e61d0b834554672e1ddf061c41e4fecca89`. Relative to the previously reviewed head `22dfb9f66b`, production allocator/reallocator source is unchanged. The follow-up moves the three Ot placeholder declarations into their library-specific header and adds `FT_Free` null-input coverage that verifies the block and free/allocation counters remain unchanged until a valid release. The author reports cross-platform standalone/header builds and the allocation/reallocation fixture passing three times on Windows and Ubuntu WSL, plus a clean current-main merge/conventions check. The PR keeps `Depends on: #12004`; it remains stacked on that open prerequisite. I inspected the new diff and `git diff --check`; I did not rerun the author’s builds or tests locally. Hosted checks for the new head are still queued.
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!12373
No description provided.