Commit Graph

233 Commits

Author SHA1 Message Date
Dean 6f3d485fca
Merge pull request #723 from alfalfa-star/feat/libkernel-module-info-from-addr
feat(libkernel): implement sceKernelGetModuleInfoFromAddr
2026-10-06 22:29:00 +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
raghav314 670ffb9da3 feat(libkernel): implement sceKernelGetAvailableCpumask
Returns the CPU mask threads get by default (DEFAULT_THREAD_AFFINITY,
0x1FFF), the value itself rather than an error code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 09:41:52 +05:30
Dean 0db5bfcf36
Merge pull request #792 from CnRJay/feat/libkernel-sendmsg-recvmsg
feat(libkernel): implement sendmsg and recvmsg
2026-10-06 16:31:19 +13:00
Nicolas Abosch 7789c0a57b feat(libs): implement homebrew libc and kernel runtime exports 2026-10-05 22:40:16 -03:00
Chad 03afdb55bb Merge remote-tracking branch 'upstream/main' into feat/libkernel-sendmsg-recvmsg
# Conflicts:
#	core/libs/prx/libkernel/Unimplemented.cpp
2026-10-05 20:23:13 -05:00
Dean 6136e52110
Merge pull request #785 from NahuelGenchi/feat/kernel-futimes
feat(libkernel): implement futimes
2026-10-06 14:15:34 +13:00
Dean aa22e43932
Merge pull request #784 from NahuelGenchi/feat/kernel-fchmod
feat(libkernel): implement fchmod and sceKernelFchmod
2026-10-06 14:14:52 +13:00
Chad 77550ab731 feat(libkernel): implement sendmsg and recvmsg
Both take the FreeBSD msghdr (48 bytes, iovecs of a pointer and a 64-bit
length) and run on the host sockets: sendmsg gathers the iovecs and sends
through sendto, recvmsg receives into one buffer and scatters it. A
datagram longer than the iovecs is cut and reported with MSG_TRUNC, also
on Windows where recvfrom fails with WSAEMSGSIZE. More than 1024 iovecs
fail with EMSGSIZE. No ancillary data is ever received, so recvmsg
clears msg_controllen; sending control data throws.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 20:10:13 -05: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
Dean 3e9bcee7b9
Merge pull request #756 from CnRJay/feat/amm-prt
feat(libs): implement the AMM PRT commands
2026-10-06 13:17:24 +13:00
Dean 5cc58621a9
Merge pull request #749 from CnRJay/feat/amm-remap-protect
feat(libs): implement the AMM remap, multimap and protection changes
2026-10-06 13:17:14 +13:00
Dean ece9990d89
Merge pull request #748 from CnRJay/feat/amm-core
feat(libs): implement the AMM map, map direct and unmap commands and the APR map region
2026-10-06 13:16:31 +13:00
Dean 633459b09c
Merge pull request #672 from NahuelGenchi/fix/linux-guest-export-namespace
fix(relinker): keep host prx references out of guest modules on Linux
2026-10-06 13:15:49 +13:00
Nahuel Genchi ec17b9811c feat(libkernel): implement futimes 2026-10-05 20:47:34 -03:00
Nahuel Genchi eded1e010f feat(libkernel): implement fchmod and sceKernelFchmod 2026-10-05 20:46:34 -03:00
Dean 7de111f98a
Merge pull request #773 from Raghav314/feat/kernel-sync-on-address-wait8-16
feat(libkernel): implement sceKernelSyncOnAddressWait8 and sceKernelSyncOnAddressWait16
2026-10-06 12:45:18 +13:00
Dean e0f1382bb7
Merge pull request #777 from adriadam10/feat/kernel-is-signal-return
feat(libkernel): implement _is_signal_return
2026-10-06 12:45:07 +13:00
Dean c8c4621a17
Merge pull request #747 from CnRJay/feat/apr-gather-scatter
feat(libs): implement the APR gather and scatter reads
2026-10-06 12:25:06 +13:00
Dean b2e192cfa3
Merge pull request #717 from merwie/feat/kernel-dlopen-relinked-guest-module
feat(libkernel): load the relinked module for a guest module path
2026-10-06 12:18:55 +13:00
Dean 90f20b393d
Merge pull request #699 from merwie/feat/libs-ppsa12544-exports
feat(libs): add exports imported by PPSA12544
2026-10-06 12:18:11 +13:00
Dean 0c4b80dc61
Merge pull request #761 from merwie/fix/pthread-adopted-thread-stack
fix(libkernel): report the stack of adopted threads
2026-10-06 12:16:47 +13:00
Dean 106ebfff68
Merge pull request #710 from merwie/fix/param-json-default-language
fix(libkernel): read defaultLanguage from localizedParameters
2026-10-06 12:16:36 +13:00
Dean 4519ae61cc
Merge pull request #743 from Blizzeq/fix/linux-socket-errno
fix(libkernel): report EINVAL, EACCES, ENOBUFS, ETIMEDOUT and EINTR from Linux sockets
2026-10-06 12:14:58 +13:00
Adrià Franch 3a81905dd3 feat(libkernel): implement _is_signal_return
Guest signal handlers are called from a host dispatcher, so no guest PC is
a signal trampoline: return 0 for every address, as KytyPS5 and prosper do.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-10-06 01:09:00 +02:00
raghav314 ce6d94793c feat(libkernel): implement sceKernelSyncOnAddressWait8 and sceKernelSyncOnAddressWait16
Wait8 and Wait16 compare the 1- or 2-byte value at the address with the
comparand and share the waiter queue of the other sizes.
sceKernelSyncOnAddressWake accepts any non-null address: libc's
__std_atomic_notify_one/all pass the atomic's own address, which for 8- and
16-bit atomics need not be 4-byte aligned.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 04:30:12 +05:30
Nahuel Genchi 5fab03e4e5 fix(relinker): keep host prx references out of guest modules on Linux
On Linux every module resolves its references through one global scope,
and the guest modules are listed ahead of the host prx. When a title
bundles its own libc.prx, the host libc and the other host prx bound
their references to their own NIDs to the guest libc, so the host libc
built its standard streams on top of the guest _Stdout.

