A raise delivered some other way (the deliverer sampled the target in guest
code and redirected it) disarms the return breakpoint by clearing DR0 and
DR7 with SetThreadContext. When the target reaches the armed return address
at the same moment, the debug exception is already raised but the context
Windows hands to the handler carries the cleared registers: DR0, DR6 and DR7
are 0. ReturnBreakHandler required DR6.B0, so it declined, and the unhandled
EXCEPTION_SINGLE_STEP ended the process with 0x80000004. Under parallel load
guest_raise_in_host_code failed this way 18 times in 900 runs; a diagnostic
in the declining branch showed every failure at an address armed earlier on
that same thread, with no live return break, DR0 = DR6 = DR7 = 0 and TF
clear.
The ring of armed addresses now records the thread with each address. A
single-step that has TF clear, no breakpoint hit in DR6 and no breakpoint
enabled in DR7, at an address this library armed on the faulting thread, is
taken as that disarmed return breakpoint and continues; any other
single-step is left to the next handler. A DR0 hit is likewise matched
against the addresses armed on the faulting thread.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
A target in host code got the delivery as an APC as well as through the
return breakpoint and the sampling. An APC runs in any alertable wait,
so host code that waits alertably while holding a lock would have run
the guest handler inside that wait with the lock held. The APC is now
queued only while the target is in a libkernel wait (Pthread waitCount),
the point where the handler already ran before; a target elsewhere in
host code takes the delivery when it returns into guest code.
guest_raise_leaves_host_code adds a target in an alertable
WaitForSingleObjectEx: each raise must return in under 500 ms and the
handler must run in the executable after the wait was released. The
earlier behaviour (an APC for every host-code target) fails it.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
RaiseOn suspended the target and, while it sat in host code, resampled
it until a 50 ms limit and then redirected it into the handler there.
A handler that waits, as Unity's GC thread-stop handler does, then held
whatever host lock the thread had: in Graveyard Keeper 2 a job worker
stopped inside shader specialization kept the shader registration lock,
another worker blocked on that lock never ran its own stop, and the
load froze with 39 of 40 threads acknowledged (about 1 in 15 loads).
A target in host code is never redirected now. The raise queues the
delivery as an APC (taken when the thread waits alertably), arms a
debug register 0 execute breakpoint at the frame's return address into
guest code (found with the image's own .pdata and RtlVirtualUnwind,
stopping at frames that push a machine frame, guarded against faults),
and hands the target to a host deliverer thread that keeps sampling it.
The first of the three to reach the thread delivers, through one taken
flag per delivery. A target in guest code is still redirected at once;
a target inside NtContinue still makes the raise throw after 1 s.
guest_raise_leaves_host_code checks that a handler never runs in host
code, for a target blocked in WaitForSingleObject and one busy in
MultiByteToWideChar, and that each raise of the blocked one returns in
under 500 ms.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
On PS5 firmware 13.60 setpriority(PRIO_PROCESS, 0, v) returns 0 for -25,
-5, 5 and 25, and getpriority keeps returning 0. setpriority keeps its
target checks and returns 0 without storing the value.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Implement pthread_attr_setcreatesuspend_np, pthread_resume_np,
pthread_resume_all_np and pthread_multi_np with the sce forms
scePthreadAttrSetcreatesuspend, scePthreadResume, scePthreadResumeAll
and scePthreadMulti, following FreeBSD 11.4 libthr and the firmware
13.42 libkernel_sys module. A thread created suspended waits before its
start routine, outside any cancellation point, until it is resumed.
sceKernelRaiseException throws on Windows for a thread still suspended
at creation.
A handler that read the mask and put it back with SIG_SETMASK stored its
own signal, which sigprocmask reports from the hold, in the process mask
and cleared the hold, so the signal stayed blocked after the handler
returned. pselect, setcontext and a siglongjmp inside the handler replace
the mask the same way. When the handler's own thread releases a hold, the
signal now gets back its bit from before the handler when the handler
returns, as FreeBSD's sigreturn puts back the mask from before it. A mask
another thread sets meanwhile is kept.
On PS5 firmware 13.60 sceKernelGetProsperoSystemSwVersion and
sceKernelGetSystemSwVersion return 0 for every value in the leading size
field, keep it, write the string and the packed version, and return 0
without writing for a null block.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Main's #10706 moves the declarations of exported functions and their types
into the libraries' public headers, and gives WaitForPendingInSet a
KernelTimespec timeout. The merge keeps this branch's DeliverUnblockedPending
and ChangeBlockedMask with main's KernelTimespec. It takes main's side of
the declarations in GuestSignalSets.cpp, whose setjmp and longjmp this
branch had added and libc's Api.hpp now declares. GuestSignalHandlerMask.cpp
includes the libkernel and libc public headers in place of its own
declarations and GuestSignalSet and GuestSigaction types, as the
public_headers audit requires.
The PS5 3.20 export lists have swapcontext in libkernel as well as
libkernel_sys, and on Windows a libkernel import never reaches
libkernel_sys. The assembly entry in UserContext.cpp now is
swapcontext_nid_postfix, and the libkernel_sys jump stub is gone.