- 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 :)

svn path=/trunk/; revision=24413
This commit is contained in:
Alex Ionescu 2006-10-05 16:14:28 +00:00
parent eb8c705ce9
commit 093d1a3aba
4 changed files with 34 additions and 143 deletions

View file

@ -853,9 +853,6 @@ VOID
NTAPI
ExPhase2Init(PVOID Context)
{
UNICODE_STRING EventName;
HANDLE InitDoneEventHandle;
OBJECT_ATTRIBUTES ObjectAttributes;
LARGE_INTEGER Timeout;
HANDLE ProcessHandle;
HANDLE ThreadHandle;
@ -949,113 +946,37 @@ ExPhase2Init(PVOID Context)
/* 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 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);
}
/* 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);
}
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);
/* FIXME: We should free the initial process' memory!*/
} else {
/* Increase init phase */
ExpInitializationPhase += 1;
/* 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);
}
/* Jump into zero page thread */
MmZeroPageThreadMain(NULL);
}
}
/* EOF */

View file

@ -974,7 +974,9 @@ MmGetContinuousPages(
NTSTATUS
NTAPI
MmInitZeroPageThread(VOID);
MmZeroPageThreadMain(
PVOID Context
);
/* i386/page.c *********************************************************/

View file

@ -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 FreeZeroedPageListHead;
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 @@ MmAllocPagesSpecifyRange(ULONG Consumer,
return NumberOfPagesFound;
}
VOID STDCALL
NTSTATUS
NTAPI
MmZeroPageThreadMain(PVOID Ignored)
{
NTSTATUS Status;
@ -1149,6 +1147,13 @@ MmZeroPageThreadMain(PVOID Ignored)
PFN_TYPE Pfn;
ULONG Count;
/* Free initial kernel memory */
MiFreeInitMemory();
/* Set our priority to 0 */
KeGetCurrentThread()->BasePriority = 0;
KeSetPriorityThread(KeGetCurrentThread(), 0);
while(1)
{
Status = KeWaitForSingleObject(&ZeroPageThreadEvent,
@ -1160,13 +1165,12 @@ MmZeroPageThreadMain(PVOID Ignored)
{
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 @@ MmZeroPageThreadMain(PVOID Ignored)
}
}
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;
}

View file

@ -455,7 +455,6 @@ MmInit3(VOID)
MmDeletePageTable(NULL, 0);
#endif
MmInitZeroPageThread();
MmCreatePhysicalMemorySection();
MiInitBalancerThread();