Use official THREAD_STATE enumeration for thread states

svn path=/trunk/; revision=14671
This commit is contained in:
Alex Ionescu 2005-04-18 15:49:57 +00:00
parent 6733de66c9
commit 610dd8e8bc
16 changed files with 77 additions and 70 deletions

View file

@ -338,7 +338,7 @@ typedef struct _SYSTEM_THREAD_INFORMATION
KPRIORITY Priority;
LONG BasePriority;
ULONG ContextSwitches;
ULONG ThreadState;
LONG ThreadState;
KWAIT_REASON WaitReason;
} SYSTEM_THREAD_INFORMATION, *PSYSTEM_THREAD_INFORMATION;

View file

@ -878,10 +878,10 @@ KdbpCmdThread(ULONG Argc, PCHAR Argv[])
ULONG Eip;
ULONG ul = 0;
PCHAR State, pend, str1, str2;
STATIC CONST PCHAR ThreadStateToString[THREAD_STATE_MAX] =
STATIC CONST PCHAR ThreadStateToString[DeferredReady+1] =
{ "Initialized", "Ready", "Running",
"Suspended", "Frozen", "Terminated1",
"Terminated2", "Blocked" };
"Standby", "Terminated", "Waiting",
"Transition", "DeferredReady" };
ASSERT(KdbCurrentProcess != NULL);
if (Argc >= 2 && _stricmp(Argv[1], "list") == 0)
@ -943,7 +943,7 @@ KdbpCmdThread(ULONG Argc, PCHAR Argv[])
if (Ebp != NULL) /* FIXME: Should we attach to the process to read Ebp[1]? */
KdbpSafeReadMemory(&Eip, Ebp + 1, sizeof (Eip));;
}
if (Thread->Tcb.State < THREAD_STATE_MAX)
if (Thread->Tcb.State < (DeferredReady + 1))
State = ThreadStateToString[Thread->Tcb.State];
else
State = "Unknown";
@ -1001,7 +1001,7 @@ KdbpCmdThread(ULONG Argc, PCHAR Argv[])
}
}
if (Thread->Tcb.State < THREAD_STATE_MAX)
if (Thread->Tcb.State < (DeferredReady + 1))
State = ThreadStateToString[Thread->Tcb.State];
else
State = "Unknown";

View file

@ -572,8 +572,10 @@ QSI_DEF(SystemProcessInformation)
return (STATUS_INFO_LENGTH_MISMATCH); // in case buffer size is too small
}
DPRINT1("getting next proc\n");
syspr = PsGetNextProcess(NULL);
pr = syspr;
DPRINT1("next proc: %x\n", pr);
pCur = (unsigned char *)Spi;
do
@ -661,6 +663,7 @@ QSI_DEF(SystemProcessInformation)
// SpiCur->Threads[i].CreateTime = current->CreateTime;
SpiCur->Threads[i].WaitTime = current->Tcb.WaitTime;
SpiCur->Threads[i].StartAddress = (PVOID) current->StartAddress;
DPRINT1("cid: %d\n", current->Cid.UniqueThread);
SpiCur->Threads[i].ClientId = current->Cid;
SpiCur->Threads[i].Priority = current->Tcb.Priority;
SpiCur->Threads[i].BasePriority = current->Tcb.BasePriority;
@ -672,6 +675,7 @@ QSI_DEF(SystemProcessInformation)
}
pr = PsGetNextProcess(pr);
DPRINT1("next proc: %x\n", pr);
nThreads = 0;
if ((pr == syspr) || (pr == NULL))
{
@ -688,6 +692,7 @@ QSI_DEF(SystemProcessInformation)
}
*ReqSize = ovlSize;
DPRINT1("done\n");
return (STATUS_SUCCESS);
}

View file

@ -49,6 +49,17 @@ struct _KEXCEPTION_FRAME;
#define IPI_REQUEST_DPC 2
#define IPI_REQUEST_FREEZE 3
typedef enum _KTHREAD_STATE {
Initialized,
Ready,
Running,
Standby,
Terminated,
Waiting,
Transition,
DeferredReady,
} THREAD_STATE, *PTHREAD_STATE;
/* MACROS *************************************************************************/
#define KeEnterCriticalRegion(X) \

View file

