Skip to content

fix(libkernel): sceKernelReleaseDirectMemory returns 0 for a length of 0 - #17553

Open
xXPBSXx wants to merge 5 commits into
boykopovar:mainfrom
xXPBSXx:fix/kernel-release-direct-memory-zero-length
Open

xXPBSXx wants to merge 5 commits into
boykopovar:mainfrom
xXPBSXx:fix/kernel-release-direct-memory-zero-length

Conversation

@xXPBSXx

@xXPBSXx xXPBSXx commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

What

sceKernelReleaseDirectMemory returned EINVAL for a length of 0, and guest_memory pinned Release(0, 0) as EINVAL without a console result. On a PS5, releasing a length of 0 at an aligned start returns 0, while a length of 1 and an unaligned start (phys + 1, 16 KiB) return EINVAL, and releasing a block and releasing it again return 0 (cases 9.44 to 9.48, lines 48 to 52 of the raw output). This returns 0 for a length of 0 at an aligned start before the range is claimed; the two EINVAL cases and a start below 0 or unaligned are unchanged. The test now expects Release(0, 0) to return 0 and pins the five measured results. A debt fragment, docs/dev/debt/changes/fix-kernel-release-direct-memory-zero-length.md, changes the sceKernelReleaseDirectMemory entry of docs/dev/debt/libkernel.md to record the measurement; an unaligned start with a length of 0, a start at the end of direct memory and a title process were not measured.

Tested

Measured on a PS5 with firmware 11.60 (kernel_get_fw_version 0x11600005), from a homebrew payload process (ps5-payload-sdk v0.45, elfldr), on 2026-11-07 at 08:55 UTC. A title process may differ. The calls released a block of the probe's own 4 MiB direct memory; the cases are 9.44 to 9.48, lines 48 to 52 of the raw output in the first comment.

Call PS5, payload process, firmware 11.60 AnyPS5 main before here
sceKernelReleaseDirectMemory(phys, 0) 0 EINVAL 0
sceKernelReleaseDirectMemory(phys, 1) 0x80020016 EINVAL 0x80020016
sceKernelReleaseDirectMemory(phys + 1, 16 KiB) 0x80020016 EINVAL 0x80020016
sceKernelReleaseDirectMemory(phys, 16 KiB), then again 0, then 0 0, then 0 0, then 0

On this branch, main eb2d16b170b, on 2026-11-17: with only the test commit b220bf30d12, guest_memory fails on Windows (MinGW, Release, 23:01 to 23:05 UTC, one run) with Guest memory check failed at core/libs/tests/GuestMemory.cpp:1052, which is Release(0, 0) == 0, and on Linux (WSL, Release, from 22:29 UTC, one run) with Subprocess aborted; with the fix commit 81531bed9b8 it passes in 3 of 3 runs on Linux, and with the docs commit 15a8b0b46f8 it passes in 1 run on Windows (23:04 to 23:07 UTC) and in 3 of 3 runs on Linux. The Linux commits were applied with git am to a clean checkout of main. tools/check_conventions.py --base upstream/main passes on each of the three commits on Linux. The probe source and its raw output are in the first comment. Not tested: macOS, the CI runner, a title process and any other firmware.

