127 Commits
Author SHA1 Message Date
Dean 682da9f57a Merge pull request #27297 from kiansaeidnia/feat/libkernel-dlopen-nodelete-noload
feat(libkernel): honour RTLD_NODELETE and RTLD_NOLOAD in dlopen, as FreeBSD 11 rtld does
2026-11-28 13:01:51 +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
turnip b3caad165c fix(libkernel): validate the guest TLS index pointer in __tls_get_addr (#22061)
* fix(libkernel): validate the guest TLS index pointer in __tls_get_addr
* fix(tests): check VirtualProtect return value as BOOL
* perf(libkernel): use unsynced guest copy in __tls_get_addr
2026-11-28 05:02:29 +13:00
Dean 14a5332d0b Merge pull request #22839 from kaiffeetasse/contrib/kernel-loadstartmodule-guest-path
fix(libkernel): copy the module path sceKernelLoadStartModule loads out of guest memory
2026-11-28 04:03:56 +13:00
Dean 0dd6b47978 Merge pull request #22392 from fogydes/fix/libkernel-unwind-info-flags
fix(libkernel): follow firmware 13.60 for module unwind info flags and failures
2026-11-27 22:27:27 +13:00
Dean 71780d88bd Merge pull request #20622 from milescoviello/fix/kernel-probe-dlsym-name
fix(libkernel): safely probe the symbol name of dlsym
2026-11-26 08:49:57 +13:00
KianandClaude Opus 5.5 1f4afa20c9 feat(libkernel): honour RTLD_NODELETE and RTLD_NOLOAD in dlopen, as FreeBSD 11 rtld does
dlopen refused every flag outside 0x103. It now accepts RTLD_NODELETE
(0x1000) and RTLD_NOLOAD (0x2000), mapped as FreeBSD 11 rtld_dlopen maps
them to RTLD_LO_NODELETE and RTLD_LO_NOLOAD:

- RTLD_NOLOAD returns a new handle that holds a reference to an image the
  process already has loaded (GetModuleHandleExW on Windows, the host
  RTLD_NOLOAD elsewhere). For an existing file that is not loaded it
  returns NULL and leaves dlerror untouched, as rtld load_object does; a
  file that does not exist sets a dlerror message
- RTLD_NODELETE pins the image (GET_MODULE_HANDLE_EX_FLAG_PIN on Windows,
  the host RTLD_NODELETE elsewhere), and the last dlclose keeps its guest
  image registration

Other bits, such as RTLD_TRACE, are still refused; the gap is recorded in
the libkernel debt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 04:53:33 +10:00
Kikoarl a8953d6561 fix(libkernel): validate guest destination pointers upfront in BatchMap2 and StopUnloadModule 2026-11-24 20:01:14 +01:00
kaiffeetasse b751a54770 fix(libkernel): copy the module path sceKernelLoadStartModule loads out of guest memory 2026-11-18 13:00:18 +01:00
Dean 1763f6878f Merge pull request #21578 from milescoviello/fix/libkernel-module-result-guest-copy
fix(libkernel): write the module load and unload results through checked copies
2026-11-18 17:19:28 +13:00
fogydesandClaude Opus 5.5 7f6d0f2cf8 fix(libkernel): follow firmware 13.60 for module unwind info flags and failures
Firmware 13.60's libkernel accepts only flags 1 and 2, checks the
caller's st_size, clears the whole structure for bad flags and when no
module matches, and keeps the caller's st_size on success. Flags 2
searches another per-module range and still throws.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 18:54:22 +05:30
Dean cc1dc9db1d Merge pull request #21589 from milescoviello/fix/libkernel-elf-phdr-match-guest-copy
fix(libkernel): read __elf_phdr_match_addr's segment table through a checked copy
2026-11-17 20:45:03 +13:00
Dean 4292c0dbb4 Merge pull request #16922 from ycbuzi/fix/libkernel-dlclose-opaque-handle
fix(libkernel): read the module image through dlinfo and never own the program's own handle
2026-11-17 16:15:59 +13:00
milescovielloandClaude Opus 5.5 922b26448f fix(libkernel): read __elf_phdr_match_addr's segment table through a checked copy
__elf_phdr_match_addr walked the caller's ModuleInfoEx segments in place,
so an unreadable record crashed the host. The four segment records and
their count are now read with one GuestCopyIn_nid_no_patch, keeping errno,
and an unreadable record throws, as a null one does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 08:04:29 -05:00
milescovielloandClaude Opus 5.5 d59580c986 fix(libkernel): write the module load and unload results through checked copies
sceKernelLoadStartModule and sceKernelStopUnloadModule stored res straight
through the caller's pointer. sceKernelLoadStartModule now writes it with
GuestCopyOut_nid_no_patch and returns EFAULT before loading for an
unwritable res; sceKernelStopUnloadModule checks res with
GuestWritable_nid_no_patch before unloading and returns EFAULT, leaving the
module loaded. errno is kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 07:51:21 -05:00
fogydes 7c72db307a fix(libkernel): include unwind table terminator in Windows size 2026-11-16 13:58:46 +05:30
Dean 2a09d0566a Merge pull request #18111 from HenriksApsitis/fix/module-info-query-match
fix(libkernel): consume queried module info in address matching
2026-11-16 15:19:49 +13:00
milescovielloandClaude Opus 5.5 2a769e4875 fix(libkernel): safely probe the symbol name of dlsym
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 06:12:53 -05:00
Dean 5aff60f1a7 Merge pull request #20135 from pushkarreddyy/fix/libkernel-module-text-location-segment-info-probing
fix(libkernel): safely probe output pointers in sceKernelGetLibkernelTextLocation and sceKernelInternalMemoryGetModuleSegmentInfo
2026-11-15 06:59:39 +13:00
Dean 033d172875 Merge pull request #18342 from JJenkx/fix/libkernel-bare-module-name-app0
fix(libkernel): find a module dlopen names without a directory in /app0's module directories
2026-11-15 06:42:02 +13:00
pushkarreddyy 46a1c118a6 fix(libkernel): safely probe output pointers in sceKernelGetLibkernelTextLocation and sceKernelInternalMemoryGetModuleSegmentInfo 2026-11-14 23:01:21 +05:30
Ryuzaki e8b95881c3 fix(libkernel): guard dlsym guest result pointer (#18532) 2026-11-13 17:40:59 +13:00
xXPBSXxandClaude Sonnet 5.5 9572abdc1a fix(kernel): leave res unchanged when sceKernelStopUnloadModule fails with an unknown handle
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-12 15:46:51 +01:00
JJenkxandClaude Opus 5.5 b7c47a0a8a fix(libkernel): find a module dlopen names without a directory in /app0's module directories
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 05:02:15 -05:00
HenriksApsitis 50695b0d9b fix(libkernel): consume queried module info in address matching 2026-11-10 15:24:23 +02:00
Dean Galvin 7c2ddf09ef fix(libkernel): keep a skipped deferred sweep pending until a load carries start arguments
A module's sweep list is read from its metadata, which is cleared once the module has started, so a sweep skipped at a load without start arguments could never run at that module's next load. The skipped list is now remembered and run at the next deferred load that carries start arguments.
2026-11-11 00:42:06 +13:00
Dean Galvin 4be08ec932 fix(libkernel): do not run the deferred sweep at a load without start arguments
The deferred sweep starts every module another module depends on at the
first deferred load of the title. When that first load carries no
argument block (a module the title starts with args 0 and argp null),
the swept modules were started with the same empty block, and a module
that reads *argp in its module_start faulted: Darkest Dungeon II
(PPSA19591) aborted in NativePluginPS5Example a few seconds after start.

A load whose argp is null no longer triggers the sweep and leaves it
pending, so it runs at the next deferred load that carries start
arguments, which is the block the swept modules get when the title
starts them through their dependent. guest_deferred_module_sweep_no_arguments
loads a module with no arguments first and checks that the swept module
is not started, then loads it with arguments and checks that the sweep
ran with them.

Root cause found and reported by JJenkx in #18053.
2026-11-10 23:50:33 +13:00
Adrià 47ba34c571 Merge pull request #13587 from pushkarreddyy/fix/module-info-efault
fix(libkernel): return EFAULT from module info and list queries for invalid memory pointers
2026-11-08 05:19:02 +01:00
bluandClaude Opus 5.5 d3980857b1 fix(libkernel): read the module image through dlinfo and never own the program's own handle
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-07 12:50:22 -07:00
pushkarreddyy 0bc6be3649 fix(libkernel): return EFAULT from module info and list queries for invalid memory pointers 2026-11-07 22:27:18 +05:30
BunnyFlandClaude Opus 5.5 d164e44244 Merge upstream/main into fix/libkernel-module-call-arguments
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-06 23:09:31 +01:00
Dean Galvin 987911807e fix(libkernel): keep the deferred module start state in HostThreadLocal
The deferred-dependency start state in InitializeDeferredModule (the
resolving vector and the started-results map) were thread_local objects with
destructors. On Windows a thread_local destructor in a module runs after
emulated TLS has freed the object, and prx_thread_local_destructors fails on
main for it. Hold both in HostThreadLocal like the other prx modules; the
trivial depth counter stays thread_local. Behaviour is unchanged.
2026-11-05 10:05:01 +13:00
BunnyFlandClaude Opus 5.5 5ee657294b fix(libkernel): check the module load and unload arguments as firmware 13.42 does
Firmware 13.42's libkernel_sys.sprx returns 0x80020016 from
sceKernelLoadStartModule for nonzero flags or a non-null opt, and from
sceKernelStopUnloadModule for nonzero flags, a non-null opt or handle 0.
Both ignored these arguments. sceKernelLoadStartModuleForSysmodule
accepts flags there, so it no longer forwards them.

Record that sceKernelStopUnloadModule never runs module_stop.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-03 19:43:46 +01:00
Dean Galvin 778c69a47f fix(relinker): drop the stored start results when the outermost deferred load ends
A module started as a dependency or by the sweep kept its start result, so a later
load of it by the title returned that result instead of 0 (guest_deferred_module_*
failed in the Windows job with 'module start result').
2026-11-04 04:20:52 +13:00
Dean Galvin 2909af1d77 test(relinker): sweep with a module that fails to start, and log non-std failures
A swept module whose start throws is skipped with a log line, whatever it throws, and
the load that triggered the sweep, and later loads, still succeed.
2026-11-04 03:34:59 +13:00
Dean Galvin 331dcf74bf fix(relinker): skip a swept module that fails to start instead of failing the load 2026-11-04 03:34:16 +13:00
Dean Galvin 3bff46c0aa fix(relinker): make the deferred sweep wait-safe and start a swept trigger in order
Concurrent first loads now wait for the one sweep; a failed sweep is retried by the
next first load. The sweep no longer skips the module that triggered it, so a swept
module that depends on it starts after it, and the trigger keeps its start result.
2026-11-04 03:32:55 +13:00
Dean Galvin 29178b2917 fix(relinker): start the deferred modules others depend on at the first load of any deferred module
A deferred module that only another deferred module names (PSNCommon, needed by
PSNCore) started after the plugins that use it (SPFXUnityPlugin) and crashed
Soul Hackers 2 on Windows. The first title load of any deferred module now starts
every deferred module some module depends on, in dependency order, with that
load's start arguments, and logs the sweep. Boot is unchanged.
2026-11-04 03:29:14 +13:00
Dean Galvin d77d8bc98e fix(relinker): format the deferred start log inside the guarded start 2026-11-04 02:39:12 +13:00
Dean Galvin 62aec71ad8 fix(relinker): start what a deferred module the executable needs depends on, and log each deferred start
On Windows a module the executable needs or imports from stays deferred, but its
dependencies were deferred too and started only when the title loads it, so a title
that calls it first ran them uninitialised (Soul Hackers 2, #15370 rerun). They start
at startup again, as on main. The loader prints one line per deferred start.
2026-11-04 02:36:53 +13:00
Dean Galvin 2cdb4d40d4 fix(relinker): start a deferred module's deferred dependencies before it on Windows
Since #12621 a Windows runtime module that another runtime module needs is deferred instead of started at boot, but loading a deferred module only started that module. A Unity plugin such as SPFXUnityPlugin that calls into a deferred module it needs (Il2CppUserAssemblies in Media/Modules) ran against code whose initializers had never run, and PPSA03743 crashed about 2.6 s in.

A deferred module's initialization table now lists the deferred modules it depends on (names, after the initializer array, behind a magic number so older output reads as having none). DynamicLoader starts those first, transitively and once each through the existing per-module state, with the start arguments of the load that began it, then starts the module itself. The module start result stays the module's own. Boot still starts no deferred module.

Linux is unchanged: its deferred modules still start only when loaded.
2026-11-03 16:03:33 +13:00
krishalivaibhavandClaude Opus 5.5 5afd6df8cc feat(libkernel): report eh_frame_hdr for relinked images on macOS
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 14:32:54 +05:30
krishalivaibhavandClaude Opus 5.5 ce09c08f44 fix(libkernel): keep hidden modules out of main-program lookups on macOS
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 14:32:54 +05:30
krishalivaibhavandClaude Opus 5.5 f82257e8f9 fix(libkernel): unregister a closed module under its load bias on macOS
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 14:32:53 +05:30
0e145b86e1 fix(libkernel): build the file, module and rtld calls on macOS hosts
NativeStat, SharedMemory, Stdio, DynamicLoader, ModuleInfo and Rtld used
Linux-only APIs (st_atim, memfd_create, sys/vfs.h, link.h and dl_iterate_phdr),
so libkernel did not compile on macOS. Add macOS paths behind __APPLE__:
st_*timespec and a long-path fstatat walk, an unlinked temp file for shared
memory, statfs, dlopen/dladdr and Mach-O segment walks for module and rtld
queries. The Linux and Windows paths are unchanged.

Extracted from feat/macos-port (#8658).

Co-authored-by: Himansh Raj <iamthehimansh@gmail.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-31 14:32:53 +05:30
pista 2c22b68133 fix(libs): reject unsupported WebAssembly module unwind queries 2026-10-30 10:50:57 +09:00
Adrià f9a8813b11 Merge pull request #12179 from p3n1cillin/claude/kernel-executable-module-handle
feat(libkernel): add sceKernelGetExecutableModuleHandle
2026-10-30 02:01:01 +01:00
Adrià 5a3c1a2f81 Merge pull request #10627 from maximilianfv/fix/libkernel-dlerror-long-messages
fix(libkernel): keep dlerror messages whole
2026-10-30 01:02:55 +01:00
p3nicillinandClaude Opus 5.5 4cf7411a46 feat(libkernel): add sceKernelGetExecutableModuleHandle
Return the main program's handle, the first one sceKernelGetModuleList
lists and one sceKernelGetModuleInfo accepts. reSOT (PPSA99023) imports
it from libkernel and passes the handle to sceKernelGetModuleInfo to find
its own code segment; before this its eboot failed to load on the
unresolved import.

The PS5 3.20 export lists have it in libkernel as well as libkernel_sys,
and on Windows a libkernel import never reaches libkernel_sys, so the
throwing libkernel_sys stub moves to libkernel as pselect did.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-29 12:17:59 +00:00
Dean 5023cd5a25 Merge pull request #9263 from imellag/fix/libkernel-macos-guest-unwind-info
fix(libkernel): report unwind information for guest and host addresses on macOS
2026-10-27 18:19:28 +13:00