Try to allocate new stack for a thread if needed
This commit is contained in:
parent
a6c3924b56
commit
02f35dbd8c
@ -52,8 +52,13 @@ KeInitializeThread(IN PKPROCESS Process,
|
|||||||
IN PVOID Stack)
|
IN PVOID Stack)
|
||||||
{
|
{
|
||||||
PKWAIT_BLOCK TimerWaitBlock;
|
PKWAIT_BLOCK TimerWaitBlock;
|
||||||
|
BOOLEAN Allocation;
|
||||||
|
XTSTATUS Status;
|
||||||
ULONG Index;
|
ULONG Index;
|
||||||
|
|
||||||
|
/* No stack allocation was done yet */
|
||||||
|
Allocation = FALSE;
|
||||||
|
|
||||||
/* Initialize thread dispatcher header */
|
/* Initialize thread dispatcher header */
|
||||||
Thread->Header.Type = ThreadObject;
|
Thread->Header.Type = ThreadObject;
|
||||||
Thread->Header.SignalState = 0;
|
Thread->Header.SignalState = 0;
|
||||||
@ -118,6 +123,21 @@ KeInitializeThread(IN PKPROCESS Process,
|
|||||||
/* Initialize Thread Environment Block*/
|
/* Initialize Thread Environment Block*/
|
||||||
Thread->EnvironmentBlock = EnvironmentBlock;
|
Thread->EnvironmentBlock = EnvironmentBlock;
|
||||||
|
|
||||||
|
/* Make sure there is a valid stack available */
|
||||||
|
if(!Stack)
|
||||||
|
{
|
||||||
|
/* Allocate new stack */
|
||||||
|
Status = MmAllocateKernelStack(&Stack, FALSE, 0);
|
||||||
|
if(Status != STATUS_SUCCESS || !Stack)
|
||||||
|
{
|
||||||
|
/* Stack allocation failed */
|
||||||
|
return STATUS_INSUFFICIENT_RESOURCES;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Mark allocation as successful */
|
||||||
|
Allocation = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
Thread->InitialStack = Stack;
|
Thread->InitialStack = Stack;
|
||||||
Thread->StackBase = Stack;
|
Thread->StackBase = Stack;
|
||||||
Thread->StackLimit = Stack - KERNEL_STACK_SIZE;
|
Thread->StackLimit = Stack - KERNEL_STACK_SIZE;
|
||||||
@ -129,7 +149,16 @@ KeInitializeThread(IN PKPROCESS Process,
|
|||||||
}
|
}
|
||||||
__except(EXCEPTION_EXECUTE_HANDLER)
|
__except(EXCEPTION_EXECUTE_HANDLER)
|
||||||
{
|
{
|
||||||
/* Failed to initialize thread context */
|
/* Failed to initialize thread context, check stack allocation */
|
||||||
|
if(Allocation)
|
||||||
|
{
|
||||||
|
/* Deallocate stack */
|
||||||
|
MmFreeKernelStack(Stack, FALSE);
|
||||||
|
Thread->InitialStack = NULL;
|
||||||
|
Thread->StackBase = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Thread initialization failed */
|
||||||
return STATUS_UNSUCCESSFUL;
|
return STATUS_UNSUCCESSFUL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user