feat(libkernel): implement __elf_phdr_match_addr #337
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/337"
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 DotDebian on 2026-10-02T09:18:13Z.
What
Implements
__elf_phdr_match_addrincore/libs/prx/libkernel/Module/src/Module.cpp. It returns 1 when the address lies in an executablePT_LOADsegment of the given module, 0 otherwise.lib/libc/gen/elf_utils.c(same symbol name), as found inreleng/9.0andreleng/11.0: segments that are notPT_LOADor lackPF_Xare skipped, and a segment matches whendlpi_addr + p_vaddr <= addrandaddr + sizeof(addr) < dlpi_addr + p_vaddr + p_memsz.(ModuleInfo* module, std::uint64_t address); FreeBSD declares(struct dl_phdr_info *phdr_info, void *addr). The parameters are now(dl_phdr_info*, void*), using the existing types fromprx/libc/include/specifics/linux/ElfTypes.hpp. Symbol name and argument count are unchanged.phdr_infounchecked. A nullphdr_infothrowsstd::invalid_argumenthere.mainhas since dropped the+ sizeof(addr)term. This PR keeps it, as the 9.x and 11.x branches do. That the console's libkernel matches those branches is inferred from the lineage, not checked against a binary.Tested
Windows 11, MinGW-w64 GCC 15.2.0, Release build with
-DBUILD_TESTING=ON. No title or homebrew was run:dl_iterate_phdrstill throws on Windows, so nothing hands adl_phdr_infoto this function end to end yet. Linux was not built locally.New ctest
guest_elf_phdr_match(core/libs/tests/GuestElfPhdrMatch.cpp), on a syntheticdl_phdr_infowith four program headers and a non-zerodlpi_addr:PT_LOAD→ 1;PT_LOADwithoutPF_X→ 0;PT_LOAD→ 0;addr + 8 == end - 1→ 1,addr + 8 == end→ 0,addr == end→ 0;p_vaddrwithoutdlpi_addradded → 0;dlpi_phnum == 0→ 0.The null
phdr_infocase is not covered by the test. With the upper bound changed from<to<=the test fails. Full suite: 108/108 tests pass.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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-04T05:26:04Z.
Progress report (
e1654a9→7fd0890)📈 System libraries: 80.8% (+0.04%, +1 implemented functions)
✅ 1 implemented
__elf_phdr_match_addr_nid_postfixImported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T23:09:15Z.
Thanks. This is a line-for-line port of FreeBSD releng/11.0
lib/libc/gen/elf_utils.c: it skips headers that aren'tPT_LOADor lackPF_X, and matches ondlpi_addr + p_vaddr <= addr && addr + sizeof(addr) < dlpi_addr + p_vaddr + p_memsz. The old(ModuleInfo*, uint64_t)signature was wrong, and the repo'sdl_phdr_infohas the same first four fields as FreeBSD's, which are the only ones read here. The test covers both edges of thesizeof(addr)term.guest_elf_phdr_matchpasses on my Linux build (in a batch with this PR), and CI is now green on both platforms. Good to merge from my side.For context: PPSA21564's eboot doesn't import
__elf_phdr_match_addr(Fjc4-n1+y2g). Only the Sonylibc.prxit ships references it.