Index: dll/ntdll/ldr/ldrinit.c =================================================================== --- dll/ntdll/ldr/ldrinit.c (révision 58535) +++ dll/ntdll/ldr/ldrinit.c (copie de travail) @@ -508,7 +508,7 @@ /* Allocate an Activation Context Stack */ DPRINT("ActivationContextStack %p\n", NtCurrentTeb()->ActivationContextStackPointer); - Status = RtlAllocateActivationContextStack((PVOID*)&NtCurrentTeb()->ActivationContextStackPointer); + Status = RtlAllocateActivationContextStack(&NtCurrentTeb()->ActivationContextStackPointer); if (!NT_SUCCESS(Status)) { DPRINT1("Warning: Unable to allocate ActivationContextStack\n"); @@ -1709,7 +1709,7 @@ } /* Allocate an Activation Context Stack */ - Status = RtlAllocateActivationContextStack((PVOID *)&Teb->ActivationContextStackPointer); + Status = RtlAllocateActivationContextStack(&Teb->ActivationContextStackPointer); if (!NT_SUCCESS(Status)) return Status; // FIXME: Loader private heap is missing Index: dll/win32/kernel32/client/fiber.c =================================================================== --- dll/win32/kernel32/client/fiber.c (révision 58535) +++ dll/win32/kernel32/client/fiber.c (copie de travail) @@ -15,15 +15,15 @@ typedef struct _FIBER /* Field offsets: */ { /* 32 bit 64 bit */ /* this must be the first field */ - LPVOID Parameter; /* 0x00 0x00 */ - struct _EXCEPTION_REGISTRATION_RECORD * ExceptionList; /* 0x04 0x08 */ - LPVOID StackBase; /* 0x08 0x10 */ - LPVOID StackLimit; /* 0x0C 0x18 */ - LPVOID DeallocationStack; /* 0x10 0x20 */ + PVOID Parameter; /* 0x00 0x00 */ + PEXCEPTION_REGISTRATION_RECORD ExceptionList; /* 0x04 0x08 */ + PVOID StackBase; /* 0x08 0x10 */ + PVOID StackLimit; /* 0x0C 0x18 */ + PVOID DeallocationStack; /* 0x10 0x20 */ CONTEXT Context; /* 0x14 0x28 */ ULONG GuaranteedStackBytes; /* 0x2E0 */ PVOID FlsData; /* 0x2E4 */ - PVOID ActivationContextStack; /* 0x2E8 */ + PACTIVATION_CONTEXT_STACK ActivationContextStack; /* 0x2E8 */ } FIBER, *PFIBER; /* PRIVATE FUNCTIONS **********************************************************/ @@ -171,7 +171,7 @@ PFIBER Fiber; NTSTATUS Status; INITIAL_TEB InitialTeb; - PVOID ActivationContextStack = NULL; + PACTIVATION_CONTEXT_STACK ActivationContextStack = NULL; DPRINT("Creating Fiber\n"); /* Check for invalid flags */ @@ -210,9 +210,9 @@ /* Free the fiber */ RtlFreeHeap(GetProcessHeap(), 0, Fiber); - /* Free the activation context */ - DPRINT1("Leaking activation stack because nobody implemented free"); - //RtlFreeActivationContextStack(&ActivationContextStack); + /* Free the activation context stack */ + // DPRINT1("Leaking activation stack because nobody implemented free"); + RtlFreeActivationContextStack(&ActivationContextStack); /* Failure */ BaseSetLastNTError(Status); @@ -271,9 +271,9 @@ /* Get rid of FLS */ if (Fiber->FlsData) BaseRundownFls(Fiber->FlsData); - /* Get rid of the activation stack */ - DPRINT1("Leaking activation stack because nobody implemented free"); - //RtlFreeActivationContextStack(Fiber->ActivationContextStack); + /* Get rid of the activation context stack */ + // DPRINT1("Leaking activation stack because nobody implemented free"); + RtlFreeActivationContextStack(Fiber->ActivationContextStack); /* Free the fiber data */ RtlFreeHeap(GetProcessHeap(), 0, lpFiber); Index: dll/win32/kernel32/client/thread.c =================================================================== --- dll/win32/kernel32/client/thread.c (révision 58535) +++ dll/win32/kernel32/client/thread.c (copie de travail) @@ -171,7 +171,7 @@ ULONG Dummy; PTEB Teb; THREAD_BASIC_INFORMATION ThreadBasicInfo; - PVOID ActivationContextStack = NULL; + PACTIVATION_CONTEXT_STACK ActivationContextStack = NULL; ACTIVATION_CONTEXT_BASIC_INFORMATION ActCtxInfo; ULONG_PTR Cookie; ULONG ReturnLength; @@ -191,7 +191,7 @@ dwCreationFlags & STACK_SIZE_PARAM_IS_A_RESERVATION ? dwStackSize : 0, &InitialTeb); - if(!NT_SUCCESS(Status)) + if (!NT_SUCCESS(Status)) { BaseSetLastNTError(Status); return NULL; @@ -241,7 +241,7 @@ ERROR_DBGBREAK("SXS: %s - Failing thread create because " "NtQueryInformationThread() failed with status %08lx\n", __FUNCTION__, Status); - return NULL; + goto Quit; } /* Allocate the Activation Context Stack */ @@ -252,7 +252,7 @@ ERROR_DBGBREAK("SXS: %s - Failing thread create because " "RtlAllocateActivationContextStack() failed with status %08lx\n", __FUNCTION__, Status); - return NULL; + goto Quit; } /* Save it */ @@ -274,7 +274,13 @@ ERROR_DBGBREAK("SXS: %s - Failing thread create because " "RtlQueryInformationActivationContext() failed with status %08lx\n", __FUNCTION__, Status); - return NULL; + + /* Free the activation context stack */ + // RtlFreeThreadActivationContextStack(); + RtlFreeActivationContextStack(Teb->ActivationContextStackPointer); + Teb->ActivationContextStackPointer = NULL; + + goto Quit; } /* Does it need to be activated? */ @@ -291,7 +297,13 @@ ERROR_DBGBREAK("SXS: %s - Failing thread create because " "RtlActivateActivationContextEx() failed with status %08lx\n", __FUNCTION__, Status); - return NULL; + + /* Free the activation context stack */ + // RtlFreeThreadActivationContextStack(); + RtlFreeActivationContextStack(Teb->ActivationContextStackPointer); + Teb->ActivationContextStackPointer = NULL; + + goto Quit; } } } @@ -299,9 +311,7 @@ /* Notify CSR */ if (!BaseRunningInServerProcess) { - /* Notify CSR */ Status = BasepNotifyCsrOfThread(hThread, &ClientId); - ASSERT(NT_SUCCESS(Status)); } else { @@ -317,19 +327,34 @@ { /* Call it instead of going through LPC */ Status = CsrCreateRemoteThread(hThread, &ClientId); - ASSERT(NT_SUCCESS(Status)); } } } - /* Success */ - if (lpThreadId) *lpThreadId = HandleToUlong(ClientId.UniqueThread); +Quit: + if (NT_SUCCESS(Status)) + { + /* Success */ + if (lpThreadId) *lpThreadId = HandleToUlong(ClientId.UniqueThread); - /* Resume it if asked */ - if (!(dwCreationFlags & CREATE_SUSPENDED)) NtResumeThread(hThread, &Dummy); + /* Resume it if asked */ + if (!(dwCreationFlags & CREATE_SUSPENDED)) NtResumeThread(hThread, &Dummy); - /* Return handle to thread */ - return hThread; + /* Return handle to thread */ + return hThread; + } + else + { + /* Fail */ + Status = STATUS_NO_MEMORY; + + BaseFreeThreadStack(hProcess, &InitialTeb); + NtTerminateThread(hThread, Status); + NtClose(hThread); + BaseSetLastNTError(Status); + + return NULL; + } } /* Index: include/asm/genincdata.c =================================================================== --- include/asm/genincdata.c (révision 58535) +++ include/asm/genincdata.c (copie de travail) @@ -31,14 +31,14 @@ { /* 32 bit 64 bit */ /* this must be the first field */ PVOID Parameter; /* 0x00 0x00 */ - struct _EXCEPTION_REGISTRATION_RECORD * ExceptionList; /* 0x04 0x08 */ + PEXCEPTION_REGISTRATION_RECORD ExceptionList; /* 0x04 0x08 */ PVOID StackBase; /* 0x08 0x10 */ PVOID StackLimit; /* 0x0C 0x18 */ PVOID DeallocationStack; /* 0x10 0x20 */ CONTEXT Context; /* 0x14 0x28 */ ULONG GuaranteedStackBytes; /* 0x2E0 */ PVOID FlsData; /* 0x2E4 */ - PVOID ActivationContextStack; /* 0x2E8 */ + PACTIVATION_CONTEXT_STACK ActivationContextStack; /* 0x2E8 */ } FIBER, *PFIBER; typedef struct Index: include/ndk/rtlfuncs.h =================================================================== --- include/ndk/rtlfuncs.h (révision 58547) +++ include/ndk/rtlfuncs.h (copie de travail) @@ -3503,7 +3503,7 @@ NTSTATUS NTAPI RtlAllocateActivationContextStack( - _In_ PVOID *Context + _In_ PACTIVATION_CONTEXT_STACK *Stack ); NTSYSAPI Index: lib/rtl/actctx.c =================================================================== --- lib/rtl/actctx.c (révision 58547) +++ lib/rtl/actctx.c (copie de travail) @@ -2429,7 +2429,7 @@ VOID NTAPI -RtlFreeActivationContextStack(PACTIVATION_CONTEXT_STACK Stack) +RtlFreeActivationContextStack(IN PACTIVATION_CONTEXT_STACK Stack) { PRTL_ACTIVATION_CONTEXT_STACK_FRAME ActiveFrame, PrevFrame; @@ -2775,15 +2775,15 @@ NTSTATUS NTAPI -RtlAllocateActivationContextStack(IN PVOID *Context) +RtlAllocateActivationContextStack(IN PACTIVATION_CONTEXT_STACK *Stack) { PACTIVATION_CONTEXT_STACK ContextStack; /* Check if it's already allocated */ - if (*Context) return STATUS_SUCCESS; + if (*Stack) return STATUS_SUCCESS; /* Allocate space for the context stack */ - ContextStack = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, sizeof (ACTIVATION_CONTEXT_STACK) ); + ContextStack = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(ACTIVATION_CONTEXT_STACK)); if (!ContextStack) { return STATUS_NO_MEMORY; @@ -2796,7 +2796,7 @@ ContextStack->NextCookieSequenceNumber = 1; ContextStack->StackId = 1; //TODO: Timer-based - *Context = ContextStack; + *Stack = ContextStack; return STATUS_SUCCESS; }