From f1fa92f6fc5e36b011edf68208094ca808d2bbca Mon Sep 17 00:00:00 2001 From: Thomas Bluemel Date: Sun, 13 Mar 2005 23:03:31 +0000 Subject: [PATCH] initialize the handle tables before creating them svn path=/trunk/; revision=14040 --- reactos/ntoskrnl/ex/handle.c | 9 +++++++++ reactos/ntoskrnl/ex/init.c | 18 +++++++++++++++--- reactos/ntoskrnl/ps/process.c | 25 ++++++++++++++++++++++++- reactos/ntoskrnl/ps/psmgr.c | 15 --------------- reactos/ntoskrnl/ps/thread.c | 27 +++++++++++++++++---------- 5 files changed, 65 insertions(+), 29 deletions(-) diff --git a/reactos/ntoskrnl/ex/handle.c b/reactos/ntoskrnl/ex/handle.c index c987614c5e2..1c0d9d39445 100644 --- a/reactos/ntoskrnl/ex/handle.c +++ b/reactos/ntoskrnl/ex/handle.c @@ -77,6 +77,8 @@ static LARGE_INTEGER ExpHandleShortWait; #define IS_VALID_EX_HANDLE(index) \ (((index) & ~VALID_HANDLE_MASK) == 0) +static BOOLEAN ExpInitialized = FALSE; + /******************************************************************************/ VOID @@ -85,6 +87,8 @@ ExpInitializeHandleTables(VOID) ExpHandleShortWait.QuadPart = -50000; InitializeListHead(&ExpHandleTableHead); ExInitializeFastMutex(&ExpHandleTableListLock); + + ExpInitialized = TRUE; } PHANDLE_TABLE @@ -94,6 +98,11 @@ ExCreateHandleTable(IN PEPROCESS QuotaProcess OPTIONAL) PAGED_CODE(); + if(!ExpInitialized) + { + KEBUGCHECK(0); + } + if(QuotaProcess != NULL) { /* FIXME - Charge process quota before allocating the handle table! */ diff --git a/reactos/ntoskrnl/ex/init.c b/reactos/ntoskrnl/ex/init.c index bb094d85acb..6737db07272 100644 --- a/reactos/ntoskrnl/ex/init.c +++ b/reactos/ntoskrnl/ex/init.c @@ -33,6 +33,8 @@ extern LIST_ENTRY KiProfileSourceListHead; extern KSPIN_LOCK KiProfileLock; #endif +VOID PspPostInitSystemProcess(VOID); + /* FUNCTIONS ****************************************************************/ static @@ -479,6 +481,18 @@ ExpInitializeExecutive(VOID) /* Initialize Basic System Objects and Worker Threads */ ExInit3(); + /* Create the system handle table, assign it to the system process, create + the client id table and assign a PID for the system process. This needs + to be done before the worker threads are initialized so the system + process gets the first PID (4) */ + PspPostInitSystemProcess(); + + /* initialize the worker threads */ + ExInitializeWorkerThreads(); + + /* initialize callbacks */ + ExpInitializeCallbacks(); + /* Initialize the GDB Stub and break */ KdInit1(); @@ -656,18 +670,16 @@ ExInit2(VOID) VOID INIT_FUNCTION ExInit3 (VOID) { - ExInitializeWorkerThreads(); ExpInitializeEventImplementation(); ExpInitializeEventPairImplementation(); ExpInitializeMutantImplementation(); ExpInitializeSemaphoreImplementation(); ExpInitializeTimerImplementation(); - ExpInitializeHandleTables(); LpcpInitSystem(); ExpInitializeProfileImplementation(); ExpWin32kInit(); ExpInitUuids(); - ExpInitializeCallbacks(); + ExpInitializeHandleTables(); } /* EOF */ diff --git a/reactos/ntoskrnl/ps/process.c b/reactos/ntoskrnl/ps/process.c index eee2f3a04b5..4715090e2ec 100644 --- a/reactos/ntoskrnl/ps/process.c +++ b/reactos/ntoskrnl/ps/process.c @@ -16,6 +16,8 @@ /* GLOBALS ******************************************************************/ +VOID INIT_FUNCTION PsInitClientIDManagment(VOID); + PEPROCESS EXPORTED PsInitialSystemProcess = NULL; POBJECT_TYPE EXPORTED PsProcessType = NULL; @@ -393,7 +395,6 @@ PsInitProcessManagment(VOID) MmInitializeAddressSpace(PsInitialSystemProcess, &PsInitialSystemProcess->AddressSpace); - ObCreateHandleTable(NULL,FALSE,PsInitialSystemProcess); KeInitializeEvent(&PsInitialSystemProcess->LockEvent, SynchronizationEvent, FALSE); PsInitialSystemProcess->LockCount = 0; @@ -421,6 +422,28 @@ PsInitProcessManagment(VOID) SepCreateSystemProcessToken(PsInitialSystemProcess); } +VOID +PspPostInitSystemProcess(VOID) +{ + NTSTATUS Status; + + /* this routine is called directly after the exectuive handle tables were + initialized. We'll set up the Client ID handle table and assign the system + process a PID */ + PsInitClientIDManagment(); + + ObCreateHandleTable(NULL, FALSE, PsInitialSystemProcess); + + Status = PsCreateCidHandle(PsInitialSystemProcess, + PsProcessType, + &PsInitialSystemProcess->UniqueProcessId); + if(!NT_SUCCESS(Status)) + { + DPRINT1("Failed to create CID handle (unique process id) for the system process!\n"); + KEBUGCHECK(0); + } +} + VOID STDCALL PiDeleteProcessWorker(PVOID pContext) { diff --git a/reactos/ntoskrnl/ps/psmgr.c b/reactos/ntoskrnl/ps/psmgr.c index 73338eccdb9..82285f8f1ce 100644 --- a/reactos/ntoskrnl/ps/psmgr.c +++ b/reactos/ntoskrnl/ps/psmgr.c @@ -14,8 +14,6 @@ #define NDEBUG #include -VOID INIT_FUNCTION PsInitClientIDManagment(VOID); - /* FUNCTIONS ***************************************************************/ VOID PiShutdownProcessManager(VOID) @@ -28,23 +26,10 @@ VOID PiShutdownProcessManager(VOID) VOID INIT_FUNCTION PiInitProcessManager(VOID) { - NTSTATUS Status; - - PsInitClientIDManagment(); PsInitJobManagment(); PsInitProcessManagment(); PsInitThreadManagment(); PsInitIdleThread(); - - Status = PsCreateCidHandle(PsInitialSystemProcess, - PsProcessType, - &PsInitialSystemProcess->UniqueProcessId); - if(!NT_SUCCESS(Status)) - { - DPRINT1("Failed to create CID handle (unique process id) for the system process!\n"); - KEBUGCHECK(0); - } - PsInitialiseSuspendImplementation(); PsInitialiseW32Call(); } diff --git a/reactos/ntoskrnl/ps/thread.c b/reactos/ntoskrnl/ps/thread.c index 2d85c83b645..b22f1582a67 100644 --- a/reactos/ntoskrnl/ps/thread.c +++ b/reactos/ntoskrnl/ps/thread.c @@ -731,9 +731,9 @@ PsInitThreadManagment(VOID) * FUNCTION: Initialize thread managment */ { - HANDLE PiReaperThreadHandle; - PETHREAD FirstThread; + PETHREAD FirstThread, ReaperThread; ULONG i; + KIRQL oldIrql; NTSTATUS Status; for (i=0; i < MAXIMUM_PRIORITY; i++) @@ -782,20 +782,27 @@ PsInitThreadManagment(VOID) */ PsInitializeThreadReaper(); KeInitializeEvent(&PiReaperThreadEvent, SynchronizationEvent, FALSE); - Status = PsCreateSystemThread(&PiReaperThreadHandle, - THREAD_ALL_ACCESS, - NULL, - NULL, - NULL, - PiReaperThreadMain, - NULL); + Status = PsInitializeThread(NULL, + &ReaperThread, + NULL, + FALSE); if (!NT_SUCCESS(Status)) { DPRINT1("PS: Failed to create reaper thread.\n"); KEBUGCHECK(0); } - NtClose(PiReaperThreadHandle); + ReaperThread->StartAddress = PiReaperThreadMain; + Status = KiArchInitThread(&ReaperThread->Tcb, PiReaperThreadMain, NULL); + if (!NT_SUCCESS(Status)) + { + DPRINT1("PS: Failed to initialize reaper thread.\n"); + KEBUGCHECK(0); + } + + oldIrql = KeAcquireDispatcherDatabaseLock (); + PsUnblockThread(ReaperThread, NULL, 0); + KeReleaseDispatcherDatabaseLock(oldIrql); } /*