On Fri Nov 22 18:30:32 2024 +0000, Brendan Shanks wrote:
Ah I see, the key is "As long as you do it at the same place as the Linux case it should work fine". Right now in `__wine_syscall_dispatcher_return` I'm resetting GSBASE much earlier than the Linux %fs is set, since the `SYSCALL_HAVE_XSAVE` case accesses %gs. Maybe the FP/xstate restore could be moved below the `%rsp > frame` line? Or `xstate_features_mask` could be stored in the syscall frame?
I was able to re-order things so that `%rsp > frame` is the first instruction of `__wine_syscall_dispatcher_return`, followed by the Linux/Mac `fs`/`gs` restore.
I was still getting crashes though, from earlier in the syscall dispatcher after switching to the kernel stack but before GSBASE is set to `pthread_teb`. That accesses `%gs` to get to `pthread_teb`, and there's also an access for `syscall_table`. I think these `%gs` accesses need to be moved to before the kernel stack switch--once we switch to the kernel stack, GSBASE could be set to the TSD at any time by a signal.