Overlap (2026-11-18, list of open pull requests read from 23:59 UTC on 2026-11-17 to 00:16 UTC, test-merged at 00:18 UTC against main 4568142448e, head 15a8b0b46f84): of the 1786 open pull requests, 12 change core/libs/prx/libkernel/DirectMemory/Export.cpp, core/libs/tests/GuestMemory.cpp or core/libs/prx/libkernel/DirectMemory/MemoryPool.cpp (#22051, #22040, #22013, #21569, #20349, #19183, #18293, #17936, #17718, #16945, #16372 and #12315), and each was merged with and without this branch. None conflicts only with this branch: five conflict with main by themselves (#21569, #17718 and #16945 in DirectMemory/Export.cpp, #18293 in WindowsMappings.hpp, #12315 in libSceLibreSsl3) and the other seven merge cleanly with and without it. None of them changes sceKernelReleaseDirectMemory; #22013, #20349, #17718, #16945 and #12315 only add or keep calls of it in tests, and the hunk of #19183 sits in sceKernelCheckedReleaseDirectMemory. The branch no longer edits docs/dev/debt/libkernel.md, so the debt lines of #16869 (merged on 2026-11-12) and #16945 no longer meet this change, and no open pull request changes a debt line that names sceKernelReleaseDirectMemory.

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
  • 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 (documentation and a host-independent memory check only)
  • AI-assisted: yes

@xXPBSXx

xXPBSXx commented Nov 8, 2026

Copy link
Copy Markdown
Contributor Author

Probe source (built with ps5-payload-sdk v0.45; PROBE_BUILD is the first 12 hex digits of the source's SHA-256, 0d06ff05df67) and its raw output, from the run on 2026-11-07 at 08:55 UTC. The clock in the PROBE line is the console's own clock and is not UTC. The pull request uses only the ReleaseDirectMemory cases 9.44 to 9.48; the probe also ran other direct memory, mapping and protection calls.

probe.c
#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);
}

/* Probe F: sceKernelAllocateDirectMemory, sceKernelMapDirectMemory, sceKernelMprotect, sceKernelMunmap and
   sceKernelReleaseDirectMemory on firmware 11.60 (docs/dev/debt/libkernel.md: direct memory entries). Only memory this probe
   reserves itself is touched: one 4 MiB direct-memory block, mapped in small pieces and given back at the end. Addresses
   are never printed; each case reports the return value, errno, and whether the first byte of the range can be read and
   written afterwards. Prototypes are assumptions from the case sheets:
   sceKernelAllocateDirectMemory(off_t start, off_t end, size_t len, size_t align, int type, off_t* phys),
   sceKernelMapDirectMemory(void** addr, size_t len, int prot, int flags, off_t phys, size_t align),
   sceKernelMprotect(void* addr, size_t len, int prot), sceKernelMunmap(void* addr, size_t len),
   sceKernelReleaseDirectMemory(off_t start, size_t len). */
#include <dlfcn.h>
#include <setjmp.h>
#include <stdint.h>

static sigjmp_buf guard_env;
static volatile int guard_sig = 0;
static void guard_handler(int s) {
  guard_sig = s;
  siglongjmp(guard_env, 1);
}

typedef long (*dmsize_fn)(void);
typedef int (*alloc_fn)(long, long, size_t, size_t, int, long*);
typedef int (*map_fn)(void**, size_t, int, int, long, size_t);
typedef int (*prot_fn)(void*, size_t, int);
typedef int (*unmap_fn)(void*, size_t);
typedef int (*rel_fn)(long, size_t);

static dmsize_fn f_size;
static alloc_fn f_alloc;
static map_fn f_map;
static prot_fn f_prot;
static unmap_fn f_unmap;
static rel_fn f_rel;

#define RUN(stmt)                       \
  do {                                  \
    errno = 0;                          \
    guard_sig = 0;                      \
    if (sigsetjmp(guard_env, 1) == 0) { \
      stmt;                             \
    }                                   \
    e = errno;                          \
  } while (0)

#define KB 1024UL
#define MB (1024UL * 1024UL)

/* 'R' readable, 'W' writable (a write of the byte already there), '-' a fault; recorded without printing the address */
static void access_state(volatile unsigned char* p, char* out) {
  out[0] = out[1] = '-';
  out[2] = 0;
  if (!p) return;
  guard_sig = 0;
  if (sigsetjmp(guard_env, 1) == 0) {
    unsigned char v = *p;
    out[0] = 'R';
    *p = v;
    out[1] = 'W';
  }
}

static int id_n = 0;
static void emit(const char* grp, const char* call, long r, int e, const char* extra) {
  char id[16];
  snprintf(id, sizeof id, "%s.%d", grp, ++id_n);
  probe_case(id, call, r, e, extra);
}

/* one map of 'len' bytes at phys 'ph'; on success the range is returned in *out and stays mapped */
static int do_map(void** out, size_t len, int prot, int flags, long ph, size_t align, int* err) {
  int r = -99, e;
  void* a = 0;
  RUN(r = f_map(&a, len, prot, flags, ph, align));
  *err = e;
  *out = (r == 0 && !guard_sig) ? a : 0;
  return guard_sig ? -98 : r;
}

int main(void) {
  signal(SIGALRM, probe_alarm);
  alarm(PROBE_MAX_S);
  probe_header();
  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);

  f_size = (dmsize_fn)dlsym(RTLD_DEFAULT, "sceKernelGetDirectMemorySize");
  f_alloc = (alloc_fn)dlsym(RTLD_DEFAULT, "sceKernelAllocateDirectMemory");
  f_map = (map_fn)dlsym(RTLD_DEFAULT, "sceKernelMapDirectMemory");
  f_prot = (prot_fn)dlsym(RTLD_DEFAULT, "sceKernelMprotect");
  f_unmap = (unmap_fn)dlsym(RTLD_DEFAULT, "sceKernelMunmap");
  f_rel = (rel_fn)dlsym(RTLD_DEFAULT, "sceKernelReleaseDirectMemory");
  char line[160], extra[220], call[120], st[4];
  snprintf(line, sizeof line, "size=%d alloc=%d map=%d mprotect=%d munmap=%d release=%d", !!f_size, !!f_alloc, !!f_map, !!f_prot, !!f_unmap, !!f_rel);
  probe_case("0", "dlsym exported (1 yes, 0 no)", 0, 0, line);
  if (!f_alloc || !f_map || !f_unmap || !f_rel || !f_prot) {
    probe_end();
    return 0;
  }

  int e, r;
  long total = f_size ? f_size() : 0;
  snprintf(extra, sizeof extra, "total_mib=%ld", total / (long)MB);
  probe_case("1", "sceKernelGetDirectMemorySize()", total, 0, extra);

  long ph = -1;
  RUN(r = f_alloc(0, total ? total : 0x100000000L, 4 * MB, 2 * MB, 3, &ph));
  snprintf(extra, sizeof extra, "phys_set=%d phys_mod_2mib=%ld signal=%d", ph != -1, ph == -1 ? -1L : (long)(ph % (long)(2 * MB)), (int)guard_sig);
  probe_case("2", "sceKernelAllocateDirectMemory(0, total, 4 MiB, 2 MiB, 3, &phys)", r, e, extra);
  if (r != 0 || ph == -1) {
    probe_end();
    return 0;
  }

  void* a;
  /* piece 0..8: protection values of the titles, 16 KiB each, alignment 0 */
  static const int prots[] = {3, 0x33, 0xc2, 0xf2, 0x3f2, 0x32, 2, 1, 0};
  for (int i = 0; i < 9; i++) {
    int er;
    r = do_map(&a, 16 * KB, prots[i], 0, ph + (long)i * (long)(16 * KB), 0, &er);
    access_state((volatile unsigned char*)a, st);
    snprintf(extra, sizeof extra, "access=%s signal=%d", st, (int)guard_sig);
    snprintf(call, sizeof call, "MapDirectMemory(16 KiB, prot 0x%x, flags 0, align 0)", prots[i]);
    emit("3", call, r, er, extra);
    if (a) f_unmap(a, 16 * KB);
  }
  /* flags of the titles with prot 3 */
  static const int flg[] = {0x10, 0x400010, 0x90, 0x400000, 0x80};
  for (int i = 0; i < 5; i++) {
    int er;
    r = do_map(&a, 16 * KB, 3, flg[i], ph + 128 * (long)KB, 0, &er);
    access_state((volatile unsigned char*)a, st);
    snprintf(extra, sizeof extra, "access=%s signal=%d", st, (int)guard_sig);
    snprintf(call, sizeof call, "MapDirectMemory(16 KiB, prot 3, flags 0x%x, align 0)", flg[i]);
    emit("4", call, r, er, extra);
    if (a) f_unmap(a, 16 * KB);
  }
  /* alignments of the titles (phys is 2 MiB aligned, so phys + 0 satisfies all of them) */
  static const size_t als[] = {16 * KB, 64 * KB, 1 * MB, 2 * MB, 4 * MB};
  for (int i = 0; i < 5; i++) {
    int er;
    r = do_map(&a, 16 * KB, 3, 0, ph, als[i], &er);
    access_state((volatile unsigned char*)a, st);
    snprintf(extra, sizeof extra, "addr_aligned_to_request=%d access=%s signal=%d", a ? ((uintptr_t)a % als[i]) == 0 : -1, st, (int)guard_sig);
    snprintf(call, sizeof call, "MapDirectMemory(16 KiB, prot 3, flags 0, align 0x%zx)", als[i]);
    emit("5", call, r, er, extra);
    if (a) f_unmap(a, 16 * KB);
  }

  /* Mprotect on a 64 KiB mapping of our own */
  void* m;
  int er;
  r = do_map(&m, 64 * KB, 3, 0, ph + 1 * (long)MB, 0, &er);
  emit("6", "MapDirectMemory(64 KiB, prot 3) for the Mprotect cases", r, er, "-");
  if (m) {
    static const int mp[] = {0x11, 0x12, 0x3f2, 0xc2, 0xc3, 0x42, 0x82, 0x13, 0x3, 0x1, 0x7};
    for (int i = 0; i < 11; i++) {
      RUN(r = f_prot(m, 64 * KB, mp[i]));
      access_state((volatile unsigned char*)m, st);
      snprintf(extra, sizeof extra, "access_after=%s signal=%d", st, (int)guard_sig);
      snprintf(call, sizeof call, "Mprotect(mapped 64 KiB, prot 0x%x)", mp[i]);
      emit("7", call, r, e, extra);
    }
    RUN(r = f_prot(m, 64 * KB, 3));
    emit("7", "Mprotect(mapped 64 KiB, prot 3) restore", r, e, "-");
    RUN(r = f_prot(m, 0, 3));
    emit("7", "Mprotect(mapped, len 0, prot 3)", r, e, "-");
    RUN(r = f_prot(m, 100, 3));
    emit("7", "Mprotect(mapped, len 100, prot 3)", r, e, "-");
    RUN(r = f_prot((char*)m + 1, 16 * KB, 3));
    emit("7", "Mprotect(mapped + 1, 16 KiB, prot 3)", r, e, "-");
    RUN(r = f_prot(m, 128 * KB, 3));
    emit("7", "Mprotect(mapped, 128 KiB over a 64 KiB mapping, prot 3)", r, e, "-");
    /* Munmap on the same mapping */
    RUN(r = f_unmap(m, 0));
    emit("8", "Munmap(mapped, len 0)", r, e, "-");
    RUN(r = f_unmap(m, 100));
    emit("8", "Munmap(mapped, len 100)", r, e, "-");
    RUN(r = f_unmap(m, 16 * KB));
    emit("8", "Munmap(mapped, 16 KiB of 64 KiB)", r, e, "-");
    access_state((volatile unsigned char*)m, st);
    emit("8", "access after partial Munmap (first 16 KiB)", 0, 0, st);
    RUN(r = f_unmap((char*)m + 16 * KB, 48 * KB));
    emit("8", "Munmap(rest 48 KiB)", r, e, "-");
    RUN(r = f_unmap(m, 64 * KB));
    emit("8", "Munmap(already unmapped 64 KiB)", r, e, "-");
    RUN(r = f_prot(m, 64 * KB, 3));
    emit("8", "Mprotect(already unmapped 64 KiB, prot 3)", r, e, "-");
  }

  /* ReleaseDirectMemory: only inside the 4 MiB this probe allocated */
  RUN(r = f_rel(ph, 1));
  emit("9", "ReleaseDirectMemory(phys, 1)", r, e, "-");
  RUN(r = f_rel(ph, 0));
  emit("9", "ReleaseDirectMemory(phys, 0)", r, e, "-");
  RUN(r = f_rel(ph + 1, 16 * KB));
  emit("9", "ReleaseDirectMemory(phys + 1, 16 KiB)", r, e, "-");
  RUN(r = f_rel(ph, 16 * KB));
  emit("9", "ReleaseDirectMemory(phys, 16 KiB)", r, e, "-");
  RUN(r = f_rel(ph, 16 * KB));
  emit("9", "ReleaseDirectMemory(phys, 16 KiB) again", r, e, "-");
  RUN(r = f_rel(ph, 4 * MB));
  emit("9", "ReleaseDirectMemory(phys, 4 MiB) rest of the block", r, e, "-");
  RUN(r = f_rel(ph, 4 * MB));
  emit("9", "ReleaseDirectMemory(phys, 4 MiB) again", r, e, "-");
  probe_end();
  return 0;
}
stdout
PROBE	libkernel_dmem	fw=0x11600005	build=0d06ff05df67	pid=111	utc=2026-11-07T10:36:49Z
CASE	0	dlsym exported (1 yes, 0 no)	0	0	size=1 alloc=1 map=1 mprotect=1 munmap=1 release=1
CASE	1	sceKernelGetDirectMemorySize()	0	0	total_mib=0
CASE	2	sceKernelAllocateDirectMemory(0, total, 4 MiB, 2 MiB, 3, &phys)	0	0	phys_set=1 phys_mod_2mib=0 signal=0
CASE	3.1	MapDirectMemory(16 KiB, prot 0x3, flags 0, align 0)	0	0	access=RW signal=0
CASE	3.2	MapDirectMemory(16 KiB, prot 0x33, flags 0, align 0)	0	0	access=RW signal=0
CASE	3.3	MapDirectMemory(16 KiB, prot 0xc2, flags 0, align 0)	0	0	access=RW signal=0
CASE	3.4	MapDirectMemory(16 KiB, prot 0xf2, flags 0, align 0)	0	0	access=RW signal=0
CASE	3.5	MapDirectMemory(16 KiB, prot 0x3f2, flags 0, align 0)	0	0	access=RW signal=0
CASE	3.6	MapDirectMemory(16 KiB, prot 0x32, flags 0, align 0)	0	0	access=RW signal=0
CASE	3.7	MapDirectMemory(16 KiB, prot 0x2, flags 0, align 0)	0	0	access=RW signal=0
CASE	3.8	MapDirectMemory(16 KiB, prot 0x1, flags 0, align 0)	0	0	access=R- signal=11
CASE	3.9	MapDirectMemory(16 KiB, prot 0x0, flags 0, align 0)	0	0	access=-- signal=11
CASE	4.10	MapDirectMemory(16 KiB, prot 3, flags 0x10, align 0)	-2147352554	0	access=-- signal=0
CASE	4.11	MapDirectMemory(16 KiB, prot 3, flags 0x400010, align 0)	-2147352554	0	access=-- signal=0
CASE	4.12	MapDirectMemory(16 KiB, prot 3, flags 0x90, align 0)	-2147352554	0	access=-- signal=0
CASE	4.13	MapDirectMemory(16 KiB, prot 3, flags 0x400000, align 0)	0	0	access=RW signal=0
CASE	4.14	MapDirectMemory(16 KiB, prot 3, flags 0x80, align 0)	0	0	access=RW signal=0
CASE	5.15	MapDirectMemory(16 KiB, prot 3, flags 0, align 0x4000)	0	0	addr_aligned_to_request=1 access=RW signal=0
CASE	5.16	MapDirectMemory(16 KiB, prot 3, flags 0, align 0x10000)	0	0	addr_aligned_to_request=1 access=RW signal=0
CASE	5.17	MapDirectMemory(16 KiB, prot 3, flags 0, align 0x100000)	0	0	addr_aligned_to_request=1 access=RW signal=0
CASE	5.18	MapDirectMemory(16 KiB, prot 3, flags 0, align 0x200000)	0	0	addr_aligned_to_request=1 access=RW signal=0
CASE	5.19	MapDirectMemory(16 KiB, prot 3, flags 0, align 0x400000)	0	0	addr_aligned_to_request=1 access=RW signal=0
CASE	6.20	MapDirectMemory(64 KiB, prot 3) for the Mprotect cases	0	0	-
CASE	7.21	Mprotect(mapped 64 KiB, prot 0x11)	0	0	access_after=R- signal=11
CASE	7.22	Mprotect(mapped 64 KiB, prot 0x12)	0	0	access_after=RW signal=0
CASE	7.23	Mprotect(mapped 64 KiB, prot 0x3f2)	0	0	access_after=RW signal=0
CASE	7.24	Mprotect(mapped 64 KiB, prot 0xc2)	0	0	access_after=RW signal=0
CASE	7.25	Mprotect(mapped 64 KiB, prot 0xc3)	0	0	access_after=RW signal=0
CASE	7.26	Mprotect(mapped 64 KiB, prot 0x42)	0	0	access_after=RW signal=0
CASE	7.27	Mprotect(mapped 64 KiB, prot 0x82)	0	0	access_after=RW signal=0
CASE	7.28	Mprotect(mapped 64 KiB, prot 0x13)	0	0	access_after=RW signal=0
CASE	7.29	Mprotect(mapped 64 KiB, prot 0x3)	0	0	access_after=RW signal=0
CASE	7.30	Mprotect(mapped 64 KiB, prot 0x1)	0	0	access_after=R- signal=11
CASE	7.31	Mprotect(mapped 64 KiB, prot 0x7)	0	0	access_after=RW signal=0
CASE	7.32	Mprotect(mapped 64 KiB, prot 3) restore	0	0	-
CASE	7.33	Mprotect(mapped, len 0, prot 3)	0	0	-
CASE	7.34	Mprotect(mapped, len 100, prot 3)	0	0	-
CASE	7.35	Mprotect(mapped + 1, 16 KiB, prot 3)	0	0	-
CASE	7.36	Mprotect(mapped, 128 KiB over a 64 KiB mapping, prot 3)	0	0	-
CASE	8.37	Munmap(mapped, len 0)	-2147352554	22	-
CASE	8.38	Munmap(mapped, len 100)	0	0	-
CASE	8.39	Munmap(mapped, 16 KiB of 64 KiB)	0	0	-
CASE	8.40	access after partial Munmap (first 16 KiB)	0	0	--
CASE	8.41	Munmap(rest 48 KiB)	0	0	-
CASE	8.42	Munmap(already unmapped 64 KiB)	0	0	-
CASE	8.43	Mprotect(already unmapped 64 KiB, prot 3)	0	0	-
CASE	9.44	ReleaseDirectMemory(phys, 1)	-2147352554	22	-
CASE	9.45	ReleaseDirectMemory(phys, 0)	0	0	-
CASE	9.46	ReleaseDirectMemory(phys + 1, 16 KiB)	-2147352554	22	-
CASE	9.47	ReleaseDirectMemory(phys, 16 KiB)	0	0	-
CASE	9.48	ReleaseDirectMemory(phys, 16 KiB) again	0	0	-
CASE	9.49	ReleaseDirectMemory(phys, 4 MiB) rest of the block	0	0	-
CASE	9.50	ReleaseDirectMemory(phys, 4 MiB) again	0	0	-
END	53

