Repository navigation
docs(libkernel_sys): record the module list sceKernelGetModuleListInternal and the check order of sceKernelGetModuleInfoInternal on firmware 11.60 - #26803
Merged
oneandonlydean merged 1 commit intoNov 25, 2026
Conversation
…ernal and the check order of sceKernelGetModuleInfoInternal on firmware 11.60 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Contributor
Author
|
Probe source (built with ps5-payload-sdk; raw output (stdout)probe.c/* Probe: sceKernelGetModuleInfoInternal and sceKernelGetModuleListInternal, read only, payload process, firmware 11.60 (debt libkernel_sys.md entry:
they answer for every loaded module, system modules included; sceKernelGetModuleInfoInternal fills the 0x1A8-byte SceKernelModuleInfoEx of a
module handle the way sceKernelGetModuleInfoFromAddr does for an address, with shadPS4's checks in their order: EFAULT for a null pointer, EINVAL
when st_size is not 0x1A8, ESRCH for an unknown handle; sceKernelGetModuleListInternal returns the same list as sceKernelGetModuleList, as
fpPS4 does, which fpPS4 marks as a guess; neither is checked on a PS5). Prototypes from the repo: int sceKernelGetModuleInfoInternal(int handle,
ModuleInfoEx* info) with the 0x1A8-byte layout (st_size at 0, the name at 8, the handle at 0x108, four segments of address, size and protection
from 0x160, segment_count at 0x1A0, ref_count at 0x1A4), int sceKernelGetModuleListInternal(int* handles, size_t count, size_t* actual); for the
comparison int sceKernelGetModuleList(int*, size_t, size_t*) and int sceKernelGetModuleInfo(int, ModuleInfo*) (0x160 bytes). The names are looked
up with dlsym in libkernel.sprx, then in the global scope; sceKernelLoadStartModuleForSysmodule is only looked up and never called, no module is
loaded. Cases: the existence of the exports; both lists into a 256-entry array (return code, the number, whether the number and the handles in order are
equal); the list with a count of 4 and of 0 (return code, actual); then for the first 8 handles the info from the Internal function (return code, st_size
as returned, the base name of the module only, at most 24 characters, the segment count, the sizes and protections of the segments and their addresses
as offsets from the first segment, ref_count) and whether name, segment count and the segments equal those of sceKernelGetModuleInfo; the error
order: a NULL info (single call, guarded), st_size 0, 0x1A7, 0x1A9, 0x1B0 and 0x100 with a valid handle, the handles 0, -1 and 0x7fff with a valid
st_size, then both faults at once (NULL info with an invalid handle, a wrong st_size with an invalid handle). No path, no absolute address
is printed. A fault in the NULL call is caught by a guard (one hit, more than eight end the probe with _exit(125)). Nothing is written, nothing is sent. */
#include <dlfcn.h>
#include <errno.h>
#include <pthread.h>
#include <signal.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <ps5/kernel.h> /* only for kernel_get_fw_version() */
#ifndef PROBE_NAME
#define PROBE_NAME "unnamed"
#endif
#ifndef PROBE_BUILD
#define PROBE_BUILD "unbuilt"
#endif
/* Self limit: the runner can only close the connection, it cannot end the process on the console, so the probe ends
itself after PROBE_MAX_S seconds at the latest (set by the build script). */
#ifndef PROBE_MAX_S
#define PROBE_MAX_S 50
#endif
static volatile int g_handle = -1;
static int (*volatile g_setmargins)(int, int, int) = 0; /* unused here */
static void reset_rate(void) {
if (g_setmargins && g_handle >= 0) g_setmargins(g_handle, 0, 0);
}
static void probe_alarm(int sig) {
static const char msg[] = "TIMEOUT\tprobe self limit\n";
(void)sig;
(void)!write(1, msg, sizeof msg - 1);
reset_rate();
_exit(124);
}
/* Watchdog thread: alarm()/SIGALRM does not help when the main thread hangs in a blocking system call or IPC. The
thread sleeps PROBE_MAX_S seconds, writes TIMEOUT with write() and ends the process with _exit(124). alarm() stays
as a second safeguard. */
static void* probe_watchdog(void* arg) {
static const char msg[] = "TIMEOUT\tprobe watchdog thread\n";
unsigned left = PROBE_MAX_S;
(void)arg;
while (left) left = sleep(left);
(void)!write(1, msg, sizeof msg - 1);
reset_rate();
_exit(124);
return 0;
}
static void probe_watchdog_start(void) {
pthread_t t;
if (pthread_create(&t, 0, probe_watchdog, 0) == 0) pthread_detach(t);
}
static int cases = 0;
static void probe_header(void) {
char utc[32];
time_t now = time(0);
probe_watchdog_start();
struct tm tmv;
gmtime_r(&now, &tmv);
strftime(utc, sizeof utc, "%Y-%m-%dT%H:%M:%SZ", &tmv);
printf("PROBE\t%s\tfw=0x%08x\tbuild=%s\tpid=%d\tutc=%s\n", PROBE_NAME, kernel_get_fw_version(), PROBE_BUILD,
getpid(), utc);
fflush(stdout);
}
static void probe_case(const char* id, const char* call, long ret, int err, const char* extra) {
printf("CASE\t%s\t%s\t%ld\t%d\t%s\n", id, call, ret, err, extra ? extra : "-");
fflush(stdout);
cases++;
}
static void probe_end(void) {
printf("END\t%d\n", cases);
fflush(stdout);
}
#include <setjmp.h>
typedef int (*fn_list)(int*, size_t, size_t*);
typedef int (*fn_info_ex)(int, void*);
typedef int (*fn_info)(int, void*);
static sigjmp_buf guard_env;
static volatile int guard_sig = 0, guard_active = 0, guard_hits = 0;
static void guard_handler(int s) {
static const char msg[] = "FAULT\tguard\n";
guard_sig = s;
if (!guard_active || ++guard_hits > 8) { (void)!write(1, msg, sizeof msg - 1); _exit(125); }
guard_active = 0;
siglongjmp(guard_env, 1);
}
static void* find(void* lk, const char* name) {
return 0;
}
int main(void) {
struct sigaction sa;
memset(&sa, 0, sizeof sa);
sa.sa_handler = guard_handler;
sigaction(SIGSEGV, &sa, 0);
sigaction(SIGBUS, &sa, 0);
signal(SIGALRM, probe_alarm);
alarm(PROBE_MAX_S);
probe_header();
char extra[320], id[16], label[100];
(void)find;
errno = 0;
void* lk = dlopen("libkernel.sprx", RTLD_LAZY);
probe_case("0", "load libkernel.sprx", lk ? 0 : -1, errno, lk ? "loaded" : dlerror());
if (!lk) { probe_end(); return 0; }
fn_list l_int = (fn_list)dlsym(lk, "sceKernelGetModuleListInternal");
fn_info_ex i_int = (fn_info_ex)dlsym(lk, "sceKernelGetModuleInfoInternal");
void* lsm = dlsym(lk, "sceKernelLoadStartModuleForSysmodule");
int where_l = l_int ? 1 : 0, where_i = i_int ? 1 : 0;
if (!l_int) { l_int = (fn_list)dlsym(RTLD_DEFAULT, "sceKernelGetModuleListInternal"); where_l = l_int ? 2 : 0; }
if (!i_int) { i_int = (fn_info_ex)dlsym(RTLD_DEFAULT, "sceKernelGetModuleInfoInternal"); where_i = i_int ? 2 : 0; }
if (!lsm) lsm = dlsym(RTLD_DEFAULT, "sceKernelLoadStartModuleForSysmodule");
fn_list l_pub = (fn_list)dlsym(lk, "sceKernelGetModuleList");
fn_info i_pub = (fn_info)dlsym(lk, "sceKernelGetModuleInfo");
snprintf(extra, sizeof extra, "ListInternal=%d (0 none, 1 libkernel, 2 global) InfoInternal=%d LoadStartModuleForSysmodule_exists=%d GetModuleList=%d GetModuleInfo=%d",
where_l, where_i, lsm != 0, l_pub != 0, i_pub != 0);
probe_case("0b", "dlsym of the functions (nothing is loaded)", 0, 0, extra);
if (!l_int && !i_int) { probe_end(); return 0; }
int h1[256], h2[256];
size_t n1 = 0, n2 = 0;
int have = 0;
memset(h1, 0, sizeof h1);
memset(h2, 0, sizeof h2);
if (l_int) {
errno = 0;
int r = l_int(h1, 256, &n1);
snprintf(extra, sizeof extra, "rc=0x%08x errno=%d actual=%zu", (unsigned)r, errno, n1);
probe_case("1.1", "sceKernelGetModuleListInternal(list[256], 256, &n)", r, errno, extra);
have = r == 0;
}
if (l_pub) {
errno = 0;
int r = l_pub(h2, 256, &n2);
int same = n1 == n2;
for (size_t k = 0; same && k < n1 && k < 256; ++k) if (h1[k] != h2[k]) same = 0;
snprintf(extra, sizeof extra, "rc=0x%08x errno=%d actual=%zu same_count_and_handles_as_Internal=%d", (unsigned)r, errno, n2, l_int ? same : -1);
probe_case("1.2", "sceKernelGetModuleList(list[256], 256, &n)", r, errno, extra);
}
if (l_int) {
int small[4];
size_t a = 0;
errno = 0;
int r = l_int(small, 4, &a);
snprintf(extra, sizeof extra, "rc=0x%08x errno=%d actual=%zu", (unsigned)r, errno, a);
probe_case("1.3", "sceKernelGetModuleListInternal(list[4], 4, &n)", r, errno, extra);
a = 77;
errno = 0;
r = l_int(small, 0, &a);
snprintf(extra, sizeof extra, "rc=0x%08x errno=%d actual=%zu", (unsigned)r, errno, a);
probe_case("1.4", "sceKernelGetModuleListInternal(list, 0, &n)", r, errno, extra);
}
/* c) info of the first 8 handles */
int first = 0;
if (i_int && have) {
for (size_t k = 0; k < 8 && k < n1; ++k) {
unsigned char b[0x1A8];
memset(b, 0xaa, sizeof b);
unsigned long long ssz = 0x1A8;
memcpy(b, &ssz, 8);
errno = 0;
int r = i_int(h1[k], b);
int e = errno;
unsigned long long st = 0;
memcpy(&st, b, 8);
char nm[25];
memcpy(nm, b + 8, 24);
nm[24] = 0;
const char* base = strrchr(nm, '/');
base = base ? base + 1 : nm;
unsigned segc = 0, refc = 0;
memcpy(&segc, b + 0x1A0, 4);
memcpy(&refc, b + 0x1A4, 4);
unsigned long long a0 = 0;
char seg[160] = "";
for (unsigned s = 0; s < segc && s < 4; ++s) {
unsigned long long ad = 0;
unsigned sz = 0;
int pr = 0;
memcpy(&ad, b + 0x160 + s * 16, 8);
memcpy(&sz, b + 0x160 + s * 16 + 8, 4);
memcpy(&pr, b + 0x160 + s * 16 + 12, 4);
if (s == 0) a0 = ad;
char t[40];
snprintf(t, sizeof t, " [+%llx size %x prot %d]", ad - a0, sz, pr);
strncat(seg, t, sizeof seg - strlen(seg) - 1);
}
int eq = -1;
if (i_pub) {
unsigned char p[0x160];
memset(p, 0, sizeof p);
unsigned long long psz = 0x160;
memcpy(p, &psz, 8);
int pr = i_pub(h1[k], p);
eq = pr == 0 && memcmp(p + 8, b + 8, 256) == 0 && memcmp(p + 0x108, b + 0x160, 64) == 0 && memcmp(p + 0x148, b + 0x1A0, 4) == 0;
}
snprintf(id, sizeof id, "2.%zu", k + 1);
snprintf(label, sizeof label, "sceKernelGetModuleInfoInternal(handle #%zu in the list)", k + 1);
snprintf(extra, sizeof extra, "rc=0x%08x errno=%d st_size=0x%llx name=%s segment_count=%u ref_count=%u segments:%s equals_GetModuleInfo=%d", (unsigned)r, e, st, base, segc,
refc, seg, eq);
probe_case(id, label, r, e, extra);
if (k == 0) first = h1[0];
}
}
/* d) error order */
if (i_int) {
int hv = have && n1 ? h1[0] : 1;
unsigned long long sizes[5] = {0, 0x1A7, 0x1A9, 0x1B0, 0x100};
for (int i = 0; i < 5; ++i) {
unsigned char b[0x1B8];
memset(b, 0, sizeof b);
memcpy(b, &sizes[i], 8);
errno = 0;
int r = i_int(hv, b);
snprintf(id, sizeof id, "3.%d", i + 1);
snprintf(label, sizeof label, "InfoInternal(valid handle, st_size 0x%llx)", sizes[i]);
snprintf(extra, sizeof extra, "rc=0x%08x errno=%d", (unsigned)r, errno);
probe_case(id, label, r, errno, extra);
}
int bad[3] = {0, -1, 0x7fff};
for (int i = 0; i < 3; ++i) {
unsigned char b[0x1A8];
memset(b, 0, sizeof b);
unsigned long long ssz = 0x1A8;
memcpy(b, &ssz, 8);
errno = 0;
int r = i_int(bad[i], b);
snprintf(id, sizeof id, "4.%d", i + 1);
snprintf(label, sizeof label, "InfoInternal(handle %d, st_size 0x1A8)", bad[i]);
snprintf(extra, sizeof extra, "rc=0x%08x errno=%d", (unsigned)r, errno);
probe_case(id, label, r, errno, extra);
}
unsigned char b[0x1A8];
memset(b, 0, sizeof b);
unsigned long long wrong = 0x100;
memcpy(b, &wrong, 8);
errno = 0;
int r = i_int(0x7fff, b);
snprintf(extra, sizeof extra, "rc=0x%08x errno=%d", (unsigned)r, errno);
probe_case("4.4", "InfoInternal(invalid handle 0x7fff, wrong st_size 0x100)", r, errno, extra);
guard_sig = 0;
r = -1;
int e = 0;
if (sigsetjmp(guard_env, 1) == 0) {
guard_active = 1;
errno = 0;
r = i_int(0x7fff, 0);
e = errno;
guard_active = 0;
}
snprintf(extra, sizeof extra, "rc=0x%08x errno=%d fault_signal=%d", (unsigned)r, e, (int)guard_sig);
probe_case("5.1", "InfoInternal(invalid handle 0x7fff, NULL info)", r, e, extra);
guard_sig = 0;
r = -1;
e = 0;
if (sigsetjmp(guard_env, 1) == 0) {
guard_active = 1;
errno = 0;
r = i_int(hv, 0);
e = errno;
guard_active = 0;
}
snprintf(extra, sizeof extra, "rc=0x%08x errno=%d fault_signal=%d", (unsigned)r, e, (int)guard_sig);
probe_case("5.2", "InfoInternal(valid handle, NULL info)", r, e, extra);
}
if (l_int) {
guard_sig = 0;
int r = -1, e = 0;
size_t a = 0;
if (sigsetjmp(guard_env, 1) == 0) {
guard_active = 1;
errno = 0;
r = l_int(0, 8, &a);
e = errno;
guard_active = 0;
}
snprintf(extra, sizeof extra, "rc=0x%08x errno=%d actual=%zu fault_signal=%d", (unsigned)r, e, a, (int)guard_sig);
probe_case("5.3", "sceKernelGetModuleListInternal(NULL list, 8, &n)", r, e, extra);
}
(void)first;
probe_end();
return 0;
}AI-assisted (Claude Code). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The debt entry for
sceKernelGetModuleInfoInternal,sceKernelGetModuleListInternalandsceKernelLoadStartModuleForSysmodule(docs/dev/debt/libkernel_sys.md) says thatsceKernelGetModuleListInternalreturns the same list assceKernelGetModuleList, "as fpPS4 does", that fpPS4 marks this as a guess, and that "neither is checked on a PS5"; it also describes the check order ofsceKernelGetModuleInfoInternal(EFAULTfor a null pointer,EINVALwhenst_sizeis not 0x1A8,ESRCHfor an unknown handle) as shadPS4's. A probe on a PS5 with firmware 11.60, from a payload process, measured both.sceKernelGetModuleListInternalreturned 5 modules (eboot.bin,libkernel_sys.sprx,libSceLibcInternal.sprx,libSceSysmodule.sprx,libSceNet.sprx; line 4 of the raw output) wheresceKernelGetModuleListreturned 1 (line 5), so the two lists are not the same there.sceKernelGetModuleInfoInternalchecked in the order of the entry: a NULLinforeturnedEFAULT(14) first, for an unknown handle too (lines 22 and 23); a wrongst_size(0, 0x1A7, 0x1A9, 0x1B0, 0x100) returnedEINVAL(22), also for an unknown handle (lines 13 to 17 and 21); the handles -1 and 0x7fff returnedESRCH(3) with the rightst_size(lines 19 and 20); the handle 0 returned 0 (line 18).This pull request records that as a change fragment,
docs/dev/debt/changes/docs-libkernel-sys-module-list-internal-console-1160.md, and it splits the entry in two, because one entry holding both new passages (the check-order sentence and the list measurement put into the old entry unchanged) would be 1351 characters and the limit is 1000: the first entry keepssceKernelGetModuleInfoInternalandsceKernelLoadStartModuleForSysmodulewith one added sentence for the check order (848 characters, 951 before); the second, new one issceKernelGetModuleListInternalwith the list result (537 characters). All other words of the existing entry stay; the sentence aboutsceKernelGetModuleListInternalmoves into the second entry, and its closing words "and neither is checked on a PS5" are replaced by the measurement. Counted with the list marker, ascheck_conventionsdoes.AnyPS5 still returns the list of
sceKernelGetModuleListforsceKernelGetModuleListInternal; no code changes, and this says nothing about a title process: the five modules are the ones of a payload process, and a title process may differ. It also says nothing aboutsceKernelIsModuleLoaded, which askssceKernelGetModuleListInternal, for a title.Tested
Measured on a PS5 with firmware 11.60 (
kernel_get_fw_version0x11600005, line 1 of the raw output), from a homebrew payload process, on 2026-11-18 at 05:05 UTC (the console's own clock in thePROBEline reads 06:47:43Z, 1 h 42 min ahead of the runner's clock). One run,END 23(line 25). A title process may differ. The probe changed nothing: besides loadinglibkernel.sprxand looking the names up withdlsym, it called onlysceKernelGetModuleListInternal,sceKernelGetModuleListandsceKernelGetModuleInfoInternal.sceKernelGetModuleListInternalsceKernelGetModuleListsceKernelGetModuleListsceKernelGetModuleInfoInternal, NULLinfoEFAULTbefore the handle is checked (lines 22, 23)st_size, any handleEINVALbeforeESRCH(lines 13 to 17, 21)st_sizeESRCH(lines 19, 20)Documentation change: no test was added or run. The fragment is one commit (head
9d8433e605) onmainat 61cce6e, only the fragment file, 9 lines in; its blob has no carriage return. On the head merged intomainat a40a139 I rantools/check_conventions.py --base upstream/main(no finding, 0 errors) andtools/debt_fold.py --check(exit code 0). The first comment holds the probe source and the raw output. Not tested: Linux, macOS, the CI runner, a title process, a second run, and firmware other than 11.60.Overlap: counted on 2026-11-24 from the 2467 open pull requests (file lists from the GitHub API, the 17 with 100 or more files read in full through the files API; the patches of the 1554 pull requests that change a file under
docs/dev/debt/or a libkernel or module file were searched forsceKernelGetModuleListInternal,sceKernelGetModuleInfoInternal,sceKernelLoadStartModuleForSysmoduleand the fragment name, at 21:36 to 22:04 UTC). This pull request adds one file,docs/dev/debt/changes/docs-libkernel-sys-module-list-internal-console-1160.md, and no code; no open pull request has a file of that name. Eleven open pull requests changedocs/dev/debt/libkernel_sys.md(#21464, #19486, #18190, #17936, #15037, #12642, #12315, #12130, #10657, #9302, #9297), none of them the entry of these three functions. #18112 (mirror libkernel exports throughlibkernel_web) addssceKernelGetModuleInfoInternal_nid_no_patchin code; it changes neither the entry nor the fragment. A merge of this head intomainat a40a139 was checked withgit merge-treeand is clean; as the head only adds a new file, it cannot conflict with another pull request unless that one adds the same file. This pull request does not depend on any of them (Depends on: none).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)