diff --git a/reactos/ntoskrnl/ex/init.c b/reactos/ntoskrnl/ex/init.c index 6fbd3f32bc6..b445f99d80b 100644 --- a/reactos/ntoskrnl/ex/init.c +++ b/reactos/ntoskrnl/ex/init.c @@ -367,6 +367,38 @@ ExInit3(VOID) ExpInitUuids(); } +ULONG +NTAPI +ExComputeTickCountMultiplier(IN ULONG ClockIncrement) +{ + ULONG MsRemainder = 0, MsIncrement; + ULONG IncrementRemainder; + ULONG i; + + /* Count the number of milliseconds for each clock interrupt */ + MsIncrement = ClockIncrement / (10 * 1000); + + /* Count the remainder from the division above, with 24-bit precision */ + IncrementRemainder = ClockIncrement - (MsIncrement * (10 * 1000)); + for (i= 0; i < 24; i++) + { + /* Shift the remainders */ + MsRemainder <<= 1; + IncrementRemainder <<= 1; + + /* Check if we've went past 1 ms */ + if (IncrementRemainder >= (10 * 1000)) + { + /* Increase the remainder by one, and substract from increment */ + IncrementRemainder -= (10 * 1000); + MsRemainder |= 1; + } + } + + /* Return the increment */ + return (MsIncrement << 24) | MsRemainder; +} + BOOLEAN NTAPI ExpInitSystemPhase0(VOID) @@ -574,12 +606,12 @@ ExpInitializeExecutive(IN ULONG Cpu, /* Setup system time */ KiInitializeSystemClock(); - /* Initialize the second stage of the kernel */ - KeInit2(); - /* Initialize the executive at phase 0 */ if (!ExInitSystem()) KEBUGCHECK(PHASE0_INITIALIZATION_FAILED); + /* Break into the Debugger if requested */ + if (KdPollBreakIn()) DbgBreakPointWithStatus(DBG_STATUS_CONTROL_C); + /* Set system ranges */ SharedUserData->Reserved1 = (ULONG_PTR)MmHighestUserAddress; SharedUserData->Reserved3 = (ULONG_PTR)MmSystemRangeStart; @@ -611,10 +643,7 @@ ExpInitializeExecutive(IN ULONG Cpu, */ ExpNlsTableSize += 2 * PAGE_SIZE; // BIAS FOR FREELDR. HACK! - /* - * Allocate the table in pool memory, so we can stop depending on the - * memory given to use by the loader, which is freed later. - */ + /* Allocate the NLS buffer in the pool since loader memory will be freed */ ExpNlsTableBase = ExAllocatePoolWithTag(NonPagedPool, ExpNlsTableSize, TAG('R', 't', 'l', 'i')); @@ -661,8 +690,7 @@ ExpInitializeExecutive(IN ULONG Cpu, if (!ObInit()) KEBUGCHECK(OBJECT_INITIALIZATION_FAILED); /* Load basic Security for other Managers */ - if (!SeInit1()) KEBUGCHECK(SECURITY_INITIALIZATION_FAILED); - if (!SeInit2()) KEBUGCHECK(SECURITY1_INITIALIZATION_FAILED); + if (!SeInit()) KEBUGCHECK(SECURITY_INITIALIZATION_FAILED); /* Set up Region Maps, Sections and the Paging File */ MmInit2(); @@ -671,16 +699,26 @@ ExpInitializeExecutive(IN ULONG Cpu, if (!ObInit()) KEBUGCHECK(OBJECT_INITIALIZATION_FAILED); /* Initialize the Process Manager */ - PspInitPhase0(); + if (!PsInitSystem()) KEBUGCHECK(PROCESS_INITIALIZATION_FAILED); - /* Break into the Debugger if requested */ - if (KdPollBreakIn()) DbgBreakPointWithStatus (DBG_STATUS_CONTROL_C); + /* Calculate the tick count multiplier */ + ExpTickCountMultiplier = ExComputeTickCountMultiplier(KeMaximumIncrement); + SharedUserData->TickCountMultiplier = ExpTickCountMultiplier; - /* Initialize all processors */ - HalAllProcessorsStarted(); + /* Set the OS Version */ + SharedUserData->NtMajorVersion = NtMajorVersion; + SharedUserData->NtMinorVersion = NtMinorVersion; - /* Do Phase 1 HAL Initialization */ - HalInitSystem(1, KeLoaderBlock); + /* Set the machine type */ +#if defined(_X86_) + SharedUserData->ImageNumberLow = IMAGE_FILE_MACHINE_I386; + SharedUserData->ImageNumberHigh = IMAGE_FILE_MACHINE_I386; +#elif defined(_PPC_) // <3 Arty + SharedUserData->ImageNumberLow = IMAGE_FILE_MACHINE_POWERPC; + SharedUserData->ImageNumberHigh = IMAGE_FILE_MACHINE_POWERPC; +#elif +#error "Unsupported ReactOS Target" +#endif } VOID @@ -698,6 +736,15 @@ ExPhase2Init(PVOID Context) /* Set us at maximum priority */ KeSetPriorityThread(KeGetCurrentThread(), HIGH_PRIORITY); + /* Initialize the second stage of the kernel */ + KeInit2(); + + /* Initialize all processors */ + HalAllProcessorsStarted(); + + /* Do Phase 1 HAL Initialization */ + HalInitSystem(1, KeLoaderBlock); + /* Initialize Basic System Objects and Worker Threads */ ExInit3(); diff --git a/reactos/ntoskrnl/ex/time.c b/reactos/ntoskrnl/ex/time.c index 5671b7e755e..bc618fd82a1 100644 --- a/reactos/ntoskrnl/ex/time.c +++ b/reactos/ntoskrnl/ex/time.c @@ -25,6 +25,7 @@ TIME_ZONE_INFORMATION ExpTimeZoneInfo; LARGE_INTEGER ExpTimeZoneBias; ULONG ExpTimeZoneId; +ULONG ExpTickCountMultiplier; /* FUNCTIONS ****************************************************************/ diff --git a/reactos/ntoskrnl/include/internal/ex.h b/reactos/ntoskrnl/include/internal/ex.h index 39fa724ca3e..caa6aab5659 100644 --- a/reactos/ntoskrnl/include/internal/ex.h +++ b/reactos/ntoskrnl/include/internal/ex.h @@ -6,6 +6,7 @@ extern TIME_ZONE_INFORMATION ExpTimeZoneInfo; extern LARGE_INTEGER ExpTimeZoneBias; extern ULONG ExpTimeZoneId; +extern ULONG ExpTickCountMultiplier; extern POBJECT_TYPE ExEventPairObjectType; extern ULONG NtBuildNumber; extern ULONG NtMajorVersion; diff --git a/reactos/ntoskrnl/include/internal/ntoskrnl.h b/reactos/ntoskrnl/include/internal/ntoskrnl.h index bd3859d3cab..ba21d3fe351 100644 --- a/reactos/ntoskrnl/include/internal/ntoskrnl.h +++ b/reactos/ntoskrnl/include/internal/ntoskrnl.h @@ -64,7 +64,6 @@ VOID IoInit(VOID); VOID IoInit2(BOOLEAN BootLog); VOID NTAPI IoInit3(VOID); BOOLEAN NTAPI ObInit(VOID); -VOID PsInit(VOID); VOID CmInitializeRegistry(VOID); VOID NTAPI CmInitHives(BOOLEAN SetupBoot); VOID CmInit2(PCHAR CommandLine); diff --git a/reactos/ntoskrnl/include/internal/ps.h b/reactos/ntoskrnl/include/internal/ps.h index e62e472242d..2b26031037b 100644 --- a/reactos/ntoskrnl/include/internal/ps.h +++ b/reactos/ntoskrnl/include/internal/ps.h @@ -81,7 +81,7 @@ PspShutdownProcessManager( BOOLEAN NTAPI -PspInitPhase0( +PsInitSystem( VOID ); diff --git a/reactos/ntoskrnl/include/internal/se.h b/reactos/ntoskrnl/include/internal/se.h index a158320434f..112deace2fb 100644 --- a/reactos/ntoskrnl/include/internal/se.h +++ b/reactos/ntoskrnl/include/internal/se.h @@ -86,11 +86,7 @@ extern PSECURITY_DESCRIPTOR SeUnrestrictedSd; /* Functions */ BOOLEAN NTAPI -SeInit1(VOID); - -BOOLEAN -NTAPI -SeInit2(VOID); +SeInit(VOID); BOOLEAN NTAPI diff --git a/reactos/ntoskrnl/ps/psmgr.c b/reactos/ntoskrnl/ps/psmgr.c index 158a443db72..a02e4398ad4 100644 --- a/reactos/ntoskrnl/ps/psmgr.c +++ b/reactos/ntoskrnl/ps/psmgr.c @@ -397,6 +397,14 @@ PspInitPhase0(VOID) return TRUE; } +BOOLEAN +NTAPI +PsInitSystem(VOID) +{ + /* For now, do only Phase 0 */ + return PspInitPhase0(); +} + /* PUBLIC FUNCTIONS **********************************************************/ /* diff --git a/reactos/ntoskrnl/se/semgr.c b/reactos/ntoskrnl/se/semgr.c index da9b141d681..9f3f82740fc 100644 --- a/reactos/ntoskrnl/se/semgr.c +++ b/reactos/ntoskrnl/se/semgr.c @@ -27,8 +27,7 @@ static ERESOURCE SepSubjectContextLock; static BOOLEAN SepInitExports(VOID); #if defined (ALLOC_PRAGMA) -#pragma alloc_text(INIT, SeInit1) -#pragma alloc_text(INIT, SeInit2) +#pragma alloc_text(INIT, SeInit) #pragma alloc_text(INIT, SepInitExports) #endif @@ -37,7 +36,7 @@ static BOOLEAN SepInitExports(VOID); BOOLEAN INIT_FUNCTION NTAPI -SeInit1(VOID) +SeInit(VOID) { SepInitLuid(); @@ -58,30 +57,20 @@ SeInit1(VOID) /* Initialize the subject context lock */ ExInitializeResource(&SepSubjectContextLock); + /* Initialize token objects */ + SepInitializeTokenImplementation(); + + /* Clear impersonation info for the idle thread */ + PsGetCurrentThread()->ImpersonationInfo = NULL; + PspClearCrossThreadFlag(PsGetCurrentThread(), CT_ACTIVE_IMPERSONATION_INFO_BIT); + + /* Initailize the boot token */ + ObInitializeFastReference(&PsGetCurrentProcess()->Token, NULL); + ObInitializeFastReference(&PsGetCurrentProcess()->Token, + SepCreateSystemProcessToken()); return TRUE; } - -BOOLEAN -INIT_FUNCTION -NTAPI -SeInit2(VOID) -{ - /* Initialize token objects */ - SepInitializeTokenImplementation(); - - /* Clear impersonation info for the idle thread */ - PsGetCurrentThread()->ImpersonationInfo = NULL; - PspClearCrossThreadFlag(PsGetCurrentThread(), CT_ACTIVE_IMPERSONATION_INFO_BIT); - - /* Initailize the boot token */ - ObInitializeFastReference(&PsGetCurrentProcess()->Token, NULL); - ObInitializeFastReference(&PsGetCurrentProcess()->Token, - SepCreateSystemProcessToken()); - return TRUE; -} - - BOOLEAN NTAPI SeInitSRM(VOID)