The exports of guest modules, and the guest and executable imports that
a guest module satisfies, now carry a #guest suffix. The title's imports
still reach the guest modules first, and a host prx only sees host
definitions, as on Windows. sceKernelDlsym also looks for the suffixed
name.
2026-10-05 19:58:39 -03:00
Merijn fd37c58391 fix(libkernel): report the stack of adopted threads
scePthreadAttrGet reported a null stack address and a zero size for an
adopted thread (the main thread), and for every guest thread on Linux,
where the stack range was never recorded. A garbage collector that scans
thread stacks through scePthreadAttrGetstackaddr and
scePthreadAttrGetstacksize (Unity IL2CPP in PPSA12544) then skipped the
main thread's stack and freed objects it still referenced. The range now
comes from the host thread: GetCurrentThreadStackLimits on Windows,
pthread_getattr_np on Linux.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 23:00:41 +02:00
Merijn 9489b851ae fix(libkernel): read defaultLanguage from localizedParameters
A PS5 param.json keeps defaultLanguage inside localizedParameters, next to
the language entries. The parser looked for it at the root only, then fell
back to en-US and to the first member, which is the defaultLanguage string
when no en-US entry exists (PPSA12544 has only en-GB), and threw
"expected JSON object". defaultLanguage is now read from
localizedParameters first, and the fallback takes the first language
object.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 22:48:06 +02:00
Chad cf3d0f6fc7 feat(libs): implement the AMM PRT commands
sceAmprAmmCommandBufferMapAsPrt, AllocatePaForPrt, RemapIntoPrt and
UnmapToPrt, with the MapAsPrt and AllocatePaForPrt measures. Signatures,
checks and their order follow ampr_emu.

The executor keeps the PRT pages of the AMM ranges. Unbacked PRT pages
are zero-filled with GPU read access; AllocatePaForPrt backs each
unbacked page with a pool page and changes the type and protection of
backed ones; RemapIntoPrt moves a mapped range into a PRT range; and
UnmapToPrt returns the pages to the pool and zero-fills them again. A
plain map, unmap or remap over a PRT range ends it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 15:45:28 -05:00
Chad 166ea44993 feat(libs): implement the AMM remap, multimap and protection changes
libSceAmpr gains sceAmprAmmCommandBufferRemap, MultiMap, ModifyProtect
and ModifyMtypeProtect with their GPU mask forms and the eight measure
functions. Signatures and the protection and mask checks follow ampr_emu.

