Skip to content

fix(libkernel): sceKernelMapNamedDirectMemory returns ENAMETOOLONG for a 32 character name and EFAULT for a NULL name - #16945

Open
xXPBSXx wants to merge 3 commits into
boykopovar:mainfrom
xXPBSXx:fix/kernel-map-named-direct-memory-name-v2
Open

xXPBSXx wants to merge 3 commits into
boykopovar:mainfrom
xXPBSXx:fix/kernel-map-named-direct-memory-name-v2

Conversation

@xXPBSXx

@xXPBSXx xXPBSXx commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

What

sceKernelMapNamedDirectMemory returned 0 for a name of 32 or more characters and named the range with the name cut to 31, and returned 0 for a NULL name. On a PS5 the mapping succeeds in both cases and the call returns SCE_KERNEL_ERROR_ENAMETOOLONG (0x8002003f, errno 63) for a name of 32 characters and SCE_KERNEL_ERROR_EFAULT (0x8002000e, errno 14) for a NULL name; the range stays mapped and has no name of its own (it reads anon: and hex digits), and a name of 31 characters is stored (lines 57 to 59 of the output in the first comment). This does the same: after a successful mapping, a name of 32 or more bytes returns ENAMETOOLONG and a NULL name returns EFAULT, and neither names the range. A test pins the three results, a non-null mapping in each case, and the name read back; it also pins that sceKernelMapNamedFlexibleMemory is unchanged. The debt entry in docs/dev/debt/libkernel.md states the measurement through a debt fragment.

The NULL is what the probe passed. The probe's case 6.8 is labelled "name of 0 chars", but its table entry is {0x33, 0, 64 * KB, 0}, so the name argument is a NULL pointer, and the label comes from printing 0 for a NULL name (mp[i].name ? strlen(mp[i].name) : 0 in the probe source in the first comment). The first version of this pull request returned EFAULT for an empty string and called that measured; the review pointed out that no probe case passes an empty string, so that is removed. An empty string is not measured and is unchanged here, and the entry says so.