The process ended with exit value 0.

@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 27590 core/libs/prx/libkernel/DirectMemory/Export.cpp L498-499

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 16372 core/libs/tests/GuestMemory.cpp
PR 20978 core/libs/tests/GuestMemory.cpp
PR 21569 core/libs/prx/libkernel/DirectMemory/Export.cpp
core/libs/tests/GuestMemory.cpp
PR 28264 core/libs/prx/libkernel/DirectMemory/Export.cpp
core/libs/tests/GuestMemory.cpp

@JJenkx

JJenkx commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Windows check of head 635a3cc392, merged onto main 22ae9a397d (8093a1918a, clean merge).

Setup: Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT, Release. The hosted Windows check does not run these tests on pull requests.

  • guest_memory, guest_mmap_executable, guest_mmap_fixed_anonymous pass in 3 of 3 runs, none skipped.

AI-assisted: yes.

@ycbuzi

ycbuzi commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

Tested 635a3cc392 merged into main, with the whole ctest suite on each machine below. Nothing fails that does not also fail on main on the same machine.

  • Windows Server 2022 (GitHub-hosted runner), full build, WinLibs GCC 15.2.0: 99% tests passed, 42 tests failed out of 5018; 99% tests passed, 42 tests failed out of 5018. 42 of the failing tests fail on main too. run
  • Windows Server 2025 (GitHub-hosted runner), full build, WinLibs GCC 15.2.0: 99% tests passed, 16 tests failed out of 5018; 99% tests passed, 16 tests failed out of 5018. 16 of the failing tests fail on main too. run

