Repository navigation
docs(debt): record the fstatat results on firmware 11.60 - #22523
oneandonlydean merged 1 commit into
Conversation
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Probe source (built with ps5-payload-sdk v0.45; probe.c/* fstatat, payload process, firmware 11.60 (debt libkernel_sys.md fstatat entry: AnyPS5 passes AT_FDCWD (-100) and
absolute paths to stat, or to lstat with AT_SYMLINK_NOFOLLOW (0x200); any other relative path is joined to the descriptor's
host directory, found the same way as for fchdir, so guest path aliases and case-insensitive name matching do not apply to it,
and a ".." component is not kept inside the guest root; it returns EBADF for a descriptor that is not open [...]; the
console's answers are not measured). The probe looks fstatat and stat up with dlsym in libkernel.sprx and reads only metadata
of existing paths: fstatat(AT_FDCWD, "/dev/null", ...) against stat("/dev/null") (mode and inode equal), with and without
AT_SYMLINK_NOFOLLOW; a descriptor of the probe directory opened read-only with O_DIRECTORY (no listing): fstatat(dirfd, "."),
fstatat(dirfd, "..") against the same path reached through an absolute path (inode equal), a name that does not exist, an absolute path with a descriptor that is not open (-1: does it succeed); an invalid descriptor (-1 and 999) with a
relative path; a descriptor of /dev/null (not a directory) with a relative path. Only the return code, errno and the
equality of mode and inode are printed. No file is created, nothing is listed, no descriptor of the payload is closed.
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 <fcntl.h>
#include <sys/stat.h>
typedef int (*fn_fstatat)(int, const char*, struct stat*, int);
static void fault(int sig) {
static const char msg[] = "FAULT\tsignal in the call\n";
(void)sig;
(void)!write(1, msg, sizeof msg - 1);
_exit(125);
}
static fn_fstatat g_fs;
static void fs_case(const char* id, const char* label, int fd, const char* path, int flag, const struct stat* ref) {
struct stat st;
memset(&st, 0xaa, sizeof st);
char extra[140];
errno = 0;
int r = g_fs(fd, path, &st, flag);
int e = errno;
if (r == 0 && ref)
snprintf(extra, sizeof extra, "rc=0 is_dir=%d same_mode_as_ref=%d same_ino_as_ref=%d", S_ISDIR(st.st_mode) != 0,
st.st_mode == ref->st_mode, st.st_ino == ref->st_ino);
else if (r == 0)
snprintf(extra, sizeof extra, "rc=0 is_dir=%d", S_ISDIR(st.st_mode) != 0);
else
snprintf(extra, sizeof extra, "rc=%d errno=%d", r, e);
probe_case(id, label, r, e, extra);
}
int main(void) {
signal(SIGALRM, probe_alarm);
signal(SIGSEGV, fault);
signal(SIGBUS, fault);
alarm(PROBE_MAX_S);
probe_header();
char extra[160];
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; }
g_fs = (fn_fstatat)dlsym(lk, "fstatat");
snprintf(extra, sizeof extra, "fstatat=%d", g_fs != 0);
probe_case("0b", "dlsym of fstatat", g_fs ? 0 : -1, 0, extra);
if (!g_fs) { probe_end(); return 0; }
struct stat sn, sd, sr;
int a = stat("/dev/null", &sn), b = stat("/data/anyps5_probe", &sd);
snprintf(extra, sizeof extra, "stat(/dev/null)=%d stat(probe dir)=%d", a, b);
probe_case("1", "reference stats", 0, 0, extra);
if (a != 0 || b != 0) { probe_end(); return 0; }
memset(&sr, 0, sizeof sr);
int pr = g_fs(-100, "/data/anyps5_probe/..", &sr, 0);
snprintf(extra, sizeof extra, "fstatat(AT_FDCWD, probe dir/..)=%d", pr);
probe_case("1b", "reference stat of the parent through an absolute path", pr, errno, extra);
fs_case("2.1", "fstatat(AT_FDCWD, \"/dev/null\", 0)", -100, "/dev/null", 0, &sn);
fs_case("2.2", "fstatat(AT_FDCWD, \"/dev/null\", AT_SYMLINK_NOFOLLOW)", -100, "/dev/null", 0x200, &sn);
fs_case("2.3", "fstatat(-1, \"/dev/null\", 0) absolute path with no descriptor", -1, "/dev/null", 0, &sn);
int dirfd = open("/data/anyps5_probe", O_RDONLY | O_DIRECTORY);
snprintf(extra, sizeof extra, "opened=%d", dirfd >= 0);
probe_case("3a", "open the probe directory read-only with O_DIRECTORY", dirfd, errno, extra);
if (dirfd >= 0) {
fs_case("3.1", "fstatat(dirfd, \".\", 0)", dirfd, ".", 0, &sd);
fs_case("3.2", "fstatat(dirfd, \"..\", 0)", dirfd, "..", 0, pr == 0 ? &sr : 0);
fs_case("3.3", "fstatat(dirfd, \"zzz_not_here\", 0)", dirfd, "zzz_not_here", 0, 0);
close(dirfd);
}
fs_case("4.1", "fstatat(-1, \"null\", 0) relative path", -1, "null", 0, 0);
fs_case("4.2", "fstatat(999, \"null\", 0) relative path", 999, "null", 0, 0);
int fileFd = open("/dev/null", O_RDONLY);
if (fileFd >= 0) {
fs_case("5.1", "fstatat(fd of /dev/null, \"x\", 0) not a directory", fileFd, "x", 0, 0);
close(fileFd);
}
probe_end();
return 0;
}stdoutAI-assisted (Claude Code). |
What
The
fstatatentry indocs/dev/debt/libkernel_sys.mddescribes how AnyPS5 passesAT_FDCWDand absolute paths tostatorlstat, joins any other relative path to the directory descriptor's host directory and returnsEBADFandENOTDIRfor descriptors that are not open or not a directory, and ends with "Console behaviour is unverified". A probe has now calledfstatatinlibkernel.sprxfrom a payload process on firmware 11.60. The pull request replaces that last sentence through a debt fragment, as the contribution rules ask; no code changes.On firmware 11.60
fstatat(AT_FDCWD, "/dev/null", ...)returned 0 with the same mode and inode asstat, with flags 0 and withAT_SYMLINK_NOFOLLOW(cases 2.1 and 2.2, lines 6 and 7), and so did an absolute path with descriptor -1, which is not open (2.3, line 8). Through a descriptor of the probe directory (opened read-only withO_DIRECTORY),.returned 0 with the mode and inode of that directory asstatgives them (3.1, line 10) and..returned 0 with the mode and inode of its parent asfstatatgave them for an absolute path (3.2, line 11); a name that does not exist returned -1 witherrno2 (ENOENT, 3.3, line 12). A relative path with descriptor -1 or 999 returned -1 witherrno9 (EBADF, 4.1 and 4.2, lines 13 and 14), and a relative path with the descriptor of/dev/nullreturned -1 witherrno20 (ENOTDIR, 5.1, line 15).When the code is read, AnyPS5 answers the same way:
fstatat_nid_postfix(libkernel_sys/Export.cpp, lines 1135 to 1143) sendsAT_FDCWDand absolute paths tostatorlstat(line 1139), also with descriptor -1, and other relative paths toStatInDirectory_nid_no_patch(line 1140), whereGetDirectoryDescriptorPath_nid_no_patchreturnsEBADFfor a descriptor that is not open andENOTDIRfor an open one without a directory path (libkernel/File/src/DirectoryDescriptor.cpp, lines 489 to 500). The testGuestKernelSyspins the successes with a directory descriptor and withAT_FDCWD,ENOENT, the absolute path with descriptor -1 andEBADFfor -1 (lines 2242 to 2258). The emulator itself was not run for this pull request; descriptor 999 and a/dev/nulldescriptor take the same code paths but were not run, and..is compared only in that both answer with the parent directory, not for the console's directory tree.Not measured: flags other than
AT_SYMLINK_NOFOLLOW(the entry saysEINVAL), symbolic links,..above the guest root, a relative path withAT_FDCWD, guest path aliases and case-insensitive name matching, and a title process.Tested
Measured on a PS5 with firmware 11.60 (
kernel_get_fw_version0x11600005), from a homebrew payload process (ps5-payload-sdk v0.45, elfldr) that loadslibkernel.sprxand takesfstatatandstatwithdlsym, on 2026-11-17 at 16:04 UTC. A title process may differ. The cases are 0 to 5.1, lines 2 to 15 of the raw output in the first comment.main(code read, not run)fstatat(AT_FDCWD, "/dev/null", 0), withAT_SYMLINK_NOFOLLOW, and with descriptor -1stat(lines 6 to 8)statorlstatfstatat(dirfd, "."),fstatat(dirfd, "..")stat) and of its parent (fstatat, absolute path) (lines 10, 11)fstatat(dirfd, "zzz_not_here")ENOENT(line 12)ENOENTEBADF(lines 13, 14)EBADF/dev/nullENOTDIR(line 15)ENOTDIRfor an open descriptor without a directory pathtools/check_conventions.py --base upstream/mainpasses with no error and no warning (the entry is 998 characters, up from 632). This is a documentation change, so no test was added or run, and no GPU test applies. Not tested: the emulator against these calls, a title process, other firmware, and the cases listed above as not measured.Overlap: the other open pull requests that change the file of this branch (the fragment
docs/dev/debt/changes/docs-libkernel-sys-fstatat-console-1160.md, a new file),core/libs/prx/libkernel_sys/Export.cpporcore/libs/prx/libkernel/File/src/DirectoryDescriptor.cpp, which the entry links, or the debt entry it changes, found by reading the changed files of all 1751 open pull requests at about 17:38 UTC, by reading what they change indocs/dev/debt/libkernel_sys.mdand in the fragments underdocs/dev/debt/changes/forfstatat, and by searching their titles and branch names for the same name (no hit), were test-merged on 2026-11-17 at about 18:35 UTC againstmain89b0eef7ab4together with this head; the branch is based on4b83e9d2234, an ancestor of it, merges intomainwithout a conflict, andtools/debt_fold.py --checkapplies the fragment to thelibkernel_sysdebt file ofmainwithout an error (checked without the fragmentlibressl3-20171-inventory.md, which already conflicts withfeat-libressl3-evp-pkey-new-mac-key-v2.mdonmainand is not part of this change), the text the change names occurs in exactly one entry, and no other fragment changes that entry. Ten pull requests listExport.cppoflibkernel_sys(#22219, #21984, #18190, #17908, #17897, #17885, #15037, #12315, #9389 and #6918) and none listsDirectoryDescriptor.cpp; as this branch adds only a fragment, none of them conflicts only with this change, and none changes a line that namesfstatator the debt entry of this branch. The merged result was not built or run; this is a documentation change.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)