Commit Graph
94 Commits
Author SHA1 Message Date
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
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 <[email protected]>
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
orezraeyandClaude Opus 5.5 19f56c530a fix(libkernel): write the module handles before failing a null count as measured on a PS5
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-25 19:04:34 -03:00
memob b9858031a7 refactor(libkernel): declare __tls_get_addr once with its real signature
The public header declared the unimplemented placeholder int __tls_get_addr(void). It now declares void* __tls_get_addr(const KernelTlsIndex*), the tls_index pointer the ABI passes, and the implementation and the test use that declaration and type instead of their own.
2026-10-24 20:30:50 -04:00
memob cf27259538 feat(libkernel): implement __tls_get_addr
Resolve a FreeBSD/ELF tls_index {module, offset} the way the relinker's
DTPMOD64 values are laid out: on Windows through the PE _tls_index the
module word points at and the thread's ThreadLocalStoragePointer, on
Linux through glibc's __tls_get_addr.
2026-10-24 20:29:20 -04:00
boykopovar f38d29fd08 refactor(sdk): add canonical headers for remaining libraries 2026-10-24 23:17:42 +03:00
Dean Galvin d7e2371a84 Merge main into fix/libkernel-macos-guest-unwind-info 2026-10-25 01:14:01 +13:00
Dean 0fc488a06d Merge pull request #10230 from orezraey/fix/libkernel-module-info-from-addr-measured-ps5
fix(libkernel): answer sceKernelGetModuleInfoFromAddr's flags and failures as measured on a PS5
2026-10-25 00:24:17 +13:00
Maximilian FleckensteinandClaude Opus 5.5 4bf9853dbf fix(libkernel): keep dlerror messages whole
dlerror returned the last loader error from a 512-byte buffer, so a
longer message was cut off. On macOS the reason dyld gives for a failed
dlopen lists every path it tried, and the message for a module that was
not relinked runs to over 1,000 characters; the end of it, the hint to
relink with --module-dir, was lost, and guest_dynamic_loader failed.
Keep the message in a host thread-local string, through
HostThreadLocal so MinGW does not run its destructor on freed
thread-local storage.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-24 06:44:57 -03:00
JJenkx 2d4d55036d test(loader): preserve explicit zero-argument module starts 2026-10-23 11:15:40 -04:00
JJenkx 74878ee102 feat(loader): prototype deferred Linux runtime module lifecycles 2026-10-23 11:15:40 -04:00
orezraeyandClaude Opus 5.5 3717573887 fix(libkernel): answer sceKernelGetModuleInfoFromAddr's flags and failures as measured on a PS5
Flags 1 finds any module and flags 2 only non-system ones; other flags return EINVAL instead of throwing, every failure clears the 0x1A8 bytes, and st_size is left 0.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-23 11:49:24 -03:00
Dean 5e9f4b8966 Merge pull request #9832 from johandavidcm/fix/libkernel-dlopen-unrelinked
fix(libkernel): fail dlopen of an unrelinked module without the Windows Bad Image dialog
2026-10-23 23:18:00 +13:00
Johan David dc84bec7b9 fix(libkernel): fail dlopen of an unrelinked module without the Windows Bad Image dialog
On Windows, dlopen passed a module that was never relinked to LoadLibraryExW, which raised the
modal Bad Image hard-error dialog and blocked the calling thread until someone answered it. The
load now runs with SEM_FAILCRITICALERRORS set for that thread only, so it fails at once with the
same result as before. Every failed load is reported once per file on stderr with a [module]
prefix; a file that exists with no relinked .guest.prx names the relinker's --module-dir option.
2026-10-22 13:05:34 -05:00
Yossi Yadgar 36d4939b4e feat(libkernel): fill SceKernelModuleInfoEx by module handle 2026-10-22 15:52:18 +03:00
Emanueleandmugurc bfa5368657 fix(libkernel): report unwind information for guest and host addresses on macOS
Two unwind queries a title makes went wrong on macOS, so a C++ exception the title would catch ended the process instead: God of War Sons of Sparta (PPSA28997) stops on an IL2CPP exception it normally handles.

- sceKernelGetModuleInfoForUnwind found a relinked image and its PT_GNU_EH_FRAME header but left eh_frame_addr and eh_frame_size at zero, so the title's unwinder found no FDE for its own frame. The tables are now read with EhFrame::ReadTables over the image's load segments, as ModuleInfo does on Linux, and eh_frame_size includes the zero terminator, as on Linux.
- sceSysmoduleGetModuleInfoForUnwind read /proc/self/maps outside Windows and threw on every call on macOS. It now answers from mach_vm_region, with the image path from dladdr, as the Linux branch answers from the mapping.

