fix(libc): allocate the getifaddrs list on the application heap #6213

Merged
milescoviello merged 1 commit from upstream-pr/6213 into main 2026-10-17 20:47:10 +00:00
milescoviello commented 2026-10-15 04:02:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-15T04:02:24Z.


What

Doom 3 BFG (PPSA99313, catalog release) stops at start-up on main, right after its splash:

[libc] unhandled exception 'St13runtime_error' thrown from ...
  what():  guest allocation is not registered

The throw is in GuestHeapFree, called from the title's free. With gdb, the title walks the list it got from getifaddrs (AF_INET, IFF_UP, comparing with 127.0.0.1) and then passes the list itself to free. That is how FreeBSD releases it: getifaddrs allocates the whole list as one malloc block and freeifaddrs is free(ifp).

AnyPS5's getifaddrs built that block with the host's std::malloc, so it only worked with AnyPS5's own freeifaddrs. The guest heap never saw it, and the title's free stopped on it. The block now comes from the application heap (ApplicationHeapAllocate_nid_no_patch, as strdup and realpath do), and freeifaddrs returns it there. Either way of releasing it works.

guest_interfaces now registers the default application heap (as guest_realpath does) and releases one list with the guest's free.

Tested

Ubuntu 24.04, GCC 13.3, Release, on main a077a88df:

  • guest_interfaces passes 5/5. With main's Interfaces.cpp and the new check, it fails with the title's message, guest allocation is not registered.
  • All 376 guest_* tests pass.
  • PPSA99313, relinked with --to-intel and run on Linux (RTX 4070 Ti): on main it stops at 0 s. With this change it gets past the list (loopback in its log), initializes its file system and declarations, and reaches its first draw 3 s in. That draw stops on an unrelated color-target format, COLOR_8_8 UINT, which #5999 adds. With #5999's line as well, the title runs to its own Sys_Error: Could not load default font "Arial_Narrow". The catalog build ships no game data, so its own Couldn't load image warnings are expected.
  • tools/check_conventions.py --base upstream/main passes, and tools/pr_overlap.py --branch fix/libc-getifaddrs-guest-heap finds no overlap.

@overlordxrz-source confirmed the root cause independently on Linux with lavapipe and an AddressSanitizer build of main b7cedd900 (comment): the block PPSA99313 frees was allocated by malloc in getifaddrs_nid_postfix.

@nicolasfalesy ran Doom 3 BFG (PPSA99313) on Linux with an Intel Arc GPU (Mesa ANV). On main 5d9dcc42d it stops with guest allocation is not registered. With this PR that line is gone, and it creates its textures before a later, separate stop: AGC graphics: unsupported color format 3 number type 4 component swap 0.

The same on Linux here (RTX 4070 Ti), with main 5d9dcc42d and two 60 s runs each: main stops at 0 s on guest allocation is not registered, and with this PR it gets to the later color-target stop at 3 s. With #5999 as well, which adds that 8_8 UINT target, it draws on to its own Sys_Error: Could not load default font "Arial_Narrow", because no game data was installed.

@iDiesIrae-Req ran it on Windows (RTX 4070 Laptop, Windows 11, WinLibs GCC 15.2.0, Release), 30 s per run, 3 runs each. On main 5d9dcc42d it stops within 2 s on guest allocation is not registered. With this PR (403c09fa2) it gets to the 8_8 UINT color target refusal, and with #5999 as well to Sys_Error: Could not load default font "Arial_Narrow", where it needs the BFG data. That matches the Linux runs above, stop for stop.

