Commit Graph
200 Commits
Author SHA1 Message Date
Dean c28cf99512 Merge pull request #11438 from p3n1cillin/claude/direct-map-refuses-execute
fix(libkernel): refuse to map direct memory with execute as the console does
2026-10-27 21:26:17 +13:00
Dean 699ffce388 Merge pull request #10550 from GitamarT045T3R/fix/libkernel-munmap-unaligned
fix(libkernel): round an unaligned munmap address down like FreeBSD
2026-10-27 21:11:19 +13:00
Dean 36e6c092c0 Merge pull request #9011 from JJenkx/perf/mapped-readable-run-lease-b5d763
perf(agc): lease mapped readable runs for import events
2026-10-27 21:05:23 +13:00
Adrià 50a28679c4 Merge pull request #10528 from akkadbakkad89/fix/direct-remap-block-index
fix(libkernel): walk direct-memory physical ranges by block, not page
2026-10-27 05:35:38 +01:00
Dean 4571f48bff Merge pull request #11173 from p3n1cillin/claude/mmap-excl-ignored
fix(libkernel): ignore MAP_EXCL in fixed anonymous mmap as measured on a PS5
2026-10-27 15:01:30 +13:00
p3nicillinandClaude Opus 5.5 3b210875a8 fix(libkernel): refuse to map direct memory with execute
PS5_PayloadSDK measured in a title (firmware 12.09) that
sceKernelMapDirectMemory with read-execute or read-write-execute returns
0x80020016, and that sceKernelMprotect then grants execute to a
read-write mapping. The map granted execute directly.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-26 21:40:24 +00:00
Dean c3fc606849 Merge pull request #11179 from MarcZX10/marc/build-tsan-option
build: add an ANYPS5_ENABLE_TSAN option for ThreadSanitizer builds
2026-10-27 10:39:03 +13:00
p3nicillinandClaude Opus 5.5 2387f0ece7 test(libkernel): check that MAP_EXCL replacement leaves neighbouring pages alone
Also word the debt entry as Prospero Win's report, not a measurement here.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-26 01:24:42 +00:00
Adrià 90f918fa71 Merge pull request #9645 from dantdmdarealguy/test/guest-memory-process-commit
test(libkernel): measure the remapped direct memory charge in the test process
2026-10-25 22:28:01 +01:00
akkadbakkad89 304220f524 fix(libkernel): reprotect same-state fixed remaps and order block publish
The same-range/same-protection fast path in RemapFixedIntoRegistered
returned without touching host pages, but DoMprotect/DoMtypeprotect
change host protection without updating the recorded nativeProtection,
so a stale record could leave guest pages with the wrong host
permissions. The shortcut now reissues the per-block backing map with
records skipped, keeping the bookkeeping optimization while reapplying
the requested host protection.

CreateDirectMemoryBacking registered g_physBlocks before building the
per-page map, so a bad_alloc during page construction left an orphaned
physical block that poisoned later allocations; the block now publishes
after the page map is built.

