mirror of
https://github.com/reactos/reactos.git
synced 2025-05-01 03:29:37 +00:00
- 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:
parent
eb8c705ce9
commit
093d1a3aba
4 changed files with 34 additions and 143 deletions
|
@ -853,9 +853,6 @@ VOID
|
||||||
NTAPI
|
NTAPI
|
||||||
ExPhase2Init(PVOID Context)
|
ExPhase2Init(PVOID Context)
|
||||||
{
|
{
|
||||||
UNICODE_STRING EventName;
|
|
||||||
HANDLE InitDoneEventHandle;
|
|
||||||
OBJECT_ATTRIBUTES ObjectAttributes;
|
|
||||||
LARGE_INTEGER Timeout;
|
LARGE_INTEGER Timeout;
|
||||||
HANDLE ProcessHandle;
|
HANDLE ProcessHandle;
|
||||||
HANDLE ThreadHandle;
|
HANDLE ThreadHandle;
|
||||||
|
@ -949,113 +946,37 @@ ExPhase2Init(PVOID Context)
|
||||||
/* Initialize shared user page. Set dos system path, dos device map, etc. */
|
/* Initialize shared user page. Set dos system path, dos device map, etc. */
|
||||||
InitSystemSharedUserPage(KeLoaderBlock);
|
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 */
|
/* Launch initial process */
|
||||||
Status = ExpLoadInitialProcess(&ProcessHandle,
|
Status = ExpLoadInitialProcess(&ProcessHandle,
|
||||||
&ThreadHandle);
|
&ThreadHandle);
|
||||||
|
|
||||||
/* Check for success, Bugcheck if we failed */
|
/* Wait 5 seconds for it to initialize */
|
||||||
if (!NT_SUCCESS(Status)) {
|
Timeout.QuadPart = Int32x32To64(5, -10000000);
|
||||||
|
Status = ZwWaitForSingleObject(ProcessHandle, FALSE, &Timeout);
|
||||||
KEBUGCHECKEX(SESSION4_INITIALIZATION_FAILED, Status, 0, 0, 0);
|
if (Status == STATUS_SUCCESS)
|
||||||
|
{
|
||||||
|
/* Bugcheck the system if SMSS couldn't initialize */
|
||||||
|
KeBugCheck(SESSION5_INITIALIZATION_FAILED);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
/* Wait on the Completion Event */
|
{
|
||||||
if (InitDoneEventHandle != INVALID_HANDLE_VALUE) {
|
/* Close process handles */
|
||||||
|
ZwClose(ThreadHandle);
|
||||||
HANDLE Handles[2]; /* Init event, Initial process */
|
ZwClose(ProcessHandle);
|
||||||
|
|
||||||
/* 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* FIXME: FILIP!
|
* FIXME: FILIP!
|
||||||
* Disable the Boot Logo
|
* Disable the Boot Logo
|
||||||
*/
|
*/
|
||||||
if (!NoGuiBoot) InbvEnableBootDriver(FALSE);
|
if (!NoGuiBoot) InbvEnableBootDriver(FALSE);
|
||||||
|
|
||||||
/* Signal the Event and close the handle */
|
/* FIXME: We should free the initial process' memory!*/
|
||||||
ZwSetEvent(InitDoneEventHandle, NULL);
|
|
||||||
ZwClose(InitDoneEventHandle);
|
|
||||||
|
|
||||||
} else {
|
/* Increase init phase */
|
||||||
|
ExpInitializationPhase += 1;
|
||||||
|
|
||||||
/* On failure to create 'ReactOSInitDone' event, go to text mode ASAP */
|
/* Jump into zero page thread */
|
||||||
if (!NoGuiBoot) InbvEnableBootDriver(FALSE);
|
MmZeroPageThreadMain(NULL);
|
||||||
|
|
||||||
/* 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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* EOF */
|
/* EOF */
|
||||||
|
|
|
@ -974,7 +974,9 @@ MmGetContinuousPages(
|
||||||
|
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
NTAPI
|
NTAPI
|
||||||
MmInitZeroPageThread(VOID);
|
MmZeroPageThreadMain(
|
||||||
|
PVOID Context
|
||||||
|
);
|
||||||
|
|
||||||
/* i386/page.c *********************************************************/
|
/* i386/page.c *********************************************************/
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
|
|
||||||
#if defined (ALLOC_PRAGMA)
|
#if defined (ALLOC_PRAGMA)
|
||||||
#pragma alloc_text(INIT, MmInitializePageList)
|
#pragma alloc_text(INIT, MmInitializePageList)
|
||||||
#pragma alloc_text(INIT, MmInitZeroPageThread)
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -62,8 +61,6 @@ static LIST_ENTRY FreeZeroedPageListHead;
|
||||||
static LIST_ENTRY FreeUnzeroedPageListHead;
|
static LIST_ENTRY FreeUnzeroedPageListHead;
|
||||||
static LIST_ENTRY BiosPageListHead;
|
static LIST_ENTRY BiosPageListHead;
|
||||||
|
|
||||||
static PETHREAD ZeroPageThread;
|
|
||||||
static CLIENT_ID ZeroPageThreadId;
|
|
||||||
static KEVENT ZeroPageThreadEvent;
|
static KEVENT ZeroPageThreadEvent;
|
||||||
static BOOLEAN ZeroPageThreadShouldTerminate = FALSE;
|
static BOOLEAN ZeroPageThreadShouldTerminate = FALSE;
|
||||||
|
|
||||||
|
@ -1139,7 +1136,8 @@ MmAllocPagesSpecifyRange(ULONG Consumer,
|
||||||
return NumberOfPagesFound;
|
return NumberOfPagesFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID STDCALL
|
NTSTATUS
|
||||||
|
NTAPI
|
||||||
MmZeroPageThreadMain(PVOID Ignored)
|
MmZeroPageThreadMain(PVOID Ignored)
|
||||||
{
|
{
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
|
@ -1149,6 +1147,13 @@ MmZeroPageThreadMain(PVOID Ignored)
|
||||||
PFN_TYPE Pfn;
|
PFN_TYPE Pfn;
|
||||||
ULONG Count;
|
ULONG Count;
|
||||||
|
|
||||||
|
/* Free initial kernel memory */
|
||||||
|
MiFreeInitMemory();
|
||||||
|
|
||||||
|
/* Set our priority to 0 */
|
||||||
|
KeGetCurrentThread()->BasePriority = 0;
|
||||||
|
KeSetPriorityThread(KeGetCurrentThread(), 0);
|
||||||
|
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
Status = KeWaitForSingleObject(&ZeroPageThreadEvent,
|
Status = KeWaitForSingleObject(&ZeroPageThreadEvent,
|
||||||
|
@ -1160,13 +1165,12 @@ MmZeroPageThreadMain(PVOID Ignored)
|
||||||
{
|
{
|
||||||
DbgPrint("ZeroPageThread: Wait failed\n");
|
DbgPrint("ZeroPageThread: Wait failed\n");
|
||||||
KEBUGCHECK(0);
|
KEBUGCHECK(0);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ZeroPageThreadShouldTerminate)
|
if (ZeroPageThreadShouldTerminate)
|
||||||
{
|
{
|
||||||
DbgPrint("ZeroPageThread: Terminating\n");
|
DbgPrint("ZeroPageThread: Terminating\n");
|
||||||
return;
|
return STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
Count = 0;
|
Count = 0;
|
||||||
KeAcquireSpinLock(&PageListLock, &oldIrql);
|
KeAcquireSpinLock(&PageListLock, &oldIrql);
|
||||||
|
@ -1201,46 +1205,11 @@ MmZeroPageThreadMain(PVOID Ignored)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
DPRINT("Zeroed %d pages.\n", Count);
|
DPRINT1("Zeroed %d pages.\n", Count);
|
||||||
KeResetEvent(&ZeroPageThreadEvent);
|
KeResetEvent(&ZeroPageThreadEvent);
|
||||||
KeReleaseSpinLock(&PageListLock, oldIrql);
|
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;
|
return STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -455,7 +455,6 @@ MmInit3(VOID)
|
||||||
MmDeletePageTable(NULL, 0);
|
MmDeletePageTable(NULL, 0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
MmInitZeroPageThread();
|
|
||||||
MmCreatePhysicalMemorySection();
|
MmCreatePhysicalMemorySection();
|
||||||
MiInitBalancerThread();
|
MiInitBalancerThread();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue