feat(libc): implement getifaddrs and freeifaddrs #1772
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1772"
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 LuisBiceps on 2026-10-08T18:48:33Z.
What
Implements
getifaddrs(NIDj-gWL6wDros) andfreeifaddrs(NIDN2OjwJJGjeQ) in libc. 16 of the homebrew titles in the #1578 audit import both from libSceLibcInternal, which resolves through libc.struct ifaddrswith FreeBSDsockaddr_in/sockaddr_in6(length byte,AF_INET2,AF_INET628). Every entry has a netmask. Broadcast interfaces get the IPv4 broadcast address, point-to-point interfaces the destination address. Flags use FreeBSD's values (IFF_MULTICASTis0x8000, not Linux's0x1000).getifaddrs. Windows readsGetAdaptersAddresses: names fromConvertInterfaceLuidToNameA(NDIS names such asloopback_0), netmask fromOnLinkPrefixLength, broadcast from the address and netmask.freeifaddrsis a singlefree.errno, asgetcwdhere does: a null list pointer givesEFAULT, and host or allocation failures giveENOMEM,ENOBUFS,EMFILEorENFILE. Any other host failure throws.IFF_POINTOPOINT, and an IPv4 broadcast address the host omits is computed from the netmask, so a flag always comes with its address, as on FreeBSD.IFF_UP,IFF_RUNNING,IFF_LOOPBACK,IFF_BROADCASTandIFF_MULTICAST, derived from the adapter.IFF_BROADCASTnorIFF_POINTOPOINT, since their peer address is not reported and FreeBSD always fillsifa_dstaddrwithIFF_POINTOPOINT.IFNAMSIZis 16) becomesif<index>.AF_LINKentries and theirif_dataare not produced, so interfaces without an address are omitted.Tested
guest_interfacestest, registered in ctest:getifaddrson Linux,GetAdaptersAddresseson Windows). Family, address, netmask and IPv6 scope id must match, with up to 3 attempts in case DHCP or a VPN changes an address between the two snapshots.127.0.0.1/8withIFF_UP | IFF_LOOPBACKand noIFF_BROADCAST.getifaddrs(nullptr)must return -1 withEFAULT, andfreeifaddrs(nullptr)must return.IFF_MULTICASTleaking through, the loopback flag dropped, loopback marked broadcast);errno.15.2.0posix-14.0.0-ucrt-r7), Release, onmainc963432d:guest_interfacespasses (--repeat until-fail:3), and so does the full suite. The NID-patchedlibc.prxexports both NIDs.ANYPS5_ENABLE_SPIRV_TOOLS=ON, onmainc963432d:guest_interfacespasses (--repeat until-fail:3), and so does the full suite.tools/check_test_registration.pyandtools/check_conventions.pypass.--windows(bundledlibc.prxunwrapped) and run on Windows 10:mainc963432d:FAIL: unresolved ELF import j-gWL6wDros from libSceLibcInternal.prx(getifaddrs)mainc963432d+ this PR: PSBoxFAIL: unresolved ELF import oxMp8uPqa+U from libkernel.prx(pthread_set_name_np), Cloud PlayFAIL: unresolved ELF import 04AjkP0jO9U from libkernel.prx(_umtx_op, #1482)main197ffac9, after #2605, with each title's ownlibc.prxloaded, on Linux (Ubuntu 24.04) and Windows 11: four catalog titles stop at these functions, and all four get past them with this PR.mainj-gWL6wDros(getifaddrs)0NJDcQ2B8vE(execvp)j-gWL6wDros(getifaddrs)04AjkP0jO9U(_umtx_op, #1482)N2OjwJJGjeQ(freeifaddrs)5G2ONUzRgjY(memrchr)j-gWL6wDros(getifaddrs)oxMp8uPqa+U(pthread_set_name_np)Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by SleglJan on 2026-10-08T19:24:04Z.
Linux run (the description lists Windows and WSL2): CachyOS, kernel 7.2.9, GCC 16.2.1, Release with
BUILD_TESTING=ONandANYPS5_ENABLE_SPIRV_TOOLS=ON. This PR's head def34666 merged ontomainb858fdc4, which merges cleanly.guest_interfacesaborts in 3 of 3 runs here, at the line 140 check,if (item->flags & 0x10) Require(item->destination != nullptr)(found with a local build that prints the failingRequire's line). The host has a TUN interface withIFF_POINTOPOINT, one IPv4 address and two IPv6 addresses; the hostgetifaddrsgives anifa_dstaddrfor the IPv4 address and none for the IPv6 ones, so the implementation leaves those two destinations null and the test rejects them. The previous head d074b21f, whose test has no such check, passed--repeat until-fail:3on the same host; the Linux destination code is the same in both heads. Host interfaces:lo, two Ethernet links with IPv4 and IPv6 addresses, a wireless interface that is down, and the tunnel.libc.prxexportsj-gWL6wDrosandN2OjwJJGjeQ.tools/check_conventions.py --base upstream/mainandtools/check_test_registration.pypass.tools/import_audit.pyon five of the 16 titles from the #1578 table, absent imports onmainb858fdc4→ with this PR: PPSA17641 SymphonyStation5 35 → 33, PPSA97510 PSXS5 72 → 70, PPSA99009 ProsperoLichess 37 → 35, PPSA99082 OpenNOW PS5 - Prototype 36 → 34, PPSA99808 PICO-8 for PS5 28 → 26. In each case the two that disappear aregetifaddrsandfreeifaddrs; no title was run, since each still has other absent imports.AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by LuisBiceps on 2026-10-09T02:58:02Z.
Thanks for testing on a TUN host. That failure is fixed in the current head, 4f10bd00, pushed after your run. An address on a point-to-point interface without a peer of the same family now loses
IFF_POINTOPOINT, as on FreeBSD, where the flag meansifa_dstaddris filled. I reproduced your layout on Ubuntu 26.04 (WSL2): atuninterface with one IPv4 address with a peer and two IPv6 addresses without one. def34666 aborts there, and 4f10bd00 passes--repeat until-fail:3. It also passes with an IPv4 address without a peer, an IPv6 address with a peer, and a dummy interface with/32and/128addresses.Imported from boykopovar/AnyPS5. Originally posted by LuisBiceps on 2026-10-09T03:42:35Z.
A title reaches
getifaddrsonce its current stop is resolved. Cloud Play (PPSA99600) 1.0.0, from the homebrew catalog, relinked with--windowsonmainf1451396and run on Windows 10, stops at:mainFAIL: unresolved ELF import 6kPnj51T62Y from libSceVideoOut.prx(sceVideoOutGetResolutionStatus, #1714)main+ #1714FAIL: unresolved ELF import j-gWL6wDros from libSceLibcInternal.prx(getifaddrs)main+ #1714 + this PRFAIL: unresolved ELF import e-YMQ+2tj9M from libSceAgcDriver.prx(sceAgcDriverGetTFRing, #1978)main+ #1714 + this PR + #1978FAIL: unresolved ELF import Jc6E7N+dHz0 from libkernel.prx(system, #1859)Imported from boykopovar/AnyPS5. Originally posted by CouchRiv on 2026-10-09T12:05:35Z.
A title that stops first on this: PSBox Cloud Gaming (PPSA99810, v0.8.0 from the homebrew catalog), relinked for Linux and run on
maind70b8998(CachyOS, GCC, Release, in a bubblewrap sandbox):j-gWL6wDrosisgetifaddrs, the first unresolved import it binds. Not run with this PR.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-09T13:12:42Z.
Progress report (
3d1a7d9→63a20d6)📈 System libraries: 85.76% (+0.01%, +2 implemented functions)
✅ 2 implemented
freeifaddrs_nid_postfixgetifaddrs_nid_postfixImported from boykopovar/AnyPS5. Originally posted by LuisBiceps on 2026-10-09T14:18:37Z.
Thanks @CouchRiv. It reproduces on Windows, and with this PR PSBox Cloud Gaming moves on to the next import. Version 0.7.0 is the catalog's and 0.8.0 is its newest release. Both, relinked with
--windowsand run on Windows 10, stop at the same imports:maind70b8998FAIL: unresolved ELF import j-gWL6wDros from libSceLibcInternal.prx(getifaddrs)maind70b8998+ this PRFAIL: unresolved ELF import JGfTMBOdUJo from libkernel.prx(sceKernelGetFsSandboxRandomWord, #1807)The branch was conflicting in TechnicalDebt, so I merged
maininto it; the commits already reviewed are unchanged. A commit before the merge moves theguest_interfacestest and the TechnicalDebt entry to lines no other open pull request changes, so the merge needed no hand edits and later merges shouldn't conflict with this one.guest_interfacespasses--repeat until-fail:3on the merged head on Windows 10 and Ubuntu 26.04, and so do the full suites.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T20:14:39Z.
Please rebase onto main and force-push instead of merging main into the branch (f4e507f8); merge commits aren't taken here.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T08:28:44Z.
Rebased onto current
mainas requested: the merge commit is gone and the four commits are replayed in order. Conflicts were only adjacency incore/libs/prx/libc/CMakeLists.txtanddocs/dev/TechnicalDebt.md; the test block and the TechnicalDebt line sit where your last commit put them. Source and test files are unchanged.Checked on Linux: scoped build and ctest (58 tests) green,
guest_interfacespasses; merging once CI is green.Imported from boykopovar/AnyPS5. Originally posted by LuisBiceps on 2026-10-10T09:06:12Z.
Thanks for rebasing it. The replayed last commit added the
getifaddrsTechnicalDebt entry twice (lines 369 and 370 of dff45a05), so I force-pushed63a20d67: the same four commits, with the second copy dropped from the last one. Nothing else changed, and it still merges cleanly withmain919c49b9.The
write-watch (macos-15-intel)failure on dff45a05 was awrite_watch_threadstimeout. That job builds onlyWriteWatch.cppandGuestWriteWatch.cpp, which this PR doesn't touch.Imported from boykopovar/AnyPS5. Originally posted by klosixgaming-arch on 2026-10-10T11:25:10Z.
Independent validation on Windows
Built and ran the PR head
63a20d67on my own box:Release,BUILD_TESTING=ON.Results:
guest_interface_testsPASSES — 3 consecutive runs (exit 0). It compares every guest entry (in order) against a liveGetAdaptersAddresseshost snapshot, checks the FreeBSDifaddrs/sockaddrlayout + 8-byte alignment, the loopback127.0.0.1/8withIFF_UP|IFF_LOOPBACKand noIFF_BROADCAST, and the null-pointerEFAULT/freeifaddrs(nullptr)contract.ws2_32 iphlpapion Windows) compiles and links cleanly.TechnicalDebt.mdentry honestly documents the limits (AF_LINK/if_datanot produced, host names, Windows flag rules) — good.Rigor check (is the test real, or a pass-through?): I deliberately broke the Windows flag translation — changed
IF_TYPE_SOFTWARE_LOOPBACK → flags |= guestLoopbacktoflags |= guestUp— rebuilt, and the test aborted (FATAL: abort() (SIGABRT)fromRequire(matched)), because the loopback assertion no longer held. Restoring the line → PASS (3×). So the test genuinely exercises the host↔guest comparison and flag mapping rather than passing unconditionally.Honest limits of what I verified:
GetAdaptersAddressespath (my host). I could not verify the Linux/POSIXgetifaddrspath or the Linux-only edge cases (point-to-point address without a peer losingIFF_POINTOPOINT, IPv4 broadcast computed from the netmask,IFF_NOARP/PROMISC/ALLMULTI), since I have no Linux here.Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-10T12:49:00Z.
Title check on current
main, since the title stops moved after #2605.63a20d67merged ontomain197ffac9(clean), Linux (Ubuntu 24.04, GCC 13) and Windows 11 (MinGW-w64 GCC 15.2 from WinLibs), Release.guest_interfacespasses 5/5 on both (--repeat until-fail:5).libc.prxloaded (required since #2605, details in #1578), four catalog titles stop at this PR's functions onmain, and all four get past them on both:mainj-gWL6wDros(getifaddrs)0NJDcQ2B8vE(execvp)j-gWL6wDros(getifaddrs)04AjkP0jO9U(_umtx_op, #1482)N2OjwJJGjeQ(freeifaddrs)5G2ONUzRgjY(memrchr)j-gWL6wDros(getifaddrs)oxMp8uPqa+U(pthread_set_name_np)Example lines for PS5MC:
mainWindowsFAIL: unresolved ELF import j-gWL6wDros (getifaddrs) from libSceLibcInternal.prx; with this PR, Linuxapp.elf: symbol lookup error: app.elf: undefined symbol: 0NJDcQ2B8vE, WindowsFAIL: unresolved ELF import 0NJDcQ2B8vE (execvp) from libkernel.prx.