When SIGUSR1 is called while running inside `__wine_syscall_dispatcher`, the CPU context is not in a consistent state. To ensure that the captured context is always consistent: * If the SIGUSR1 arrives while saving the context, set a flag and defer handling it until after the context is fully saved. * If the SIGUSR1 arrives while restoring the context, rewind and retry restoring the context from the beginning. The latter relies on context restore being idempotent. The only case where that is not true is when the instrumentation callback is enabled. To address this, first make that path idempotent by saving the user %rip into %r10 in paths that enable the instrumentation callback. This fixes a regression introduced by 0a5f7a710365 which started leaking bogus SP values, but also generally fixes all other register value leaks due to SIGUSR1 racing with the syscall dispatcher. Supersedes: !10232 (FYI, the threadctx test introduced in this MR is stricter and also checks %rip, which will fail with that previous MR). Fixes: 0a5f7a710365 ("ntdll: Switch to the user stack before restoring the %fs register.") \ Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=59333 -- https://gitlab.winehq.org/wine/wine/-/merge_requests/10419