Try to allocate new stack for a thread if needed
All checks were successful
Builds / ExectOS (amd64) (push) Successful in 31s
Builds / ExectOS (i686) (push) Successful in 28s

This commit is contained in:
Rafal Kupiec 2023-11-03 16:04:10 +01:00
parent a6c3924b56
commit 02f35dbd8c
Signed by: belliash
GPG Key ID: 4E829243E0CFE6B4

View File

@ -52,8 +52,13 @@ KeInitializeThread(IN PKPROCESS Process,
IN PVOID Stack)
{
PKWAIT_BLOCK TimerWaitBlock;
BOOLEAN Allocation;
XTSTATUS Status;
ULONG Index;
/* No stack allocation was done yet */
Allocation = FALSE;
/* Initialize thread dispatcher header */
Thread->Header.Type = ThreadObject;
Thread->Header.SignalState = 0;
@ -118,6 +123,21 @@ KeInitializeThread(IN PKPROCESS Process,
/* Initialize Thread Environment Block*/
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->StackBase = Stack;
Thread->StackLimit = Stack - KERNEL_STACK_SIZE;
@ -129,7 +149,16 @@ KeInitializeThread(IN PKPROCESS Process,
}
__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;
}