AI-assisted: yes (Claude Code); the runs are automated, this summary was written from their reports.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Nov 12, 2026
@gabichuuuuu

Copy link
Copy Markdown
Contributor

Windows check of head 635a3cc392, merged onto main 28237a8567 (clean merge, built together with other open PRs that touch different files).

Setup: Windows 11 x64, WinLibs GCC 15.2.0 (r7), Ninja, Release, BUILD_TESTING=ON, Python 3.15.

  • Tests built from this PR's test files: guest_memory, guest_mmap_executable, guest_mmap_fixed_anonymous.
  • All of them pass in 3 of 3 runs.
  • Negative control: with this PR's code reverted to main (files it adds removed) and rebuilt, guest_memory fails in 2 of 2 runs, so the tests detect the change; guest_mmap_executable, guest_mmap_fixed_anonymous still pass.

AI-assisted: yes.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

@xXPBSXx the code and test look right to me: the zero-length shortcut sits after the alignment and range checks, which matches your fw 11.60 probe cases, and CheckReleaseDirectMemoryZeroLength exercises the real API. The docs need work before this can pass:

  1. The branch deletes docs/dev/debt/changes/fix-libc-hypotl-msun-ld80.md and edits fix-libc-ld80-inverse-hyperbolic.md, which reverts libc work already on main. Please drop both from the PR.
  2. docs/dev/debt/libkernel.md keeps the old sceKernelReleaseDirectMemory bullet under the new one, so the entry is duplicated.
  3. The same file rewrites the sceKernelSetVirtualRangeName bullet back to "length 0 returns EINVAL". Main says length 0 returns 0 (measured), so please keep main's text.
  4. There is no fragment under docs/dev/debt/changes/ for this behaviour change. Please add one.

