Commit Graph

31 Commits

Author SHA1 Message Date
Lexroid b1a14c6f36 fix(libkernel): unregister guest module images in dlclose and propagate failures
Move the image unregistration out of the Module destructor into
dlclose_nid_postfix. It runs while the handle is still registered, so a
failure (the image stays leased by GPU work) propagates to the caller and
leaves the module loaded and usable. Images shared by another open
handle stay registered until the last handle closes.

guest_memory now checks that dlclose under a held lease throws and keeps
the module, its symbols and its protection.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-10 10:23:50 +02:00
Lexroid 57c179c74d fix(libkernel): unregister guest module images when they are unloaded
A .guest.prx image registered by sceKernelMprotect stayed in the guest
allocation registry after dlclose freed it, so its dead ranges blocked
later mappings at that address and could reach GPU builds.

The Windows module destructor now unregisters the image before
FreeLibrary. Unregistering waits for outstanding leases on the image like
unmap and protect do; if the wait fails the module stays loaded.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-10 10:23:42 +02:00
Adrià 426fe62282
Merge pull request #2028 from overlordxrz-source/feat/libkernel-get-module-list
feat(libkernel): implement sceKernelGetModuleList and sceKernelGetModuleInfo
2026-10-10 03:15:01 +02:00
Adrià Franch 78d92881b0 fix(libkernel): throw when the Linux guest unwind lookup fails
As requested in review: a failed sceKernelGetModuleInfoFromAddr no longer
reports an empty answer. Adds a failure test (symbol interposition) and
extends the metadata test (EH record walk, terminator, no-header DSO).

Co-authored-by: jweidenh <38249793+jweidenh@users.noreply.github.com>
Co-Authored-By: Claude <noreply@anthropic.com>
2026-10-10 02:10:08 +02:00
clem-gb 1bd1923718 fix(libkernel): report guest unwind tables in sceKernelGetModuleInfoForUnwind on Linux
A title that ships its own libc.prx unwinds C++ exceptions with that
libc's libunwind, which asks sceKernelGetModuleInfoForUnwind where each
frame's eh_frame is. On Linux the call always reported no tables, so
no C++ exception thrown in guest code could be caught. For the main
executable and .guest.prx images, report the PT_GNU_EH_FRAME tables
that sceKernelGetModuleInfoFromAddr finds, as Windows does from
.ehmeta. Other host images still report none.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HeC9bA3n74TzJRYv9AgBE8
2026-10-10 02:09:56 +02:00
overlordxrz-source 8a41d280af feat(libkernel): implement sceKernelGetModuleInfo
Fill takes either info struct, so sceKernelGetModuleInfo reports the
name and segments sceKernelGetModuleInfoFromAddr reports for the same
image, on Linux and Windows.
2026-10-09 19:39:49 -04:00
overlordxrz-source 6d42f3a910 feat(libkernel): implement sceKernelGetModuleList 2026-10-09 19:39:49 -04:00
jeffrey12cali 36c979b369 fix(libkernel): pass module args and argp to runtime-loaded modules on Linux
sceKernelLoadStartModule discarded its arguments, and the relinker's Linux guest writer
synthesized an initialisation trampoline that also cleared the argument registers before
jumping to the module entry point, so a converted module always reached its own start-up
code with args = 0 and argp = NULL.

On PPSA28997 two of the title's own modules validate that parameter block as their first
act and dereference it unconditionally: SaveData faults on `mov (%rsi),%eax` with rsi = 0
beside its `cmp $0x10` size checks, and PSN faults the same way at PSN+0x3ee7 with rbx = 0.
The Windows branch delivers the block, so identical code reports its parameter-version
error and continues instead of faulting.

sceKernelLoadStartModule now records the pair before dlopen and clears it afterwards, and
the emitted DT_INIT stub reads it through two accessors exported by libkernel. The
initialiser is called rather than tail-jumped so its return value can be reported through
*res as the PS5 API specifies. The state is thread_local, which makes the handoff per-call:
ld.so runs a module's initialiser on the thread that called dlopen. DT_FINI keeps a plain
call-through, so unloading neither reads stale arguments nor reports a result.