CheckFixedRemapReprotectsAfterMprotect covers both shortcut directions
with stale records and verifies the host protection via VirtualQuery /
proc maps, and the existing remap test gains the current uint64 Munmap
call.
2026-10-25 21:06:12 +00:00
Dean Galvin b7d6ee572e Merge branch 'main' into fix/libkernel-munmap-unaligned 2026-10-26 09:57:14 +13:00
akkadbakkad89 3f6e2b3304 fix(libkernel): carry native protection on direct mappings so fixed remaps reprotect 2026-10-25 20:56:58 +00:00
MarcZX10 81a0f6b815 test(libkernel): skip host mlock result checks in guest_memory under ThreadSanitizer
CheckMlock reads VmLck and expects ENOMEM from mlock of reserved and unmapped ranges. ThreadSanitizer, like AddressSanitizer, replaces mlock and munlock with interceptors that return 0 without locking anything, so skip the same checks that ANYPS5_ENABLE_ASAN already skips. The guest arena range check stays as is: a ThreadSanitizer build keeps the default range.
2026-10-25 20:38:12 +00:00
p3nicillinandClaude Opus 5.5 8df80bdc3f fix(libkernel): ignore MAP_EXCL in fixed anonymous mmap as measured on a PS5
Prospero Win measured on firmware 12.02 that the PS5 kernel accepts
MAP_EXCL but ignores it: MAP_FIXED | MAP_EXCL over an existing mapping
replaces it without error. Fixed anonymous mmap now does the same instead
of FreeBSD's ENOMEM. MAP_EXCL without MAP_FIXED stays EINVAL.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-25 20:33:23 +00:00
Adrià 1ee8f4bec1 Merge pull request #9181 from Dripl1x/fix/no-resident-write-faults
fix(libc): stop write-protecting resident runs on Windows
2026-10-25 14:26:12 +01:00
dantdmdarealguy dc31bdea09 test(libkernel): measure the remapped direct memory charge in the test process
CheckRemappedDirectMemoryIsChargedOnce compared the system-wide commit
total (K32GetPerformanceInfo) before and after mapping, unmapping and
remapping 256 MiB of direct memory, and required the growth to stay under
384 MiB in one of three attempts. Every other process on the host changes
that total, so guest_memory failed at GuestMemory.cpp:2164 whenever a
parallel test or a compiler committed and freed more than 128 MiB during
each attempt.