Not checked on a console.

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
  • Unblocks: none
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4867995115 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6213). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-15T04:02:24Z. --- ### What Doom 3 BFG (PPSA99313, catalog release) stops at start-up on `main`, right after its splash: ``` [libc] unhandled exception 'St13runtime_error' thrown from ... what(): guest allocation is not registered ``` The throw is in `GuestHeapFree`, called from the title's `free`. With gdb, the title walks the list it got from `getifaddrs` (`AF_INET`, `IFF_UP`, comparing with 127.0.0.1) and then passes the list itself to `free`. That is how FreeBSD releases it: `getifaddrs` [allocates the whole list as one `malloc` block](https://github.com/freebsd/freebsd-src/blob/releng/11.0/lib/libc/net/getifaddrs.c#L203) and `freeifaddrs` [is `free(ifp)`](https://github.com/freebsd/freebsd-src/blob/releng/11.0/lib/libc/net/getifaddrs.c#L340-L344). AnyPS5's `getifaddrs` built that block with the host's `std::malloc`, so it only worked with AnyPS5's own `freeifaddrs`. The guest heap never saw it, and the title's `free` stopped on it. The block now comes from the application heap (`ApplicationHeapAllocate_nid_no_patch`, as `strdup` and `realpath` do), and `freeifaddrs` returns it there. Either way of releasing it works. `guest_interfaces` now registers the default application heap (as `guest_realpath` does) and releases one list with the guest's `free`. ### Tested Ubuntu 24.04, GCC 13.3, Release, on `main` a077a88df: - `guest_interfaces` passes 5/5. With `main`'s `Interfaces.cpp` and the new check, it fails with the title's message, `guest allocation is not registered`. - All 376 `guest_*` tests pass. - PPSA99313, relinked with `--to-intel` and run on Linux (RTX 4070 Ti): on `main` it stops at 0 s. With this change it gets past the list (`loopback` in its log), initializes its file system and declarations, and reaches its first draw 3 s in. That draw stops on an unrelated color-target format, `COLOR_8_8` `UINT`, which #5999 adds. With #5999's line as well, the title runs to its own `Sys_Error: Could not load default font "Arial_Narrow"`. The catalog build ships no game data, so its own `Couldn't load image` warnings are expected. - `tools/check_conventions.py --base upstream/main` passes, and `tools/pr_overlap.py --branch fix/libc-getifaddrs-guest-heap` finds no overlap. @overlordxrz-source confirmed the root cause independently on Linux with lavapipe and an AddressSanitizer build of `main` b7cedd900 ([comment](https://github.com/boykopovar/AnyPS5/pull/6213#issuecomment-6205053336)): the block PPSA99313 frees was allocated by `malloc` in `getifaddrs_nid_postfix`. @nicolasfalesy [ran Doom 3 BFG (PPSA99313)](https://github.com/boykopovar/AnyPS5/pull/6213#issuecomment-6206823042) on Linux with an Intel Arc GPU (Mesa ANV). On `main` 5d9dcc42d it stops with `guest allocation is not registered`. With this PR that line is gone, and it creates its textures before a later, separate stop: `AGC graphics: unsupported color format 3 number type 4 component swap 0`. The same on Linux here (RTX 4070 Ti), with `main` 5d9dcc42d and two 60 s runs each: `main` stops at 0 s on `guest allocation is not registered`, and with this PR it gets to the later color-target stop at 3 s. With #5999 as well, which adds that 8_8 UINT target, it draws on to its own `Sys_Error: Could not load default font "Arial_Narrow"`, because no game data was installed. @iDiesIrae-Req [ran it on Windows](https://github.com/boykopovar/AnyPS5/pull/6213#issuecomment-6208341852) (RTX 4070 Laptop, Windows 11, WinLibs GCC 15.2.0, Release), 30 s per run, 3 runs each. On `main` 5d9dcc42d it stops within 2 s on `guest allocation is not registered`. With this PR (403c09fa2) it gets to the 8_8 UINT color target refusal, and with #5999 as well to `Sys_Error: Could not load default font "Arial_Narrow"`, where it needs the BFG data. That matches the Linux runs above, stop for stop. Not checked on a console. ### 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 - [x] Unblocks: none - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-15 12:16:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T12:16:47Z.


Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 6044 core/libs/tests/GuestInterfaces.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6191834246 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6213#issuecomment-6191834246). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-15T12:16:47Z. --- <!-- pr-overlap --> Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/tests/GuestInterfaces.cpp` |
overlordxrz-source commented 2026-10-16 00:16:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by overlordxrz-source on 2026-10-16T00:16:58Z.


Independent Linux confirmation of the root cause, on main b7cedd900 (lavapipe, AddressSanitizer build, RelWithDebInfo). Doom 3 BFG (PPSA99313) stops with guest allocation is not registered in GuestHeapFree <- ApplicationHeapFree. At the throw, __asan_describe_address on the freed pointer reports:

0x7d5ff33e3380 is located 0 bytes inside of 592-byte region [0x7d5ff33e3380,0x7d5ff33e35d0)
allocated by thread T0 here:
  #0 malloc
  #1 getifaddrs_nid_postfix core/libs/prx/libc/src/Interfaces.cpp:216

So the block the title passes to free is the host-malloced getifaddrs list, which is the case this PR moves onto the application heap.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6205053336 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6213#issuecomment-6205053336). Originally posted by [overlordxrz-source](https://github.com/overlordxrz-source) on 2026-10-16T00:16:58Z. --- Independent Linux confirmation of the root cause, on `main` b7cedd900 (lavapipe, AddressSanitizer build, RelWithDebInfo). Doom 3 BFG (PPSA99313) stops with `guest allocation is not registered` in `GuestHeapFree` <- `ApplicationHeapFree`. At the throw, `__asan_describe_address` on the freed pointer reports: ``` 0x7d5ff33e3380 is located 0 bytes inside of 592-byte region [0x7d5ff33e3380,0x7d5ff33e35d0) allocated by thread T0 here: #0 malloc #1 getifaddrs_nid_postfix core/libs/prx/libc/src/Interfaces.cpp:216 ``` So the block the title passes to `free` is the host-`malloc`ed `getifaddrs` list, which is the case this PR moves onto the application heap. AI-assisted: yes
milescoviello commented 2026-10-16 00:20:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-16T00:20:26Z.


