Initial implementation of the thread initialization

This commit is contained in:
2023-02-23 20:11:21 +01:00
parent 9c083dc050
commit c4d1f1cd0d
13 changed files with 356 additions and 13 deletions

View File

@@ -51,6 +51,178 @@ KeInitializeThread(IN PKTHREAD Thread,
IN PVOID EnvironmentBlock,
IN PKPROCESS Process)
{
UNIMPLEMENTED;
return STATUS_NOT_IMPLEMENTED;
PKWAIT_BLOCK TimerWaitBlock;
BOOLEAN Allocation;
XTSTATUS Status;
ULONG Index;
/* Initialize thread dispatcher header */
Thread->Header.Type = ThreadObject;
Thread->Header.SignalState = 0;
/* Initialize thread wait list */
RtlInitializeListHead(&Thread->Header.WaitListHead);
/* Initialize thread mutant list head */
RtlInitializeListHead(&Thread->MutantListHead);
/* Initialize the builtin wait blocks */
for(Index = 0; Index <= KTHREAD_WAIT_BLOCK; Index++)
{
Thread->WaitBlock[Index].Thread = Thread;
}
/* Initialize stack resident and stack swap */
Thread->AutoAlignment = Process->AutoAlignment;
Thread->StackResident = TRUE;
Thread->StackSwap = TRUE;
Thread->SwapBusy = FALSE;
/* Set priority adjustment reason */
Thread->AdjustReason = AdjustNone;
/* Initialize thread lock */
KeInitializeSpinLock(&Thread->ThreadLock);
/* Set thread service table */
Thread->ServiceTable = KeServiceDescriptorTable;
/* Initialize thread APC */
Thread->ApcStatePointer[0] = &Thread->ApcState;
Thread->ApcStatePointer[1] = &Thread->SavedApcState;
Thread->ApcQueueable = TRUE;
Thread->ApcState.Process = Process;
Thread->Process = Process;
/* Initialize APC list heads */
RtlInitializeListHead(&Thread->ApcState.ApcListHead[KernelMode]);
RtlInitializeListHead(&Thread->ApcState.ApcListHead[UserMode]);
/* Initialize APC queue lock */
KeInitializeSpinLock(&Thread->ApcQueueLock);
/* Initialize kernel-mode suspend APC */
KeInitializeApc(&Thread->SuspendApc, Thread, OriginalApcEnvironment, KepSuspendNop,
KepSuspendRundown, KepSuspendThread, KernelMode, NULL);
/* Initialize suspend semaphore */
KeInitializeSemaphore(&Thread->SuspendSemaphore, 0, 2);
/* Initialize the builtin timer */
KeInitializeTimer(&Thread->Timer);
TimerWaitBlock = &Thread->WaitBlock[KTIMER_WAIT_BLOCK];
TimerWaitBlock->Object = &Thread->Timer;
TimerWaitBlock->WaitKey = STATUS_TIMEOUT;
TimerWaitBlock->WaitType = WaitAny;
TimerWaitBlock->WaitListEntry.Flink = &(&Thread->Timer)->Header.WaitListHead;
TimerWaitBlock->WaitListEntry.Blink = &(&Thread->Timer)->Header.WaitListHead;
/* Initialize Thread Environment Block*/
Thread->EnvironmentBlock = EnvironmentBlock;
Thread->InitialStack = Stack;
Thread->StackBase = Stack;
Thread->StackLimit = Stack - KERNEL_STACK_SIZE;
/* Initialize thread context */
KepInitializeThreadContext(Thread, SystemRoutine, StartRoutine, StartContext, Context);
/* Mark thread as initialized and run it */
Thread->State = Initialized;
KeStartThread(Thread);
/* Return success */
return STATUS_SUCCESS;
}
/**
* Starts the thread.
*
* @param Thread
* Supplies a pointer to the thread.
*
* @return This routine does not return any value.
*
* @since NT 5.1
*/
XTAPI
VOID
KeStartThread(IN PKTHREAD Thread)
{
UNIMPLEMENTED;
}
/**
* Suspend APC-built thread NOP routine. It takes no actions.
*
* @param Apc
* Supplies a pointer to the APC object.
*
* @param NormalRoutine
* Supplies a pointer to the normal routine set during the APC initialization. Unused by this routine.
*
* @param NormalContext
* Supplies a pointer a context data set during the APC initialization. Unused by this routine.
*
* @param SystemArgument1
* Supplies a pointer to an unused system argument.
*
* @param SystemArgument2
* Supplies a pointer to an unused system argument.
*
* @return This routine does not return any value.
*
* @since XT 1.0
*/
XTAPI
VOID
KepSuspendNop(IN PKAPC Apc,
IN OUT PKNORMAL_ROUTINE *NormalRoutine,
IN OUT PVOID *NormalContext,
IN OUT PVOID *SystemArgument1,
IN OUT PVOID *SystemArgument2)
{
/* No action here */
}
/**
* Suspend APC-built thread rundown routine. It takes no actions.
*
* @param Apc
* Supplies a pointer to the APC object.
*
* @return This routine does not return any value.
*
* @since XT 1.0
*/
XTAPI
VOID
KepSuspendRundown(IN PKAPC Apc)
{
/* No action here */
}
/**
* Suspends thread execution by waiting on the thread's semaphore.
*
* @param NormalContext
* Supplies a pointer a context data set during the APC initialization. Unused by this routine.
*
* @param SystemArgument1
* Supplies a pointer to an unused system argument.
*
* @param SystemArgument2
* Supplies a pointer to an unused system argument.
*
* @return This routine does not return any value.
*
* @since XT 1.0
*/
XTAPI
VOID
KepSuspendThread(IN PVOID NormalContext,
IN PVOID SystemArgument1,
IN PVOID SystemArgument2)
{
UNIMPLEMENTED;
}