The accessor names use the _nid_no_patch suffix so the NID resolver leaves them alone and a
guest import can name them exactly.
2026-10-10 00:57:51 +02:00
Adrià 5bc7886ab8
Merge pull request #1188 from MathiasDevelopes/feat/kernel-module-info-windows
feat(libkernel): implement sceKernelGetModuleInfoFromAddr on Windows
2026-10-09 23:22:46 +02:00
jeffrey12cali 34616c425b fix(module): resolve the default dlsym scope against guest exports only
Titles pass handle 0 (RTLD_DEFAULT) for a process-wide lookup, and the loader rejected it: the handle is
not in the module map, so every such lookup failed even when a loaded module exports the symbol. Handle 0
and -2 now take the default scope, searching the global modules by plain name, NID and `#guest` form, and
then the process-wide scope.

The process-wide scope of the real loader also contains glibc and libstdc++, so an unfiltered fallback
would answer `malloc`, `dlopen` and `pthread_create` where PS5 reports the symbol as missing: handle 0 is
the main program, whose lookup sees the program's exports, not the host C++ runtime. A result from the
process scope is therefore accepted only when `dladdr` attributes it to a converted or replacement module
(a `.prx` library or the executable), which keeps the fallback for guest symbols and removes the host
leak. `guest_dynamic_loader` asserts the three host names are not found; disabling the filter makes that
test fail.

The scripting heap that an earlier revision of this branch added has been dropped: the title reaches the
same boot milestone with the lookup failing honestly, so the export was an inference rather than a
requirement, and prosper's bring-up notes report `ESRCH` for that name on hardware.
2026-10-08 14:30:55 +02:00
mugurc 939c3d98f7 feat(libc): exception runtime on macOS hosts
On macOS the host keeps libc++abi: libc++ binds __cxa_throw two-level,
so moving only the personality into this runtime would leave the two
halves disagreeing on the exception header. The host personalities stay
libc++abi's and libunwind's, and libc.prx serves guest code:

- the guest's libstdc++ std::exception_ptr is modelled directly, since
  libc++'s differs, and the Itanium type_info layouts that libc++abi
  keeps private are declared for the runtime;
- guest frames are found through their PT_GNU_EH_FRAME, using a
  dl_iterate_phdr emulation over the ELF program headers that relinked
  images keep in __APS5DATA,__meta (written by relinker --macos, which
  comes in a later pull request);
- host frames are found by scanning __TEXT,__eh_frame;
- sceKernelGetModuleInfoForUnwind uses the same emulation and falls back
  to dladdr for host images.

The libc++ paths compile only with libc++/libc++abi and the rest only
on __APPLE__, so Linux and Windows builds are unchanged.
exception_c_cleanup throws from host code, which this runtime does not
serve on macOS, so it is not built there.
2026-10-08 13:16:41 +03:00
Claude 9abc931a18
refactor(libkernel): share eh_frame_hdr parsing between module info calls
sceKernelGetModuleInfoForUnwind and sceKernelGetModuleInfoFromAddr each
parsed .ehmeta and the eh_frame_hdr it names. Both now read them through
Module/EhFrame.hpp, so a bad table fails the same way in both: an
eh_frame_hdr version other than 1, an indirect or non-absptr/pcrel
encoding, a 64-bit record length or anything outside the image throws.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JkiyF6p7oDAaTtVe8ci5zP
2026-10-08 06:47:14 +00:00
MathiasDevelopes 77ef75c1da
feat(libkernel): implement sceKernelGetModuleInfoFromAddr on Windows
Read the module layout from the PE image that holds the address. A
relinked image reports its .elf sections as segments and the
eh_frame_hdr recorded in .ehmeta; any other image reports its sections
with memory access and its .ehfram section. The eh_frame_hdr and
eh_frame helpers are shared with the Linux path, and the guest module
info test now also runs on Windows.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-08 05:46:48 +00:00
Merijn b86370285b fix(kernel): throw on unsupported unwind tables in sceKernelGetModuleInfoForUnwind
Once an image has .ehmeta, an eh_frame_hdr version other than 1, an
eh_frame_ptr encoding other than absptr or pcrel, a 64-bit record length,
an eh_frame_ptr outside the image or a missing terminator now throw
instead of returning the empty answer. The test queries a fixture DLL
whose .ehmeta it can break, since the unwinder reads the same section.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 00:54:43 +02:00
Merijn e975d9a926 fix(libkernel): report guest unwind tables in sceKernelGetModuleInfoForUnwind
On Windows the call returned no eh_frame_hdr for every address, so a
title's own libc (its libunwind) found no frame information and
terminated on the first C++ exception thrown in guest code. PPSA12544
died that way after its intro cinematic: IL2CPP raised an
AmbiguousMatchException that Unity catches and logs, and the runtime
called terminate instead. For an address in a relinked guest image the
call now returns the PT_GNU_EH_FRAME segment named by .ehmeta, the
eh_frame it points to and its size, and the image as seg0; host images
keep the empty answer.

