Commit Graph

95 Commits

Author SHA1 Message Date
Hannah Lyons 97e81c4224 feat(libkernel): implement sync 2026-10-10 18:12:21 -04:00
Dean 6c008c180e
Merge pull request #2935 from AchrafReyani/feat/libkernel-siglongjmp
feat(libkernel): implement siglongjmp
2026-10-11 09:09:18 +13:00
Achraf Reyani 0272f99ad3 feat(libkernel): implement siglongjmp
PokeMMO Prospero (PPSA98001) stops at siglongjmp (pebqbE5ws8s) from
libkernel. The title links its own FreeBSD sigsetjmp, so siglongjmp
follows FreeBSD's amd64 __siglongjmp and its sigjmp_buf layout: when the
save-mask flag at offset 88 is set it restores the mask saved at 72
through _sigprocmask, then reloads rbx, rsp, rbp, r12-r15 and the x87
control word and returns to the saved address with val, or 1 for 0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-11 03:25:07 +09:00
LeandroLP23 df415ff1fd feat(libkernel): implement pthread_sigmask
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-10 19:45:28 +02:00
overlordxrz-source 9a70477170 feat(libkernel): implement kill
ProsperoStore (PPSA99000) imports kill from libkernel and stops at it on
current main. Its crash reporter resets a crash signal to SIG_DFL and
sends it again with kill(getpid(), signal).

kill follows FreeBSD's kern_kill and killpg1 for the only guest process:
EINVAL for signals outside 0 to 128, signal 0 only checks the target,
and the caller's own pid, 0 and minus its pid deliver through raise.
Any other pid, and -1, which skips the caller, report ESRCH.
2026-10-10 11:06:12 +02:00
Adrià 9d249f365e
Merge pull request #2613 from oneandonlydean/fix/carry-2564
fix(libkernel): return every command-line argument as UTF-8 from getargv on Windows
2026-10-10 10:49:51 +02:00
Doston Abdullayev 5cb7de6ba9 fix(libkernel): return every command-line argument as UTF-8 from getargv on Windows
On Windows, getargc and getargv reported only the executable path, read
with GetModuleFileNameA in the ANSI code page, and dropped every other
argument. Linux returns the whole command line from /proc/self/cmdline,
and the relinker's Windows entry stub already passes the guest entry all
arguments converted to UTF-8.

Parse GetCommandLineW with CommandLineToArgvW and convert each argument
to UTF-8 with WC_ERR_INVALID_CHARS, as the entry stub does, so getargv
matches the entry's argv and the Linux behaviour. The Linux path is
unchanged.
2026-10-10 21:20:29 +13:00
AlxcBTW bc8587a6fe fix(libc): end the process without detach routines in _Exit on Windows
On Windows std::_Exit ends in ExitProcess, which still runs every module's
DLL_PROCESS_DETACH and TLS callbacks after the other threads are gone. A
static destructor that joins a worker then waits forever: a title that calls
_Exit while libSceVideoOut's flip queue runs (ps5-opengl's retirement
fail-stop) stays alive in FlipQueue's destructor. _Exit and libkernel's _exit
now terminate the process with TerminateProcess, as _exit ends a POSIX
process: no atexit handlers, stream flushes or module destructors.
2026-10-10 21:20:29 +13:00
LuisBiceps 918bc0a49c feat(libkernel): report no child processes from waitpid
waitpid returns -1 with ECHILD, or EINVAL for an option FreeBSD does not know, and leaves the status unwritten: AnyPS5 runs the title as one process and exports nothing that creates a child. VLC PPSA85300 stops on main at this import.
2026-10-10 10:11:04 +02:00
Scott Schuster 570aac4677 fix(libkernel): accept SCHED_OTHER in sched_get_priority_max/min
SDL queries the SCHED_OTHER range before it sets a thread priority. It gets
the same 256 to 767 range as SCHED_FIFO and SCHED_RR, which
pthread_setschedparam applies regardless of policy. The console's answer is
unverified and recorded in TechnicalDebt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-10 00:47:11 -05:00
Dean ad0b5ba586
Merge pull request #2090 from LeandroLP23/feat/libkernel-environ
feat(libkernel): export environ as an empty environment
2026-10-10 17:43:44 +13:00
Jan Šlégl c26c1cae5b fix(libkernel): block guest signals by FreeBSD's bit n - 1
sigprocmask keeps the first word of the title's set as it is, where
FreeBSD keeps signal n at bit n - 1 (_SIG_BIT), but Dispatch tested bit
n. A title that blocked SIGTERM with a FreeBSD-built set (bit 14) was
not protected, and a set with bit 15 blocked SIGTERM instead of SIGURG.
Dispatch now tests bit n - 1; the stored mask and the set returned by
sigprocmask are unchanged.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-10 01:30:55 +02:00
Adrià 76bff21fbe
Merge pull request #1421 from popcoder565/fix/kernel-raise-exception-ntcontinue
fix(libkernel): stop losing and deadlocking sceKernelRaiseException deliveries on Windows
2026-10-10 01:23:17 +02:00
john.maia e462d0602a refactor(libkernel): size the delivered signal handler table like the dispositions
Assisted by Claude Code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DwFnKjMxmwGDWiuYYf1v4D
2026-10-09 23:42:43 +01:00
john.maia cfe4a277c4 feat(libkernel): implement sigaction
EVO-PLAYER (PPSA99039) v0.11.0 stops at sigaction once its earlier
imports resolve: it installs a crash handler for SIGSEGV, SIGBUS and
SIGABRT and a quit handler for SIGTERM, SIGINT and SIGHUP at start-up.

