feat(libkernel): add sceKernelGetLibkernelTextLocation (AmJ0mn2l4lM) #4675
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4675"
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 nabilfp on 2026-10-12T18:33:57Z.
What
Adds
sceKernelGetLibkernelTextLocation(NIDAmJ0mn2l4lM) to libkernel. The function returns the text segment location (address and size) of the libkernel module.Signature from fpPS4:
int sceKernelGetLibkernelTextLocation(uint64_t* address, uint64_t* size), returns 0 on success.Implementation:
GetModuleHandleW("libkernel.dll")(fallback to main module) and reads PE headers to get base address and image size.dladdrto find the libkernel module's base from the function's own address, then iterates program headers to locate the executable LOAD segment (PT_LOAD with PF_X) and returns its address and memsz.Null checks return
SCE_KERNEL_ERROR_EFAULT; missing module/segment returnsSCE_KERNEL_ERROR_ESRCH.This resolves the unresolved import reported in #4560.
Tested
python tools/check_conventions.py --base origin/mainpasses.python tools/nid_names.py --nid AmJ0mn2l4lMnow reports "already-implemented".No build/tests were run locally due to environment constraints; the change follows existing code patterns in the codebase (ModuleInfo, etc.).
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 repositoryImported from boykopovar/AnyPS5. Originally posted by fma-rc on 2026-10-12T18:40:06Z.
@nabilfp fyi your commit is attributed to 'Test Contributor', not your github account. Haven't reviewed the PR.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-12T19:13:43Z.
Code review location:
core/libs/prx/libkernel/Module/src/Module.cpp; line 263The Windows CMake target is emitted as
libkernel.prx(the shared-library loop setsSUFFIX .prx), soGetModuleHandleW(L"libkernel.dll")will not find this module. The fallbackGetModuleHandleW(nullptr)then returns the host executable, making the function report the wrong module. Also,SizeOfImageis the entire PE image rather than its executable text range. Could this locate the containing module from this function’s address (for example withGetModuleHandleEx(FROM_ADDRESS)) and return the.textsection address/size?Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-12T19:17:18Z.
Review: COMMENTED
The overlap report is substantive: #4567 is still open and implements the same
sceKernelGetLibkernelTextLocationexport/NID. The two PRs also choose different targets: #4567 returns the main executable’s first segment (following fpPS4), while this PR tries to report libkernel’s own text. They cannot both be merged as written, and the console behavior is still unverified. Could you coordinate with #4567’s author and establish the expected target from an observed call/result or other authoritative evidence, then mark the chosen PR as depending on any shared changes? Also, the Windows lookup issue from my inline comment remains.Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-12T20:24:35Z.
Linux build, the one line that is missing, and the value the function actually returns
I built this head on Linux. It does not compile. One line fixes that, and then the function works and exports the NID you computed — but what it returns differs from the reference it cites, and its two platforms return different quantities. I have no PR against this path and nothing here is a request for a change I have not measured.
Head
0eb817ae1b, base/merge-base2a5eca11c,upstream/main1acfa7f78.1. The build fails
The include guard at
core/libs/prx/libkernel/Module/src/Module.cpp:13-23is#ifdef _WIN32/#elif defined(__APPLE__)/#else, and<dlfcn.h>sits in the Apple arm. That is correct for main: the file's only otherDl_info/dladdruse (:155-156) is inside the__APPLE__block that opens at:123and closes at:168. The new Linux code at:281and:289is in the#elsearm, where nothing declares them.Four other files in the tree include it for their Linux branch —
core/libs/prx/libkernel/Module/src/DynamicLoader.cpp:18-20(same directory),core/libs/prx/libSceLibcInternal/Export.cpp:11-13,core/libs/prx/libc/src/exception/Unwind.cpp:6-7,core/libs/prx/libSceAgcDriver/Execution/src/ThreadPriority.cpp:14-16— so the pattern is right there.2. What the fix is, and what it is not (my arm, not yours)
Adding only
<dlfcn.h>to the#elsebranch:Adding
<link.h>as well does not work, and it is the obvious next guess: it collides with the project's own header, which defines those types for platforms that lack them —Worth knowing why the second "Tested" item passed:
tools/nid_names.pydecidesalready-implementedfromcompute_nid(suggestion) == nidplus the name appearing incollect_real_names(), which scans source definitions (tools/nid_names.py:105-113). It reads the added line and cannot see that the file does not compile.compute_nid("sceKernelGetLibkernelTextLocation")isAmJ0mn2l4lM, so the NID half of your claim holds.3. What it returns, measured
With the include added, driving the built module (probe linked against
unpatched/libkernel.prx):So on Linux it returns the native
libkernel.prx's own executable segment at its host mapping. That is a different quantity from the reference this PR cites. fpPS4's body (pinned04cefd43e6,kernel/ps4_libkernel.pas:330-340) is— the application's segment 0, with a nil guard returning -1, not
EFAULT. And the function this one exists to serve,sceKernelInternalMemoryGetModuleSegmentInfo, is still a throwing stub on this base (core/libs/prx/libkernel/Module/src/Module.cpp:245,// unknown signature), so nothing in-tree reaches the new export; open PR #4193 implements it, and its body says it "returns the first segment reported bysceKernelGetModuleInfofor the main program", explicitly recording that the console "may instead report libkernel's text" as unverified. If both land, a title gets the app's first segment from the segment-info call and libkernel's text from this one.The Windows arm returns yet a third thing. Every guest library is built
PREFIX ""/SUFFIX .prx(core/libs/CMakeLists.txt:127-134, and:72-74for libc), so the module on disk islibkernel.prx, andGetModuleHandleW(L"libkernel.dll")(core/libs/prx/libkernel/Module/src/Module.cpp:256) cannot match it — the lookup fails and the code takes the fallback to the main module, returning the title's image base andSizeOfImage. The two arms of one function therefore disagree, silently. Whichever meaning is intended, it is worth saying in the debt entry; the probe above is reproducible if you want the numbers on your side.4. The named title
The bar here is a title ID and the log line where that title stops, and this PR has neither: #4560's evidence is hypothetical ("Any title, homebrew port, or loader that queries this symbol directly fails"), and
AmJ0mn2l4lMappears in none of the five title trees I hold — searched with a positive control, since the same search does find-YTW+qXc3CQinPPSA02929-app0/sce_module/libc.prx. If you have a title that importsAmJ0mn2l4lM, its log line is the thing that would carry this;sceKernelInternalMemoryGetModuleSegmentInfo's 44-title importer list (named in #4193) is a different symbol.5. Nothing exercises it
One file changed, no test, and the body's own Tested section says no build was run. A behavioural case would have caught the compile break and the cross-platform difference at once —
guest_module_info_testsis the neighbouring target, and #4193 shipped a test with the same shape.6. Merge state
Merges cleanly with
upstream/main(git merge-tree --write-tree pr-4675 upstream/mainexits 0). It conflicts with open #4193 incore/libs/prx/libkernel/Module/src/Module.cpp(merge-treeexits 1) — the overlap bot lists this one already, and since #4193 is the consumer this helper was written for, the two authors probably want to agree on the meaning above before either lands.What I could not check: anything on Windows (the arm is not compiled by CI for a pull request, so neither a compile nor the
GetModuleHandleWfallback is covered there), and what the console's own value is — fpPS4's body and itssegmentInfo[0]naming disagree with each other, and no title run here reaches the call.AI-assisted review; every number above comes from a command run here.
Hermes Agent 🤖 at your service
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-12T20:31:42Z.
Thanks for the independent Linux build and the detailed reference comparison. This confirms the missing
dlfcn.hinclude and adds an important semantic ambiguity: Linux reports the title image fallback, while the intended export target is still unverified. My review already asks the author to reconcile this with #4567 and establish the expected console result; I agree the PR should remain blocked on both target semantics and the Windows module lookup rather than taking only the compile fix.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-12T21:10:56Z.
Progress report (
9f7c40e→0eb817a)📈 System libraries: 86.37% (+0.01%, +1 implemented functions)
✅ 1 implemented
sceKernelGetLibkernelTextLocation_nid_postfixImported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-12T21:11:54Z.
Closing: this export was merged in #4567, so this PR duplicates it and can't be merged next to it.
Besides that:
core/libs/prx/libkernel/Module/src/Module.cpp:280does not compile on Linux:Dl_info/dladdrneed<dlfcn.h>, which is only included in the__APPLE__arm (confirmed by @Dextroid17's build).Feel free to reopen if there is a gap left on top of #4567, with a build that passes and a test that fails without the change.
Pull request closed