Skip to content

docs(libSceKeyboard): record Read and ReadState before initialisation on firmware 11.60 - #28876

Open
xXPBSXx wants to merge 1 commit into
boykopovar:mainfrom
xXPBSXx:docs-libscekeyboard-read-before-init-measured
Open

xXPBSXx wants to merge 1 commit into
boykopovar:mainfrom
xXPBSXx:docs-libscekeyboard-read-before-init-measured

Conversation

@xXPBSXx

@xXPBSXx xXPBSXx commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

What

sceKeyboardRead and sceKeyboardReadState (core/libs/prx/libSceKeyboard/src/keyboard_impl.cpp) return NOT_INITIALIZED before any sceKeyboardInit in AnyPS5, and ReadState clears its output record first. The fragment keyboard-read-check-order.md on main records the order of the checks from a firmware 13.42 reading, and no entry says what a console answers. This change adds one new technical debt entry with that measurement. It does not change code or tests, and it does not touch the existing entry in docs/dev/debt/libSceKeyboard.md (line 5).

It adds one fragment, docs/dev/debt/changes/docs-libscekeyboard-read-before-init-measured.md (## add Functional), one entry of 897 characters counted with the leading - (limit 1000). On a PS5 with firmware 11.60, in a homebrew payload process, before any sceKeyboardInit: Read(1, buffer, 1) returns 0x80da0005 and leaves the buffer unchanged; ReadState(1, buffer) returns 0x80da0005 after clearing the 96-byte record and writing a length of 1 at offset 20; Read(1, NULL, 1) returns 0x80da0005, so the initialisation is checked before the pointer; ReadState(1, NULL) returns 0x80da0001. Reading keyboard_impl.cpp, the host model returns the same four values. The entry also says that in the first run the sceKeyboardInit call that followed did not return within 50 s and the process did not exit (one run).

Not measured, and said so in the entry: anything after a successful initialisation, sceKeyboardOpen and handles other than 1, a title process (it may differ), and the cause of the hang in that one run. The prototypes (int handle, void* data, int num) and (int handle, void* data) are assumptions.

Tested

Measured on a PS5 with firmware 11.60 (kernel_get_fw_version 0x11600005), from a homebrew payload process, on 2026-12-04 at 08:31 UTC and 09:31 UTC, two runs with two probe builds. Both runs gave the same four results above (p.1 to p.4, signal=0). The first run is the one whose later sceKeyboardInit call did not return; the second run has no such call and ended normally with END 8. The two probe sources and the complete output of both runs are in the first comment.

This is documentation only; no build or test was run for it. I ran tools/check_conventions.py --base upstream/main with the title and this description and tools/debt_fold.py --check on the merge of this branch (head 3990a55fb849) with main at df9c2376c425 on 2026-12-04 at about 11:35 UTC: it reports "All conventions checks passed", and debt_fold.py --check exits with 0.

Overlap: counted on 2026-12-04 from the 1886 open pull requests (file lists from the GitHub API, the pull requests with 100 or more files read in full through the files API; the 1092 pull requests that change a file with libSceKeyboard or keyboard in its path or a file under docs/dev/debt/, or have keyboard in the title or branch name, had their patches of the files under docs/dev/debt/ and of the files with libSceKeyboard or Keyboard in the path searched for sceKeyboardRead, sceKeyboardReadState, sceKeyboardInit, keyboard_impl, 0x80da0005 and the fragment name, from 11:08 to 11:28 UTC, main at df9c2376c425 at the start). No open pull request changes the fragment docs/dev/debt/changes/docs-libscekeyboard-read-before-init-measured.md or the entry at docs/dev/debt/libSceKeyboard.md:5, and no patch of a debt file or of a keyboard file contains a searched name. 7 open pull requests change a file with keyboard in its path: #25454, #25470, #25477, #25493 and #25500 (libSceUserService, a Keyboard.cpp and a KeyboardDialog.cpp of that library), #20016 (KeyboardMouse.cpp of libSceVideoOut) and #6743 (perf(agc): defer pipeline artifacts with first-use preparation, which changes keyboard_impl.cpp among other keyboard files in a larger change, without a searched name in its patch); all 7 merge cleanly with this head. On main, docs/dev/debt/changes/keyboard-read-check-order.md records the order of the checks of sceKeyboardRead and sceKeyboardReadState from a firmware 13.42 reading, and docs/dev/debt/changes/fix-libSceKeyboard-guest-output-pointers.md has entries for other functions (sceKeyboardGetConnection, sceKeyboardDebugGetDeviceId, sceKeyboardGetKey2Char): both are other entries than this one, which is an add Functional entry with the console answers before initialisation. One commit has been merged to main since 63b98e5bf852, the base of this branch; it changed no keyboard file, and a merge of this head into main at df9c2376c425 was checked at 11:30 UTC and is clean. This pull request does not depend on any of them (Depends on: none).

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt and the licence notice of code adapted from upstream (see AGENTS.md)
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a (no GPU code)
  • AI-assisted: yes

Summary by CodeRabbit

  • Documentation
    • Added measured documentation describing keyboard read behavior before initialization, including return values and buffer effects for both null and non-null pointers.
    • Recorded matching results from the host model and noted that behavior after initialization has not yet been measured.

… on firmware 11.60

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@xXPBSXx

xXPBSXx commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

Probe sources and the complete raw output of the two runs this pull request cites. PROBE_BUILD in a PROBE line is the first 12 hex digits of the SHA-256 of the original source file; the copies below omit a label word from their first comment. The utc in a PROBE line is the console's own clock, about 1 h 43 min ahead of real UTC; the run with pid 124 started at 08:31:11 UTC and the run with pid 127 at 09:31:08 UTC on 2026-12-04. Both ran in a PS5 payload process (firmware 11.60; a title process may differ). The first source calls only Read and ReadState before any initialisation. The second source also calls sceKeyboardInit; its run printed lines up to the marker before the first sceKeyboardInit call and then printed nothing more and no END line (the runner reported a timeout), which is the evidence for the last sentence of the entry. The header comment of the second source says that earlier runs got no handle from sceKeyboardOpen with error 0x809b0081; that sentence is wrong: 0x809b0081 is a return value of scePadOpen, no earlier run called sceKeyboardOpen, and no result of sceKeyboardOpen is cited here.

probe.c, build b7bf3ca07138 (Read and ReadState before initialisation; no call to sceKeyboardInit)
#include <errno.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: on timeout the runner can only close the connection, not end the process on the console.
   The probe ends itself after at most PROBE_MAX_S seconds (the build script sets timeout - 10 s). */
#ifndef PROBE_MAX_S
#define PROBE_MAX_S 50
#endif

static void probe_alarm(int sig) {
  static const char msg[] = "TIMEOUT\tprobe self limit\n";
  (void)sig;
  (void)!write(1, msg, sizeof msg - 1);
  _exit(124);
}

static int cases = 0;

static void probe_header(void) {
  char utc[32];
  time_t now = time(0);
  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);
}

