Rémi Bernon : ntdll: Clear the first ~1MB of stack in signal_start_thread.

Alexandre Julliard julliard at winehq.org
Wed Apr 21 15:57:53 CDT 2021


Module: wine
Branch: master
Commit: 96f5968a651609aa22ba482d4b244e6599095735
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=96f5968a651609aa22ba482d4b244e6599095735

Author: Rémi Bernon <rbernon at codeweavers.com>
Date:   Wed Mar 31 12:23:37 2021 +0200

ntdll: Clear the first ~1MB of stack in signal_start_thread.

Instead of the whole stack.

Stack creation in virtual_alloc_thread_stack and RtlCreateUserStack, as
well as Windows rounding logic, enforce a minimum reserved size of 1MB.

There's a few guard and canary pages used on the bottom, plus a few more
on the top for initial context, and we have to keep a bit of space if we
ever need a stack while doing this, so we clear a bit less than 1MB to
be safe.

Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/ntdll/signal_i386.c   | 9 ++++-----
 dlls/ntdll/signal_x86_64.c | 4 +---
 2 files changed, 5 insertions(+), 8 deletions(-)

diff --git a/dlls/ntdll/signal_i386.c b/dlls/ntdll/signal_i386.c
index 635b8f4de81..59d9e1d0df9 100644
--- a/dlls/ntdll/signal_i386.c
+++ b/dlls/ntdll/signal_i386.c
@@ -504,13 +504,12 @@ USHORT WINAPI RtlCaptureStackBackTrace( ULONG skip, ULONG count, PVOID *buffer,
  */
 __ASM_GLOBAL_FUNC( signal_start_thread,
                    "movl 4(%esp),%esi\n\t"   /* context */
-                   "leal -12(%esi),%ecx\n\t"
+                   "leal -12(%esi),%edi\n\t"
                    /* clear the thread stack */
-                   "andl $~0xfff,%ecx\n\t"   /* round down to page size */
-                   "movl %fs:8,%edi\n\t"     /* NtCurrentTeb()->Tib.StackLimit */
-                   "addl $0x1000,%edi\n\t"
+                   "andl $~0xfff,%edi\n\t"   /* round down to page size */
+                   "movl $0xf0000,%ecx\n\t"
+                   "subl %ecx,%edi\n\t"
                    "movl %edi,%esp\n\t"
-                   "subl %edi,%ecx\n\t"
                    "xorl %eax,%eax\n\t"
                    "shrl $2,%ecx\n\t"
                    "rep; stosl\n\t"
diff --git a/dlls/ntdll/signal_x86_64.c b/dlls/ntdll/signal_x86_64.c
index d88f7ae553a..c5a6666f4d2 100644
--- a/dlls/ntdll/signal_x86_64.c
+++ b/dlls/ntdll/signal_x86_64.c
@@ -1544,9 +1544,7 @@ __ASM_GLOBAL_FUNC( signal_start_thread,
                    "movq %rcx,%rbx\n\t"        /* context */
                    /* clear the thread stack */
                    "andq $~0xfff,%rcx\n\t"     /* round down to page size */
-                   "movq %gs:0x30,%rax\n\t"
-                   "movq 0x10(%rax),%rdi\n\t"  /* NtCurrentTeb()->Tib.StackLimit */
-                   "addq $0x2000,%rdi\n\t"
+                   "leaq -0xf0000(%rcx),%rdi\n\t"
                    "movq %rdi,%rsp\n\t"
                    "subq %rdi,%rcx\n\t"
                    "xorl %eax,%eax\n\t"




More information about the wine-cvs mailing list