fix(libc): allocate the getifaddrs list on the application heap #6213
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6213"
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 milescoviello on 2026-10-15T04:02:24Z.
What
Doom 3 BFG (PPSA99313, catalog release) stops at start-up on
main, right after its splash:The throw is in
GuestHeapFree, called from the title'sfree. With gdb, the title walks the list it got fromgetifaddrs(AF_INET,IFF_UP, comparing with 127.0.0.1) and then passes the list itself tofree. That is how FreeBSD releases it:getifaddrsallocates the whole list as onemallocblock andfreeifaddrsisfree(ifp).AnyPS5's
getifaddrsbuilt that block with the host'sstd::malloc, so it only worked with AnyPS5's ownfreeifaddrs. The guest heap never saw it, and the title'sfreestopped on it. The block now comes from the application heap (ApplicationHeapAllocate_nid_no_patch, asstrdupandrealpathdo), andfreeifaddrsreturns it there. Either way of releasing it works.guest_interfacesnow registers the default application heap (asguest_realpathdoes) and releases one list with the guest'sfree.Tested
Ubuntu 24.04, GCC 13.3, Release, on
maina077a88df:guest_interfacespasses 5/5. Withmain'sInterfaces.cppand the new check, it fails with the title's message,guest allocation is not registered.guest_*tests pass.--to-inteland run on Linux (RTX 4070 Ti): onmainit stops at 0 s. With this change it gets past the list (loopbackin 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_8UINT, which #5999 adds. With #5999's line as well, the title runs to its ownSys_Error: Could not load default font "Arial_Narrow". The catalog build ships no game data, so its ownCouldn't load imagewarnings are expected.tools/check_conventions.py --base upstream/mainpasses, andtools/pr_overlap.py --branch fix/libc-getifaddrs-guest-heapfinds no overlap.@overlordxrz-source confirmed the root cause independently on Linux with lavapipe and an AddressSanitizer build of
mainb7cedd900(comment): the block PPSA99313 frees was allocated bymallocingetifaddrs_nid_postfix.@nicolasfalesy ran Doom 3 BFG (PPSA99313) on Linux with an Intel Arc GPU (Mesa ANV). On
main5d9dcc42dit stops withguest 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
main5d9dcc42dand two 60 s runs each:mainstops at 0 s onguest 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 ownSys_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
main5d9dcc42dit stops within 2 s onguest allocation is not registered. With this PR (403c09fa2) it gets to the 8_8 UINT color target refusal, and with #5999 as well toSys_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
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)🤖 Generated with Claude Code
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.
core/libs/tests/GuestInterfaces.cppImported from boykopovar/AnyPS5. Originally posted by overlordxrz-source on 2026-10-16T00:16:58Z.
Independent Linux confirmation of the root cause, on
mainb7cedd900(lavapipe, AddressSanitizer build, RelWithDebInfo). Doom 3 BFG (PPSA99313) stops withguest allocation is not registeredinGuestHeapFree<-ApplicationHeapFree. At the throw,__asan_describe_addresson the freed pointer reports:So the block the title passes to
freeis the host-mallocedgetifaddrslist, which is the case this PR moves onto the application heap.AI-assisted: yes
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
mallocingetifaddrsdirectly, where my gdb session only got there by following the pointer. I've added your result to the description.AI-assisted: yes
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).
main5d9dcc42d: stops withguest allocation is not registered.main5d9dcc42d+ this PR: that line is gone. It runs on and creates its textures (StorageTexturelines), 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
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
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.
main5d9dcc42dguest allocation is not registered(3 of 3)loopback), initializes its file system and decls, then stops onAGC graphics: unsupported color format 3 number type 4 component swap 0(3 of 3)Sys_Error: Could not load default font "Arial_Narrow"(3 of 3), which is where it needs the BFG dataSo Windows matches the Linux results above, stop for stop. Both PRs merged cleanly onto
maintogether.AI-assisted: yes, Claude Code ran the builds and tests; I reviewed the results.
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