diff --git a/dlls/kernel32/tests/thread.c b/dlls/kernel32/tests/thread.c index 0f3564f4bfc..33797d84892 100644 --- a/dlls/kernel32/tests/thread.c +++ b/dlls/kernel32/tests/thread.c @@ -287,7 +287,6 @@ static DWORD WINAPI thread_actctx_func(void *p) cur = (void*)0xdeadbeef; ret = pGetCurrentActCtx(&cur); ok(ret, "thread GetCurrentActCtx failed, %u\n", GetLastError()); -todo_wine ok(cur == param->handle, "got %p, expected %p\n", cur, param->handle); param->thread_context = cur; @@ -1550,6 +1549,17 @@ static void test_thread_actctx(void) ok(b, "GetCurentActCtx failed: %u\n", GetLastError()); ok(handle == 0, "active context %p\n", handle); + /* without active context */ + param.thread_context = (void*)0xdeadbeef; + param.handle = NULL; + thread = CreateThread(NULL, 0, thread_actctx_func, ¶m, 0, &tid); + ok(thread != NULL, "failed, got %u\n", GetLastError()); + + ret = WaitForSingleObject(thread, 1000); + ok(ret == WAIT_OBJECT_0, "wait timeout\n"); + ok(param.thread_context == NULL, "got wrong thread context %p\n", param.thread_context); + CloseHandle(thread); + b = pActivateActCtx(context, &cookie); ok(b, "activation failed: %u\n", GetLastError()); @@ -1568,7 +1578,6 @@ static void test_thread_actctx(void) ret = WaitForSingleObject(thread, 1000); ok(ret == WAIT_OBJECT_0, "wait timeout\n"); -todo_wine ok(param.thread_context == context, "got wrong thread context %p, %p\n", param.thread_context, context); CloseHandle(thread); @@ -1579,7 +1588,6 @@ todo_wine ret = WaitForSingleObject(thread, 1000); ok(ret == WAIT_OBJECT_0, "wait timeout\n"); -todo_wine ok(param.thread_context == context, "got wrong thread context %p, %p\n", param.thread_context, context); CloseHandle(thread); diff --git a/dlls/ntdll/thread.c b/dlls/ntdll/thread.c index 703e83cf1be..9c34c0c2603 100644 --- a/dlls/ntdll/thread.c +++ b/dlls/ntdll/thread.c @@ -432,7 +432,7 @@ NTSTATUS WINAPI RtlCreateUserThread( HANDLE process, const SECURITY_DESCRIPTOR * pthread_attr_t attr; struct ntdll_thread_data *thread_data; struct startup_info *info = NULL; - HANDLE handle = 0; + HANDLE handle = 0, actctx = 0; TEB *teb = NULL; DWORD tid = 0; int request_pipe[2]; @@ -497,6 +497,21 @@ NTSTATUS WINAPI RtlCreateUserThread( HANDLE process, const SECURITY_DESCRIPTOR * teb->StaticUnicodeString.Buffer = teb->StaticUnicodeBuffer; teb->StaticUnicodeString.MaximumLength = sizeof(teb->StaticUnicodeBuffer); + /* create default activation context frame for new thread */ + RtlGetActiveActivationContext(&actctx); + if (actctx) + { + RTL_ACTIVATION_CONTEXT_STACK_FRAME *frame; + + frame = RtlAllocateHeap(GetProcessHeap(), 0, sizeof(*frame)); + frame->Previous = NULL; + frame->ActivationContext = actctx; + frame->Flags = 0; + teb->ActivationContextStack.ActiveFrame = frame; + + RtlAddRefActivationContext(actctx); + } + info = (struct startup_info *)(teb + 1); info->teb = teb; info->entry_point = start;