ntdll: Always use the TEB that was passed to signal_start_thread().

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard 2021-06-14 12:59:05 +02:00
parent 9a430dc6db
commit a5cec4f5fb
2 changed files with 24 additions and 22 deletions

View File

@ -2342,7 +2342,7 @@ void signal_init_process(void)
/*********************************************************************** /***********************************************************************
* init_thread_context * init_thread_context
*/ */
static void init_thread_context( CONTEXT *context, LPTHREAD_START_ROUTINE entry, void *arg ) static void init_thread_context( CONTEXT *context, LPTHREAD_START_ROUTINE entry, void *arg, TEB *teb )
{ {
context->SegCs = get_cs(); context->SegCs = get_cs();
context->SegDs = get_ds(); context->SegDs = get_ds();
@ -2353,7 +2353,7 @@ static void init_thread_context( CONTEXT *context, LPTHREAD_START_ROUTINE entry,
context->EFlags = 0x202; context->EFlags = 0x202;
context->Eax = (DWORD)entry; context->Eax = (DWORD)entry;
context->Ebx = (DWORD)arg; context->Ebx = (DWORD)arg;
context->Esp = (DWORD)NtCurrentTeb()->Tib.StackBase - 16; context->Esp = (DWORD)teb->Tib.StackBase - 16;
context->Eip = (DWORD)pRtlUserThreadStart; context->Eip = (DWORD)pRtlUserThreadStart;
context->FloatSave.ControlWord = 0x27f; context->FloatSave.ControlWord = 0x27f;
((XSAVE_FORMAT *)context->ExtendedRegisters)->ControlWord = 0x27f; ((XSAVE_FORMAT *)context->ExtendedRegisters)->ControlWord = 0x27f;
@ -2369,7 +2369,7 @@ static void init_thread_context( CONTEXT *context, LPTHREAD_START_ROUTINE entry,
/*********************************************************************** /***********************************************************************
* get_initial_context * get_initial_context
*/ */
PCONTEXT DECLSPEC_HIDDEN get_initial_context( LPTHREAD_START_ROUTINE entry, void *arg, BOOL suspend ) PCONTEXT DECLSPEC_HIDDEN get_initial_context( LPTHREAD_START_ROUTINE entry, void *arg, BOOL suspend, TEB *teb )
{ {
CONTEXT *ctx; CONTEXT *ctx;
@ -2377,15 +2377,15 @@ PCONTEXT DECLSPEC_HIDDEN get_initial_context( LPTHREAD_START_ROUTINE entry, void
{ {
CONTEXT context = { CONTEXT_ALL }; CONTEXT context = { CONTEXT_ALL };
init_thread_context( &context, entry, arg ); init_thread_context( &context, entry, arg, teb );
wait_suspend( &context ); wait_suspend( &context );
ctx = (CONTEXT *)((ULONG_PTR)context.Esp & ~15) - 1; ctx = (CONTEXT *)((ULONG_PTR)context.Esp & ~15) - 1;
*ctx = context; *ctx = context;
} }
else else
{ {
ctx = (CONTEXT *)((char *)NtCurrentTeb()->Tib.StackBase - 16) - 1; ctx = (CONTEXT *)((char *)teb->Tib.StackBase - 16) - 1;
init_thread_context( ctx, entry, arg ); init_thread_context( ctx, entry, arg, teb );
} }
pthread_sigmask( SIG_UNBLOCK, &server_block_set, NULL ); pthread_sigmask( SIG_UNBLOCK, &server_block_set, NULL );
ctx->ContextFlags = CONTEXT_FULL | CONTEXT_FLOATING_POINT | CONTEXT_EXTENDED_REGISTERS; ctx->ContextFlags = CONTEXT_FULL | CONTEXT_FLOATING_POINT | CONTEXT_EXTENDED_REGISTERS;
@ -2409,17 +2409,19 @@ __ASM_GLOBAL_FUNC( signal_start_thread,
"pushl %edi\n\t" "pushl %edi\n\t"
__ASM_CFI(".cfi_rel_offset %edi,-12\n\t") __ASM_CFI(".cfi_rel_offset %edi,-12\n\t")
/* store exit frame */ /* store exit frame */
"movl %ebp,%fs:0x1f4\n\t" /* x86_thread_data()->exit_frame */ "movl 24(%ebp),%ecx\n\t" /* teb */
"movl %ebp,0x1f4(%ecx)\n\t" /* x86_thread_data()->exit_frame */
/* set syscall frame */ /* set syscall frame */
"cmpl $0,%fs:0x1f8\n\t" /* x86_thread_data()->syscall_frame */ "cmpl $0,0x1f8(%ecx)\n\t" /* x86_thread_data()->syscall_frame */
"jnz 1f\n\t" "jnz 1f\n\t"
"leal -0x380(%esp),%eax\n\t" /* sizeof(struct syscall_frame) */ "leal -0x380(%esp),%eax\n\t" /* sizeof(struct syscall_frame) */
"andl $~63,%eax\n\t" "andl $~63,%eax\n\t"
"movl %eax,%fs:0x1f8\n" /* x86_thread_data()->syscall_frame */ "movl %eax,0x1f8(%ecx)\n" /* x86_thread_data()->syscall_frame */
/* switch to thread stack */ /* switch to thread stack */
"1:\tmovl %fs:4,%eax\n\t" /* NtCurrentTeb()->StackBase */ "1:\tmovl 4(%ecx),%eax\n\t" /* teb->StackBase */
"leal -0x1004(%eax),%esp\n\t" "leal -0x1000(%eax),%esp\n\t"
/* attach dlls */ /* attach dlls */
"pushl %ecx\n\t" /* teb */
"pushl 16(%ebp)\n\t" /* suspend */ "pushl 16(%ebp)\n\t" /* suspend */
"pushl 12(%ebp)\n\t" /* arg */ "pushl 12(%ebp)\n\t" /* arg */
"pushl 8(%ebp)\n\t" /* entry */ "pushl 8(%ebp)\n\t" /* entry */

View File

@ -2603,13 +2603,13 @@ void signal_init_process(void)
/*********************************************************************** /***********************************************************************
* init_thread_context * init_thread_context
*/ */
static void init_thread_context( CONTEXT *context, LPTHREAD_START_ROUTINE entry, void *arg ) static void init_thread_context( CONTEXT *context, LPTHREAD_START_ROUTINE entry, void *arg, TEB *teb )
{ {
__asm__( "movw %%cs,%0" : "=m" (context->SegCs) ); __asm__( "movw %%cs,%0" : "=m" (context->SegCs) );
__asm__( "movw %%ss,%0" : "=m" (context->SegSs) ); __asm__( "movw %%ss,%0" : "=m" (context->SegSs) );
context->Rcx = (ULONG_PTR)entry; context->Rcx = (ULONG_PTR)entry;
context->Rdx = (ULONG_PTR)arg; context->Rdx = (ULONG_PTR)arg;
context->Rsp = (ULONG_PTR)NtCurrentTeb()->Tib.StackBase - 0x28; context->Rsp = (ULONG_PTR)teb->Tib.StackBase - 0x28;
context->Rip = (ULONG_PTR)pRtlUserThreadStart; context->Rip = (ULONG_PTR)pRtlUserThreadStart;
context->EFlags = 0x200; context->EFlags = 0x200;
context->u.FltSave.ControlWord = 0x27f; context->u.FltSave.ControlWord = 0x27f;
@ -2620,7 +2620,7 @@ static void init_thread_context( CONTEXT *context, LPTHREAD_START_ROUTINE entry,
/*********************************************************************** /***********************************************************************
* get_initial_context * get_initial_context
*/ */
PCONTEXT DECLSPEC_HIDDEN get_initial_context( LPTHREAD_START_ROUTINE entry, void *arg, BOOL suspend ) PCONTEXT DECLSPEC_HIDDEN get_initial_context( LPTHREAD_START_ROUTINE entry, void *arg, BOOL suspend, TEB *teb )
{ {
CONTEXT *ctx; CONTEXT *ctx;
@ -2629,15 +2629,15 @@ PCONTEXT DECLSPEC_HIDDEN get_initial_context( LPTHREAD_START_ROUTINE entry, void
CONTEXT context = { 0 }; CONTEXT context = { 0 };
context.ContextFlags = CONTEXT_ALL; context.ContextFlags = CONTEXT_ALL;
init_thread_context( &context, entry, arg ); init_thread_context( &context, entry, arg, teb );
wait_suspend( &context ); wait_suspend( &context );
ctx = (CONTEXT *)((ULONG_PTR)context.Rsp & ~15) - 1; ctx = (CONTEXT *)((ULONG_PTR)context.Rsp & ~15) - 1;
*ctx = context; *ctx = context;
} }
else else
{ {
ctx = (CONTEXT *)((char *)NtCurrentTeb()->Tib.StackBase - 0x30) - 1; ctx = (CONTEXT *)((char *)teb->Tib.StackBase - 0x30) - 1;
init_thread_context( ctx, entry, arg ); init_thread_context( ctx, entry, arg, teb );
} }
pthread_sigmask( SIG_UNBLOCK, &server_block_set, NULL ); pthread_sigmask( SIG_UNBLOCK, &server_block_set, NULL );
ctx->ContextFlags = CONTEXT_FULL; ctx->ContextFlags = CONTEXT_FULL;
@ -2666,17 +2666,17 @@ __ASM_GLOBAL_FUNC( signal_start_thread,
"movq %r15,8(%rsp)\n\t" "movq %r15,8(%rsp)\n\t"
__ASM_CFI(".cfi_rel_offset %r15,8\n\t") __ASM_CFI(".cfi_rel_offset %r15,8\n\t")
/* store exit frame */ /* store exit frame */
"movq %gs:0x30,%rax\n\t" "movq %rsp,0x320(%r8)\n\t" /* amd64_thread_data()->exit_frame */
"movq %rsp,0x320(%rax)\n\t" /* amd64_thread_data()->exit_frame */
/* set syscall frame */ /* set syscall frame */
"cmpq $0,0x328(%rax)\n\t" /* amd64_thread_data()->syscall_frame */ "cmpq $0,0x328(%r8)\n\t" /* amd64_thread_data()->syscall_frame */
"jnz 1f\n\t" "jnz 1f\n\t"
"leaq -0x400(%rsp),%r10\n\t" /* sizeof(struct syscall_frame) */ "leaq -0x400(%rsp),%r10\n\t" /* sizeof(struct syscall_frame) */
"andq $~63,%r10\n\t" "andq $~63,%r10\n\t"
"movq %r10,0x328(%rax)\n" /* amd64_thread_data()->syscall_frame */ "movq %r10,0x328(%r8)\n" /* amd64_thread_data()->syscall_frame */
/* switch to thread stack */ /* switch to thread stack */
"1:\tmovq 8(%rax),%rax\n\t" /* NtCurrentTeb()->Tib.StackBase */ "1:\tmovq 8(%r8),%rax\n\t" /* teb->Tib.StackBase */
"movq %rcx,%rbx\n\t" /* thunk */ "movq %rcx,%rbx\n\t" /* thunk */
"movq %r8,%rcx\n\t" /* teb */
"leaq -0x1000(%rax),%rsp\n\t" "leaq -0x1000(%rax),%rsp\n\t"
/* attach dlls */ /* attach dlls */
"call " __ASM_NAME("get_initial_context") "\n\t" "call " __ASM_NAME("get_initial_context") "\n\t"