Please also rebase onto main; the libkernel.md bullets overlap with #16869.

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Nov 17, 2026
xXPBSXx and others added 3 commits November 17, 2026 23:24
…ength of 0

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…r a length of 0

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Nov 18, 2026
@xXPBSXx
xXPBSXx force-pushed the fix/kernel-release-direct-memory-zero-length branch from 6c33cf2 to 15a8b0b Compare November 18, 2026 00:50
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Nov 18, 2026
@xXPBSXx

xXPBSXx commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review. The branch is rebuilt on main eb2d16b170b as three commits of its own (test b220bf30d12, fix 81531bed9b8, docs 15a8b0b46f8; head 15a8b0b46f8). It changes three files: core/libs/tests/GuestMemory.cpp, core/libs/prx/libkernel/DirectMemory/Export.cpp and one new debt fragment. The two earlier "merge main" commits are no longer in it, and the code and the test are unchanged from what you read.

  1. The deletion of fix-libc-hypotl-msun-ld80.md and the edit of fix-libc-ld80-inverse-hyperbolic.md came from those merge commits; neither file is touched any more.
  2. docs/dev/debt/libkernel.md is not edited any more, so the sceKernelReleaseDirectMemory entry exists once.
  3. The sceKernelSetVirtualRangeName entry is untouched, so it keeps main's text (length 0 returns 0).
  4. The debt change is now a fragment, docs/dev/debt/changes/fix-kernel-release-direct-memory-zero-length.md, with one change of the sceKernelReleaseDirectMemory entry (512 characters before, 732 now). tools/debt_fold.py --check applies it to a copy of main without an error.

