Repository navigation
Exception handler delivery (sceKernelRaiseException, fault handlers) #727
merwie
started this conversation in
Architecture changes
Replies: 1 comment
|
This seems to be formatted as an issue. I would close this discussion and create an issue instead of explaining your problem. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Problem
sceKernelRaiseException(thread, signum)and delivery to handlers installed withsceKernelInstallExceptionHandler(recorded by #724) are not implemented.Unity IL2CPP titles need them for garbage collection. PPSA12544's
Media/Modules/PS5Util.prxinstalls a SIGUSR1 (30) handler and stops each thread withsceKernelRaiseException(thread, 30). The handler runs on the stopped thread, readsuc_mcontext.mc_rsp(offset 0xf8 of the context) and calls Unity's callback, which records the thread and waits throughsceKernelSyncOnAddressWaituntil the collector wakes it. Details: #726.Requirements taken from that code:
(signum, ucontext*)with the PS5 layout:uc_sigmask(16 bytes), 48 bytes, then FreeBSD amd64mcontext(mc_rdi...mc_rsp,mc_rip,mc_rflags,mc_fsbase, ...).AssetGarbageCollectorHelperthreads are inside host waits under libkernel when the first raise happens. The collector waits for every target's handler, so a target that never runs the handler deadlocks the title.Host faults (SIGSEGV, SIGBUS, SIGILL, SIGFPE) to installed handlers are the same mechanism with a synchronous source.
Proposal
Linux. Map the guest signal to a host signal (a real-time signal for SIGUSR1, so it cannot collide with the host's own SIGUSR1 users), deliver it with
pthread_killto the target's native thread, and in a hostSA_SIGINFOhandler convert the hostucontext_tto the PS5 layout, call the guest handler, and copy the result back. Blocked syscalls are interrupted by the host signal; libkernel waits restart or return as their PS5 counterparts do.Windows. There are no asynchronous signals, so two parts:
SuspendThread+GetThreadContext, build the PS5ucontextand a copy of the hostCONTEXTon the target's stack below the red zone, pointripat a trampoline (rdi= signum,rsi= ucontext),SetThreadContext,ResumeThread. The trampoline calls the handler, writes the possibly modified registers back into the savedCONTEXTand returns withRtlRestoreContext.nanosleep, equeue) wait on a per-thread alertable or signalable object as well;sceKernelRaiseExceptionmarks the signal pending and wakes the wait; the wait runs pending handlers on its own thread (with a context describing the return into the wait) and then resumes waiting with the remaining timeout.Faults go through a vectored exception handler that converts
EXCEPTION_POINTERSthe same way, when a guest handler is installed for the signal; otherwise the current crash report stays.Questions
sigprocmaskstate (Signals.cpp) honoured from the start, or is that a follow-up?I am willing to implement this in steps: Linux delivery and Windows running-thread delivery first (each with tests that raise on a busy thread and check the context), then the interruptible waits.
All reactions