Commit Graph

60 Commits

Author SHA1 Message Date
Dean 698254f048
Merge pull request #2236 from mrk1987/fix/release-direct-memory-unmaps-views
fix(libkernel): unmap direct memory views when the memory is released
2026-10-10 17:45:32 +13:00
Dean b860fa0c9f
Merge pull request #1929 from MarcZX100/fix/virtualquery-partial-unmap
fix(libkernel): query non-readable live mappings
2026-10-10 17:42:50 +13:00
Dean 6dbc921d90
Merge pull request #1633 from babyhuey/feat/libkernel-madvise
feat(libkernel): implement madvise
2026-10-10 17:40:10 +13:00
Hannah Lyons d7e52cb295 feat(libkernel): implement madvise 2026-10-09 21:22:44 -04:00
Saranxzi e06c459534 test(libkernel): cover virtual query after partial unmap
Carry over the direct mmap regression from PR #2267. The live-extent implementation is already present in the preceding commits.
2026-10-09 22:11:35 +00:00
MarcZX100 f7de40f9bb fix(libkernel): query non-readable live guest ranges 2026-10-09 22:10:33 +00:00
Praveen Kumar 6f62ec6a6f fix(libkernel): query current guest mapping extents
Use the current registered range after protection splits and partial unmaps, including FIND_NEXT lookups. Add a regression covering extents, protection and surviving contents.

AI-assisted: yes
2026-10-09 22:10:32 +00:00
Andreas 24474e3d28 fix(libkernel): unmap direct memory views when the memory is released
Releasing direct memory left the virtual ranges that mapped it registered,
so sceKernelVirtualQuery reported them as flexible memory at offset 0 and
titles walking a range with FIND_NEXT released physical page 0.

Collect every view of the released pages before freeing them and unmap
them through UnmapRegistered, as shadPS4's MemoryManager::Free does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 14:42:17 +02:00
Scott Schuster a43f1411c4 fix(libc): align guest heap allocations to 32 bytes
Clang's PS4 and PS5 targets set the default new alignment and the suitable
alignment to 32 bytes, so PS5 code may store to a fresh malloc or operator
new result with 32-byte-aligned AVX instructions. The guest heap aligned
blocks to 16 bytes, and the arena's 32-byte classes put every small block
16 bytes past a 32-byte boundary after its header, so such a store faulted.
The minimum alignment is now 32 bytes; the padding still assumes only the
16-byte alignment the raw blocks guarantee.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 09:42:06 -05:00
Dean 8763483811
Merge pull request #1370 from gjonn/fix/kernel-fixed-map-replaces-overlap
fix(libkernel): replace partly overlapped allocations with a fixed mapping
2026-10-08 22:35:53 +13:00
Adrià Franch 53a31b512e test(guest_memory): pin mprotect on an unmapped and a wrapping range
Both return -1/EINVAL: FreeBSD kern_mprotect (sys/vm/vm_mmap.c) maps only
PROTECTION_FAILURE, RESOURCE_SHORTAGE and OUT_OF_BOUNDS to their own errno, so
KERN_INVALID_ADDRESS falls to EINVAL.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-10-08 08:24:12 +02:00
kjhq 35ae8742a9 feat(libkernel): implement POSIX mprotect
mprotect changes the protection of guest memory through the same path
as sceKernelMprotect and reports failures through errno: EINVAL for a
null or overflowing range or a range the allocation tracker rejects,
ENOMEM when allocation fails. A zero length succeeds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 08:24:06 +02:00
Adrià 311c0493bd
Merge pull request #957 from JAB-dev/feat/kernel-flexible-internal-hint
feat(libkernel): accept flag 0x8000 in sceKernelMapNamedFlexibleMemoryInternal
2026-10-08 07:42:56 +02:00
Gjon Gojcevic 5cf013a299 fix(libkernel): replace partly overlapped allocations with a fixed mapping
A fixed mapping without no-overwrite unmaps the registered pieces it overlaps before mapping, as it already did when the range lay inside registered allocations.
2026-10-07 20:31:08 -04:00
Adrià Franch c572650575 test(libkernel): cover a sub-page shared backing offset and a gap after a direct mapping
Co-Authored-By: Claude <noreply@anthropic.com>
2026-10-07 23:16:22 +02:00
alfalfa-star 815d274736 feat(agc): import shared direct memory through udmabuf on Linux
On Linux, direct memory is a memfd mapped MAP_SHARED. amdgpu accepts only
private anonymous memory for a host pointer import (libdrm sets
AMDGPU_GEM_USERPTR_ANONONLY), so every import of direct memory failed with
VK_ERROR_INVALID_EXTERNAL_HANDLE and its ranges were copied.