Thanks for checking. The ASan report ties the freed block to the malloc in getifaddrs directly, where my gdb session only got there by following the pointer. I've added your result to the description.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6205097536 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6213#issuecomment-6205097536). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-16T00:20:26Z. --- Thanks for checking. The ASan report ties the freed block to the `malloc` in `getifaddrs` directly, where my gdb session only got there by following the pointer. I've added your result to the description. AI-assisted: yes
nicolasfalesy commented 2026-10-16 02:40:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by nicolasfalesy on 2026-10-16T02:40:43Z.


A title that reaches this: Doom 3 BFG (PPSA99313) from the homebrew catalog, on Linux (Intel Arc, Mesa ANV).

  • main 5d9dcc42d: stops with guest allocation is not registered.
  • main 5d9dcc42d + this PR: that line is gone. It runs on and creates its textures (StorageTexture lines), then stops at a later, different check, AGC graphics: unsupported color format 3 number type 4 component swap 0 (terminate called after throwing an instance of 'std::runtime_error').

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6206823042 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6213#issuecomment-6206823042). Originally posted by [nicolasfalesy](https://github.com/nicolasfalesy) on 2026-10-16T02:40:43Z. --- A title that reaches this: **Doom 3 BFG (PPSA99313)** from the homebrew catalog, on Linux (Intel Arc, Mesa ANV). - `main` 5d9dcc42d: stops with `guest allocation is not registered`. - `main` 5d9dcc42d + this PR: that line is gone. It runs on and creates its textures (`StorageTexture` lines), then stops at a later, different check, `AGC graphics: unsupported color format 3 number type 4 component swap 0` (`terminate called after throwing an instance of 'std::runtime_error'`). AI-assisted: yes
milescoviello commented 2026-10-16 02:42:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-16T02:42:16Z.


Thank you, @nicolasfalesy. A catalog title with a before-and-after run on Intel Arc is exactly the evidence this needed. I've added it to the description.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6206840665 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6213#issuecomment-6206840665). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-16T02:42:16Z. --- Thank you, @nicolasfalesy. A catalog title with a before-and-after run on Intel Arc is exactly the evidence this needed. I've added it to the description. AI-assisted: yes
iDiesIrae-Req commented 2026-10-16 04:51:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by iDiesIrae-Req on 2026-10-16T04:51:02Z.


Windows run for this PR: Doom 3 BFG (PPSA99313, catalog release 1.0, no BFG data), RTX 4070 Laptop, Windows 11 26300, WinLibs GCC 15.2.0 r7, Release. Same converted title for every build, only the libraries differ; 30 s per run, 3 runs each.

Build Result
main 5d9dcc42d stops within 2 s on guest allocation is not registered (3 of 3)
+ 403c09fa2 (this PR) gets past the list (loopback), initializes its file system and decls, then stops on AGC graphics: unsupported color format 3 number type 4 component swap 0 (3 of 3)
+ 403c09fa2 + #5999 (a214a4e2c) runs to Sys_Error: Could not load default font "Arial_Narrow" (3 of 3), which is where it needs the BFG data

So Windows matches the Linux results above, stop for stop. Both PRs merged cleanly onto main together.

AI-assisted: yes, Claude Code ran the builds and tests; I reviewed the results.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6208341852 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6213#issuecomment-6208341852). Originally posted by [iDiesIrae-Req](https://github.com/iDiesIrae-Req) on 2026-10-16T04:51:02Z. --- Windows run for this PR: Doom 3 BFG (PPSA99313, catalog release 1.0, no BFG data), RTX 4070 Laptop, Windows 11 26300, WinLibs GCC 15.2.0 r7, Release. Same converted title for every build, only the libraries differ; 30 s per run, 3 runs each. | Build | Result | |---|---| | `main` 5d9dcc42d | stops within 2 s on `guest allocation is not registered` (3 of 3) | | + 403c09fa2 (this PR) | gets past the list (`loopback`), initializes its file system and decls, then stops on `AGC graphics: unsupported color format 3 number type 4 component swap 0` (3 of 3) | | + 403c09fa2 + #5999 (a214a4e2c) | runs to `Sys_Error: Could not load default font "Arial_Narrow"` (3 of 3), which is where it needs the BFG data | So Windows matches the Linux results above, stop for stop. Both PRs merged cleanly onto `main` together. AI-assisted: yes, Claude Code ran the builds and tests; I reviewed the results.
milescoviello commented 2026-10-16 04:52:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-16T04:52:00Z.


Thanks @iDiesIrae-Req, good to have Windows matching the Linux results stop for stop. I added it to the description.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6208352446 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6213#issuecomment-6208352446). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-16T04:52:00Z. --- Thanks @iDiesIrae-Req, good to have Windows matching the Linux results stop for stop. I added it to the description. AI-assisted: yes
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!6213
No description provided.