diff --git a/reactos/ntoskrnl/ex/sysinfo.c b/reactos/ntoskrnl/ex/sysinfo.c index 084744df023..9ec4a3c8eed 100644 --- a/reactos/ntoskrnl/ex/sysinfo.c +++ b/reactos/ntoskrnl/ex/sysinfo.c @@ -15,6 +15,7 @@ #define NDEBUG #include +extern PEPROCESS PsIdleProcess; extern ULONG NtGlobalFlag; /* FIXME: it should go in a ddk/?.h */ ULONGLONG STDCALL KeQueryInterruptTime(VOID); @@ -611,13 +612,20 @@ QSI_DEF(SystemProcessInformation) SpiCur->ProcessName.Buffer = (void*)(pCur+curSize); // copy name to the end of the struct - RtlInitAnsiString(&imgName, pr->ImageFileName); - RtlAnsiStringToUnicodeString(&SpiCur->ProcessName, &imgName, FALSE); + if(pr != PsIdleProcess) + { + RtlInitAnsiString(&imgName, pr->ImageFileName); + RtlAnsiStringToUnicodeString(&SpiCur->ProcessName, &imgName, FALSE); + } + else + { + RtlInitUnicodeString(&SpiCur->ProcessName, NULL); + } SpiCur->BasePriority = pr->Pcb.BasePriority; SpiCur->ProcessId = pr->UniqueProcessId; SpiCur->InheritedFromProcessId = pr->InheritedFromUniqueProcessId; - SpiCur->HandleCount = ObpGetHandleCountByHandleTable(pr->ObjectTable); + SpiCur->HandleCount = (pr->ObjectTable ? ObpGetHandleCountByHandleTable(pr->ObjectTable) : 0); SpiCur->VmCounters.PeakVirtualSize = pr->PeakVirtualSize; SpiCur->VmCounters.VirtualSize = pr->VirtualSize.QuadPart; SpiCur->VmCounters.PageFaultCount = pr->LastFaultCount; @@ -670,10 +678,6 @@ QSI_DEF(SystemProcessInformation) } while ((pr != syspr) && (pr != NULL)); *ReqSize = ovlSize; - if (pr != NULL) - { - ObDereferenceObject(pr); - } return (STATUS_SUCCESS); } @@ -849,7 +853,7 @@ QSI_DEF(SystemHandleInformation) do { - hCount = hCount + ObpGetHandleCountByHandleTable(pr->ObjectTable); + hCount = hCount + (pr->ObjectTable ? ObpGetHandleCountByHandleTable(pr->ObjectTable) : 0); pr = PsGetNextProcess(pr); if ((pr == syspr) || (pr == NULL)) @@ -858,11 +862,6 @@ QSI_DEF(SystemHandleInformation) DPRINT("SystemHandleInformation 2\n"); - if (pr != NULL) - { - ObDereferenceObject(pr); - } - curSize = sizeof(SYSTEM_HANDLE_INFORMATION)+ ( (sizeof(SYSTEM_HANDLE_TABLE_ENTRY_INFO) * hCount) - (sizeof(SYSTEM_HANDLE_TABLE_ENTRY_INFO) )); @@ -883,9 +882,9 @@ QSI_DEF(SystemHandleInformation) do { - int Count = 0, HandleCount = 0; + int Count = 0, HandleCount; - HandleCount = ObpGetHandleCountByHandleTable(pr->ObjectTable); + HandleCount = (pr->ObjectTable ? ObpGetHandleCountByHandleTable(pr->ObjectTable) : 0); for (Count = 0; HandleCount > 0 ; HandleCount--) { @@ -900,12 +899,6 @@ QSI_DEF(SystemHandleInformation) break; } while ((pr != syspr) && (pr != NULL)); - - if (pr != NULL) - { - ObDereferenceObject(pr); - } - DPRINT("SystemHandleInformation 4\n"); return (STATUS_SUCCESS); diff --git a/reactos/ntoskrnl/ps/idle.c b/reactos/ntoskrnl/ps/idle.c index 11e846408e3..430d4acd001 100644 --- a/reactos/ntoskrnl/ps/idle.c +++ b/reactos/ntoskrnl/ps/idle.c @@ -16,6 +16,8 @@ /* GLOBALS *******************************************************************/ +extern PEPROCESS PsIdleProcess; + /* FUNCTIONS *****************************************************************/ /** System idle thread procedure @@ -53,8 +55,8 @@ PsInitIdleThread(VOID) NTSTATUS Status; PETHREAD IdleThread; KIRQL oldIrql; - - Status = PsInitializeThread(NULL, + + Status = PsInitializeThread(PsIdleProcess, &IdleThread, NULL, KernelMode, diff --git a/reactos/ntoskrnl/ps/process.c b/reactos/ntoskrnl/ps/process.c index 651c8dda8cf..ed1788bd912 100644 --- a/reactos/ntoskrnl/ps/process.c +++ b/reactos/ntoskrnl/ps/process.c @@ -19,6 +19,7 @@ VOID INIT_FUNCTION PsInitClientIDManagment(VOID); PEPROCESS EXPORTED PsInitialSystemProcess = NULL; +PEPROCESS PsIdleProcess = NULL; POBJECT_TYPE EXPORTED PsProcessType = NULL; @@ -120,34 +121,36 @@ PsGetNextProcess(PEPROCESS OldProcess) if (OldProcess == NULL) { - Status = ObReferenceObjectByPointer(PsInitialSystemProcess, + Status = ObReferenceObjectByPointer(PsIdleProcess, PROCESS_ALL_ACCESS, PsProcessType, KernelMode); if (!NT_SUCCESS(Status)) { - CPRINT("PsGetNextProcess(): ObReferenceObjectByPointer failed for PsInitialSystemProcess\n"); + CPRINT("PsGetNextProcess(): ObReferenceObjectByPointer failed for PsIdleProcess\n"); KEBUGCHECK(0); } - return PsInitialSystemProcess; + return PsIdleProcess; } ExAcquireFastMutex(&PspActiveProcessMutex); NextProcess = OldProcess; while (1) { - if (NextProcess->ProcessListEntry.Blink == &PsActiveProcessHead) + PLIST_ENTRY Flink = (NextProcess == PsIdleProcess ? PsActiveProcessHead.Flink : + NextProcess->ProcessListEntry.Flink); + if (Flink != &PsActiveProcessHead) { - NextProcess = CONTAINING_RECORD(PsActiveProcessHead.Blink, - EPROCESS, - ProcessListEntry); + NextProcess = CONTAINING_RECORD(Flink, + EPROCESS, + ProcessListEntry); } else { - NextProcess = CONTAINING_RECORD(NextProcess->ProcessListEntry.Blink, - EPROCESS, - ProcessListEntry); + NextProcess = NULL; + break; } + Status = ObReferenceObjectByPointer(NextProcess, PROCESS_ALL_ACCESS, PsProcessType, @@ -162,8 +165,7 @@ PsGetNextProcess(PEPROCESS OldProcess) } else if (!NT_SUCCESS(Status)) { - CPRINT("PsGetNextProcess(): ObReferenceObjectByPointer failed\n"); - KEBUGCHECK(0); + continue; } } @@ -362,6 +364,44 @@ PsInitProcessManagment(VOID) RtlZeroMemory(PiProcessNotifyRoutine, sizeof(PiProcessNotifyRoutine)); RtlZeroMemory(PiLoadImageNotifyRoutine, sizeof(PiLoadImageNotifyRoutine)); + /* + * Initialize the idle process + */ + Status = ObCreateObject(KernelMode, + PsProcessType, + NULL, + KernelMode, + NULL, + sizeof(EPROCESS), + 0, + 0, + (PVOID*)&PsIdleProcess); + if (!NT_SUCCESS(Status)) + { + DPRINT1("Failed to create the idle process object, Status: 0x%x\n", Status); + KEBUGCHECK(0); + return; + } + + RtlZeroMemory(PsIdleProcess, sizeof(EPROCESS)); + + PsIdleProcess->Pcb.Affinity = 0xFFFFFFFF; + PsIdleProcess->Pcb.IopmOffset = 0xffff; + PsIdleProcess->Pcb.LdtDescriptor[0] = 0; + PsIdleProcess->Pcb.LdtDescriptor[1] = 0; + PsIdleProcess->Pcb.BasePriority = PROCESS_PRIO_IDLE; + PsIdleProcess->Pcb.ThreadQuantum = 6; + InitializeListHead(&PsIdleProcess->Pcb.ThreadListHead); + InitializeListHead(&PsIdleProcess->ThreadListHead); + InitializeListHead(&PsIdleProcess->ProcessListEntry); + KeInitializeDispatcherHeader(&PsIdleProcess->Pcb.DispatcherHeader, + ProcessObject, + sizeof(EPROCESS), + FALSE); + PsIdleProcess->Pcb.DirectoryTableBase = + (LARGE_INTEGER)(LONGLONG)(ULONG)MmGetPageDirectory(); + strcpy(PsInitialSystemProcess->ImageFileName, "Idle"); + /* * Initialize the system process */ @@ -376,7 +416,9 @@ PsInitProcessManagment(VOID) (PVOID*)&PsInitialSystemProcess); if (!NT_SUCCESS(Status)) { - return; + DPRINT1("Failed to create the system process object, Status: 0x%x\n", Status); + KEBUGCHECK(0); + return; } /* System threads may run on any processor. */ @@ -886,7 +928,7 @@ exitdereferenceobjects: Process->Win32WindowStation = (HANDLE)0; ExAcquireFastMutex(&PspActiveProcessMutex); - InsertHeadList(&PsActiveProcessHead, &Process->ProcessListEntry); + InsertTailList(&PsActiveProcessHead, &Process->ProcessListEntry); InitializeListHead(&Process->ThreadListHead); ExReleaseFastMutex(&PspActiveProcessMutex); diff --git a/reactos/ntoskrnl/ps/thread.c b/reactos/ntoskrnl/ps/thread.c index c8f80637877..08a0a10dd02 100644 --- a/reactos/ntoskrnl/ps/thread.c +++ b/reactos/ntoskrnl/ps/thread.c @@ -28,6 +28,7 @@ /* GLOBALS ******************************************************************/ extern LIST_ENTRY PsActiveProcessHead; +extern PEPROCESS PsIdleProcess; POBJECT_TYPE EXPORTED PsThreadType = NULL; @@ -703,7 +704,7 @@ PsPrepareForApplicationProcessorInit(ULONG Id) PETHREAD IdleThread; PKPRCB Prcb = ((PKPCR)((ULONG_PTR)KPCR_BASE + Id * PAGE_SIZE))->Prcb; - PsInitializeThread(NULL, + PsInitializeThread(PsIdleProcess, &IdleThread, NULL, KernelMode,