[PATCH 2/2] ntdll: Report SegDs to be identical to SegSs in x86_64 exception handlers.
Zebediah Figura
z.figura12 at gmail.com
Wed Mar 24 22:47:55 CDT 2021
Based on a patch by Dávid Török.
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=47970
Signed-off-by: Zebediah Figura <z.figura12 at gmail.com>
---
Actually, the behaviour of segment registers on x86_64 Windows is more
complicated:
* By default, %ss == %ds == %es == %gs == 0x2b; %cs == 0x33; %fs == 0x53.
* NtGetContextThread() does not capture the actual values, but instead returns
the default values.
* All system calls restore all segments to their default values, including
NtContinue().
* RtlRestoreContext() also restores all segments to their default values.
* SegDs, SegEs, SegFs, SegGs all restore default values in exception handlers;
SegSs returns the actual value of %ss.
* RtlCaptureContext() does capture the actual values.
I did not test:
* whether %cs is correctly captured or restored in any functions;
* whether segment registers are restored from exception handlers (either to
the default values or to the values set in the context).
We could, to a point, emulate the above, but it gets tricky. According to the
Intel 64 and IA-32 Architectures Software Developer's Manual:
* %es, %ds, %ss can point to any segment—the entire contents of the descriptor
table are effectively ignored (if I'm reading Volume 3 §3.4.4 right). However,
they have to point to a *valid* segment (cf. Volume 1 §3.4.2.1).
* %cs is more restricted—the attributes in the descriptor table are also
validated (Volume 3 §5.2.1).
* I don't even know about %fs and %gs; the manual is too vague and confusing.
dlls/ntdll/tests/exception.c | 2 +-
dlls/ntdll/unix/signal_x86_64.c | 8 +++-----
2 files changed, 4 insertions(+), 6 deletions(-)
diff --git a/dlls/ntdll/tests/exception.c b/dlls/ntdll/tests/exception.c
index e2a8071168d..90af9de1bba 100644
--- a/dlls/ntdll/tests/exception.c
+++ b/dlls/ntdll/tests/exception.c
@@ -3000,7 +3000,7 @@ static DWORD WINAPI handler( EXCEPTION_RECORD *rec, ULONG64 frame,
"%u: Unexpected exception address %p/%p\n", entry,
rec->ExceptionAddress, (char*)context->Rip );
- todo_wine ok( context->SegDs == context->SegSs,
+ ok( context->SegDs == context->SegSs,
"%u: ds %#x does not match ss %#x\n", entry, context->SegDs, context->SegSs );
if (except->status == STATUS_BREAKPOINT && is_wow64)
diff --git a/dlls/ntdll/unix/signal_x86_64.c b/dlls/ntdll/unix/signal_x86_64.c
index 7dab5fbf4ed..814f2824129 100644
--- a/dlls/ntdll/unix/signal_x86_64.c
+++ b/dlls/ntdll/unix/signal_x86_64.c
@@ -1500,11 +1500,6 @@ static void save_context( struct xcontext *xcontext, const ucontext_t *sigcontex
context->SegFs = FS_sig(sigcontext);
context->SegGs = GS_sig(sigcontext);
context->EFlags = EFL_sig(sigcontext);
-#ifdef DS_sig
- context->SegDs = DS_sig(sigcontext);
-#else
- __asm__("movw %%ds,%0" : "=m" (context->SegDs));
-#endif
#ifdef ES_sig
context->SegEs = ES_sig(sigcontext);
#else
@@ -1515,6 +1510,9 @@ static void save_context( struct xcontext *xcontext, const ucontext_t *sigcontex
#else
__asm__("movw %%ss,%0" : "=m" (context->SegSs));
#endif
+ /* Legends of Runeterra depends on having SegDs == SegSs in an exception
+ * handler. */
+ context->SegDs = context->SegSs;
context->Dr0 = amd64_thread_data()->dr0;
context->Dr1 = amd64_thread_data()->dr1;
context->Dr2 = amd64_thread_data()->dr2;
--
2.30.2
More information about the wine-devel
mailing list