428 Commits
Author SHA1 Message Date
Dean 09aa8adb84 Merge pull request #27348 from aKazm1/fix/kernel-direct-memory-query-13
fix(libkernel): accept sceKernelDirectMemoryQuery flags as firmware 13.00 does
2026-11-30 01:31:24 +13:00
Dean db14134b45 Merge pull request #27323 from kiansaeidnia/fix/libkernel-mprotect-range-bounds
fix(libkernel): clamp mprotect ranges to the user map, as FreeBSD 11.4 does
2026-11-30 01:30:57 +13:00
Dean ddc1bb9d42 Merge pull request #27303 from kiansaeidnia/fix/libkernel-mmap-freebsd-flags
fix(libkernel): accept shared anonymous, MAP_ALIGNED and hint flags in mmap, as FreeBSD 11.4 does
2026-11-30 01:30:31 +13:00
Dean 7b21970337 Merge pull request #20349 from Gag21/fix/kernel-fixed-map-ignores-alignment
fix(libkernel): place a fixed mapping at any page-aligned address whatever its alignment
2026-11-30 01:28:24 +13:00
Dean c91cca29ff Merge pull request #24743 from nodex0/fix/libkernel-munmap-page-range
fix(libkernel): round sceKernelMunmap ranges to guest pages
2026-11-29 23:13:56 +13:00
Dean 9c9ab25053 Merge pull request #22013 from brajankw/fix/libkernel-virtual-query-committed-direct-only
fix(libkernel): report is_committed from sceKernelVirtualQuery only for direct memory, as a PS5 does
2026-11-29 23:12:20 +13:00
Dean 9d8f60b234 Merge pull request #27457 from Herolias/fix/kernel-fixed-reserve-partial-overlap
fix(libkernel): replace the mapped parts of a partly free fixed reservation
2026-11-29 19:54:53 +13:00
Dean b19e5a8a96 Merge pull request #26643 from LeandroLP23/feat/libc-windows-read-traps
feat(libc): trap guest reads for the write watch on Windows
2026-11-28 11:02:38 +13:00
Dean 2a40d29631 Merge pull request #25960 from Kikoarl/fix/kernel-guest-copy-errno
fix(libkernel): validate guest destination pointers upfront in sceKernelBatchMap2 and sceKernelStopUnloadModule
2026-11-28 07:39:31 +13:00
Dean d986e14a09 Merge pull request #24469 from domx4q/fix/libkernel-map-memory-guest-pointers
fix(libkernel): copy the memory map address slots through guest copies
2026-11-28 03:43:45 +13:00
Dean 577a70fcef Merge pull request #23301 from gurtgg/fix-libkernel-memory-pool-committed-ranges
fix(libkernel): track committed ranges accurately in memory pool block stats
2026-11-27 15:48:02 +13:00
EliasandClaude Sonnet 5.5 6c43a60bf8 fix(libkernel): wait for GPU leases before checking a partly free fixed reservation
Unmapping waits for a GPU lease on a mapped part with the registry lock released,
and that wait came after the reservation had checked the free parts. A free part
taken during the wait made the call fail after the unmap. The wait now comes
first, so the check sees a part taken during it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-27 02:38:53 +01:00
EliasandClaude Sonnet 5.5 2cfb1642b4 fix(libkernel): refuse a fixed reservation over image memory before unmapping
A MAP_FIXED reservation over a range with mappings below registered image memory
unmapped them and then failed with "guest image memory cannot be unmapped", so
sceKernelMemoryPoolReserve returned EINVAL with a mapping gone. Such a range is
now refused before anything is unmapped, with the answer given before.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-27 02:21:55 +01:00
EliasandClaude Sonnet 5.5 094cec8fe5 fix(libkernel): replace the mapped parts of a partly free fixed reservation
sceKernelReserveVirtualRange with MAP_FIXED over a range that was partly mapped
and partly free ended the process with "fixed mapping ... overlaps a registered
guest allocation", and sceKernelMemoryPoolReserve returned EINVAL. Without
no-overwrite they now replace the mapped parts, as FreeBSD 11.4's vm_map_fixed
deletes the range before it inserts, and as shadPS4 does. A range that also
holds a host region still fails with ENOMEM, before anything is unmapped.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-26 14:20:32 +01:00
Abdulrahman Al-KazmiandClaude Opus 5.5 3f2ad166c5 fix(libkernel): throw for sceKernelDirectMemoryQuery flag bits that were not measured
A second firmware 13.00 payload run tried every single flag bit on a block,
in a released range before another block and past the last block, plus
negative offsets. Bits 1 to 27 are ignored; bit 28 returns EINVAL; bit 30
returns EINVAL only on a block and EACCES where none is found; bits 29 and
31 return EACCES where no block is found and write other records on a block,
so they throw there. Find-next keeps working with other bits set. A negative
offset returns EACCES for flags 0, bit 30 and bit 31; with find-next it
returned a block, so that throws. Unmeasured combinations throw and are
listed in the debt entry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 02:55:50 +03:00
Abdulrahman Al-KazmiandClaude Opus 5.5 cfe445e3f6 fix(libkernel): accept sceKernelDirectMemoryQuery flags as firmware 13.00 does
A payload process on firmware 13.00 got the block for flags 2 and 4 and for
other bits besides bit 30 (EINVAL), a size of 0 returned 0 without writing,
and flags 2, 4 and 8 where no block is found returned EACCES. Bit 31 wrote
another record and a size of 0 with no block was not measured, so both throw.
System software 12.40 returned EINVAL for flags 2 and 4; the debt entry keeps
that.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 00:49:25 +03:00
KianandClaude Opus 5.5 59c15fb0dc fix(libkernel): clamp mprotect ranges to the user map, as FreeBSD 11.4 does
mprotect returns EINVAL only when the page-rounded end of the range
wraps, as FreeBSD 11.4 kern_mprotect does, and skips the part of the
range below the first page or at or above 0x800000000000, as
vm_map_protect clamps with VM_MAP_RANGE_CHECK. A range at NULL or
outside the user map now returns 0 and changes nothing instead of
EINVAL, matching the unmapped ranges measured on a PS5 (firmware 13.60).
On Windows the protection walk ends where VirtualQuery reports an
address above the process address space, so such a range is a gap.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 06:27:58 +10:00
KianandClaude Opus 5.5 2de888d9fe fix(libkernel): accept shared anonymous, MAP_ALIGNED and hint flags in mmap, as FreeBSD 11.4 does
MAP_SHARED | MAP_ANON, with or without MAP_FIXED, maps zero-filled memory
through the private anonymous path; fd -1 and offset 0 stay required.
MAP_ALIGNED(n) places a map without MAP_FIXED at a 2^n aligned address,
fails with EINVAL for n below the 16 KiB page shift or from 64, and is
ignored with MAP_FIXED, for anonymous and file maps; from 47 no user
address is so aligned and the map fails with ENOMEM. A hint inside a
sceKernelReserveVirtualRange reservation is rounded up to the requested
alignment before it is placed there, as vm_map_find searches upward from
it; this also applies to sceKernelMapDirectMemory and
sceKernelMapDirectMemory2, and the caller's address is written only once
the map succeeds. MAP_ALIGNED_SUPER aligns only maps of 2 MiB or more
to 2 MiB, as pmap_align_superpage does. MAP_HASSEMAPHORE, MAP_NOSYNC, MAP_NOCORE and
MAP_PREFAULT_READ are accepted. All of these failed with EOPNOTSUPP.
Other flags still fail with EOPNOTSUPP and are recorded as debt;
FreeBSD ignores 0x20 and 0x40 and refuses the rest of its unknown bits
with EINVAL. Source: FreeBSD 11.4 sys/vm/vm_mmap.c kern_mmap_fpcheck and
vm_mmap_object, sys/vm/vm_map.c vm_map_find, sys/sys/mman.h.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 05:13:57 +10:00
brajankwandClaude Opus 5.5 8f161a08b2 fix(libkernel): report is_committed from sceKernelVirtualQuery only for direct memory, as a PS5 does
sceKernelVirtualQuery set is_committed for every registered or
host-queried range. A PS5 payload (firmware 13.590.001) reports it only
for direct memory, and 0 for flexible memory whether touched or not,
stacks, images and reservations. It is now set only for a direct
mapping.