sigaction records the handler, flags and mask of signals 1 to 128 and
reports them back, with FreeBSD's EINVAL cases. signal shares the table
and records SA_RESTART, as FreeBSD's libc does. Plain handlers on the
signals signal already delivers run as signal handlers do; SA_SIGINFO
handlers and other signals are recorded only, and raise of such a
signal throws.

Assisted by Claude Code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DwFnKjMxmwGDWiuYYf1v4D
2026-10-09 23:42:43 +01:00
popcoder565 5dc7021c38 Merge remote-tracking branch 'origin/main' into fix/kernel-raise-exception-ntcontinue
Keeps both new TechnicalDebt entries: this branch's note that a raise
can still reenter host code it interrupted, and #2107's sigaltstack note.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 18:07:20 -04:00
Adrià 6642559456
Merge pull request #1675 from Recapi/feat/libkernel-getrlimit
feat(libkernel): implement getrlimit for RLIMIT_DATA
2026-10-10 00:00:57 +02:00
Adrià 7331a123e9
Merge pull request #2107 from LeandroLP23/feat/libkernel-sigaltstack
feat(libkernel): implement sigaltstack
2026-10-09 23:56:02 +02:00
Adrià db06355f84
Merge pull request #1859 from overlordxrz-source/feat/libkernel-system
feat(libkernel): implement system
2026-10-09 23:55:09 +02:00
Adrià 8d47cfba88
Merge pull request #1807 from SleglJan/feat/libkernel-sandbox-random-word
feat(libkernel): implement sceKernelGetFsSandboxRandomWord
2026-10-09 23:52:40 +02:00
Adrià d724cad38c
Merge pull request #1748 from danielradosa/feat/libkernel-seteuid-setegid
feat(libkernel): implement seteuid and setegid
2026-10-09 23:23:34 +02:00
LeandroLP23 a3f0120da2 feat(libkernel): export environ as an empty environment
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 23:22:58 +02:00
Adrià 870ac041c5
Merge pull request #1685 from overlordxrz-source/feat/libkernel-sysctl-hw-ncpu
feat(libkernel): implement sysctl and sysctlbyname for hw.ncpu
2026-10-09 23:20:13 +02:00
LeandroLP23 c54143dbb9 feat(libkernel): implement sigaltstack
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 23:16:18 +02:00
Adrià 27cb335be1
Merge pull request #1650 from Pedroj-64/feat/libkernel-uid-gid
feat(libkernel): implement getuid, geteuid, getgid, getegid and issetugid
2026-10-09 23:04:27 +02:00
Adrià 4c36741929
Merge pull request #1641 from SleglJan/feat/libkernel-sigset
feat(libkernel): implement the sigset functions
2026-10-09 22:58:56 +02:00
popcoder565 570e7affdb Merge remote-tracking branch 'origin/main' into fix/kernel-raise-exception-ntcontinue
Keeps this branch's CONTEXT_FULL | CONTEXT_SEGMENTS read, context-first
order and bounded retry in RaiseOn, and adds #1478's ymm save fields to
both deliveries. The test keeps both phase sets; the vectors phase runs
after the continuing, selfing and looping phases and counts their
deliveries. The TechnicalDebt entry about ymm upper halves is dropped,
since #1478 preserves them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 16:04:14 -04:00
Dean 87e773689e
Merge pull request #1478 from awake-devel/fix/guest-signal-delivery
fix(libkernel): keep ymm upper halves across a redirected raise
2026-10-10 08:05:04 +13:00
Dean fffb830363
Merge pull request #1477 from awake-devel/fix/current-cpu-in-guest-mask
fix(libkernel): report the current CPU within the thread's guest affinity
2026-10-10 08:04:50 +13:00
Daniel Radosa 1414b27d29 feat(libkernel): implement seteuid and setegid
The guest process is assumed to run as root. Under FreeBSD's
sys_seteuid and sys_setegid, id 0 is then accepted without a privilege
check and changes no credential, so both return 0. Any other id would
change the effective credential, which is not modelled, and throws.