guest_unwind_module_info now runs on macOS: the test executable carries the __APS5DATA,__meta program headers that the macOS dl_iterate_phdr reads from a relinked image. guest_sysmodule checks the macOS answers against mach_vm_region.

Co-authored-by: mugurc <[email protected]>
2026-10-21 18:39:48 +02:00
Dean Galvin 0f7241f3a7 Merge origin/main into PR 6519 2026-10-21 21:35:27 +13:00
MarcZX10 05cc68cd95 style(libkernel): keep regression comments out of code 2026-10-20 20:52:44 +00:00
MarcZX10 e1e20f0f2e fix(libkernel): match module info segment records 2026-10-20 20:50:05 +00:00
Adrià 324e0e48e0 Merge pull request #6482 from Ondra97/codex/team-20261015-worker-1-ready
fix(libkernel): preserve RTLD_GLOBAL visibility on Windows
2026-10-19 03:39:21 +02:00
Get-fix ca75c94cc2 feat(libkernel): load system libraries from their console paths
PS4 programs load system libraries with sceKernelLoadStartModule and
their console path. The OpenOrbis piglet sample loads
/<sandbox word>/common/lib/libScePigletv2VSH.sprx and
libScePrecompiledShaders.sprx, the sandboxed form of
/system/common/lib/ that sceKernelGetFsSandboxRandomWord names. The path
was opened as a guest file and the load failed with ENOENT.

A path in /system/common/lib/ or in the sandboxed /<word>/common/lib/
whose file name ends in .sprx now loads the host libs/<name>.prx, as
libSceSysmodule does for module IDs. Names with a directory part are
not mapped, so such a path cannot leave libs/.
2026-10-17 04:46:19 +03:00
Adrià 5b70a50680 Merge pull request #5955 from fma-rc/fix/libkernel-linux-guest-module-protect
fix(libkernel): register a relinked guest module's image when Linux protects its pages
2026-10-16 23:29:46 +02:00
Ondra97 819eb9bb4c fix(libkernel): preserve RTLD_GLOBAL visibility on Windows 2026-10-15 18:35:19 +02:00
Adrià 3751c55111 Merge pull request #5700 from specbug/fix/default-scope-guest-symbols
fix(libkernel): resolve renamed guest exports in the default scope
2026-10-15 17:04:10 +02:00
fma-rc c1783f9d64 fix(libkernel): register a relinked guest module's image when Linux protects its pages 2026-10-14 18:24:45 +02:00
Renan Pires 13b1113d93 fix(libkernel): find main-program symbols when the executable is not position independent 2026-10-14 12:35:22 +02:00
JAB-devandClaude Sonnet 5.5 19c55dc804 fix(libkernel): drop the unwind cache's freshness check and let a failed forget throw
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-10-14 07:41:54 +02:00
Rishit Vora 2caefdb8ed fix(libkernel): resolve renamed guest exports in the default scope 2026-10-14 04:19:49 +00:00
JAB-devandClaude Sonnet 5.5 05bf752bfa fix(libkernel): clear the unwind cache when forgetting unloaded images fails
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-10-14 02:57:39 +02:00
JAB-devandClaude Sonnet 5.5 434e0b9edf fix(libkernel): forget unwind images only when their module is unloaded and read tables outside the lock
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-10-14 02:49:16 +02:00
JAB-devandClaude Sonnet 5.5 cf8c63b9b8 perf(libkernel): find a cached module's unwind tables without VirtualQuery on Windows
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-10-13 21:40:15 +02:00
JAB-devandClaude Sonnet 5.5 61ed25d9ed fix(libkernel): drop the cached unwind tables when the loader frees a module
The cache key of relinked images has no time stamp or check sum, so a
different module of the same size loaded at the same base was served the
old tables. The loader now forgets the image when it frees the module, the
cache has a separate valid flag, and the sysmodule name cache is left out
of this change.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-10-13 18:13:12 +02:00
JAB-devandClaude Sonnet 5.5 5339c084e8 perf(libkernel): cache the unwind tables and image name per module on Windows
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-10-13 08:14:53 +02:00
Dean 88f48fddef Merge pull request #4688 from eliyarson/fix/kernel-stat-relinked-prx
fix(libkernel): resolve original .prx names to relinked .guest.prx in stat, open and reachability
2026-10-13 17:48:42 +13:00
jagrat Singh ea03a22c7f feat(libkernel): implement sceKernelInternalMemoryGetModuleSegmentInfo 2026-10-13 04:29:25 +05:30