/* CASE: id, description of the call, return value as long, errno (0 if not set), extra (hex/bytes). */
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 <dlfcn.h>
#include <setjmp.h>
#include <stdlib.h>
#include <pthread.h>
#include <sys/mman.h>
#include <sys/types.h>

static sigjmp_buf guard_env;
static volatile int guard_sig = 0;
static volatile int guard_active = 0;
static volatile int guard_hits = 0;
static void guard_handler(int s) {
  static const char msg[] = "FAULT\tprobe guard: fault outside a guarded call or too many faults\n";
  if(!guard_active || ++guard_hits > 8) {
    (void)!write(1, msg, sizeof msg - 1);
    _exit(125);
  }
  guard_sig = s;
  guard_active = 0;
  siglongjmp(guard_env, 1);
}
static void guard_arm(void) {
  struct sigaction sa;
  memset(&sa, 0, sizeof sa);
  sa.sa_handler = guard_handler;
  sigaction(SIGSEGV, &sa, 0);
  sigaction(SIGBUS, &sa, 0);
  sigaction(SIGABRT, &sa, 0);
}
#define CALL(rvar, evar, expr) do { errno = 0; guard_sig = 0; rvar = -1; if(sigsetjmp(guard_env, 1) == 0) { guard_active = 1; rvar = (expr); } guard_active = 0; evar = errno; } while(0)
#include <time.h>