Part of #1578.
2026-10-09 19:14:02 +02:00
Renan Pires 851f3b7a10 feat(libkernel): implement getrlimit for RLIMIT_DATA 2026-10-08 23:52:33 -03:00
overlordxrz-source 8f09ec3616 feat(libkernel): implement system 2026-10-08 18:15:49 -04:00
Jan Šlégl 7785933807 feat(libkernel): implement sceKernelGetFsSandboxRandomWord
Returns the name of the directory under which a title's sandbox exposes
system files, which homebrew SDKs splice into paths such as
/<name>/common/cert/CA_LIST.cer and /<name>/common/lib/libc.sprx. The
name is fixed here; recorded in TechnicalDebt together with the fact
that nothing is mounted under it.

Registers guest_sandbox_random_word.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-08 21:39:11 +02:00
overlordxrz-source 18798620e8 feat(libkernel): implement sysctl and sysctlbyname for hw.ncpu
ScreenTester5 (PPSA69420) stops at start-up on the unresolved sysctlbyname
import and also imports sysctl. hw.ncpu (CTL_HW.HW_NCPU) reports the same
processor count as sysconf(_SC_NPROCESSORS_ONLN). Other names and MIBs throw.
2026-10-08 12:23:05 -04:00
Jan Šlégl e6a9b50512 feat(libkernel): implement the sigset functions
Add sigemptyset, sigfillset, sigaddset, sigdelset and sigismember with
FreeBSD 11 semantics (lib/libc/gen/sigsetops.c): a 128-bit set of four
32-bit words, signal n at bit n - 1, signals 1 to 128 valid. sigfillset
sets every bit. An invalid signal returns -1 with errno EINVAL and leaves
the set untouched; sigismember returns 1 or 0. A null set throws.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-08 17:45:57 +02:00
Pedro a294b80d29 feat(libkernel): implement getuid, geteuid, getgid, getegid and issetugid
Part of #1578.
2026-10-08 10:39:06 -05:00
Adrià 29e533aca0
Merge pull request #1469 from arvindfroi/refactor/coredump-stopinfo-gpu-name
refactor(libkernel): name the Jrs7UUkGOFo Coredump stub by its NID
2026-10-08 16:37:04 +02:00
popcoder565 24dc98d7c0 fix(libkernel): give up a raise whose target stays in NtContinue or winpthreads
The retry that waits for a target to leave NtContinue, NtContinueEx or
libwinpthread-1.dll had no bound, so a target that stayed there made
sceKernelRaiseException spin forever. It now throws after 1 s. A new
guest_raise_exception phase keeps a thread inside NtContinue by
continuing a context that calls NtContinue again, and checks that the
raise throws and that the handler did not run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 09:47:25 -04:00
clem-gb 15c1962e82 fix(libkernel): keep ymm upper halves across a redirected raise
A thread that sceKernelRaiseException redirects resumes through
RtlRestoreContext with a CONTEXT that has no XSTATE, so the upper halves
of ymm0-ymm15 came back as the handler and the delivery path left them.
A handler or host routine that runs vzeroupper or any VEX instruction
(Zen 2 guest code, the CRT's memcpy) cleared the upper lanes of a thread
interrupted in the middle of AVX code. The entry stub now stores
ymm0-ymm15 next to the delivery when the CPU and the OS enable AVX, and
the exit loads them back right before RtlRestoreContext, which restores
only the low halves.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HeC9bA3n74TzJRYv9AgBE8
2026-10-08 10:47:33 +02:00
clem-gb 2ba8f75e15 fix(libkernel): report the current CPU within the thread's guest affinity
sceKernelGetCurrentCpu returned the raw host CPU index. Guest affinities
are bookkeeping only and sceKernelGetAvailableCpumask advertises CPUs 0
to 12, so on a host with more than 13 logical CPUs a title could get 13
or higher, and a thread pinned to one CPU could get another one.

The host index now selects a CPU of the calling thread's affinity
clipped to the available mask, so the result is always an advertised
CPU and a thread pinned to one CPU reports that CPU.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HeC9bA3n74TzJRYv9AgBE8
2026-10-08 10:47:33 +02:00
kjhq bb1a4cbec4 fix(libkernel): flush only the paths the guest changed in sceKernelSync on Windows
Opening a volume needs administrator rights, so the volume flush skipped
every volume in a normal user session. The libc, libkernel, save data and
app content file functions now record each host file and directory they
change. On Windows sceKernelSync flushes the recorded paths that changed
since the previous call, plus their changed parent directories, through
handles a normal user can open. Linux still calls sync().
2026-10-08 08:27:22 +00:00
Arvind Frøiland c7083aa4e1 refactor(libkernel): name the Jrs7UUkGOFo Coredump stub by its NID
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 17:24:26 +09:00
Adrià da4027399e
Merge pull request #1125 from TideOPL/feat/ppsa16064-missing-exports
feat(libs): add the unimplemented exports PPSA16064 imports
2026-10-08 10:01:59 +02:00
popcoder565 384078c924 fix(libkernel): retry a raise that interrupts its target inside winpthreads
MinGW's thread_local goes through emutls and winpthreads' pthread_getspecific, which holds a per-thread spinlock. A raise that redirected a thread holding it ran the handler on that same thread, and a handler reading any thread_local, scePthreadSelf for one, spun on the lock forever. A raise that finds the target inside libwinpthread-1.dll now resumes it and suspends it again, as one inside NtContinue does.

guest_raise_exception's new phase raises at a thread that calls scePthreadSelf in a loop and checks that the handler sees its own thread. It hung in every run without the retry. TechnicalDebt records that a handler can still reenter other host code the thread was interrupted in.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 03:43:13 -04:00
popcoder565 175846186a fix(libkernel): read the raise target's context before choosing APC delivery
SuspendThread returns before the thread has stopped, and GetThreadContext waits until it has. waitCount was read right after SuspendThread, so a thread that was leaving its wait could still decrement it and drain its APCs with NtTestAlert before QueueUserAPC queued the delivery, which then waited for an alertable wait that never came. The context is now read first, so waitCount is read from a stopped thread.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 00:53:58 -04:00
popcoder565 f8c1e0c64f fix(libkernel): keep sceKernelRaiseException redirects out of NtContinue
A raised exception redirects the target thread to a stub that runs the handler and returns through RtlRestoreContext. On Windows 10 (19045) RtlRestoreContext restores in user mode only when the context flags are exactly CONTEXT_FULL | CONTEXT_SEGMENTS (CONTEXT_XSTATE aside); for the CONTEXT_FULL | CONTEXT_FLOATING_POINT context it was given, it calls NtContinue. When the next raise suspended the thread inside that system call, NtContinue then replaced the redirected context with the one it was restoring, so the handler never ran although sceKernelRaiseException had returned 0. guest_raise_exception lost such a delivery to its busy thread in about one run in five and hung until the ctest timeout.

The context is now read with CONTEXT_SEGMENTS, so the handler returns through the user-mode restore, and a raise that finds the thread inside NtContinue or NtContinueEx (an APC or an exception handler returning) resumes it and suspends it again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 23:48:16 -04:00
Adrià e674a6384d
Merge pull request #760 from merwie/feat/kernel-raise-exception-windows
feat(libkernel): deliver sceKernelRaiseException on Windows
2026-10-07 22:27:39 +02:00
Dean 9e965c5cd2
Merge pull request #1115 from Fishybeing/fix/rtld-nominmax
build(windows): guard NOMINMAX in Rtld.cpp
2026-10-08 09:23:49 +13:00
Merijn 2654e3a4ca fix(kernel): drain raised exceptions when leaving an alertable wait
A raise that suspends the thread after its wait returned but before the
wait count drops queued an APC that only ran at the next alertable wait.
Pending APCs are now run right after the count drops. The 0 ms poll in
Condition::waitSignalUntil runs under queueLock and is no longer
alertable, and a target that exits during the raise returns ESRCH.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 22:11:29 +02:00
Merijn e5b44c4536 Merge branch 'main' of https://github.com/boykopovar/AnyPS5 into feat/kernel-raise-exception-windows
# Conflicts:
#	docs/dev/TechnicalDebt.md
2026-10-07 21:23:46 +02:00