Measure the private and shared commit of the test process instead
(PrivateUsage and SharedCommitUsage of PROCESS_MEMORY_COUNTERS_EX2), which
covers both the private resident run and the direct memory section. The
remap grows it by 265 MiB on every run, so the attempts are dropped.
2026-10-24 18:29:20 -05:00
boykopovar e29ef3c6b5 fix(tests): cast memory unmap addresses to canonical type 2026-10-25 00:21:05 +03:00
boykopovar f38d29fd08 refactor(sdk): add canonical headers for remaining libraries 2026-10-24 23:17:42 +03:00
Dean 7dea7774d6 Merge pull request #10018 from JJenkx/fix/dmem-release-skips-free-pages
fix(libkernel): skip unallocated pages in sceKernelReleaseDirectMemory
2026-10-25 03:51:22 +13:00
Dean 5b02b41c1d Merge pull request #9876 from orezraey/fix/libkernel-aio-limits-measured-ps5
fix(libkernel): follow AIO limits, unknown ids and reported states as measured on a PS5
2026-10-25 00:21:25 +13:00
JJenkxandClaude Opus 5.5 462f8dff1f fix(libkernel): skip unallocated pages in sceKernelReleaseDirectMemory
The unchecked release passed its whole range to ForgetDirectMemory,
which throws on any page that is not allocated, so releasing a range
that is partly or wholly free aborted the process. Release only the
allocated runs, as shadPS4's unchecked free does; the checked variant
still returns ENOENT for them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-24 05:54:17 -04:00
Itamar Medyoni d590a3ef6f fix(libkernel): round an unaligned munmap address down like FreeBSD
munmap failed with EINVAL for an address that is not page aligned.
FreeBSD 11's sys_munmap rejects only a zero length and an address wrap;
it moves the address down to its page and grows the length by the same
offset before rounding it up, so the pages the range touches are
unmapped.
2026-10-24 12:30:23 +03:00
Dean ce965ddb7b Merge pull request #9153 from orezraey/fix/libkernel-dmem-available-measured-ps5
fix(libkernel): match sceKernelAvailableDirectMemorySize arguments to PS5
2026-10-24 22:13:10 +13:00
JJenkxandClaude Opus 5.5 f7ea1c56ea Merge main into perf/mapped-readable-run-lease-b5d763
Resolve ImportMappedRanges onto the lazy lease from #7465: ranges of
0x10000 bytes or less still take no lease, the first larger range takes
the narrow lease over the mapped runs instead of a full one, and an import
that would replace another (with the GPU mutex held) re-acquires a full
lease. The adopting path keeps its full lease for refreshImports.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-24 01:40:13 -04:00
orezraeyandClaude Opus 5.5 60135e8855 Merge main into fix/libkernel-aio-limits-measured-ps5
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-23 20:06:53 -03:00
Dean 313d905437 Merge pull request #9877 from orezraey/fix/libkernel-release-flexible-measured-ps5
fix(libkernel): keep the range sceKernelReleaseFlexibleMemory releases mapped as measured on a PS5
2026-10-24 10:37:09 +13:00
orezraeyandClaude Opus 5.5 aebed518a7 Merge main into fix/libkernel-aio-limits-measured-ps5
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-23 17:27:35 -03:00
QRMOE 5836873170 fix(memory): honor low guest mapping hints 2026-10-23 16:51:33 +02:00
orezraeyandClaude Opus 5.5 0db5b78405 test(libkernel): cover 4 KiB offsets in sceKernelReleaseFlexibleMemory
Measured on firmware 13.60: an address or length aligned to 4 KiB but
not to 16 KiB returns EINVAL.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-22 17:09:36 -03:00
orezraeyandClaude Opus 5.5 2f8177d7b4 fix(libkernel): keep the range sceKernelReleaseFlexibleMemory releases mapped
Measured on firmware 13.60: the released range stays mapped with its
protection and contents, and a fixed no-overwrite map over it fails
with ENOMEM; a null or unaligned address, an unaligned length or a
range that wraps returns EINVAL, checked before a zero length, which
returns 0, as does a range with nothing mapped.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-22 17:09:36 -03:00
orezraeyandClaude Opus 5.5 2730b6abe5 fix(libkernel): match the AIO batch, priority and parameter limits to PS5
Measured on firmware 13.60: submits take 1 to 128 requests at priority
1 to 3, the id lists of poll, wait, cancel and delete take 1 to 128 ids,
wait takes mode 1 or 2, and sceKernelAioSetParam takes a window and a
delayed count of 0 to 128, a split flag of 0 or 1 and, with split on,
split and chunk sizes of 1 to 0x1000000; everything else returns EINVAL
without writing. sceKernelAioInitializeParam writes the console's three
default scheduling structs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-22 16:57:51 -03:00
boykopovar 8b75d497c0 fix(kernel): reject unimplemented internal pool statistics 2026-10-21 21:56:05 +03:00
Adrià b00235dda0 Merge pull request #8439 from xXPBSXx/fix/mmap-anonymous-flags
fix(libkernel): accept MAP_ANON without MAP_PRIVATE and refuse MAP_SHARED with MAP_PRIVATE
2026-10-21 20:16:10 +02:00
Adrià 8e72738df6 Merge pull request #8437 from xXPBSXx/fix/mprotect-ignore-undefined-bits
fix(libkernel): drop undefined protection bits in mprotect
2026-10-21 20:08:57 +02:00
Evgeniy KazarinandClaude Opus 5.5 d6e270ea9f fix(libc): stop write-protecting resident runs on Windows
A clean resident run was made read-only so that the next collect
could skip GetWriteWatch, and the first guest store into it was
resumed on the guest thread. The exception frame Windows builds for
that fault overwrites the System V red zone below rsp (#361), which
is what #5596 removed for singly mapped direct memory. Resident runs
are now never armed and are collected with GetWriteWatch only.

Refs #9136

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-21 21:43:56 +08:00
orezraeyandClaude Opus 5.5 39cc6af2b1 fix(libkernel): compare the search start before rounding it
Measured on firmware 13.60: a start whose rounding to 16 KiB overflows
finds nothing, and of two equal free ranges the lowest is returned.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-21 10:41:28 -03:00
orezraeyandClaude Opus 5.5 4319a7a5e7 fix(libkernel): match sceKernelAvailableDirectMemorySize arguments to PS5
Measured on firmware 13.60: an alignment that is not zero or a power of
two returns EINVAL before anything else; bounds with nothing between
them return ENOMEM, a negative start searches from the bottom, only the
start is rounded up to 16 KiB and the end is used as given; null outputs
are skipped; errors leave both outputs untouched.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-21 10:39:19 -03:00
JJenkx 623501f365 perf(agc): lease mapped readable runs for import events 2026-10-21 05:28:08 -04:00
Evgeniy KazarinandClaude Opus 5.5 69f843c910 perf(libkernel): reuse released direct-memory sections that never held data
The title allocates, maps and releases about 48 direct-memory blocks per frame.
Each allocation created a pagefile-backed section and each release closed it.
A released section whose pages were never stored to (resident pages keep their
data in private memory and saved buffers, not in the section) is still blank,
so up to 256 such sections of at most 16 MiB, 256 MiB in total, are kept by
size and handed to the next allocation of that size instead of a new
CreateFileMappingW. APS5_NO_DIRECT_MEMORY_SECTION_POOL keeps the old behaviour.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-21 10:32:44 +08:00
Dean b13183e59e Merge pull request #7473 from Dripl1x/codex/skip-clean-resident-write-watch
perf(libc): skip write-watch queries for proven clean resident ranges
2026-10-21 14:55:09 +13:00
Dean c82867c77c Merge pull request #7472 from Dripl1x/codex/reuse-unreferenced-saved-memory
perf(libc): reuse saved direct-memory buffers when unreferenced
2026-10-21 13:25:04 +13:00
Evgeniy Kazarin 7898b5bd3a fix(libc): avoid repeated resident write faults 2026-10-21 03:55:51 +08:00
Evgeniy Kazarin a627328cfa perf(libc): skip write-watch queries for proven clean resident ranges 2026-10-21 03:53:50 +08:00
Evgeniy Kazarin 9d5f8326bf perf(libc): collect resident writes directly into the output buffer 2026-10-21 03:52:09 +08:00
xXPBSXxandClaude Sonnet 5.5 8977922244 fix(libkernel): drop undefined protection bits in mprotect
FreeBSD 11.4 kern_mprotect masks the argument with VM_PROT_ALL instead of
refusing it (sys/vm/vm_mmap.c:613). sceKernelMprotect already does this
since #5770; the POSIX mprotect export still failed with EINVAL.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-10-20 18:51:41 +02:00
xXPBSXxandClaude Sonnet 5.5 12785e2192 fix(libkernel): accept MAP_ANON without MAP_PRIVATE and refuse MAP_SHARED with MAP_PRIVATE
FreeBSD 11.4 kern_mmap maps anonymous memory whenever MAP_ANON is set, with
or without MAP_PRIVATE (sys/vm/vm_mmap.c:339), and fails with EINVAL when
both MAP_SHARED and MAP_PRIVATE are set (vm_mmap.c:252). The guest failed
the first with ENOTSUP (45) and the second with ENOTSUP as well.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-10-20 14:35:04 +02:00
Seif Allah Karoui be27ffa12c test(libkernel): harden signed-byte memory protection coverage 2026-10-20 12:06:06 +01:00
Dean 49fd13a741 Merge pull request #7958 from Lindamea1/fix/libkernel-available-direct-memory-enomem
fix(libkernel): return ENOMEM from sceKernelAvailableDirectMemorySize when the range has no free block
2026-10-20 17:40:24 +13:00
Adrià a700809679 Merge pull request #7448 from Tamalero/fix/libkernel-release-direct-memory-order
fix(libkernel): unmap released direct memory views before freeing the physical range
2026-10-19 23:27:29 +02:00
Lindamea1andClaude Opus 5.5 179316c452 fix(libkernel): return ENOMEM from sceKernelAvailableDirectMemorySize when the range has no free block
A search range with no free direct memory returned EAGAIN (0x80020023).
A PS5 returns ENOMEM (0x8002000c) for an occupied range, as the
PS5_RetroArch author's console capture records, and PS5_PayloadSDK's
ps5_memory_query, which RetroArch uses for its memory status, gives up
on any other error.

LargestFree now returns the error: ENOMEM when no block is found, and
EAGAIN as before for a negative start, an end at or below the start and
an alignment that overflows when rounded to a page. guest_memory expects
ENOMEM for an occupied range and EAGAIN for those arguments. The
unmeasured argument handling is recorded in the libkernel debt file.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-19 16:24:55 +01:00