On Thu Dec 5 07:05:59 2024 +0000, Brendan Shanks wrote:
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.
Moving `%gs` accesses to before the kernel stack switch did the trick, `leave_handler` now uses essentially the same check for GSBASE as it does for %fs on Linux. I'm going to do more testing in the morning, but at the moment I think this is good to go.