mincore was the only reader of is_committed and used it to tell a
mapping from a reservation, so it now asks GuestReservation directly
and still reports every mapped page as resident and a reserved one as
not.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 12:20:05 +01:00
Dean 11c9e7764e Merge pull request #24706 from olegon85/fix/libkernel-posix-mlock-locks-mapped-pages
fix(libkernel): posix mlock and munlock lock mapped pages like the console
2026-11-26 00:16:07 +13:00
RTGG d7e34c81a8 refactor(libkernel): drop redundant errno save around GuestCopyOut in MemoryPoolExport 2026-11-25 02:40:54 +01:00
Kikoarl a8953d6561 fix(libkernel): validate guest destination pointers upfront in BatchMap2 and StopUnloadModule 2026-11-24 20:01:14 +01:00
LeandroLP23andClaude Opus 5.5 650df957b4 feat(libc): trap guest reads for the write watch on Windows
Port the Linux read traps of GuestWriteWatch to Windows: a trapped
range is made PAGE_NOACCESS and a vectored exception handler added with
the first resolver runs the resolver on its own thread. Traps are set
only on read-write resident guest arena pages that WindowsMappings does
not protect itself. The arena's commit, reset and mappings and
libkernel's mprotect resolve traps over their range first, and an alias
of a resident run drops the traps in it.