Rebase: since the branch no longer edits docs/dev/debt/libkernel.md, the overlap with #16869 (merged on 12 November) is gone.

Red and green on the new commits, 17 November 2026 (UTC): with only the test commit, guest_memory fails on Windows (MinGW, Release, 23:01 to 23:05) with Guest memory check failed at core/libs/tests/GuestMemory.cpp:1052, which is Release(0, 0) == 0, and on Linux (WSL, Release, from 22:29) with Subprocess aborted; with the fix and the fragment it passes on Windows (23:04 to 23:07, 1 run) and in 3 of 3 runs on Linux, for the fix commit alone and for the docs commit. tools/check_conventions.py --base upstream/main passes on each of the three commits on Linux. The Linux commits were applied with git am to a clean checkout of main, and the trees are identical to the branch.

I will update the description to the new head and these numbers.

AI-assisted (Claude Code).

@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 — looks good

The change matches the documented PS5 payload observation, validates the range before returning success for zero length, and adds regression coverage for the changed behavior.

What I ran

Reviewed head 15a8b0b46f84bb8dfc86c39a63ce89e8fb1108a0 against the prepared diff. No tests or builds were run. Read core/libs/prx/libkernel/DirectMemory/Export.cpp, core/libs/tests/GuestMemory.cpp, and docs/dev/debt/changes/fix-kernel-release-direct-memory-zero-length.md; the complete text of each changed file was available. The excluded-file list was not available as a separate artifact.