The executor keeps a page table of the AMM ranges: each page's physical
offset, protection, memory type and whether it came from the pool. A
remap moves the pages of a fully mapped range and leaves the old range
reserved; a multimap maps the same pages again; a pool page returns to
the pool only when its last mapping goes. A protection change applies
the masked bits page by page.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 15:36:24 -05:00
Chad c16e59bfd5 feat(libs): implement the AMM map, map direct and unmap commands and the APR map region
libSceAmpr gains the AMM command buffer (constructor, destructor, map,
map direct and unmap, with their GPU mask forms and measures),
sceAmprAmmGiveDirectMemory, sceAmprAmmGetVirtualAddressRanges, the three
submit forms and sceAmprAmmWaitCommandBufferCompletion. The APR
MapBegin, MapDirectBegin and MapEnd commands and their measures record
the same map commands.

The libkernel executor now maps: a plain map takes pages from the direct
memory given to the mapper with usage 1, a direct map uses the given
offset, and an unmap returns the pages to that pool and leaves the range
reserved. The AMM ranges are reserved in the guest arena on first use.
Commands are walked by the buffer's byte offset so an AMM submission can
run raw command memory.

Signatures, the protection mask and the APR map rules follow ampr_emu;
the mapper model follows PS5PCEM. While an APR map region is open, a
second begin and every completion write return EPERM.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 15:29:33 -05:00
Chad 4b336335a8 feat(libs): implement the APR gather and scatter reads
sceAmprAprCommandBufferReadFileGather, ReadFileScatter,
ReadFileGatherScatter and ResetGatherScatterState, with their measure
functions. Signatures, argument checks and the read cursor follow
ampr_emu: each read leaves the file, the next offset and the next
destination; a gather reads at a new offset into the next destination, a
scatter continues in the file into a new destination, and a
gather-scatter takes both. Recording one needs a file read since the last
reset, tracked in the command buffer object next to its type.

sceAmprAprCommandBufferReadFile now applies the same length, offset and
destination checks and rejects a null command buffer instead of
dereferencing it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 15:12:34 -05:00
Chad 636fb5edae feat(libs): implement the AMPR 04_00 counter commands and the construct helpers
sceAmprCommandBufferWaitOnCounter_04_00 and WriteCounter_04_00 take the
counter access size and offset, the wait mask and the write operation,
with their measure functions; ConstructNop records a nop with an optional
leading word and a payload of up to 60 bytes, and ConstructMarker records
the set, push and pop markers by type. Signatures and checks follow
ampr_emu.

The executor now reads and writes counters by access: the 8-byte access
of counter n spans n and n + 1, the 2- and 1-byte accesses a half or a
byte of the counter. Waits compare at the access width, so the signed and
wrapped compares see the field's own sign bit, and the atomic writes wrap
within the field. The legacy counter commands record a 4-byte access.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 15:02:30 -05:00
Jakub Krasuski cefdea7d14 fix(libkernel): report EINVAL, EACCES, ENOBUFS, ETIMEDOUT and EINTR from Linux sockets
The Linux branch of NativeError lacked five codes the Windows branch
already translates, so they fell through to EIO. bind on a bound socket
and accept on a socket that is not listening set errno to 5 on Linux
and to 22 on Windows.