AI-assisted: yes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 00:52:14 +02:00
Fishybeing 5a04d3cc9e build(windows): guard NOMINMAX before including windows.h
Four sources defined NOMINMAX unconditionally, which redefines the macro the build already passes and warns on every MinGW build. Use the #ifndef guard the rest of the tree uses.
2026-10-06 14:57:48 +02:00
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 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 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
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 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
Dean c96745e912
Merge pull request #337 from DotDebian/feat/elf-phdr-match-addr
feat(libkernel): implement __elf_phdr_match_addr
2026-10-05 12:10:32 +13:00
Pouare514 f1a3d60b15 fix(libkernel): boot Dreaming Sarah past unwind and debug raise 2026-10-02 13:34:35 +02:00
DotDebian 7fd0890320 feat(libkernel): implement __elf_phdr_match_addr
Returns 1 when the address lies in an executable PT_LOAD segment of the
given dl_phdr_info, following FreeBSD lib/libc/gen/elf_utils.c (9.x and
11.x branches). The stub parameters become (dl_phdr_info*, void*) to
match the FreeBSD declaration; a null dl_phdr_info throws.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-02 11:18:06 +02:00
OverkillLabs 55ed2719d5 refactor: apply naming conventions and drop extern-C comment
Renames template parameters to the TKey-style the conventions doc
requires (TValue, TFunction), removes the extern "C" close comment
(not one of the two allowed structural exceptions), and replaces
the magic error/flag numbers left after the previous comment
cleanup with the existing SCE_KERNEL_ERROR_* constants and a named
RTLD_NOW constant so the code documents itself.
2026-09-29 04:20:28 +03:00
OverkillLabs d9f8d87c27 refactor: strip explanatory comments to match repo conventions
Comments in this codebase may only mark technical debt (per
docs/dev/CONVENTIONS.md), plus the #endif and namespace-close
structural exceptions. Removes the descriptive comments added on
this branch across PreciseWait.hpp, FormattingWide.cpp, the
direct-memory pool query/free-run plumbing, and the module loader
wiring, keeping the two allowed structural markers intact.
2026-09-29 04:18:04 +03:00
OverkillLabs cfe9a458cc kernel: direct-memory pool querying and module loader wiring
- DirectMemory: track each allocated block's type and extent in the
  physical pool (DirectMemoryBlock), splitting the record on a partial
  free, and expose DirectMemoryQueryBlock/DirectMemoryFreeRun. Wires
  sceKernelDirectMemoryQuery to answer with the real allocated range
  and type instead of a hardcoded one-page/type-3 guess, and
  sceKernelAvailableDirectMemorySize to report the actual free run
  instead of the whole remaining aperture. DirectMemory.cpp's mapping
  path already tolerates MAP_FIXED overlap into a registered range and
  already has honor-then-fallback address-hint handling and an
  ignored-flags mask, so it is unchanged here.
- MemoryPoolExport: implement sceKernelMemoryPoolBatch/Commit/Decommit/
  Expand/GetBlockStats/Reserve (previously all dead stubs) using the
  existing DoMprotect/DirectMemoryAlloc/DoReserveVirtual primitives and
  a small pool-state block counter.
- Module: wire sceKernelDlsym/sceKernelLoadStartModule/
  sceKernelStopUnloadModule to the existing host-module loader
  (dlopen_nid_postfix/dlsym_nid_postfix/dlclose_nid_postfix), replacing
  dead stubs. sceKernelGetModuleInfoForUnwind/FromAddr are unrelated
  and left as-is.
2026-09-28 13:18:25 +03:00
boykopovar 5887c8d6e2 feat(libkernel): add memory segment, backtrace, heap error report definitions 2026-09-27 11:43:32 +03:00
boykopovar 40101471ee feat(libkernel): add new posix, pthread, semaphore, process funcs definitions 2026-09-27 11:43:31 +03:00
SamG-Coder 453fec28c5 feat(kernel): add tracked dynamic module loading and NID lookup 2026-09-25 06:48:50 +10:00
boykopovar 5d715ee549 refactor(libkernel): move from Export.cpp to separated files 2026-09-13 16:41:04 +03:00