Results

Check Result Note
Diff and changed lines passed All added lines reviewed
Targeted code review passed Range validation precedes the zero-length return
Tests and build not run Author-reported runs only
Console behavior not run PS5 observation is author-reported

Findings

Blocking

None.

Non-blocking

None.

Not verified

The author reports PS5 firmware 11.60 behavior and host test runs; these were not independently reproduced. No tests, builds, CI, title-process behavior, or other firmware were checked. No claims are made about excluded files.

To get this to a good state

Nothing is required.

@kiwe147

kiwe147 commented Nov 21, 2026

Copy link
Copy Markdown

Tested head 15a8b0b46f, applied with git apply on main fd4aeed483 together with the other 29 PRs of one batch (#18156, #21208, #22013, #22795, #23226, #23385, #24324, #24533, #24582, #24690, #24693, #19619, #20085, #21081, #19682, #22123, #22529, #22572, #22662, #23479, #23787, #24568, #15330, #21249, #21630, #21713, #22040, #23490, #24394).

This PR makes guest_memory fail. The test passes on main and fails in the batch tree, in the full run and alone (ctest -R, 3 of 3 runs). In the batch tree, with this PR reverted the test passes, and with it applied again it fails again. I did not look for the cause inside the change.

Setup: Windows 11 Pro 10.0.26200, Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7, Release, BUILD_TESTING=ON. NVIDIA GeForce RTX 3080 (driver 621.24). No validation layer.

AI-assisted: yes (Claude Code)

This was referenced Nov 21, 2026
@oneandonlydean

Copy link
Copy Markdown
Collaborator

@xXPBSXx this head (15a8b0b) fails guest_memory when run alone on main 8b72a1e: "flexible memory exhausted: request 0x1bfbc000 with 0x64000 of 0x1c000000 in use", then "Guest memory check failed at core/libs/tests/GuestMemory.cpp:741" and the test aborts. The same train without this PR passed, so the change in this PR is what trips it. I have held it until that test passes; please rebase on main and run guest_memory locally.

xXPBSXx and others added 2 commits November 21, 2026 17:39
@xXPBSXx

xXPBSXx commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

Thank you for running this. The failing assertion is line 741 of GuestMemory.cpp, in CheckDirectMemoryFollowsPhysicalPages, a test that main gained after this branch was cut: it expects sceKernelReleaseDirectMemory(0, 0) to return EINVAL, and this pull request makes a length of 0 return 0. What was measured on the console is a length of 0 at the start of an allocated block of the probe's own, which returned 0 (case 9.45 in the first comment); this change returns 0 for a length of 0 at any aligned start, so the assertion for start 0 now expects 0. Start 0 itself was not measured; that follows from the code path (the length check comes after the alignment check, and 0 is aligned).

I merged main (f80afa8b6812) into the branch and added one commit, b561ad376036, that changes only that assertion. The merge without the new commit (2089aef17b94) fails at line 741 ("Guest memory check failed at core/libs/tests/GuestMemory.cpp:741") on Windows (MinGW GCC, Release, 17:36 to 17:45 UTC on 21 November). main alone and the merged head with the new commit both pass guest_memory. The line "flexible memory exhausted: request ... of 0x1c000000 in use" appears in the passing runs as well (on main and on the merged head), so it is not what fails the test. I did not run Linux or macOS here; the CI does.

Could you re-run it on the new head?

AI-assisted (Claude Code).

@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 — looks good

Nothing blocks this change; the targeted implementation and tests support the reported zero-length behavior.

What I ran

Reviewed head b561ad37603674c3f66d52781cacbe48b8ef2ea0 using the prepared diff and repo_read.py. No commands or tests were run in this review.

Results

Check Result Note
Diff and changed source passed Three changed files read
Tests not run Author-reported runs only

Findings

Blocking

None.

Non-blocking

None.

Not verified

No tests were run independently. The author reports PS5 measurements on firmware 11.60 in a payload process and host test runs; these were not independently verified. The changed files listed in the manifest were read: core/libs/prx/libkernel/DirectMemory/Export.cpp, core/libs/tests/GuestMemory.cpp, and docs/dev/debt/changes/fix-kernel-release-direct-memory-zero-length.md. No changed files were excluded.

To get this to a good state

Nothing is required.

@ligmaSec ligmaSec left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The Linux integration build passed the registered GuestMemory CTest, including zero-length release and neighboring argument checks.

AI-assisted: yes.

@Plyxen Plyxen 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.

I read the diff at b561ad3760. Windows 11 with GCC 15.2 and Linux (Ubuntu 24.04 in WSL2, GCC 13.3), merged into main at 6c6b29320fe together with other open PRs (so not an isolated build).

  • guest_memory: pass on both.
  • Control (the same tree with only this PR's source change taken out): on Windows it fails at line 742. On Linux, with the changed sources of the tested CPU PRs put back to main's, the same test fails too.

Not checked: a console.

AI-assisted: yes (Claude Code)

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants