#include <internal/string.h>
#include <internal/hal.h>
#include <internal/ps.h>
+#include <internal/ob.h>
#define NDEBUG
#include <internal/debug.h>
static PETHREAD CurrentThread = NULL;
-static ULONG NextThreadUniqueId = 0;
+static ULONG NextUniqueThreadId = 0;
/* FUNCTIONS ***************************************************************/
PETHREAD PsGetCurrentThread(VOID)
{
- return((PETHREAD)KeGetCurrentThread());
+ return(CurrentThread);
}
VOID PiTerminateProcessThreads(PEPROCESS Process, NTSTATUS ExitStatus)
KeReleaseSpinLock(&ThreadListLock,PASSIVE_LEVEL);
Ret = StartRoutine(StartContext);
PsTerminateSystemThread(Ret);
- for(;;);
+ KeBugCheck(0);
}
static PETHREAD PsScanThreadList(KPRIORITY Priority)
{
DPRINT("Scheduling current thread\n");
KeQueryTickCount(&TickCount);
- CurrentThread->Tcb.LastTick = GET_LARGE_INTEGER_LOW_PART(TickCount);
+ CurrentThread->Tcb.LastTick = TickCount.LowPart;
CurrentThread->Tcb.ThreadState = THREAD_STATE_RUNNING;
KeReleaseSpinLock(&ThreadListLock,irql);
return;
Candidate->Tcb.ThreadState = THREAD_STATE_RUNNING;
KeQueryTickCount(&TickCount);
- CurrentThread->Tcb.LastTick = GET_LARGE_INTEGER_LOW_PART(TickCount);
+ CurrentThread->Tcb.LastTick = TickCount.LowPart;
CurrentThread = Candidate;
Thread->Tcb.CurrentPriority=THREAD_PRIORITY_NORMAL;
Thread->Tcb.ApcList=ExAllocatePool(NonPagedPool,sizeof(LIST_ENTRY));
Thread->Tcb.SuspendCount = 1;
- if (ProcessHandle!=NULL)
+ if (ProcessHandle != NULL)
{
Status = ObReferenceObjectByHandle(ProcessHandle,
PROCESS_CREATE_THREAD,
}
else
{
- Thread->ThreadsProcess=SystemProcess;
+ Thread->ThreadsProcess = SystemProcess;
ObReferenceObjectByPointer(Thread->ThreadsProcess,
PROCESS_CREATE_THREAD,
PsProcessType,
InitializeListHead(Thread->Tcb.ApcList);
InitializeListHead(&(Thread->IrpList));
Thread->Cid.UniqueThread = (HANDLE)InterlockedIncrement(
- &NextThreadUniqueId);
+ &NextUniqueThreadId);
+ Thread->Cid.UniqueProcess = (HANDLE)Thread->ThreadsProcess->UniqueProcessId;
+ DbgPrint("Thread->Cid.UniqueThread %d\nThread->Cid.UniqueProcess %d\n",
+ Thread->Cid.UniqueThread, Thread->Cid.UniqueThread);
ObReferenceObjectByPointer(Thread,
THREAD_ALL_ACCESS,
PsThreadType,
*ThreadPtr = Thread;
- ObDereferenceObject(Thread->ThreadsProcess);
+ ObDereferenceObject(Thread->ThreadsProcess);
return(STATUS_SUCCESS);
}
VOID PsResumeThread(PETHREAD Thread)
{
DPRINT("PsResumeThread(Thread %x)\n",Thread);
-
Thread->Tcb.SuspendCount--;
- DPRINT("Thread->Tcb.SuspendCount %d\n",Thread->Tcb.SuspendCount);
- DPRINT("Thread->Tcb.ThreadState %d THREAD_STATE_RUNNING %d\n",
- Thread->Tcb.ThreadState,THREAD_STATE_RUNNING);
- if (Thread->Tcb.SuspendCount <= 0 &&
+ if (Thread->Tcb.SuspendCount <= 0 &&
Thread->Tcb.ThreadState != THREAD_STATE_RUNNING)
{
DPRINT("Setting thread to runnable\n");
}
}
-void PsInitThreadManagment(void)
+VOID PiDeleteThread(PVOID ObjectBody)
+{
+ DbgPrint("PiDeleteThread(ObjectBody %x)\n",ObjectBody);
+}
+
+VOID PsInitThreadManagment(VOID)
/*
* FUNCTION: Initialize thread managment
*/
PsThreadType->Dump = NULL;
PsThreadType->Open = NULL;
PsThreadType->Close = NULL;
- PsThreadType->Delete = NULL;
+ PsThreadType->Delete = PiDeleteThread;
PsThreadType->Parse = NULL;
PsThreadType->Security = NULL;
PsThreadType->QueryName = NULL;
Status = PsInitializeThread(ProcessHandle,&Thread,ThreadHandle,
DesiredAccess,ObjectAttributes);
- if (Status != STATUS_SUCCESS)
+ if (!NT_SUCCESS(Status))
{
return(Status);
}
- HalInitTaskWithContext(Thread,ThreadContext);
+ Status = HalInitTaskWithContext(Thread,ThreadContext);
+ if (!NT_SUCCESS(Status))
+ {
+ return(Status);
+ }
Thread->StartAddress=NULL;
if (Client!=NULL)
Status = PsInitializeThread(ProcessHandle,&Thread,ThreadHandle,
DesiredAccess,ObjectAttributes);
- if (Status != STATUS_SUCCESS)
+ if (!NT_SUCCESS(Status))
{
return(Status);
}
Thread->StartAddress=StartRoutine;
- HalInitTask(Thread,StartRoutine,StartContext);
+ Status = HalInitTask(Thread,StartRoutine,StartContext);
+ if (!NT_SUCCESS(Status))
+ {
+ return(Status);
+ }
if (ClientId!=NULL)
{