Assisted-by: Claude Opus 5.5
2026-10-05 21:41:12 +02:00
Dean 25c4a9460d
Merge pull request #650 from Celegans12/fix/windows-direct-memory-commit
fix(libkernel): state the size of a direct memory backing Windows cannot create
2026-10-06 08:03:53 +13:00
Dean 78c17a1d47
Merge pull request #661 from NumberGuan/codex/fix-metadata-download-size
fix(libkernel): preserve 64-bit metadata download sizes
2026-10-06 08:03:11 +13:00
Dean e8893dfc64
Merge pull request #633 from Celegans12/feat/kernel-sync-on-address-wait-sized
feat(libkernel): implement sceKernelSyncOnAddressWait32 and sceKernelSyncOnAddressWait64
2026-10-06 08:02:29 +13:00
Dean 17da563b25
Merge pull request #720 from adriadam10/feat/libkernel-unimplemented-names
fix(libkernel): name three Unimplemented stubs from their NIDs
2026-10-06 08:01:33 +13:00
Adrià Franch 6d81cce0db fix(libkernel): name three Unimplemented stubs from their NIDs
Co-Authored-By: Claude <noreply@anthropic.com>
2026-10-05 19:58:20 +02:00
Adrià Franch 85f16c56ee fix(libkernel): name five sceCoredump stubs from their NIDs
Co-Authored-By: Claude <noreply@anthropic.com>
2026-10-05 19:55:41 +02:00
alfalfa-star ba8c8c4b05 feat(libkernel): implement sceKernelGetModuleInfoFromAddr
A title's libc.prx calls it from __cxa_thread_atexit with flags 2 and
stores the returned module id in the destructor record. The 0x1A8-byte
info reports the name, id, TLS block, init and fini procedures,
eh_frame_hdr and eh_frame, and up to four load segments of the image
containing the address. The id is the loader handle when the image was
opened through sceKernelLoadStartModule and otherwise a stable id from
the same range. Unknown flags and st_size values throw.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 19:55:15 +02: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 de93a9492c feat(libkernel): load the relinked module for a guest module path
dlopen and sceKernelLoadStartModule passed the guest path to the host
loader, which cannot load the original ELF module. When a relinked module
<path>.guest.prx exists beside it, that module is loaded instead; for a
module the executable already loaded at startup the host loader returns
the same module. PPSA12544 loads /app0/Media/Modules/Il2CppUserAssemblies.prx
at startup and resolves IL2CPP functions through it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 19:41:47 +02:00
Merijn 4a548c0ba5 feat(libkernel): implement sceKernelGetOperationMode
NH6xARDOVv8 is the NID of sceKernelGetOperationMode. PPSA12544 passes two
int outputs and logs them as mode and submode; both are reported as 0.
B2n8aDorSH4 and PZQhiiLXRFs are sceKernelSyncOnAddressWait32 and
sceKernelSyncOnAddressWait64, implemented by #633, and are no longer added
as unimplemented exports.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 19:25:52 +02:00
Merijn 8f6328242d feat(libs): add exports imported by PPSA12544
Implement scePthreadGetschedparam and scePthreadSetschedparam on top of
the thread priority, POSIX utimes and fsync on top of sceKernelUtimes
and sceKernelFsync, and sceUserServiceGetAccessibilityZoomFollowFocus
like the other accessibility queries. Add the remaining imports of
PPSA12544 as unimplemented exports and record unknown NIDs and
signatures in the technical debt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 19:25:52 +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 62c70fb1d5 fix(libkernel): state the size of a direct memory backing Windows cannot create
On Windows each direct memory allocation is backed by a page-file
section that CreateFileMappingW commits in full. When the system commit
limit cannot cover it, the title stopped with "create direct memory
backing: Insufficient system resources exist to complete the requested
service", which did not say how much was requested.

The error now states the requested size in bytes and MiB, and the
runtime layout notes in USAGE.md describe the commit requirement and
the page file. Allocation behaviour is unchanged: committing at
allocation matches the console, where allocated direct memory is
always backed by physical memory.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 17:52:04 +02:00
Celegans12 28b2a08fa7 feat(libkernel): implement sceKernelSyncOnAddressWait32 and sceKernelSyncOnAddressWait64
libc's __std_atomic_wait_direct_32 and __std_atomic_wait_direct_64
import these functions, so a libc.prx that contains the C++20 atomic
wait wrappers does not load without them. Wait32 compares a 4-byte
value and Wait64 the full 8-byte value. Both share the waiter queue
of sceKernelSyncOnAddressWait, so sceKernelSyncOnAddressWake releases
waiters of every size on the address. A null address, or one not
aligned to the value size, throws. The by-value comparand, the return
values and the 8-byte alignment of Wait64 are assumed and recorded in
TechnicalDebt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 17:51:32 +02:00