When a host pointer import fails, the range's memfd slice is turned into a
dma-buf through /dev/udmabuf and imported with VK_EXT_external_memory_dma_buf.
The direct memory backing is sealed against shrinking and growing, as
udmabuf requires. libkernel reports the backing of a guest range through
GuestArenaSharedBacking. Without /dev/udmabuf, or past its size limit, the
range is copied as before. APS5_TRACE_HOST_IMPORT now prints the mappings
behind a failed import on Linux too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 23:09:16 +02:00
Adrià 832247b0a0
Merge pull request #283 from SP4C3B4R-8/fix/fiber-windows-stack
fix(libSceFiber): pin fiber contexts writable under write tracking on Windows
2026-10-07 22:25:25 +02:00
SP4C3B4R-8 78cb1598ce test(libc): pinned shared pages stay writable and are collected as written
Also unpin the previous context when a fiber object is initialised again
without being finalised.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 21:57:20 +02:00
Adrià 3f7fe285a0
Merge pull request #900 from alfalfa-star/feat/libkernel-acp-protection
feat(libkernel): accept the audio coprocessor memory protection bits
2026-10-07 18:26:06 +02:00
Pouare514 c25ff91a65 fix(libkernel): accept GPU coherency prot bits for host mapping 2026-10-07 17:29:28 +02:00
alfalfa-star b567bb8eed feat(libkernel): accept the audio coprocessor memory protection bits
A title maps direct memory with protection 0x3f2, which adds bits
0x100 and 0x200 to the CPU, GPU and AMPR bits, and the mapping threw.
They are the audio coprocessor (ACP) read and write bits, as named in
the KytyPS5 and etaHEN headers. The coprocessor work runs on the host
CPU, so they map to host read and read/write access like the GPU bits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 07:09:42 +02:00
JAB-dev 2dc53674f5 Merge branch 'main' of https://github.com/boykopovar/AnyPS5 into feat/kernel-flexible-internal-hint 2026-10-07 07:09:08 +02:00
Dean 0c952fe574
Merge pull request #994 from CnRJay/fix/map-no-overwrite-enomem
fix(libkernel): refuse fixed no-overwrite mappings over live memory with ENOMEM
2026-10-07 15:31:12 +13:00
Dean f6f47bf1de
Merge pull request #880 from adriadam10/feat/kernel-mtypeprotect-type
feat(kernel): apply the memory type in sceKernelMtypeprotect
2026-10-07 15:28:25 +13:00
Chad e9c8664d43 fix(libkernel): refuse fixed no-overwrite mappings over live memory with ENOMEM
MAP_FIXED | MAP_NO_OVERWRITE over a range that already holds an
allocation fails with ENOMEM and leaves the mapping in place, as in
fpPS4's TVirtualManager.check_fixed. UFC 6 (PPSA23566) relies on it to
probe for a free address and aborted on the throw.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 17:04:06 -05:00
CnR 7e3dcbc27e
feat(libkernel): implement sceKernelReleaseFlexibleMemory (#952)
* feat(libkernel): implement sceKernelReleaseFlexibleMemory

Unmaps the range through sceKernelMunmap, which returns its pages to
the flexible memory budget, as fpPS4 and prosper do.

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

* test(libkernel): keep the flexible memory release check apart from the batch map checks

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 10:20:07 +13:00
JAB-dev 2093e74661 feat(libkernel): accept flag 0x8000 in sceKernelMapNamedFlexibleMemoryInternal
The SDK 9 libc.prx heap maps its arenas with flag 0x8000, which threw as
an unsupported flag. The flag is ignored for this function, as sharpemu
does; other unknown flags still throw.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 22:21:25 +02:00
Adrià Franch 109f120595 feat(kernel): apply the memory type in sceKernelMtypeprotect
Co-Authored-By: Claude <noreply@anthropic.com>
2026-10-06 14:32:47 +02:00
Adrià Franch ca6557aed1 feat(kernel): reject invalid sceKernelBatchMap2 entries with EINVAL
Co-Authored-By: Claude <noreply@anthropic.com>
2026-10-06 14:27:48 +02:00
Dean 5d6ee4669a
Merge pull request #808 from adriadam10/feat/kernel-get-direct-memory-type
feat(libkernel): implement sceKernelGetDirectMemoryType
2026-10-06 22:32:51 +13:00
Dean 229b1287b4
Merge pull request #721 from merwie/feat/kernel-checked-release-direct-memory
feat(libkernel): implement sceKernelCheckedReleaseDirectMemory
2026-10-06 22:28:18 +13:00
Dean 1b6a7bae64
Merge pull request #700 from merwie/fix/kernel-virtual-query-reserved
fix(libkernel): report reserved virtual ranges in sceKernelVirtualQuery
2026-10-06 22:27:36 +13:00
Adrià Franch 6d2713cbdd feat(libkernel): implement sceKernelGetDirectMemoryType
Co-Authored-By: Claude <noreply@anthropic.com>
2026-10-06 07:44:18 +02:00
Dean cdb2707ad2
Merge pull request #686 from Pouare514/fix/direct-memory-release-clears-mappings
fix(libkernel): drop direct mappings when physical backing is released
2026-10-06 13:28:21 +13:00
Merijn 65e5c9932c feat(libkernel): implement sceKernelCheckedReleaseDirectMemory
Release direct memory only when the whole range is allocated: a misaligned
start or length returns EINVAL, a zero length succeeds, and a range that
leaves direct memory or covers an unallocated page returns ENOENT without
releasing anything, as in shadPS4. The check and the release run under
the pool lock.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 19:47:51 +02:00
Merijn 8e96e48fbd fix(libkernel): report reserved virtual ranges in sceKernelVirtualQuery
A range reserved with sceKernelReserveVirtualRange is registered as not
readable, and sceKernelVirtualQuery only searched readable registrations,
so a query inside a reservation fell back to the host and returned EACCES.
Reserved ranges are now tracked until a direct or flexible mapping or an
unmap covers them, and a query inside one succeeds with the reserved piece
as its extent, protection 0 and is_committed clear. PPSA12544's allocator
queries a reservation before committing it and treated the error as a
failed commit, then wrote to the inaccessible range.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 18:56:15 +02:00
Celegans12 5085746fce fix(libc): reach the application map area end with the guest arena
On Windows the guest arena ended at 0x72_0000_0000: #231 kept its
448 GiB size after #153 had moved its start down to 0x2_0000_0000.
Titles map fixed addresses up to the application map area end,
0xFC_0000_0000 (SCE_KERNEL_APP_MAP_AREA_END_ADDR on the PS4), and a
direct memory mapping above the old end threw "shared mapping outside
the guest arena".

The arena is now reserved up to 0xFC_0000_0000. The out-of-arena
errors name the address and length, and a fixed mapping over a used
arena range says whether it hit a host region. guest_memory maps
direct memory at the last two pages below the end, reads it through
an alias and checks that a mapping at the end is refused.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 17:51:26 +02:00
Pouare514 7fea9e00b6 fix(libkernel): drop direct mappings when physical backing is released
ForgetDirectMemory erased the physical pages but left g_directMappings entries pointing at the dead backing, so sceKernelVirtualQuery kept reporting is_direct with a stale physical offset. Erase (and split, on the phys axis) the affected mapping tracking on release; mapped views are untouched, so no new faults are introduced.
2026-10-05 17:22:41 +02:00
Dean 1a7323ecfc
Merge pull request #549 from Pouare514/fix/reserve-virtual-idempotent
fix(libkernel): idempotent fixed virtual reservation over registered range
2026-10-05 14:20:55 +13:00
DotDebian 774b34986c
feat(libkernel): implement sceKernelMlock
Lock the guest pages of the range with VirtualLock or mlock, following FreeBSD mlock(2): the range is widened to guest pages, a zero length succeeds, a wrapping range is EINVAL and a range that is not mapped and accessible is ENOMEM. The Windows working set limits and the Linux RLIMIT_MEMLOCK soft limit are raised when the lock needs it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 00:25:56 +00:00
Pouare514 9e0152f18d fix(libkernel): replace mappings on fixed reserve over registered range 2026-10-05 01:21:44 +02:00
Pouare514 89cd75e15f fix(libkernel): idempotent fixed virtual reservation over registered range 2026-10-04 21:02:15 +02:00
Pouare514 497a772c5d fix(libkernel): hand arena reservations to NoOverwrite mappings 2026-10-04 16:46:39 +02:00
boykopovar 74bdce6f04
Merge pull request #232 from MichonGoddijn231849/fix/guest-read-destination
fix(libkernel): read, pread, AIO and APR write into guest memory as host writes
2026-10-02 22:19:46 +03:00
boykopovar a4157bbeee
Merge pull request #355 from DotDebian/feat/map-named-flexible-memory-internal
feat(libkernel): implement sceKernelMapNamedFlexibleMemoryInternal
2026-10-02 16:45:58 +03:00
DotDebian 74fcea27f8 feat(libkernel): implement sceKernelMapNamedFlexibleMemoryInternal
libkernel did not export sceKernelMapNamedFlexibleMemoryInternal, which
the libc bundled with SDK 9 titles imports. It now forwards to
sceKernelMapNamedFlexibleMemory: the mapping counts against the flexible
budget, gets the range name and is released by sceKernelMunmap. Older
libc builds call the public function at the same sites with the same
arguments and result handling.

The known callers pass flag 0x8000, whose meaning is unknown. It is
still rejected as an unsupported mapping flag and is recorded in
TechnicalDebt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-02 14:08:58 +02:00
SP4C3B4R-8 4099ffb7d3 feat(libkernel): accept MAP_NO_OVERWRITE fixed mappings on Windows
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Bn7CrhG7pTPR6DT13tN6Me
2026-10-01 23:44:31 +02:00
SP4C3B4R-8 3fc3b993da feat(libkernel): honour non-fixed mapping address hints on Windows
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Bn7CrhG7pTPR6DT13tN6Me
2026-10-01 23:44:30 +02:00
Michon 676bbea348 fix(libkernel): read, pread, AIO and APR write into guest memory as host writes
A file read into guest memory is a host write: before the I/O it pins the shared pages it
covers, which reopens any page armed for write tracking and keeps write tracking from arming
it again until the read ends, when the pages count as written. A destination the guest cannot
write fails with EFAULT before any I/O; read and pread throw as for any failed read, AIO
reports SCE_KERNEL_ERROR_EFAULT, and APR throws. APR also throws when a read ends before the
requested size.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-01 18:56:36 +02:00
boykopovar 33e11c7ea2
Merge pull request #203 from oneandonlydean/fix/libkernel-direct-memory-memfd
fix(libkernel): back direct memory with a memfd on Linux
2026-10-01 11:31:43 +03:00