[PATCH 2/2] ntdll: Clear the first two stack pages in signal_start_thread.

Rémi Bernon rbernon at codeweavers.com
Tue Mar 30 12:30:47 CDT 2021


On 3/30/21 7:24 PM, Rémi Bernon wrote:
> Instead of the whole stack, except for the last one or two pages.
> 
> Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
> ---
>   dlls/ntdll/signal_i386.c   | 5 ++---
>   dlls/ntdll/signal_x86_64.c | 6 ++----
>   2 files changed, 4 insertions(+), 7 deletions(-)
> 
> diff --git a/dlls/ntdll/signal_i386.c b/dlls/ntdll/signal_i386.c
> index 635b8f4de81..cb04206343a 100644
> --- a/dlls/ntdll/signal_i386.c
> +++ b/dlls/ntdll/signal_i386.c
> @@ -507,9 +507,8 @@ __ASM_GLOBAL_FUNC( signal_start_thread,
>                      "leal -12(%esi),%ecx\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"
> -                   "movl %edi,%esp\n\t"
> +                   "movl %ecx,%edi\n\t"
> +                   "subl $0x2000,%edi\n\t"
>                      "subl %edi,%ecx\n\t"
>                      "xorl %eax,%eax\n\t"
>                      "shrl $2,%ecx\n\t"
> diff --git a/dlls/ntdll/signal_x86_64.c b/dlls/ntdll/signal_x86_64.c
> index b5be4f35758..418b3dbba25 100644
> --- a/dlls/ntdll/signal_x86_64.c
> +++ b/dlls/ntdll/signal_x86_64.c
> @@ -1540,10 +1540,8 @@ __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"
> -                   "movq %rdi,%rsp\n\t"
> +                   "movq %rcx,%rdi\n\t"
> +                   "subq $0x2000,%rdi\n\t"
>                      "subq %rdi,%rcx\n\t"
>                      "xorl %eax,%eax\n\t"
>                      "shrq $3,%rcx\n\t"
> 

Also out of curiosity, what was the reason not to clear the last (last 
two on x86_64) stack page(s) here?

I also removed the rsp stores, assuming it wasn't used for rep movs 
anyway but I'm now thinking that maybe all this was here for the case we 
get signaled while clearing the pages?
-- 
Rémi Bernon <rbernon at codeweavers.com>



More information about the wine-devel mailing list