No library sets traps on Windows yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 14:11:42 +01:00
Paweł SkowrońskiandDean cf1d22919f perf(agc): trap CPU reads of label readbacks on Linux instead of storing them (#19054)
* perf(agc): trap CPU reads of label readbacks on Linux instead of storing them
* fix(libc): carry the GPU mutex bypass and trapped ranges to the Linux read traps
* perf(agc): scan pending images once per label and trap only host-imported ones on Linux
* perf(agc): skip trapped images at a label while the pending set and the traps are unchanged
* fix(agc): resolve read traps on Linux before a host pointer import pins its pages
* fix(agc): keep label read traps off host pointer imports except on NVIDIA's proprietary driver
* test(agc): check that a range is not trappable once its import is gone with a host-importing context
* test(agc): check that GPU submissions survive a held read trap over the imports label traps are set on
* test(agc): run the read trap import submit test on a CPU device and report skips as device limitations
* fix(agc): let the draw committer read a label-trapped page instead of waiting for its resolver
* fix(agc): store what a label trap's resolver can before giving the blocked draw committer its held ranges unstored
* fix(agc): leave a read-trapped range unimported instead of resolving its traps under the write tracker lock
* test(libc): check that registering a new mapping over a read trap keeps the mapping's protection
* fix(libc): include <atomic> for the Windows read trap generation

Co-authored-by: Dean <158058829+oneandonlydean@users.noreply.github.com>
2026-11-24 23:32:57 +13:00
LeandroLP23andClaude Opus 5.5 2395d879be refactor(libkernel): drop more errno saves around guest copies
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 13:50:03 +01:00
adam25136andClaude Opus 5.5 53d4b0cee2 fix(libkernel): register unbacked AMM PRT pages without the GPU bits
Planet Zoo (PPSA18026) marks a 32 GiB range at 0xd000000000 as PRT with
the AMM, so its unbacked pages are zero pages with GPU read protection
(0x10). Since the AGC driver takes GPU-only memory into its leases
(#23770), every address-based build took that range in. It could neither
import it (over the host import budget) nor mirror it, so it counted it
as a copy and aborted: "an address-based build copies 32761 MiB of 3
registered ranges, past 64 MiB (APS5_ADDRESS_COPY_MAX_MIB)".

Zero pages now keep their GPU read protection (sceKernelVirtualQuery is
unchanged) but are registered without the GPU bits, so the driver leaves
them out of its leases and host imports, as it left all GPU-only memory
before #23770. Pages the AMM maps into the range keep their protection's
bits. Outside Windows, DoMapZero now passes the zero flag to
MapAnonymous instead of calling DoMapAnon; the mapping itself is
unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 02:25:44 +02:00
xXPBSXx e0ea5c32bf fix(kernel): sceKernelMtypeprotect refuses memory types 10, 127 and -1 and undefined protection bits (#19183)
* test(kernel): pin sceKernelMtypeprotect results for memory types 10, 127 and -1 and for protection 0x400
* fix(kernel): refuse memory types 10, 127 and -1 and protection 0x400 in sceKernelMtypeprotect
* docs(debt): state the PS5 results of sceKernelMtypeprotect for memory types and protection bits
2026-11-22 05:49:37 +13:00
RTGG fd45dbf835 fix(libkernel): preserve JIT shared memory entry on self-duplication 2026-11-21 16:50:38 +01:00
Oleg d97a2edee7 fix(libkernel): sceKernelGetResidentFmemCount answers ESRCH for negative pids on console 2026-11-21 16:17:11 +05:00
Dean 6ad7f9ef50 Merge pull request #17718 from xXPBSXx/fix/kernel-system-flexible-name-checks-v2
fix(libkernel): sceKernelMapNamedSystemFlexibleMemory maps and then rejects a name of 32 characters or a null name
2026-11-21 22:19:06 +13:00
Dean 6325df5b5b Merge pull request #24073 from AltewamaPrime/fix/mtypeprotect-undefined-bits
fix(libkernel): refuse undefined bits in the batch type-protect
2026-11-21 21:26:26 +13:00
Felipe Maitan ca2c49e64e feat(libkernel): map app0.zar archive-backed files (#11625)
* feat(libkernel): map archive-backed app0 files
* fix(libkernel): isolate archive mapping backings
* fix(libkernel): bound archive mapping backing to requested windows
* docs(libc): clarify archive mapping storage limits
* fix(libkernel): publish mmap errors after exception cleanup
* docs(libc): clarify archive-only path restrictions
* fix(libkernel): preserve archive mapping errors and protection checks
* fix(libc): give the archive writer sole backing cleanup ownership
2026-11-21 15:06:58 +13:00
Axel e4485b9b1c fix(libkernel): round munmap ranges to guest pages 2026-11-21 01:45:54 +01:00
Oleg 36096e40a7 fix(libkernel): posix mlock and munlock lock mapped pages like the console 2026-11-21 05:13:05 +05:00
JJenkx 6244c2ed82 perf(libkernel): back flexible memory with a memfd on Linux (#23613)
* perf(libkernel): back flexible memory with a memfd on Linux
* docs(debt): describe the flexible memory backing on Linux
* fix(libkernel): keep flexible memory anonymous and host-imported when its memfd path fails
* fix(libkernel): reject empty flexible backing queries and keep remainders when a hole punch fails
* docs(debt): shorten the flexible memory backing entry and note a failed hole punch
* fix(agc): discard a failed dma-buf import before its host-pointer retry
2026-11-21 12:20:33 +13:00
Dominik Fuchs 8818bc6b4f fix(libkernel): copy the memory map address slots through guest copies
sceKernelMapDirectMemory, sceKernelMapDirectMemory2,
sceKernelMapFlexibleMemory, sceKernelMapNamedFlexibleMemory and
sceKernelReserveVirtualRange passed the guest address slot straight to
DoMapDirect, _mapFlexible and DoReserveVirtual, which read the hint and
stored the mapped address through it, and read it again for
_releaseFlexible and the range name. An unmapped or read-only slot
crashed the host.

Each export now reads the hint into a local with
GuestCopyIn_nid_no_patch and checks the slot with
GuestWritable_nid_no_patch before mapping, so an unusable slot returns
SCE_KERNEL_ERROR_EFAULT and maps nothing, maps through the local, and
stores the result with one GuestCopyOut_nid_no_patch. errno is kept
across the copies, as the batch map code in the same file does. A null
slot still throws, and results for usable slots are unchanged.
2026-11-20 18:11:05 +01:00
Altewama 751c6fbf04 fix(libkernel): refuse undefined bits in the batch type-protect
A batch map type-protect entry passed its protection to DoMtypeprotect,
whose protection validation throws std::invalid_argument for bits outside
0x3F7, so an undefined bit ended the title instead of returning an error.
The entry now answers SCE_KERNEL_ERROR_EINVAL (0x80020016) through the
existing UndefinedProtection() helper, before its range is looked at, and
leaves the range untouched.

The single sceKernelMtypeprotect change and the batch protect masking are
left to #19183 and #22051.
2026-11-20 17:31:04 +01:00
Dean 5b4562db72 Merge pull request #23866 from mariushub/perf/libkernel-direct-memory-alloc-scan
perf(libkernel): skip a used run at once when allocating direct memory
2026-11-20 23:04:27 +13:00
Dean ed249c4ad1 Merge pull request #23971 from HighDaddyLudo/fix/windows-private-mmap-flexible-budget
fix(libkernel): release flexible memory charges after fixed private f…
2026-11-20 20:14:18 +13:00
xXPBSXxandClaude Sonnet 5.5 16cae035c8 fix(libkernel): sceKernelMapNamedSystemFlexibleMemory maps and then rejects a null or 32 character name
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-20 00:33:36 +01:00
Ludovic Adler e1fd391f25 fix(libkernel): release flexible memory charges after fixed private file mappings 2026-11-19 18:33:04 -05:00
Marius 1a5c95da66 perf(libkernel): skip a used run at once when allocating direct memory
The pool's first-fit search stepped through allocated memory by at most
the requested length and checked the release claims, under the global
direct-memory lock, at every step. A title that allocates small blocks
above a large allocated prefix walked the whole prefix on every call:
SuperTuxKart (PPSA69421) allocates about 1000 64 KiB blocks per second
above 1.4 GiB, at about 22,000 steps and lock acquisitions each.

The search now checks the page map first and moves past the whole used
run in one step, never past the search end, and checks the release
claims only for a window whose pages are free. Both checks still have to
pass, and only windows that overlap a used page or a claim are skipped,
so the first fitting address is unchanged.
2026-11-19 20:41:00 +01:00
birdmarty 87b43470da fix(kernel,agc): honor GPU-only memory protection bits 2026-11-19 17:27:47 +02:00
RTGG 46c2696a4c fix(libkernel): track committed ranges accurately in memory pool block stats 2026-11-18 22:47:39 +01:00
xXPBSXx 395ccca7af fix(libkernel): madvise rejects an address below the page size
On a PS5 payload process (firmware 11.60) madvise(0x1000), (0x2000), (0x3000)
and (0x3fff) fail with EINVAL and (0x4000), (0x4001) return 0, whatever the
length. The address is now checked against the same minimum as posix_madvise
(PS5_PAGE_SIZE, 0x4000); the upper bound already matched.
2026-11-18 12:44:42 +01:00
brajankwandClaude Opus 5.5 535808524b fix(libkernel): drop undefined protection bits in sceKernelMemoryPoolBatch's protect operation, as sceKernelMprotect does
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 12:19:35 +01:00
Dean f8d3890240 Merge pull request #19699 from roboterspinne/fix/libkernel-memory-pool-expand-unwritable-output
fix(libkernel): release the pool expansion and return EFAULT when sceKernelMemoryPoolExpand cannot write its output
2026-11-17 11:06:34 +13:00
aasishdairel aa04cdc4c3 fix(libkernel): copy batch map entries through guest copies
sceKernelBatchMap2 and sceKernelMemoryPoolBatch read each entry of the
guest batch array through the guest pointer and passed &entry.start of
that array into DoMapDirect and _mapFlexible, which read the hint and
wrote the result pointer through the raw guest memory. An unreadable
entries array or unwritable result slot faulted the host instead of
returning an error.

Each entry is now read with GuestCopyIn_nid_no_patch into a local, the
map operations run against the local, and the start a map operation
produced is stored back to the entry with GuestCopyOut_nid_no_patch.
A copy failure returns SCE_KERNEL_ERROR_EFAULT and stops the batch;
num_entries_out keeps reporting the number of entries whose operation
ran and whose start was stored.
2026-11-17 00:54:42 +05:30
milescovielloandClaude Opus 5.5 eb715598d7 fix(libkernel): copy virtual range names through a checked guest copy
sceKernelSetVirtualRangeName and the named-mapping calls read the name in
place with strnlen, so an unreadable name crashed the host. The name is now
copied through CopyGuestString_nid_no_patch, page by page and stopping at
the terminator. An unreadable name returns EFAULT from
sceKernelSetVirtualRangeName, as a null one does, leaves a named mapping
unnamed, and throws in sceKernelMapNamedSystemFlexibleMemory, as a null
name does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 07:10:10 -05:00
Dean e739b698c1 Merge pull request #20045 from pushkarreddyy/fix/libkernel-memory-pool-batch-reserve-probing
fix(libkernel): safely probe output pointers in memory pool batch and reserve
2026-11-16 21:37:59 +13:00