Not measured: a name of 33 or more characters (it follows from the 32-character case and from sceKernelSetVirtualRangeName, whose limit is the same 31 characters), an empty string, sceKernelMapNamedFlexibleMemory (unchanged, and it still cuts a longer name to 31 characters here), a title process, and other firmware. The range without a name reads as empty here where the console reports anon: and hex digits; that is not changed. git grep finds no call of sceKernelMapNamedDirectMemory in this repository outside its definition, its declaration and tests, and no test other than the new one passes NULL. #16869 is merged, so this branch is rebuilt on current main and no longer depends on it.

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 19:25 UTC (the utc in the PROBE line is the console's own clock, about 1 h 42 min ahead). A title process may differ. The calls mapped 64 KiB of an own 4 MiB direct memory block with protection 0x33 and alignment 0x10000, and the name was read back with sceKernelVirtualQuery. The probe source and its raw output are in the first comment.

Call PS5, payload process, firmware 11.60 AnyPS5 main before here
name of 31 characters 0, the name is stored (line 57) 0 0
name of 32 characters 0x8002003f, mapped, no name (anon:..., line 58) 0, the name is cut to 31 0x8002003f, mapped, no name
NULL name 0x8002000e, mapped, no name (anon:..., line 59) 0 0x8002000e, mapped, no name
empty string not measured 0, stored as an empty name unchanged

Red and green on one base: Windows 10 Pro (MinGW GCC, Release, cmake -DBUILD_TESTING=ON, ninja -j4 guest_memory_tests, ctest -R ^guest_memory$, one worktree, a checkout, cmake, ninja and ctest per phase), base upstream/main fd6d6f4a8498: on the base guest_memory passes (21:13 UTC on 2026-11-19); with the test commit ee6651cb08cf it fails (21:15 UTC; exit code 0xc0000409 and "Guest memory check failed at core/libs/tests/GuestMemory.cpp:286", the check of the call's result in the loop over the cases; the message does not name the case, and that it is the 32-character one follows from the order of the cases, where the first returns 0 on main); with the fix commit 528371df05c6 it passes (21:18 UTC); with the documentation commit ccde1e977bd0 it passes (21:21 UTC). tools/check_conventions.py --base fd6d6f4a8498 and tools/debt_fold.py --check pass on the head, and a merge into upstream/main a410f24ddad was checked with git merge-tree and is clean. The change is 3 files, +46/-2, with no new comments in code. Linux and macOS were not run here; CI will. Not tested: a title process and any other firmware.

Overlap: the other open pull requests that change the files of this branch (core/libs/prx/libkernel/DirectMemory/Export.cpp, core/libs/tests/GuestMemory.cpp and the fragment docs/dev/debt/changes/fix-kernel-map-named-direct-memory-null-name.md, a new file, for the entry of sceKernelMapNamedDirectMemory in docs/dev/debt/libkernel.md), found by reading the changed files of all 2028 open pull requests at about 22:31 to 22:50 UTC on 2026-11-19, by reading what they change in every file whose path contains DirectMemory, GuestMemory, VirtualRange or NamedDirect and in all debt files for sceKernelMapNamedDirectMemory, NameMappedRange, CopyRangeName and MapNamedFlexibleMemory, and by searching their titles and branch names for the same names, were checked on 2026-11-19 at about 23:06 UTC against main a410f24ddad together with this head: the branch is based on fd6d6f4a849, an ancestor of it, merges into main without a conflict, and tools/debt_fold.py --check applies the fragment together with every other fragment on main without an error. This branch replaces the earlier head 344e54d0f5b of this pull request, which is not an ancestor of the new head. Two other pull requests carry changes to the same function: #17718 (fix(libkernel): sceKernelMapNamedSystemFlexibleMemory maps and then rejects a name of 32 characters or a null name) contains an earlier copy of the commits of this pull request (ab942cf2991, 03ccc499427, de6c7c5e3dc, the variant with the empty-name result) in front of its own three commits, and so conflicts with this head in Export.cpp and GuestMemory.cpp; it has to be rebased onto the new head once this one is pushed. #21569 (fix(libkernel): bound virtual range names as the console does) adds a test function to GuestMemory.cpp and changes Export.cpp, and does not change a line that names these functions; it already conflicts with main in Export.cpp, and with this branch applied it also conflicts in GuestMemory.cpp (both add a check function in the same place), so whichever of the two is merged second needs a rebase of that test file. Four further pull requests show these names only as unchanged context or as other calls: #19183 and #23770 call sceKernelMapNamedDirectMemory and sceKernelMapNamedFlexibleMemory with short names in GuestMemory.cpp, #18585 calls sceKernelMapNamedDirectMemory in GuestKernelDirectMemoryMapping.cpp with the names "bad" and "test_dmem_named" (3 and 15 characters, so none is affected), and #19486 shows the definitions in its patch, but its head is identical to main in Export.cpp and GuestMemory.cpp. With this branch applied to main, all 71 pull requests that list one of these files or matched a name were merged on top of it: 31 of them already conflict with main alone, and apart from #17718 and #21569 (and the old head of this pull request) none has more conflicting files with this branch than without it. The merged result was not built or run beyond the red and green runs above.

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, 274d16c848bc) and its raw output, from the run on 2026-11-07 at 19:25 UTC. The clock in the PROBE line is the console's own clock and is not UTC. The pull request uses only the MapNamedDirectMemory cases 6.6, 6.7 and 6.8 (the other cases of the run cover other functions).

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: sceKernelClockGettime, sceKernelGettimeofday, sceKernelUsleep, sceKernelNanosleep (own sleeps, total well under 1 s)
   and sceKernelAllocateDirectMemory / sceKernelMapNamedDirectMemory (one own reservation each time, given back at once) on
   firmware 11.60 (case sheets sceKernelClockGettime_I, Gettimeofday_I, Usleep_I, Nanosleep_I, AllocateDirectMemory_I,
   MapNamedDirectMemory_I). No absolute time and no address is printed: only return codes, differences and resolutions.
   Prototypes are assumptions from the case sheets. */
#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 struct {
  long sec;
  long nsec;
} Ts;
typedef struct {
  long sec;
  long usec;
} Tv;

typedef int (*cg_fn)(int, Ts*);
typedef int (*gtod_fn)(Tv*);
typedef int (*usleep_fn)(unsigned);
typedef int (*nanosleep_fn)(const Ts*, Ts*);
typedef long (*dmsize_fn)(void);
typedef int (*alloc_fn)(long, long, size_t, size_t, int, long*);
typedef int (*mapn_fn)(void**, size_t, int, int, long, size_t, const char*);
typedef int (*unmap_fn)(void*, size_t);
typedef int (*rel_fn)(long, size_t);
typedef int (*vq_fn)(const void*, int, void*, size_t);

#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)

