94447cee
by William Horvath at 2025-08-18T13:10:21+02:00
ntdll: Check for invalid gs_base in the 64-bit segv_handler.
Adapted from check_invalid_gs in signal_i386.c. PE-side code can
manipulate %gs and cause the next call to NtCurrentTeb to segfault, as
the gs_base may be cleared with writes to %gs on x86_64 [1].
This would cause a recursive exception loop, as any PE-side code in the
exception handling chain after the segv_handler would run into the same
problem. So, catch this early, and manually repair the thread's gs_base
with the pthread TEB from the Unix side.
The 32-bit game "Alice: Madness Returns" is one example of this problem
occurring in the real world, when running under WoW64. However, this is
currently handled in Windows under both WoW64 and native 64-bit, so we should
handle both architectures as well.
[1]: https://bugs.winehq.org/show_bug.cgi?id=51152
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=57444