222 Commits
Author SHA1 Message Date
Adrià 950f8a5a53 Merge pull request #11681 from milescoviello/test/main-direct-memory
test(libkernel): cover the block sceKernelAllocateMainDirectMemory returns and its type
2026-10-29 09:31:07 +01:00
Dean 319621ba2e Merge pull request #12339 from medazizktata/fix/windows-exec-shared-mapping
fix(libkernel): map shared memory and files executable on Windows
2026-10-29 07:28:16 +13:00
Dean 9c542cac90 Merge pull request #11536 from milescoviello/test/kernel-prt-aperture
test(libkernel): cover the PRT aperture setter and getter, their index bounds and null outputs
2026-10-29 07:21:39 +13:00
Mohamed Aziz Ktata dbd826bc88 fix(libkernel): map shared memory and files executable on Windows
A guest mmap with PROT_EXEC and MAP_SHARED of a shared-memory object or a regular file threw on Windows. The section is now created from a handle reopened with GENERIC_EXECUTE, as PAGE_EXECUTE_READ or PAGE_EXECUTE_READWRITE, the owner ACE of named objects grants execute with read, and a writable shared mapping of a read-only descriptor fails with EACCES, as FreeBSD 11.4 shm_mmap and vn_mmap do.

Fixes #12337
2026-10-28 11:14:08 +01:00
harisibrar1 6413eacf9d Merge remote-tracking branch 'origin/main' into fix/map-undefined-protection-einval
# Conflicts:
#	docs/dev/debt/libkernel.md
2026-10-28 01:28:03 -04:00
Adrià 3d214c8d87 Merge pull request #11549 from milescoviello/test/kernel-memory-pool-block-stats
test(libkernel): cover sceKernelMemoryPoolGetBlockStats's checks and the block an expansion adds
2026-10-28 06:05:23 +01:00
Adrià 957a22d51f Merge pull request #11688 from milescoviello/test/batch-map-fixed
test(libkernel): cover sceKernelBatchMap mapping and unmapping at the given starts
2026-10-28 04:41:33 +01:00
Dean Galvin 97f1d41a2c Revert "Merge pull request #10809 from frankea/fix/direct-memory-12gib"
This reverts commit 780b33aea3, restoring the 13824 MiB direct memory pool.

With the pool at 12288 MiB, Astro Bot (PPSA21564) can no longer load its
level: DirectMemoryAllocator asserts "Can't allocate direct memory" for a
64 MB VideoPlayerTexture with 12228 of 12288 MB in use, then the process
faults about 26 s in (2 of 2 runs, RTX 4090, Linux, main cccdaa2734).
The same tree with only this merge reverted runs the full 150 s with no
direct memory assert (2 of 2 runs).
2026-10-28 15:45:26 +13:00
Dean 780b33aea3 Merge pull request #10809 from frankea/fix/direct-memory-12gib
fix(libkernel): report 12 GiB of direct memory, as a PS5 does
2026-10-28 13:49:57 +13:00
Dean 47f7d77bcb Merge pull request #11593 from milescoviello/test/direct-memory-query
test(libkernel): cover sceKernelDirectMemoryQuery's block lookup, find-next and argument checks
2026-10-28 12:07:11 +13:00
Adrià 9149eec852 Merge pull request #11152 from thuanquang/perf/resident-page-bookkeeping
perf(libc): keep no per-page physical state for resident guest pages on Windows
2026-10-27 12:00:39 +01:00
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
thuanquangandClaude 3f130031d8 perf(libc): keep no per-page physical state for resident guest pages on Windows
A resident direct memory mapping created a SharedPage, a Physical, a
physical map node and an aliases buffer for every 16 KiB page, about
18 MiB of heap per GiB mapped, although a page mapped once holds no
state there. Resident pages now keep only their View, with pins and the
compare-when-shared mark in it; an index from (section, offset) to the
resident run finds a live resident mapping of a physical page, and the
shared state is created when a run is demoted, or when it is evicted
with data or a compare mark. ForgetSection drops the index entries of
the section's runs.

guest_memory on Windows 11 26200 (Ryzen 5 5600X): private memory per
GiB mapped at map time drops from 30.9 MiB to 13.4 MiB.

Co-Authored-By: Claude <[email protected]>
2026-10-27 04:24:13 +01:00
milescovielloandClaude Opus 5.5 3d1463aef6 test(libkernel): keep only the main direct memory allocation and type check
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-27 03:04:33 +00:00
milescovielloandClaude Opus 5.5 3b779dee14 test(libkernel): move the main direct memory test clear of the macOS direct memory change
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-27 02:50:04 +00:00
milescovielloandClaude Opus 5.5 a5a8451218 test(libkernel): cover sceKernelBatchMap mapping and unmapping at the given starts
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-27 02:46:59 +00:00
milescovielloandClaude Opus 5.5 3134ed1658 test(libkernel): cover sceKernelAllocateMainDirectMemory's block and argument checks
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-27 02:35:01 +00: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
milescovielloandClaude Opus 5.5 aaa0958b17 test(libkernel): cover sceKernelDirectMemoryQuery's block lookup, find-next and argument checks
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-26 22:00:36 +00: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
milescovielloandClaude Opus 5.5 008c5e8e37 test(libkernel): cover sceKernelMemoryPoolGetBlockStats's checks and the block an expansion adds
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-26 20:49:30 +00:00
milescovielloandClaude Opus 5.5 29ecf14529 test(libkernel): cover the PRT aperture setter and getter, their index bounds and null outputs
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-26 17:57:09 +00: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
frankea b5c6010f80 Merge remote-tracking branch 'origin/main' into fix/direct-memory-12gib 2026-10-25 20:21:28 -04: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
harisibrar1andClaude Opus 5.5 73fffbee8e fix(libkernel): refuse undefined protection bits in the map calls with EINVAL as measured on a PS5
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-25 09:13:23 -04:00
frankea ad9a0c8ef9 fix(libkernel): report 12 GiB of direct memory, as a PS5 does
sceKernelGetDirectMemorySize returns 0x300000000 inside Gran Turismo 7 (PPSA01317) on a PS5 with firmware 13.40. DIRECT_MEMORY_SIZE was 13824 MiB.
2026-10-24 22:11:58 -04: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