@ -496,15 +496,6 @@ STDCALL
PspInitializeProcessSecurity(PEPROCESS Process,
PEPROCESS Parent OPTIONAL);
#define THREAD_STATE_INITIALIZED (0)
#define THREAD_STATE_READY (1)
#define THREAD_STATE_RUNNING (2)
#define THREAD_STATE_SUSPENDED (3)
#define THREAD_STATE_FROZEN (4)
#define THREAD_STATE_TERMINATED_1 (5)
#define THREAD_STATE_TERMINATED_2 (6)
#define THREAD_STATE_BLOCKED (7)
#define THREAD_STATE_MAX (8)
/*

View file

@ -151,16 +151,15 @@ static CPU_REGISTER GspRegisters[NUMREGS] =
{ 4, FIELD_OFFSET (KTRAP_FRAME_X86, Gs), FIELD_OFFSET (CONTEXT, SegGs), TRUE }
};
static PCHAR GspThreadStates[THREAD_STATE_MAX] =
{
"Initialized", /* THREAD_STATE_INITIALIZED */
"Ready", /* THREAD_STATE_READY */
"Running", /* THREAD_STATE_RUNNING */
"Suspended", /* THREAD_STATE_SUSPENDED */
"Frozen", /* THREAD_STATE_FROZEN */
"Terminated 1", /* THREAD_STATE_TERMINATED_1 */
"Terminated 2", /* THREAD_STATE_TERMINATED_2 */
"Blocked" /* THREAD_STATE_BLOCKED */
static PCHAR GspThreadStates[DeferredReady+1] =
{ "Initialized",
"Ready",
"Running",
"Standby",
"Terminated",
"Waiting",
"Transition",
"DeferredReady"
};
char *

View file

