Author: ion Date: Thu Oct 5 20:14:28 2006 New Revision: 24413
URL: http://svn.reactos.org/svn/reactos?rev=24413&view=rev Log: - Get rid of the completely convoluted way that Phase 1 initialization was being ended, with umpteen events and waits and timeouts all synchronized from user-mode and do a simple 5-second wait to determine if smss started OK or not. - Promote the Phase 1 initialization thread by jumping directly into the zero-page thread, and remove manual zero-page thread initialization code since we simply jump into its main routine. - 100 less lines of code :)
Modified: trunk/reactos/ntoskrnl/ex/init.c trunk/reactos/ntoskrnl/include/internal/mm.h trunk/reactos/ntoskrnl/mm/freelist.c trunk/reactos/ntoskrnl/mm/mminit.c
Modified: trunk/reactos/ntoskrnl/ex/init.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ex/init.c?rev=2441... ============================================================================== --- trunk/reactos/ntoskrnl/ex/init.c (original) +++ trunk/reactos/ntoskrnl/ex/init.c Thu Oct 5 20:14:28 2006 @@ -853,9 +853,6 @@ NTAPI ExPhase2Init(PVOID Context) { - UNICODE_STRING EventName; - HANDLE InitDoneEventHandle; - OBJECT_ATTRIBUTES ObjectAttributes; LARGE_INTEGER Timeout; HANDLE ProcessHandle; HANDLE ThreadHandle; @@ -949,113 +946,37 @@ /* Initialize shared user page. Set dos system path, dos device map, etc. */ InitSystemSharedUserPage(KeLoaderBlock);
- /* Create 'ReactOSInitDone' event */ - RtlInitUnicodeString(&EventName, L"\ReactOSInitDone"); - InitializeObjectAttributes(&ObjectAttributes, - &EventName, - 0, - NULL, - NULL); - Status = ZwCreateEvent(&InitDoneEventHandle, - EVENT_ALL_ACCESS, - &ObjectAttributes, - SynchronizationEvent, - FALSE); - - /* Check for Success */ - if (!NT_SUCCESS(Status)) { - - DPRINT1("Failed to create 'ReactOSInitDone' event (Status 0x%x)\n", Status); - InitDoneEventHandle = INVALID_HANDLE_VALUE; - } - /* Launch initial process */ Status = ExpLoadInitialProcess(&ProcessHandle, &ThreadHandle);
- /* Check for success, Bugcheck if we failed */ - if (!NT_SUCCESS(Status)) { - - KEBUGCHECKEX(SESSION4_INITIALIZATION_FAILED, Status, 0, 0, 0); - } - - /* Wait on the Completion Event */ - if (InitDoneEventHandle != INVALID_HANDLE_VALUE) { - - HANDLE Handles[2]; /* Init event, Initial process */ - - /* Setup the Handles to wait on */ - Handles[0] = InitDoneEventHandle; - Handles[1] = ProcessHandle; - - /* Wait for the system to be initialized */ - Timeout.QuadPart = (LONGLONG)-1200000000; /* 120 second timeout */ - Status = ZwWaitForMultipleObjects(2, - Handles, - WaitAny, - FALSE, - &Timeout); - if (!NT_SUCCESS(Status)) { - - DPRINT1("NtWaitForMultipleObjects failed with status 0x%x!\n", Status); - - } else if (Status == STATUS_TIMEOUT) { - - DPRINT1("WARNING: System not initialized after 120 seconds.\n"); - - } else if (Status == STATUS_WAIT_0 + 1) { - - /* Crash the system if the initial process was terminated. */ - KEBUGCHECKEX(SESSION5_INITIALIZATION_FAILED, Status, 0, 0, 0); - } + /* Wait 5 seconds for it to initialize */ + Timeout.QuadPart = Int32x32To64(5, -10000000); + Status = ZwWaitForSingleObject(ProcessHandle, FALSE, &Timeout); + if (Status == STATUS_SUCCESS) + { + /* Bugcheck the system if SMSS couldn't initialize */ + KeBugCheck(SESSION5_INITIALIZATION_FAILED); + } + else + { + /* Close process handles */ + ZwClose(ThreadHandle); + ZwClose(ProcessHandle);
/* - * FIXME: FILIP! - * Disable the Boot Logo - */ + * FIXME: FILIP! + * Disable the Boot Logo + */ if (!NoGuiBoot) InbvEnableBootDriver(FALSE);
- /* Signal the Event and close the handle */ - ZwSetEvent(InitDoneEventHandle, NULL); - ZwClose(InitDoneEventHandle); - - } else { - - /* On failure to create 'ReactOSInitDone' event, go to text mode ASAP */ - if (!NoGuiBoot) InbvEnableBootDriver(FALSE); - - /* Crash the system if the initial process terminates within 5 seconds. */ - Timeout.QuadPart = (LONGLONG)-50000000; /* 5 second timeout */ - Status = ZwWaitForSingleObject(ProcessHandle, - FALSE, - &Timeout); - - /* Check for timeout, crash if the initial process didn't initalize */ - if (Status != STATUS_TIMEOUT) KEBUGCHECKEX(SESSION5_INITIALIZATION_FAILED, Status, 1, 0, 0); - } - - /* Enable the Clock, close remaining handles */ - ZwClose(ThreadHandle); - ZwClose(ProcessHandle); - - DPRINT1("System initialization complete\n"); - { - /* FIXME: We should instead jump to zero-page thread */ - /* Free initial kernel memory */ - MiFreeInitMemory(); - - /* Set our priority to 0 */ - KeGetCurrentThread()->BasePriority = 0; - KeSetPriorityThread(KeGetCurrentThread(), 0); - - /* Wait ad-infinitum */ - for (;;) - { - LARGE_INTEGER Timeout; - Timeout.QuadPart = 0x7fffffffffffffffLL; - KeDelayExecutionThread(KernelMode, FALSE, &Timeout); - } - } -} - + /* FIXME: We should free the initial process' memory!*/ + + /* Increase init phase */ + ExpInitializationPhase += 1; + + /* Jump into zero page thread */ + MmZeroPageThreadMain(NULL); + } +} /* EOF */
Modified: trunk/reactos/ntoskrnl/include/internal/mm.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/m... ============================================================================== --- trunk/reactos/ntoskrnl/include/internal/mm.h (original) +++ trunk/reactos/ntoskrnl/include/internal/mm.h Thu Oct 5 20:14:28 2006 @@ -974,7 +974,9 @@
NTSTATUS NTAPI -MmInitZeroPageThread(VOID); +MmZeroPageThreadMain( + PVOID Context +);
/* i386/page.c *********************************************************/
Modified: trunk/reactos/ntoskrnl/mm/freelist.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/freelist.c?rev=... ============================================================================== --- trunk/reactos/ntoskrnl/mm/freelist.c (original) +++ trunk/reactos/ntoskrnl/mm/freelist.c Thu Oct 5 20:14:28 2006 @@ -17,7 +17,6 @@
#if defined (ALLOC_PRAGMA) #pragma alloc_text(INIT, MmInitializePageList) -#pragma alloc_text(INIT, MmInitZeroPageThread) #endif
@@ -62,8 +61,6 @@ static LIST_ENTRY FreeUnzeroedPageListHead; static LIST_ENTRY BiosPageListHead;
-static PETHREAD ZeroPageThread; -static CLIENT_ID ZeroPageThreadId; static KEVENT ZeroPageThreadEvent; static BOOLEAN ZeroPageThreadShouldTerminate = FALSE;
@@ -1139,7 +1136,8 @@ return NumberOfPagesFound; }
-VOID STDCALL +NTSTATUS +NTAPI MmZeroPageThreadMain(PVOID Ignored) { NTSTATUS Status; @@ -1148,6 +1146,13 @@ PPHYSICAL_PAGE PageDescriptor; PFN_TYPE Pfn; ULONG Count; + + /* Free initial kernel memory */ + MiFreeInitMemory(); + + /* Set our priority to 0 */ + KeGetCurrentThread()->BasePriority = 0; + KeSetPriorityThread(KeGetCurrentThread(), 0);
while(1) { @@ -1160,13 +1165,12 @@ { DbgPrint("ZeroPageThread: Wait failed\n"); KEBUGCHECK(0); - return; }
if (ZeroPageThreadShouldTerminate) { DbgPrint("ZeroPageThread: Terminating\n"); - return; + return STATUS_SUCCESS; } Count = 0; KeAcquireSpinLock(&PageListLock, &oldIrql); @@ -1201,46 +1205,11 @@ }
} - DPRINT("Zeroed %d pages.\n", Count); + DPRINT1("Zeroed %d pages.\n", Count); KeResetEvent(&ZeroPageThreadEvent); KeReleaseSpinLock(&PageListLock, oldIrql); } -} - -NTSTATUS -INIT_FUNCTION -NTAPI -MmInitZeroPageThread(VOID) -{ - NTSTATUS Status; - HANDLE ThreadHandle; - - ZeroPageThreadShouldTerminate = FALSE; - Status = PsCreateSystemThread(&ThreadHandle, - THREAD_ALL_ACCESS, - NULL, - NULL, - &ZeroPageThreadId, - MmZeroPageThreadMain, - NULL); - if (!NT_SUCCESS(Status)) - { - KEBUGCHECK(0); - } - - Status = ObReferenceObjectByHandle(ThreadHandle, - THREAD_ALL_ACCESS, - PsThreadType, - KernelMode, - (PVOID*)&ZeroPageThread, - NULL); - if (!NT_SUCCESS(Status)) - { - KEBUGCHECK(0); - } - - KeSetPriorityThread(&ZeroPageThread->Tcb, LOW_PRIORITY); - NtClose(ThreadHandle); + return STATUS_SUCCESS; }
Modified: trunk/reactos/ntoskrnl/mm/mminit.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/mminit.c?rev=24... ============================================================================== --- trunk/reactos/ntoskrnl/mm/mminit.c (original) +++ trunk/reactos/ntoskrnl/mm/mminit.c Thu Oct 5 20:14:28 2006 @@ -455,7 +455,6 @@ MmDeletePageTable(NULL, 0); #endif
- MmInitZeroPageThread(); MmCreatePhysicalMemorySection(); MiInitBalancerThread();