/* sceKeyboardRead and sceKeyboardReadState in libSceKeyboard.sprx on firmware 11.60 (payload process; a title process may differ), argument and handle order for debt entry libSceKeyboard.md:5. This probe makes no call to sceKeyboardInit or sceKeyboardOpen: it measures only the result of Read and ReadState BEFORE any initialisation, with an own buffer (0xAA fill) and with NULL data, and whether ReadState clears its output buffer. The prototypes (int handle, void* data, int num) and (int handle, void* data) and the 96-byte data record are ASSUMPTIONS from core/libs/prx/libSceKeyboard of AnyPS5 (upstream/main 809a271099b9). No unmapped or read-only pointer is passed. A watchdog thread ends the probe after PROBE_MAX_S. */

typedef long (*f4_t)(long, long, long, long);
static void* L;
static int stopped = 0;
static void note(const char* t) { printf("NOTE\t%s\n", t); fflush(stdout); }
static void report(const char* id, const char* what, const char* ex) { probe_case(id, what, 0, 0, ex); }
static void* wd_thread(void* arg) {
  static const char msg[] = "TIMEOUT\twatchdog thread\n";
  unsigned left = PROBE_MAX_S;
  (void)arg;
  while(left) left = sleep(left);
  (void)!write(1, msg, sizeof msg - 1);
  _exit(124);
  return 0;
}
static void wd_start(void) { pthread_t t; if(pthread_create(&t, 0, wd_thread, 0) == 0) pthread_detach(t); }
static int canary_ok(const unsigned char* p, int n) { for(int i = 0; i < n; i++) if(p[i] != 0xAA) return 0; return 1; }