@ -313,13 +313,13 @@ KiInsertQueueApc(PKAPC Apc,
Thread->ApcState.KernelApcPending = TRUE;
/* Check the Thread State */
if (Thread->State == THREAD_STATE_RUNNING) {
if (Thread->State == Running) {
/* FIXME: Use IPI */
DPRINT ("Requesting APC Interrupt for Running Thread \n");
HalRequestSoftwareInterrupt(APC_LEVEL);
} else if ((Thread->State == THREAD_STATE_BLOCKED) && (Thread->WaitIrql == PASSIVE_LEVEL) &&
} else if ((Thread->State == Waiting) && (Thread->WaitIrql == PASSIVE_LEVEL) &&
((Apc->NormalRoutine == NULL) ||
((!Thread->KernelApcDisable) && (!Thread->ApcState.KernelApcInProgress)))) {
@ -327,7 +327,7 @@ KiInsertQueueApc(PKAPC Apc,
KiAbortWaitThread(Thread, STATUS_KERNEL_APC, PriorityBoost);
}
} else if ((Thread->State == THREAD_STATE_BLOCKED) &&
} else if ((Thread->State == Waiting) &&
(Thread->WaitMode == UserMode) &&
(Thread->Alertable)) {

View file

@ -491,7 +491,7 @@ KiQuantumEnd(VOID)
/* Dispatch the Thread */
KeLowerIrql(DISPATCH_LEVEL);
KiDispatchThread(THREAD_STATE_READY);
KiDispatchThread(Ready);
}
/*

View file

@ -146,7 +146,7 @@ KeCreateApplicationProcessorIdleThread(ULONG Id)
NULL,
KernelMode,
FALSE);
IdleThread->Tcb.State = THREAD_STATE_RUNNING;
IdleThread->Tcb.State = Running;
IdleThread->Tcb.FreezeCount = 0;
IdleThread->Tcb.Affinity = 1 << Id;
IdleThread->Tcb.UserAffinity = 1 << Id;

View file

@ -45,7 +45,7 @@ VOID
KiInsertIntoThreadList(KPRIORITY Priority,
PKTHREAD Thread)
{
ASSERT(THREAD_STATE_READY == Thread->State);
ASSERT(Ready == Thread->State);
ASSERT(Thread->Priority == Priority);
if (Priority >= MAXIMUM_PRIORITY || Priority < LOW_PRIORITY) {
@ -62,7 +62,7 @@ STATIC
VOID
KiRemoveFromThreadList(PKTHREAD Thread)
{
ASSERT(THREAD_STATE_READY == Thread->State);
ASSERT(Ready == Thread->State);
RemoveEntryList(&Thread->QueueListEntry);
if (IsListEmpty(&PriorityListHead[(ULONG)Thread->Priority])) {
@ -89,12 +89,12 @@ KiScanThreadList(KPRIORITY Priority,
current = CONTAINING_RECORD(current_entry, KTHREAD, QueueListEntry);
if (current->State != THREAD_STATE_READY) {
if (current->State != Ready) {
DPRINT1("%d/%d\n", &current, current->State);
}
ASSERT(current->State == THREAD_STATE_READY);
ASSERT(current->State == Ready);
if (current->Affinity & Affinity) {
@ -123,7 +123,7 @@ KiDispatchThreadNoLock(ULONG NewThreadStatus)
CurrentThread->State = (UCHAR)NewThreadStatus;
if (NewThreadStatus == THREAD_STATE_READY) {
if (NewThreadStatus == Ready) {
KiInsertIntoThreadList(CurrentThread->Priority,
CurrentThread);
@ -137,7 +137,7 @@ KiDispatchThreadNoLock(ULONG NewThreadStatus)
if (Candidate == CurrentThread) {
Candidate->State = THREAD_STATE_RUNNING;
Candidate->State = Ready;
KeReleaseDispatcherDatabaseLockFromDpcLevel();
return;
}
@ -149,7 +149,7 @@ KiDispatchThreadNoLock(ULONG NewThreadStatus)
DPRINT("Scheduling %x(%d)\n",Candidate, CurrentPriority);
Candidate->State = THREAD_STATE_RUNNING;
Candidate->State = Ready;
OldThread = CurrentThread;
CurrentThread = Candidate;
@ -199,7 +199,7 @@ KiBlockThread(PNTSTATUS Status,
Thread->WaitBlockList = NULL;
/* Dispatch it and return status */
KiDispatchThreadNoLock (THREAD_STATE_READY);
KiDispatchThreadNoLock (Ready);
if (Status != NULL) *Status = STATUS_KERNEL_APC;
} else {
@ -211,7 +211,7 @@ KiBlockThread(PNTSTATUS Status,
Thread->WaitReason = WaitReason;
/* Dispatch it and return status */
KiDispatchThreadNoLock(THREAD_STATE_BLOCKED);
KiDispatchThreadNoLock(Waiting);
DPRINT("Dispatching Thread as blocked: %d\n", Thread->WaitStatus);
if (Status != NULL) *Status = Thread->WaitStatus;
}
@ -241,17 +241,16 @@ KiUnblockThread(PKTHREAD Thread,
PNTSTATUS WaitStatus,
KPRIORITY Increment)
{
if (THREAD_STATE_TERMINATED_1 == Thread->State ||
THREAD_STATE_TERMINATED_2 == Thread->State) {
if (Terminated == Thread->State) {
DPRINT("Can't unblock thread 0x%x because it's terminating\n",
Thread);
} else if (THREAD_STATE_READY == Thread->State ||
THREAD_STATE_RUNNING == Thread->State) {
} else if (Ready == Thread->State ||
Running == Thread->State) {
DPRINT("Can't unblock thread 0x%x because it's %s\n",
Thread, (Thread->State == THREAD_STATE_READY ? "ready" : "running"));
Thread, (Thread->State == Ready ? "ready" : "running"));
} else {
@ -279,7 +278,7 @@ KiUnblockThread(PKTHREAD Thread,
Thread->WaitStatus = *WaitStatus;
}
Thread->State = THREAD_STATE_READY;
Thread->State = Ready;
KiInsertIntoThreadList(Thread->Priority, Thread);
Processor = KeGetCurrentProcessorNumber();
Affinity = Thread->Affinity;
@ -588,7 +587,7 @@ KeAlertResumeThread(IN PKTHREAD Thread)
if (Thread->Alerted[KernelMode] == FALSE) {
/* If it's Blocked, unblock if it we should */
if (Thread->State == THREAD_STATE_BLOCKED && Thread->Alertable) {
if (Thread->State == Waiting && Thread->Alertable) {
DPRINT("Aborting Wait\n");
KiAbortWaitThread(Thread, STATUS_ALERTED, THREAD_ALERT_INCREMENT);
@ -639,7 +638,7 @@ KeAlertThread(PKTHREAD Thread,
if (PreviousState == FALSE) {
/* If it's Blocked, unblock if it we should */
if (Thread->State == THREAD_STATE_BLOCKED &&
if (Thread->State == Waiting &&
(AlertMode == KernelMode || Thread->WaitMode == AlertMode) &&
Thread->Alertable) {
@ -779,7 +778,7 @@ KeInitializeThread(PKPROCESS Process,
MmUpdatePageDir((PEPROCESS)Process, (PVOID)Thread, sizeof(ETHREAD));
/* Set the Thread to initalized */
Thread->State = THREAD_STATE_INITIALIZED;
Thread->State = Initialized;
/* The Native API function will initialize the TEB field later */
Thread->Teb = NULL;
@ -1017,7 +1016,7 @@ KeRevertToUserAffinityThread(VOID)
/* We need to dispatch a new thread */
CurrentThread->WaitIrql = OldIrql;
KiDispatchThreadNoLock(THREAD_STATE_READY);
KiDispatchThreadNoLock(Ready);
KeLowerIrql(OldIrql);
}
}
@ -1080,7 +1079,7 @@ KeSetSystemAffinityThread(IN KAFFINITY Affinity)
/* We need to dispatch a new thread */
CurrentThread->WaitIrql = OldIrql;
KiDispatchThreadNoLock(THREAD_STATE_READY);
KiDispatchThreadNoLock(Ready);
KeLowerIrql(OldIrql);
}
}
@ -1146,7 +1145,7 @@ KeSetPriorityThread(PKTHREAD Thread,
CurrentThread = KeGetCurrentThread();
if (Thread->State == THREAD_STATE_READY) {
if (Thread->State == Ready) {
KiRemoveFromThreadList(Thread);
Thread->BasePriority = Thread->Priority = (CHAR)Priority;
@ -1154,12 +1153,12 @@ KeSetPriorityThread(PKTHREAD Thread,
if (CurrentThread->Priority < Priority) {
KiDispatchThreadNoLock(THREAD_STATE_READY);
KiDispatchThreadNoLock(Ready);
KeLowerIrql(OldIrql);
return (OldPriority);
}
} else if (Thread->State == THREAD_STATE_RUNNING) {
} else if (Thread->State == Running) {
Thread->BasePriority = Thread->Priority = (CHAR)Priority;
@ -1171,7 +1170,7 @@ KeSetPriorityThread(PKTHREAD Thread,
if (Thread == CurrentThread) {
KiDispatchThreadNoLock(THREAD_STATE_READY);
KiDispatchThreadNoLock(Ready);
KeLowerIrql(OldIrql);
return (OldPriority);
@ -1229,14 +1228,14 @@ KeSetAffinityThread(PKTHREAD Thread,
Thread->Affinity = Affinity;
if (Thread->State == THREAD_STATE_RUNNING) {
if (Thread->State == Running) {
ProcessorMask = 1 << KeGetCurrentKPCR()->ProcessorNumber;
if (Thread == KeGetCurrentThread()) {
if (!(Affinity & ProcessorMask)) {
KiDispatchThreadNoLock(THREAD_STATE_READY);
KiDispatchThreadNoLock(Ready);
KeLowerIrql(OldIrql);
return STATUS_SUCCESS;
}
@ -1318,7 +1317,7 @@ KeTerminateThread(IN KPRIORITY Increment)
}
/* Find a new Thread */
KiDispatchThreadNoLock(THREAD_STATE_TERMINATED_1);
KiDispatchThreadNoLock(Terminated);
}
/*

View file

@ -53,7 +53,6 @@ ULONG KeMemoryMapRangeCount;
ULONG_PTR FirstKrnlPhysAddr;
ULONG_PTR LastKrnlPhysAddr;
ULONG_PTR LastKernelAddress;
volatile BOOLEAN Initialized = FALSE;
ULONG KeLargestCacheLine = 0x40; /* FIXME: Arch-specific */

View file

@ -724,7 +724,7 @@ KiAbortWaitThread(PKTHREAD Thread,
/* If we are blocked, we must be waiting on something also */
DPRINT("KiAbortWaitThread: %x, Status: %x, %x \n", Thread, WaitStatus, Thread->WaitBlockList);
ASSERT((Thread->State == THREAD_STATE_BLOCKED) == (Thread->WaitBlockList != NULL));
ASSERT((Thread->State == Waiting) == (Thread->WaitBlockList != NULL));
/* Remove the Wait Blocks from the list */
DPRINT("Removing waits\n");
@ -886,7 +886,7 @@ KeReleaseDispatcherDatabaseLock(KIRQL OldIrql)
if (!KeIsExecutingDpc() && OldIrql < DISPATCH_LEVEL && KeGetCurrentThread() != NULL &&
KeGetCurrentThread() == KeGetCurrentPrcb()->IdleThread) {
KiDispatchThreadNoLock(THREAD_STATE_READY);
KiDispatchThreadNoLock(Ready);
KeLowerIrql(OldIrql);
} else {

View file

@ -151,7 +151,7 @@ PspDeleteProcess(PVOID ObjectBody)
{
PEPROCESS Process = (PEPROCESS)ObjectBody;
DPRINT1("PiDeleteProcess(ObjectBody %x)\n",Process->UniqueProcessId);
DPRINT("PiDeleteProcess(ObjectBody %x)\n", ObjectBody);
/* Delete the CID Handle */
if(Process->UniqueProcessId != NULL) {
@ -160,6 +160,7 @@ PspDeleteProcess(PVOID ObjectBody)
}
/* KDB hook */
DPRINT1("deleted: %d\n", Process->UniqueProcessId);
KDB_DELETEPROCESS_HOOK(Process);
/* Dereference the Token and release Memory Information */

View file

@ -363,6 +363,7 @@ PspCreateProcess(OUT PHANDLE ProcessHandle,
Status = PsCreateCidHandle(Process,
PsProcessType,
&Process->UniqueProcessId);
DPRINT1("Created CID: %d\n", Process->UniqueProcessId);
if(!NT_SUCCESS(Status))
{
DPRINT1("Failed to create CID handle (unique process ID)! Status: 0x%x\n", Status);
@ -872,7 +873,7 @@ NtOpenProcess(OUT PHANDLE ProcessHandle,
if (ClientId->UniqueThread)
{
/* Get the Process */
DPRINT("Opening by Thread ID: %x\n", ClientId->UniqueThread);
DPRINT1("Opening by Thread ID: %x\n", ClientId->UniqueThread);
Status = PsLookupProcessThreadByCid(ClientId,
&Process,
&Thread);
@ -881,7 +882,7 @@ NtOpenProcess(OUT PHANDLE ProcessHandle,
else
{
/* Get the Process */
DPRINT("Opening by Process ID: %x\n", ClientId->UniqueProcess);
DPRINT1("Opening by Process ID: %x\n", ClientId->UniqueProcess);
Status = PsLookupProcessByProcessId(ClientId->UniqueProcess,
&Process);
DPRINT("Found: %x\n", Process);

View file

@ -104,7 +104,7 @@ PsInitThreadManagment(VOID)
ObpCreateTypeObject(PsThreadType);
PsInitializeThread(NULL, &FirstThread, NULL, KernelMode, TRUE);
FirstThread->Tcb.State = THREAD_STATE_RUNNING;
FirstThread->Tcb.State = Running;
FirstThread->Tcb.FreezeCount = 0;
FirstThread->Tcb.UserAffinity = (1 << 0); /* Set the affinity of the first thread to the boot processor */
FirstThread->Tcb.Affinity = (1 << 0);

View file

@ -164,9 +164,9 @@ VOID PsDumpThreads(BOOLEAN IncludeSystem)
Thread->ThreadsProcess->UniqueProcessId,
Thread->Cid.UniqueThread,
Thread->ThreadsProcess->ImageFileName);
if(Thread->Tcb.State == THREAD_STATE_READY ||
Thread->Tcb.State == THREAD_STATE_SUSPENDED ||
Thread->Tcb.State == THREAD_STATE_BLOCKED)
if(Thread->Tcb.State == Ready ||
Thread->Tcb.State == Standby ||
Thread->Tcb.State == Waiting)
{
ULONG i = 0;
PULONG Esp = (PULONG)Thread->Tcb.KernelStack;
@ -567,6 +567,7 @@ NtCreateThread (
/* create a client id handle */
Status = PsCreateCidHandle (
Thread, PsThreadType, &Thread->Cid.UniqueThread);
DPRINT1("cid: %d\n", Thread->Cid.UniqueThread);
if (!NT_SUCCESS(Status))
{
ObDereferenceObject(Thread);
@ -760,7 +761,7 @@ NtOpenThread(OUT PHANDLE ThreadHandle,
NTSTATUS STDCALL
NtYieldExecution(VOID)
{
KiDispatchThread(THREAD_STATE_READY);
KiDispatchThread(Ready);
return(STATUS_SUCCESS);
}