static cg_fn f_cg;
static long now_ns(void) {
  Ts t = {0, 0};
  f_cg(4, &t);
  return t.sec * 1000000000L + t.nsec;
}

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_cg = (cg_fn)dlsym(RTLD_DEFAULT, "sceKernelClockGettime");
  gtod_fn f_gtod = (gtod_fn)dlsym(RTLD_DEFAULT, "sceKernelGettimeofday");
  usleep_fn f_usleep = (usleep_fn)dlsym(RTLD_DEFAULT, "sceKernelUsleep");
  nanosleep_fn f_nano = (nanosleep_fn)dlsym(RTLD_DEFAULT, "sceKernelNanosleep");
  dmsize_fn f_size = (dmsize_fn)dlsym(RTLD_DEFAULT, "sceKernelGetDirectMemorySize");
  alloc_fn f_alloc = (alloc_fn)dlsym(RTLD_DEFAULT, "sceKernelAllocateDirectMemory");
  mapn_fn f_mapn = (mapn_fn)dlsym(RTLD_DEFAULT, "sceKernelMapNamedDirectMemory");
  unmap_fn f_unmap = (unmap_fn)dlsym(RTLD_DEFAULT, "sceKernelMunmap");
  rel_fn f_rel = (rel_fn)dlsym(RTLD_DEFAULT, "sceKernelReleaseDirectMemory");
  vq_fn f_vq = (vq_fn)dlsym(RTLD_DEFAULT, "sceKernelVirtualQuery");
  char line[160], extra[240], id[16], call[120];
  snprintf(line, sizeof line, "clock=%d gtod=%d usleep=%d nanosleep=%d dmem=%d%d%d%d%d%d", !!f_cg, !!f_gtod, !!f_usleep, !!f_nano, !!f_size, !!f_alloc, !!f_mapn, !!f_unmap, !!f_rel, !!f_vq);
  probe_case("0", "dlsym exported (1 yes, 0 no)", 0, 0, line);
  int r, e;

  if (f_cg) {
    for (int ck = 0; ck <= 20; ck++) {
      Ts t = {-1, -1};
      RUN(r = f_cg(ck, &t));
      snprintf(extra, sizeof extra, "sec_nonneg=%d nsec_below_1e9=%d signal=%d", t.sec >= 0, t.nsec >= 0 && t.nsec < 1000000000L, (int)guard_sig);
      snprintf(id, sizeof id, "1.%d", ck + 1);
      snprintf(call, sizeof call, "ClockGettime(clockid %d)", ck);
      probe_case(id, call, r, e, extra);
    }
    {
      Ts t;
      RUN(r = f_cg(4, 0));
      snprintf(extra, sizeof extra, "signal=%d", (int)guard_sig);
      probe_case("1.30", "ClockGettime(4, NULL)", r, e, extra);
      RUN(r = f_cg(-1, &t));
      probe_case("1.31", "ClockGettime(-1, &t)", r, e, "-");
    }
    long best = 1000000000L, d0 = 0;
    for (int i = 0; i < 200; i++) {
      long a = now_ns(), b2 = now_ns();
      long d = b2 - a;
      if (d > 0 && d < best) best = d;
      d0 = d;
    }
    snprintf(extra, sizeof extra, "min_nonzero_delta_ns=%ld last_delta_ns=%ld", best, d0);
    probe_case("1.32", "ClockGettime(4) resolution over 200 pairs", 0, 0, extra);
  }
  if (f_gtod) {
    Tv a = {0, 0}, b2 = {0, 0};
    RUN(r = f_gtod(&a));
    f_gtod(&b2);
    snprintf(extra, sizeof extra, "usec_below_1e6=%d delta_us=%ld", a.usec >= 0 && a.usec < 1000000, (b2.sec - a.sec) * 1000000L + (b2.usec - a.usec));
    probe_case("2.1", "Gettimeofday(&tv) twice", r, e, extra);
    RUN(r = f_gtod(0));
    snprintf(extra, sizeof extra, "signal=%d", (int)guard_sig);
    probe_case("2.2", "Gettimeofday(NULL)", r, e, extra);
  }
  if (f_usleep && f_cg) {
    static const unsigned us[] = {0, 1, 9, 10, 1000, 10000};
    for (int i = 0; i < 6; i++) {
      long t0 = now_ns();
      RUN(r = f_usleep(us[i]));
      long dt = now_ns() - t0;
      snprintf(extra, sizeof extra, "elapsed_us=%ld signal=%d", dt / 1000, (int)guard_sig);
      snprintf(id, sizeof id, "3.%d", i + 1);
      snprintf(call, sizeof call, "Usleep(%u)", us[i]);
      probe_case(id, call, r, e, extra);
    }
  }
  if (f_nano && f_cg) {
    static const Ts rq[] = {{0, 0}, {0, 1000000}, {0, 10000000}, {0, 1000000000L}, {0, -1}, {-1, 0}};
    for (int i = 0; i < 6; i++) {
      long t0 = now_ns();
      RUN(r = f_nano(&rq[i], 0));
      long dt = now_ns() - t0;
      snprintf(extra, sizeof extra, "elapsed_us=%ld signal=%d", dt / 1000, (int)guard_sig);
      snprintf(id, sizeof id, "4.%d", i + 1);
      snprintf(call, sizeof call, "Nanosleep({%ld s, %ld ns}, NULL)", rq[i].sec, rq[i].nsec);
      probe_case(id, call, r, e, extra);
    }
    Ts rem = {7, 7};
    Ts rq2 = {0, 1000000};
    RUN(r = f_nano(&rq2, &rem));
    snprintf(extra, sizeof extra, "rem_sec=%ld rem_nsec=%ld", rem.sec, rem.nsec);
    probe_case("4.7", "Nanosleep({0 s, 1 ms}, &rem)", r, e, extra);
  }

  if (f_alloc && f_rel) {
    long total = f_size ? f_size() : 0x100000000L;
    static const struct { int type; size_t len, align; } al[] = {
        {11, 1 * MB, 0}, {12, 1 * MB, 0}, {11, 4 * MB, 16 * KB}, {12, 4 * MB, 64 * KB}, {12, 1 * MB, 1 * MB}, {12, 4 * MB, 2 * MB}, {12, 4 * MB, 8 * MB}, {12, 100000, 0}, {12, 0, 0}};
    for (int i = 0; i < 9; i++) {
      long ph = -1;
      RUN(r = f_alloc(0, total, al[i].len, al[i].align, al[i].type, &ph));
      snprintf(extra, sizeof extra, "phys_set=%d phys_mod_align=%ld signal=%d", ph != -1, (ph == -1 || !al[i].align) ? -1L : ph % (long)al[i].align, (int)guard_sig);
      snprintf(id, sizeof id, "5.%d", i + 1);
      snprintf(call, sizeof call, "AllocateDirectMemory(0, total, len %zu, align 0x%zx, type %d)", al[i].len, al[i].align, al[i].type);
      probe_case(id, call, r, e, extra);
      if (r == 0 && ph != -1 && al[i].len) f_rel(ph, al[i].len); /* a zero-length reservation has nothing of its own to give back */
    }
    long ph = -1;
    RUN(r = f_alloc(1 * (long)MB, 0, 1 * MB, 0, 12, &ph));
    snprintf(extra, sizeof extra, "phys_set=%d", ph != -1);
    probe_case("5.10", "AllocateDirectMemory(start 1 MiB, end 0 (before start), 1 MiB)", r, e, extra);
    if (r == 0 && ph != -1) f_rel(ph, 1 * MB);
  }
  if (f_alloc && f_mapn && f_unmap && f_rel) {
    long total = f_size ? f_size() : 0x100000000L;
    long ph = -1;
    RUN(r = f_alloc(0, total, 4 * MB, 2 * MB, 12, &ph));
    probe_case("6.1", "AllocateDirectMemory(4 MiB, 2 MiB align, type 12) for the named maps", r, e, "-");
    if (r == 0 && ph != -1) {
      static const struct { int prot, flags; size_t align; const char* name; } mp[] = {
          {0x33, 0, 64 * KB, "f_probe_named"}, {0x32, 0, 64 * KB, "f_probe_named"}, {0x33, 0x400000, 64 * KB, "f_probe_named"}, {0x33, 0, 2 * MB, "f_probe_named"},
          {0x33, 0, 64 * KB, "0123456789012345678901234567890"}, {0x33, 0, 64 * KB, "01234567890123456789012345678901"}, {0x33, 0, 64 * KB, 0}, {0x3, 0, 64 * KB, "f_probe_rw"}};
      for (int i = 0; i < 8; i++) {
        void* a = 0;
        RUN(r = f_mapn(&a, 64 * KB, mp[i].prot, mp[i].flags, ph, mp[i].align, mp[i].name));
        char nm[40] = "-";
        int rq = -9;
        if (a && f_vq) {
          unsigned char info[160];
          memset(info, 0, sizeof info);
          rq = f_vq(a, 0, info, 72);
          memcpy(nm, info + 33, 32);
          nm[31] = 0;
          for (int k = 0; nm[k]; k++)
            if ((unsigned char)nm[k] < 32 || (unsigned char)nm[k] > 126) nm[k] = '?';
        }
        snprintf(extra, sizeof extra, "mapped=%d align_ok=%d vq_rc=%d name=[%s] signal=%d", a != 0, a ? ((uintptr_t)a % mp[i].align) == 0 : -1, rq, nm, (int)guard_sig);
        snprintf(id, sizeof id, "6.%d", i + 2);
        snprintf(call, sizeof call, "MapNamedDirectMemory(64 KiB, prot 0x%x, flags 0x%x, align 0x%zx, name of %zu chars)", mp[i].prot, mp[i].flags, mp[i].align, mp[i].name ? strlen(mp[i].name) : 0);
        probe_case(id, call, r, e, extra);
        if (a) f_unmap(a, 64 * KB);
      }
      RUN(r = f_rel(ph, 4 * MB));
      probe_case("6.10", "ReleaseDirectMemory(phys, 4 MiB) own block", r, e, "-");
    }
  }
  probe_end();
  return 0;
}
stdout
PROBE	libkernel_time_dmem2	fw=0x11600005	build=274d16c848bc	pid=121	utc=2026-11-07T21:06:50Z
CASE	0	dlsym exported (1 yes, 0 no)	0	0	clock=1 gtod=1 usleep=1 nanosleep=1 dmem=111111
CASE	1.1	ClockGettime(clockid 0)	0	0	sec_nonneg=1 nsec_below_1e9=1 signal=0
CASE	1.2	ClockGettime(clockid 1)	0	0	sec_nonneg=1 nsec_below_1e9=1 signal=0
CASE	1.3	ClockGettime(clockid 2)	0	0	sec_nonneg=1 nsec_below_1e9=1 signal=0
CASE	1.4	ClockGettime(clockid 3)	-2147352554	22	sec_nonneg=0 nsec_below_1e9=0 signal=0
CASE	1.5	ClockGettime(clockid 4)	0	0	sec_nonneg=1 nsec_below_1e9=1 signal=0
CASE	1.6	ClockGettime(clockid 5)	0	0	sec_nonneg=1 nsec_below_1e9=1 signal=0
CASE	1.7	ClockGettime(clockid 6)	-2147352554	22	sec_nonneg=0 nsec_below_1e9=0 signal=0
CASE	1.8	ClockGettime(clockid 7)	0	0	sec_nonneg=1 nsec_below_1e9=1 signal=0
CASE	1.9	ClockGettime(clockid 8)	0	0	sec_nonneg=1 nsec_below_1e9=1 signal=0
CASE	1.10	ClockGettime(clockid 9)	0	0	sec_nonneg=1 nsec_below_1e9=1 signal=0
CASE	1.11	ClockGettime(clockid 10)	0	0	sec_nonneg=1 nsec_below_1e9=1 signal=0
CASE	1.12	ClockGettime(clockid 11)	0	0	sec_nonneg=1 nsec_below_1e9=1 signal=0
CASE	1.13	ClockGettime(clockid 12)	0	0	sec_nonneg=1 nsec_below_1e9=1 signal=0
CASE	1.14	ClockGettime(clockid 13)	0	0	sec_nonneg=1 nsec_below_1e9=1 signal=0
CASE	1.15	ClockGettime(clockid 14)	0	0	sec_nonneg=1 nsec_below_1e9=1 signal=0
CASE	1.16	ClockGettime(clockid 15)	0	0	sec_nonneg=1 nsec_below_1e9=1 signal=0
CASE	1.17	ClockGettime(clockid 16)	-2147352571	5	sec_nonneg=0 nsec_below_1e9=0 signal=0
CASE	1.18	ClockGettime(clockid 17)	-2147352571	5	sec_nonneg=0 nsec_below_1e9=0 signal=0
CASE	1.19	ClockGettime(clockid 18)	-2147352571	5	sec_nonneg=0 nsec_below_1e9=0 signal=0
CASE	1.20	ClockGettime(clockid 19)	-2147352571	5	sec_nonneg=0 nsec_below_1e9=0 signal=0
CASE	1.21	ClockGettime(clockid 20)	0	0	sec_nonneg=1 nsec_below_1e9=1 signal=0
CASE	1.30	ClockGettime(4, NULL)	-2147352562	14	signal=0
CASE	1.31	ClockGettime(-1, &t)	-2147352554	22	-
CASE	1.32	ClockGettime(4) resolution over 200 pairs	0	0	min_nonzero_delta_ns=882 last_delta_ns=962
CASE	2.1	Gettimeofday(&tv) twice	0	0	usec_below_1e6=1 delta_us=1
CASE	2.2	Gettimeofday(NULL)	-2147352562	0	signal=0
CASE	3.1	Usleep(0)	0	0	elapsed_us=3 signal=0
CASE	3.2	Usleep(1)	0	0	elapsed_us=109 signal=0
CASE	3.3	Usleep(9)	0	0	elapsed_us=118 signal=0
CASE	3.4	Usleep(10)	0	0	elapsed_us=117 signal=0
CASE	3.5	Usleep(1000)	0	0	elapsed_us=1112 signal=0
CASE	3.6	Usleep(10000)	0	0	elapsed_us=10122 signal=0
CASE	4.1	Nanosleep({0 s, 0 ns}, NULL)	0	0	elapsed_us=4 signal=0
CASE	4.2	Nanosleep({0 s, 1000000 ns}, NULL)	0	0	elapsed_us=1022 signal=0
CASE	4.3	Nanosleep({0 s, 10000000 ns}, NULL)	0	0	elapsed_us=10052 signal=0
CASE	4.4	Nanosleep({0 s, 1000000000 ns}, NULL)	-2147352554	22	elapsed_us=5 signal=0
CASE	4.5	Nanosleep({0 s, -1 ns}, NULL)	-2147352554	22	elapsed_us=3 signal=0
CASE	4.6	Nanosleep({-1 s, 0 ns}, NULL)	0	0	elapsed_us=3 signal=0
CASE	4.7	Nanosleep({0 s, 1 ms}, &rem)	0	0	rem_sec=8304703408 rem_nsec=34074507440
CASE	5.1	AllocateDirectMemory(0, total, len 1048576, align 0x0, type 11)	0	0	phys_set=1 phys_mod_align=-1 signal=0
CASE	5.2	AllocateDirectMemory(0, total, len 1048576, align 0x0, type 12)	0	0	phys_set=1 phys_mod_align=-1 signal=0
CASE	5.3	AllocateDirectMemory(0, total, len 4194304, align 0x4000, type 11)	0	0	phys_set=1 phys_mod_align=0 signal=0
CASE	5.4	AllocateDirectMemory(0, total, len 4194304, align 0x10000, type 12)	0	0	phys_set=1 phys_mod_align=0 signal=0
CASE	5.5	AllocateDirectMemory(0, total, len 1048576, align 0x100000, type 12)	0	0	phys_set=1 phys_mod_align=0 signal=0
CASE	5.6	AllocateDirectMemory(0, total, len 4194304, align 0x200000, type 12)	0	0	phys_set=1 phys_mod_align=0 signal=0
CASE	5.7	AllocateDirectMemory(0, total, len 4194304, align 0x800000, type 12)	0	0	phys_set=1 phys_mod_align=0 signal=0
CASE	5.8	AllocateDirectMemory(0, total, len 100000, align 0x0, type 12)	-2147352554	22	phys_set=0 phys_mod_align=-1 signal=0
CASE	5.9	AllocateDirectMemory(0, total, len 0, align 0x0, type 12)	-2147352554	22	phys_set=0 phys_mod_align=-1 signal=0
CASE	5.10	AllocateDirectMemory(start 1 MiB, end 0 (before start), 1 MiB)	0	0	phys_set=1
CASE	6.1	AllocateDirectMemory(4 MiB, 2 MiB align, type 12) for the named maps	0	0	-
CASE	6.2	MapNamedDirectMemory(64 KiB, prot 0x33, flags 0x0, align 0x10000, name of 13 chars)	0	0	mapped=1 align_ok=1 vq_rc=0 name=[f_probe_named] signal=0
CASE	6.3	MapNamedDirectMemory(64 KiB, prot 0x32, flags 0x0, align 0x10000, name of 13 chars)	0	0	mapped=1 align_ok=1 vq_rc=0 name=[f_probe_named] signal=0
CASE	6.4	MapNamedDirectMemory(64 KiB, prot 0x33, flags 0x400000, align 0x10000, name of 13 chars)	0	0	mapped=1 align_ok=1 vq_rc=0 name=[f_probe_named] signal=0
CASE	6.5	MapNamedDirectMemory(64 KiB, prot 0x33, flags 0x0, align 0x200000, name of 13 chars)	0	0	mapped=1 align_ok=1 vq_rc=0 name=[f_probe_named] signal=0
CASE	6.6	MapNamedDirectMemory(64 KiB, prot 0x33, flags 0x0, align 0x10000, name of 31 chars)	0	0	mapped=1 align_ok=1 vq_rc=0 name=[0123456789012345678901234567890] signal=0
CASE	6.7	MapNamedDirectMemory(64 KiB, prot 0x33, flags 0x0, align 0x10000, name of 32 chars)	-2147352513	63	mapped=1 align_ok=1 vq_rc=0 name=[anon:0002000012b1] signal=0
CASE	6.8	MapNamedDirectMemory(64 KiB, prot 0x33, flags 0x0, align 0x10000, name of 0 chars)	-2147352562	14	mapped=1 align_ok=1 vq_rc=0 name=[anon:0002000012b1] signal=0
CASE	6.9	MapNamedDirectMemory(64 KiB, prot 0x3, flags 0x0, align 0x10000, name of 10 chars)	0	0	mapped=1 align_ok=1 vq_rc=0 name=[f_probe_rw] signal=0
CASE	6.10	ReleaseDirectMemory(phys, 4 MiB) own block	0	0	-
END	60

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 28301 core/libs/prx/libkernel/DirectMemory/Export.cpp L430-433

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 de6c7c5e3d, merged onto main 8eb293447e (a4e23ff066, 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.

@xXPBSXx

xXPBSXx commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

Merged main (d03beaf110) into this branch; the head is now 923988c480. The only conflict was in docs/dev/debt/libkernel.md: main added entries next to this change's sceKernelMapNamedDirectMemory entry. I kept both. tools/check_conventions.py --base upstream/main passes, and the diff against main is the same three files as before (DirectMemory/Export.cpp, GuestMemory.cpp and libkernel.md; the commits of #16869 are still included).

AI-assisted (Claude Code).

@gabichuuuuu

Copy link
Copy Markdown
Contributor

Windows check of head 923988c480, merged onto main e37e9fa3f9 (clean merge, built together with other open PRs that touch different files).

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

  • Tests chosen with tools/select_tests.py explain from this PR's test files: guest_memory, guest_mmap_executable, guest_mmap_fixed_anonymous.
  • All of them pass in 3 of 3 runs.
  • No negative control was run in this pass, so this does not show that the tests fail without the change.

AI-assisted: yes.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Nov 12, 2026
@adriadam10 adriadam10 self-assigned this Nov 12, 2026
@adriadam10
adriadam10 force-pushed the fix/kernel-map-named-direct-memory-name-v2 branch from 923988c to 344e54d Compare November 12, 2026 12:53
@oneandonlydean

Copy link
Copy Markdown
Collaborator

@xXPBSXx I reviewed 344e54d. The 31-character result (0, name stored) and the 32-character result (0x8002003f, errno 63, mapped, unnamed) match probe cases 6.6 and 6.7, and the check runs after a successful map so the other errors keep their order. One claim does not match the probe.

Probe case 6.8 is labelled "name of 0 chars", but its table entry is {0x33,0,64*KB,0}, so as I read it the call passed a NULL name pointer, and the console returned 0x8002000e for that. The PR keeps NULL returning 0 and returns EFAULT for an empty string "", which no probe case tested, and the body, the test and the debt entry all call it a measured empty-name result.

Please do one of these: re-measure with a real "" argument and keep EFAULT if the console returns 0x8002000e for it, or make NULL return 0x8002000e as measured and drop the "" claim. Either way, please say NULL in the body, the test and the debt entry where that is what was measured. A 33-character case would also help, or say that it is inferred from the 32-character one.

@adriadam10 adriadam10 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks, the 31 and 32 character results match probe cases 6.6 and 6.7. One measured claim does not match the probe, as @oneandonlydean noted:

  • Probe case 6.8 is labelled "name of 0 chars", but its table entry is {0x33, 0, 64 * KB, 0}: the name argument is NULL, not "". What the console measured is NULL name → 0x8002000e with the range mapped and unnamed.
  • This PR keeps NULL returning 0 (Export.cpp:360, if (result == 0 && name)) and returns EFAULT for "", which no probe case covers. The PR body, the test (GuestMemory.cpp:254) and the debt entry (libkernel.md:209) all present that as measured.

To fix, either:

  • re-measure with a real "" argument and keep EFAULT if the console returns it, or
  • make a NULL name return EFAULT after the mapping as measured, drop the "" claim, and say NULL in the body, test and debt entry (check that no internal caller of sceKernelMapNamedDirectMemory passes NULL).

Please also say that names longer than 32 characters are inferred from the 32 character case, or add a 33 character probe.

@ycbuzi

ycbuzi commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

Tested 344e54d0f5 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, 4 tests failed out of 5491; 99% tests passed, 5 tests failed out of 5491. 4 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, 2 tests failed out of 5491; 99% tests passed, 4 tests failed out of 5491. 4 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.

xXPBSXx and others added 2 commits November 19, 2026 22:03
… a 32 character name and a NULL name

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…irectMemory for a 32 character name or a NULL name

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

kiwe147 commented Nov 21, 2026

Copy link
Copy Markdown

Tested head ccde1e977b, applied with git apply on main fd4aeed483 together with the other 26 PRs of one batch (#16367, #16415, #22363, #23103, #23366, #24064, #21547, #21742, #22774, #22852, #23420, #23952, #24346, #21718, #21780, #21912, #21931, #22061, #22425, #22619, #22657, #18765, #19662, #19767, #20899, #21571). All applied without conflicts and the whole tree built.

Setup: Windows 11 Pro 10.0.26200, Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7, Release, BUILD_TESTING=ON. GPUs: NVIDIA GeForce RTX 3080 (driver 621.24) and the AMD Radeon iGPU of the CPU (gfx1036, driver 32.0.21036.18). No validation layer. iGPU run: ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 ANYPS5_GPU="AMD Radeon", agc_/video tests only.

tests RTX 3080 iGPU
guest_memory, guest_memory_pool_stats, guest_memory_resource (3 tests, matched by name to the test file this PR changes) all pass outside the iGPU subset

Whole batch: the full ctest -j 12 (6523 tests) on the RTX 3080 has 4 failing tests; the 4 that also fail on main fd4aeed483 are agc_driver_stencil_plane_memory, agc_driver_msaa_dcc_unwatch, agc_storage_write_back_host_retile, and pr_overlap_names, which needs a newer Python than my 3.10. Intermittent in this run (pass when rerun alone, or known flaky): agc_driver_store_over_untracked. The 2126 agc_/video tests on the iGPU have 2 failing: agc_driver_stencil_plane_memory, agc_driver_store_over_untracked (agc_driver_stencil_plane_memory also fails on main).

This is one combined tree, not a run of this PR alone.

AI-assisted: yes (Claude Code)

@xXPBSXx

xXPBSXx commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

The points of the review of 344e54d0f5 are addressed in the current head ccde1e977bd0 (the branch was rebuilt on main, so the old head no longer exists in the diff):

  • Probe case 6.8 passed a NULL name, not an empty string: NULL now returns EFAULT after the mapping (Export.cpp:391), the range stays mapped and unnamed, and the test pins nullptr -> 0x8002000e with a non-null mapping (GuestMemory.cpp, CheckMapNamedDirectMemoryNames). The body, the test and the debt entry say NULL.
  • The EFAULT claim for the empty string is removed everywhere; the debt entry says an empty name is not measured and is unchanged.
  • No caller passes NULL: git grep on upstream/main 1f2e77165a4 finds sceKernelMapNamedDirectMemory only in its definition, its declaration (Api.hpp:248) and tests; the tests pass strings (GuestFlexibleMemoryBudget.cpp:210 "budget direct", GuestMemory.cpp:430), and the new test is the only one with NULL.
  • Names of 33 or more characters are stated as following from the 32-character case; no 33-character case was probed.

The review of 344e54d0f5 is still listed as requesting changes; could you take another look at the current head when you have time?

AI-assisted (Claude Code).

@xXPBSXx

xXPBSXx commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

The change request of 12 November is addressed in the current head ccde1e977bd0 (probe case 6.8 passed a NULL name; NULL now returns EFAULT, see the comment of 24 November), and the pull request is otherwise approved and clean; it stays blocked only until that review is updated. AI-assisted (Claude Code).

@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 the added named-memory mapping cases.

AI-assisted: yes.

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