static struct { unsigned char b[18 * 96]; unsigned char can[64]; } B;
static f4_t f_init, f_open, f_close, f_read, f_rs;
static long last_r = -1;
static void runf(const char* id, const char* what, f4_t f, long a, long b, long c, long d, int own) {
  if(stopped) return;
  if(own) { memset(B.b, 0xAA, sizeof B.b); memset(B.can, 0xAA, sizeof B.can); }
  long r = -1; int e = 0;
  CALL(r, e, f(a, b, c, d));
  last_r = r;
  char ex[520];
  if(own) {
    int ch = 0, last = -1;
    for(int i = 0; i < (int)sizeof B.b; i++) if(B.b[i] != 0xAA) { ch++; last = i; }
    unsigned w[8] = {0, 0, 0, 0, 0, 0, 0, 0};
    memcpy(w, B.b, 32);
    snprintf(ex, sizeof ex, "rc=0x%08x errno=%d changed=%d last_changed=%d off20_length=0x%08x w0=0x%08x w1=0x%08x w2=0x%08x w3=0x%08x canaries_intact=%d signal=%d", (unsigned)r, e, ch, last, w[5], w[0], w[1], w[2], w[3], canary_ok(B.can, 64), (int)guard_sig);
  } else {
    snprintf(ex, sizeof ex, "rc=0x%08x errno=%d signal=%d", (unsigned)r, e, (int)guard_sig);
  }
  probe_case(id, what, guard_sig ? -1 : (int)r, e, ex);
  if(guard_sig) stopped = 1;
}
#define BP ((long)(void*)B.b)
int main(void) {
  signal(SIGALRM, probe_alarm);
  alarm(PROBE_MAX_S);
  probe_header();
  guard_arm();
  wd_start();
  note("0.pre: dlopen of libSceKeyboard.sprx next");
  L = dlopen("libSceKeyboard.sprx", RTLD_LAZY);
  { char ex[16]; snprintf(ex, sizeof ex, "%d", L != 0); report("0", "dlopen of the module (1 yes, 0 no)", ex); }
  if(!L) { probe_end(); return 0; }
  { void* k = dlopen("libkernel.sprx", RTLD_LAZY); char ex[80]; snprintf(ex, sizeof ex, "libkernel_opened=%d control_found=%d", k != 0, k ? dlsym(k, "sceKernelGetProcessTime") != 0 : 0); report("1", "control in libkernel.sprx: sceKernelGetProcessTime (dlsym, name only)", ex); }
  { char ex[40]; snprintf(ex, sizeof ex, "found=%d", dlsym(L, "probe_e_no_such_function_in_module") != 0); report("2", "negative control, a name that does not exist (expected found=0)", ex); }
  f_init = (f4_t)dlsym(L, "sceKeyboardInit");
  f_open = (f4_t)dlsym(L, "sceKeyboardOpen");
  f_close = (f4_t)dlsym(L, "sceKeyboardClose");
  f_read = (f4_t)dlsym(L, "sceKeyboardRead");
  f_rs = (f4_t)dlsym(L, "sceKeyboardReadState");
  { char ex[120]; snprintf(ex, sizeof ex, "Init=%d Open=%d Close=%d Read=%d ReadState=%d", f_init != 0, f_open != 0, f_close != 0, f_read != 0, f_rs != 0); report("3", "the five functions (dlsym, name only)", ex); }
  if(!f_init || !f_open || !f_read || !f_rs) { probe_end(); return 0; }
  note("next: before sceKeyboardInit: Read and ReadState with an own buffer (0xAA fill) and with NULL; assumed prototypes Read(int handle, void* data, int num) and ReadState(int handle, void* data), data records of 96 bytes");
  runf("p.1", "Read(1, own buffer, 1) before Init", f_read, 1, BP, 1, 0, 1);
  runf("p.2", "ReadState(1, own buffer) before Init", f_rs, 1, BP, 0, 0, 1);
  runf("p.3", "Read(1, NULL, 1) before Init", f_read, 1, 0, 1, 0, 0);
  runf("p.4", "ReadState(1, NULL) before Init", f_rs, 1, 0, 0, 0, 0);
  if(stopped) note("a fault ended the calls");
  probe_end();
  return 0;
}
Raw output of the run with pid 127 (build b7bf3ca07138)
PROBE	libSceKeyboard_read_before_init	fw=0x11600005	build=b7bf3ca07138	pid=127	utc=2026-12-04T11:14:05Z
NOTE	0.pre: dlopen of libSceKeyboard.sprx next
CASE	0	dlopen of the module (1 yes, 0 no)	0	0	1
CASE	1	control in libkernel.sprx: sceKernelGetProcessTime (dlsym, name only)	0	0	libkernel_opened=1 control_found=1
CASE	2	negative control, a name that does not exist (expected found=0)	0	0	found=0
CASE	3	the five functions (dlsym, name only)	0	0	Init=1 Open=1 Close=1 Read=1 ReadState=1
NOTE	next: before sceKeyboardInit: Read and ReadState with an own buffer (0xAA fill) and with NULL; assumed prototypes Read(int handle, void* data, int num) and ReadState(int handle, void* data), data records of 96 bytes
CASE	p.1	Read(1, own buffer, 1) before Init	-2133196795	0	rc=0x80da0005 errno=0 changed=0 last_changed=-1 off20_length=0xaaaaaaaa w0=0xaaaaaaaa w1=0xaaaaaaaa w2=0xaaaaaaaa w3=0xaaaaaaaa canaries_intact=1 signal=0
CASE	p.2	ReadState(1, own buffer) before Init	-2133196795	0	rc=0x80da0005 errno=0 changed=96 last_changed=95 off20_length=0x00000001 w0=0x00000000 w1=0x00000000 w2=0x00000000 w3=0x00000000 canaries_intact=1 signal=0
CASE	p.3	Read(1, NULL, 1) before Init	-2133196795	0	rc=0x80da0005 errno=0 signal=0
CASE	p.4	ReadState(1, NULL) before Init	-2133196799	0	rc=0x80da0001 errno=0 signal=0
END	8
probe.c, build 62e46edd5e9c (also calls sceKeyboardInit)
#include <errno.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: on timeout the runner can only close the connection, not end the process on the console.
   The probe ends itself after at most PROBE_MAX_S seconds (the build script sets timeout - 10 s). */
#ifndef PROBE_MAX_S
#define PROBE_MAX_S 50
#endif

static void probe_alarm(int sig) {
  static const char msg[] = "TIMEOUT\tprobe self limit\n";
  (void)sig;
  (void)!write(1, msg, sizeof msg - 1);
  _exit(124);
}

static int cases = 0;

static void probe_header(void) {
  char utc[32];
  time_t now = time(0);
  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);
}

/* CASE: id, description of the call, return value as long, errno (0 if not set), extra (hex/bytes). */
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 <dlfcn.h>
#include <setjmp.h>
#include <stdlib.h>
#include <pthread.h>
#include <sys/mman.h>
#include <sys/types.h>

static sigjmp_buf guard_env;
static volatile int guard_sig = 0;
static volatile int guard_active = 0;
static volatile int guard_hits = 0;
static void guard_handler(int s) {
  static const char msg[] = "FAULT\tprobe guard: fault outside a guarded call or too many faults\n";
  if(!guard_active || ++guard_hits > 8) {
    (void)!write(1, msg, sizeof msg - 1);
    _exit(125);
  }
  guard_sig = s;
  guard_active = 0;
  siglongjmp(guard_env, 1);
}
static void guard_arm(void) {
  struct sigaction sa;
  memset(&sa, 0, sizeof sa);
  sa.sa_handler = guard_handler;
  sigaction(SIGSEGV, &sa, 0);
  sigaction(SIGBUS, &sa, 0);
  sigaction(SIGABRT, &sa, 0);
}
#define CALL(rvar, evar, expr) do { errno = 0; guard_sig = 0; rvar = -1; if(sigsetjmp(guard_env, 1) == 0) { guard_active = 1; rvar = (expr); } guard_active = 0; evar = errno; } while(0)
#include <time.h>

/* sceKeyboardRead and sceKeyboardReadState in libSceKeyboard.sprx on firmware 11.60 (payload process; a title process may differ), argument and handle order for debt entry libSceKeyboard.md:5. There is no keyboard and the earlier runs got no handle from sceKeyboardOpen (error 0x809b0081 for user 0), so the output-pointer cases of the entry cannot be reached; this probe measures what is reachable: the result before and after sceKeyboardInit, the result for bad handles, NULL data and counts 0, -1, 16 and 17, and whether ReadState clears its output buffer before a bad handle is reported. The prototypes (int handle, void* data, int num) and (int handle, void* data) and the 96-byte data record are ASSUMPTIONS from core/libs/prx/libSceKeyboard of AnyPS5 (upstream/main 809a271099b9); the buffer is filled with 0xAA so that written bytes show. No unmapped or read-only pointer is passed in this probe (that part is a separate probe, last). A watchdog thread ends the probe after PROBE_MAX_S. */

typedef long (*f4_t)(long, long, long, long);
static void* L;
static int stopped = 0;
static void note(const char* t) { printf("NOTE\t%s\n", t); fflush(stdout); }
static void report(const char* id, const char* what, const char* ex) { probe_case(id, what, 0, 0, ex); }
static void* wd_thread(void* arg) {
  static const char msg[] = "TIMEOUT\twatchdog thread\n";
  unsigned left = PROBE_MAX_S;
  (void)arg;
  while(left) left = sleep(left);
  (void)!write(1, msg, sizeof msg - 1);
  _exit(124);
  return 0;
}
static void wd_start(void) { pthread_t t; if(pthread_create(&t, 0, wd_thread, 0) == 0) pthread_detach(t); }
static int canary_ok(const unsigned char* p, int n) { for(int i = 0; i < n; i++) if(p[i] != 0xAA) return 0; return 1; }

static struct { unsigned char b[18 * 96]; unsigned char can[64]; } B;
static f4_t f_init, f_open, f_close, f_read, f_rs;
static int opened_handle = 0;
static long last_r = -1;
static void runf(const char* id, const char* what, f4_t f, long a, long b, long c, long d, int own) {
  if(stopped) return;
  if(own) { memset(B.b, 0xAA, sizeof B.b); memset(B.can, 0xAA, sizeof B.can); }
  long r = -1; int e = 0;
  CALL(r, e, f(a, b, c, d));
  last_r = r;
  char ex[520];
  if(own) {
    int ch = 0, last = -1;
    for(int i = 0; i < (int)sizeof B.b; i++) if(B.b[i] != 0xAA) { ch++; last = i; }
    unsigned w[8] = {0, 0, 0, 0, 0, 0, 0, 0};
    memcpy(w, B.b, 32);
    snprintf(ex, sizeof ex, "rc=0x%08x errno=%d changed=%d last_changed=%d off20_length=0x%08x w0=0x%08x w1=0x%08x w2=0x%08x w3=0x%08x canaries_intact=%d signal=%d", (unsigned)r, e, ch, last, w[5], w[0], w[1], w[2], w[3], canary_ok(B.can, 64), (int)guard_sig);
  } else {
    snprintf(ex, sizeof ex, "rc=0x%08x errno=%d signal=%d", (unsigned)r, e, (int)guard_sig);
  }
  probe_case(id, what, guard_sig ? -1 : (int)r, e, ex);
  if(guard_sig) stopped = 1;
}
#define BP ((long)(void*)B.b)
int main(void) {
  signal(SIGALRM, probe_alarm);
  alarm(PROBE_MAX_S);
  probe_header();
  guard_arm();
  wd_start();
  note("0.pre: dlopen of libSceKeyboard.sprx next");
  L = dlopen("libSceKeyboard.sprx", RTLD_LAZY);
  { char ex[16]; snprintf(ex, sizeof ex, "%d", L != 0); report("0", "dlopen of the module (1 yes, 0 no)", ex); }
  if(!L) { probe_end(); return 0; }
  { void* k = dlopen("libkernel.sprx", RTLD_LAZY); char ex[80]; snprintf(ex, sizeof ex, "libkernel_opened=%d control_found=%d", k != 0, k ? dlsym(k, "sceKernelGetProcessTime") != 0 : 0); report("1", "control in libkernel.sprx: sceKernelGetProcessTime (dlsym, name only)", ex); }
  { char ex[40]; snprintf(ex, sizeof ex, "found=%d", dlsym(L, "probe_e_no_such_function_in_module") != 0); report("2", "negative control, a name that does not exist (expected found=0)", ex); }
  f_init = (f4_t)dlsym(L, "sceKeyboardInit");
  f_open = (f4_t)dlsym(L, "sceKeyboardOpen");
  f_close = (f4_t)dlsym(L, "sceKeyboardClose");
  f_read = (f4_t)dlsym(L, "sceKeyboardRead");
  f_rs = (f4_t)dlsym(L, "sceKeyboardReadState");
  { char ex[120]; snprintf(ex, sizeof ex, "Init=%d Open=%d Close=%d Read=%d ReadState=%d", f_init != 0, f_open != 0, f_close != 0, f_read != 0, f_rs != 0); report("3", "the five functions (dlsym, name only)", ex); }
  if(!f_init || !f_open || !f_read || !f_rs) { probe_end(); return 0; }
  note("next: before sceKeyboardInit: Read and ReadState with an own buffer (0xAA fill) and with NULL; assumed prototypes Read(int handle, void* data, int num) and ReadState(int handle, void* data), data records of 96 bytes");
  runf("p.1", "Read(1, own buffer, 1) before Init", f_read, 1, BP, 1, 0, 1);
  runf("p.2", "ReadState(1, own buffer) before Init", f_rs, 1, BP, 0, 0, 1);
  runf("p.3", "Read(1, NULL, 1) before Init", f_read, 1, 0, 1, 0, 0);
  runf("p.4", "ReadState(1, NULL) before Init", f_rs, 1, 0, 0, 0, 0);
  note("next: sceKeyboardInit once, then sceKeyboardInit a second time, then sceKeyboardOpen(user, type 0, index 0, NULL) for user 0 and -1 (a handle, if any, stays open until the process exits)");
  runf("i.1", "sceKeyboardInit()", f_init, 0, 0, 0, 0, 0);
  note("next: sceKeyboardInit a second time");
  runf("i.2", "sceKeyboardInit() again", f_init, 0, 0, 0, 0, 0);
  runf("o.1", "sceKeyboardOpen(user 0, type 0, index 0, NULL)", f_open, 0, 0, 0, 0, 0);
  if(!stopped && (int)last_r >= 0) opened_handle = 1;
  runf("o.2", "sceKeyboardOpen(user -1, type 0, index 0, NULL)", f_open, -1, 0, 0, 0, 0);
  if(!stopped && (int)last_r >= 0) opened_handle = 1;
  note("next: after Init, Read with handles 1, 2, 0, -1, 99 and an own buffer (0xAA fill), count 1");
  runf("r.1", "Read(1, own buffer, 1)", f_read, 1, BP, 1, 0, 1);
  runf("r.2", "Read(2, own buffer, 1)", f_read, 2, BP, 1, 0, 1);
  runf("r.3", "Read(0, own buffer, 1)", f_read, 0, BP, 1, 0, 1);
  runf("r.4", "Read(-1, own buffer, 1)", f_read, -1, BP, 1, 0, 1);
  runf("r.5", "Read(99, own buffer, 1)", f_read, 99, BP, 1, 0, 1);
  note("next: Read argument order: NULL data, counts 0, -1, 16, 17, each with handle 1 and (where useful) the bad handle 99");
  runf("r.6", "Read(1, NULL, 1)", f_read, 1, 0, 1, 0, 0);
  runf("r.7", "Read(99, NULL, 1)", f_read, 99, 0, 1, 0, 0);
  runf("r.8", "Read(1, own buffer, 0)", f_read, 1, BP, 0, 0, 1);
  if(opened_handle) note("skipped: a valid handle was opened, count -1 could overrun the buffer");
  else runf("r.9", "Read(1, own buffer, -1)", f_read, 1, BP, -1, 0, 1);
  runf("r.10", "Read(1, own buffer, 16)", f_read, 1, BP, 16, 0, 1);
  runf("r.11", "Read(1, own buffer, 17)", f_read, 1, BP, 17, 0, 1);
  runf("r.12", "Read(99, own buffer, 17)", f_read, 99, BP, 17, 0, 1);
  note("next: ReadState with handles 1, 2, 0, -1, 99 and an own buffer (0xAA fill), then NULL data with handle 1 and 99");
  runf("s.1", "ReadState(1, own buffer)", f_rs, 1, BP, 0, 0, 1);
  runf("s.2", "ReadState(2, own buffer)", f_rs, 2, BP, 0, 0, 1);
  runf("s.3", "ReadState(0, own buffer)", f_rs, 0, BP, 0, 0, 1);
  runf("s.4", "ReadState(-1, own buffer)", f_rs, -1, BP, 0, 0, 1);
  runf("s.5", "ReadState(99, own buffer)", f_rs, 99, BP, 0, 0, 1);
  runf("s.6", "ReadState(1, NULL)", f_rs, 1, 0, 0, 0, 0);
  runf("s.7", "ReadState(99, NULL)", f_rs, 99, 0, 0, 0, 0);
  if(stopped) note("a fault ended the calls");
  probe_end();
  return 0;
}
Raw output of the run with pid 124 (build 62e46edd5e9c); ends at the marker before sceKeyboardInit, with no END line
PROBE	libSceKeyboard_read_handle_order	fw=0x11600005	build=62e46edd5e9c	pid=124	utc=2026-12-04T10:14:08Z
NOTE	0.pre: dlopen of libSceKeyboard.sprx next
CASE	0	dlopen of the module (1 yes, 0 no)	0	0	1
CASE	1	control in libkernel.sprx: sceKernelGetProcessTime (dlsym, name only)	0	0	libkernel_opened=1 control_found=1
CASE	2	negative control, a name that does not exist (expected found=0)	0	0	found=0
CASE	3	the five functions (dlsym, name only)	0	0	Init=1 Open=1 Close=1 Read=1 ReadState=1
NOTE	next: before sceKeyboardInit: Read and ReadState with an own buffer (0xAA fill) and with NULL; assumed prototypes Read(int handle, void* data, int num) and ReadState(int handle, void* data), data records of 96 bytes
CASE	p.1	Read(1, own buffer, 1) before Init	-2133196795	0	rc=0x80da0005 errno=0 changed=0 last_changed=-1 off20_length=0xaaaaaaaa w0=0xaaaaaaaa w1=0xaaaaaaaa w2=0xaaaaaaaa w3=0xaaaaaaaa canaries_intact=1 signal=0
CASE	p.2	ReadState(1, own buffer) before Init	-2133196795	0	rc=0x80da0005 errno=0 changed=96 last_changed=95 off20_length=0x00000001 w0=0x00000000 w1=0x00000000 w2=0x00000000 w3=0x00000000 canaries_intact=1 signal=0
CASE	p.3	Read(1, NULL, 1) before Init	-2133196795	0	rc=0x80da0005 errno=0 signal=0
CASE	p.4	ReadState(1, NULL) before Init	-2133196799	0	rc=0x80da0001 errno=0 signal=0
NOTE	next: sceKeyboardInit once, then sceKeyboardInit a second time, then sceKeyboardOpen(user, type 0, index 0, NULL) for user 0 and -1 (a handle, if any, stays open until the process exits)

AI-assisted (Claude Code).

@coderabbitai

coderabbitai Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Changes: Keyboard Read Measurement

Layer / File(s) Summary
Document measured read behavior
docs/dev/debt/changes/docs-libscekeyboard-read-before-init-measured.md
The report records return values and buffer effects before initialization, matching host-model results, and that post-initialization behavior was not measured.

Suggested labels: docs

Suggested reviewers: privacyonion, marczx10

Change: Other

Merge Risk: Minimal · up to 3990a

This adds a documentation entry on measured keyboard read behavior before initialisation and changes no runtime behavior. It carries no merge risk.

Architecture risk: Low · up to 3990a

The documentation now makes measured pre-initialization keyboard read results and the limits of those measurements available; runtime behavior and the exported API are unchanged.

Changed areas: docs

Review details

Systems and components

  • observed — 1 changed file mapped to docs.
Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 327808b6-d4fb-45a1-8f4f-b3f2b112b7ab
Commits

Reviewing files that changed from the base of the PR and between 998f1e5 and 3990a55.

Files selected for processing: 1

  • docs/dev/debt/changes/docs-libscekeyboard-read-before-init-measured.md

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — no blocking findings

The documentation change is consistent with the host implementation, but I could not inspect the console measurement artifacts described by the author.

What I ran

Reviewed head 3990a55fb8492d08be10b9bf2e5953c061c95209. Read the prepared description, commit list, diff, manifest, exclusion list, and complete added fragment; inspected the relevant Read and ReadState implementations through repo_read.py. This is a documentation-only change; I ran no build or tests.

python3 repo_read.py cat core/libs/prx/libSceKeyboard/src/keyboard_impl.cpp 177 200
python3 repo_read.py cat core/libs/prx/libSceKeyboard/src/keyboard_impl.cpp 196 240

Results

Check Result Note
Changed file review passed Entire added fragment read
Host implementation context passed Read and ReadState order inspected
Build and tests not run Documentation-only change
Console measurement artifacts not run Not available in the review materials

Negative control

Not run; the change adds documentation and introduces no test or code behavior to control.

Findings

Blocking

None.

Non-blocking

None.

Sources

The added measurement entry is at docs/dev/debt/changes/docs-libscekeyboard-read-before-init-measured.md, line 5. The host model's Read and ReadState behavior is visible in keyboard_impl.cpp, lines 177–216.

Not verified

The PR description reports two PS5 firmware 11.60 runs and says the probe sources and full outputs are in the first comment; those artifacts were not available in the prepared review materials. I read the only changed file listed as reviewed in files.json; that list reports no excluded files. The repository reader printed the requested source ranges but could not append its read log in this read-only environment.

To get this to a good state

Nothing is required.

@github-actions github-actions Bot added the docs label Dec 4, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants