Author: ion Date: Mon Oct 2 19:05:03 2006 New Revision: 24362
URL: http://svn.reactos.org/svn/reactos?rev=24362&view=rev Log: - Setup memory limits in shared user data. - Loop security descriptors to find NLS data and make a copy of it in kernel pool, because the NLS buffer from NTLDR will be freed on NT. Also discovered a bug in Freeldr where it doesn't allocate ths NLS files sequentially, leaving a hole of 0x1000 between them. Added a hack to compensate (won't break NTLDR booting, just will waste 8KB of memory). - Allocate the system call count table on checked builds. - Refactor Ob/Se booting to match more closely NT, and so that we can do Se initialization in one shot.
Modified: trunk/reactos/ntoskrnl/ex/init.c trunk/reactos/ntoskrnl/include/internal/ntoskrnl.h trunk/reactos/ntoskrnl/ke/krnlinit.c trunk/reactos/ntoskrnl/ob/obinit.c
Modified: trunk/reactos/ntoskrnl/ex/init.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ex/init.c?rev=2436... ============================================================================== --- trunk/reactos/ntoskrnl/ex/init.c (original) +++ trunk/reactos/ntoskrnl/ex/init.c Mon Oct 2 19:05:03 2006 @@ -25,10 +25,9 @@ ULONG NtGlobalFlag; ULONG ExSuiteMask;
-extern ULONG MmCoreDumpType; extern LOADER_MODULE KeLoaderModules[64]; extern ULONG KeLoaderModuleCount; -extern PRTL_MESSAGE_RESOURCE_DATA KiBugCodeMessages; +extern ULONG KiServiceLimit; BOOLEAN NoGuiBoot = FALSE;
/* Init flags and settings */ @@ -45,6 +44,7 @@ ULONG ExpAnsiCodePageDataOffset, ExpOemCodePageDataOffset; ULONG ExpUnicodeCaseTableDataOffset; NLSTABLEINFO ExpNlsTableInfo; +ULONG ExpNlsTableSize;
/* FUNCTIONS ****************************************************************/
@@ -456,6 +456,8 @@ CHAR Buffer[256]; ANSI_STRING AnsiPath; NTSTATUS Status; + PLIST_ENTRY NextEntry, ListHead; + PMEMORY_ALLOCATION_DESCRIPTOR MdBlock;
/* FIXME: Deprecate soon */ ParseAndCacheLoadedModules(); @@ -578,22 +580,97 @@ /* Initialize the executive at phase 0 */ if (!ExInitSystem()) KEBUGCHECK(PHASE0_INITIALIZATION_FAILED);
+ /* Set system ranges */ + SharedUserData->Reserved1 = (ULONG_PTR)MmHighestUserAddress; + SharedUserData->Reserved3 = (ULONG_PTR)MmSystemRangeStart; + + /* Loop the memory descriptors */ + ListHead = &LoaderBlock->MemoryDescriptorListHead; + NextEntry = ListHead->Flink; + while (NextEntry != ListHead) + { + /* Get the current block */ + MdBlock = CONTAINING_RECORD(NextEntry, + MEMORY_ALLOCATION_DESCRIPTOR, + ListEntry); + + /* Check if this is an NLS block */ + if (MdBlock->MemoryType == LoaderNlsData) + { + /* Increase the table size */ + ExpNlsTableSize += MdBlock->PageCount * PAGE_SIZE; + } + + /* Go to the next block */ + NextEntry = MdBlock->ListEntry.Flink; + } + + /* + * In NT, the memory blocks are contiguous, but in ReactOS they are not, + * so unless someone fixes FreeLdr, we'll have to use this icky hack. + */ + 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. + */ + ExpNlsTableBase = ExAllocatePoolWithTag(NonPagedPool, + ExpNlsTableSize, + TAG('R', 't', 'l', 'i')); + if (!ExpNlsTableBase) KeBugCheck(PHASE0_INITIALIZATION_FAILED); + + /* Copy the codepage data in its new location. */ + RtlMoveMemory(ExpNlsTableBase, + LoaderBlock->NlsData->AnsiCodePageData, + ExpNlsTableSize); + + /* Initialize and reset the NLS TAbles */ + RtlInitNlsTables((PVOID)((ULONG_PTR)ExpNlsTableBase + + ExpAnsiCodePageDataOffset), + (PVOID)((ULONG_PTR)ExpNlsTableBase + + ExpOemCodePageDataOffset), + (PVOID)((ULONG_PTR)ExpNlsTableBase + + ExpUnicodeCaseTableDataOffset), + &ExpNlsTableInfo); + RtlResetRtlTranslations(&ExpNlsTableInfo); + + /* Initialize the Handle Table */ + ExpInitializeHandleTables(); + +#if DBG + /* On checked builds, allocate the system call count table */ + KeServiceDescriptorTable[0].Count = + ExAllocatePoolWithTag(NonPagedPool, + KiServiceLimit * sizeof(ULONG), + TAG('C', 'a', 'l', 'l')); + + /* Use it for the shadow table too */ + KeServiceDescriptorTableShadow[0].Count = KeServiceDescriptorTable[0].Count; + + /* Make sure allocation succeeded */ + if (KeServiceDescriptorTable[0].Count) + { + /* Zero the call counts to 0 */ + RtlZeroMemory(KeServiceDescriptorTable[0].Count, + KiServiceLimit * sizeof(ULONG)); + } +#endif + + /* Create the Basic Object Manager Types to allow new Object Types */ + if (!ObInit()) KEBUGCHECK(OBJECT_INITIALIZATION_FAILED); + /* Load basic Security for other Managers */ if (!SeInit1()) KEBUGCHECK(SECURITY_INITIALIZATION_FAILED); - - /* Initialize the Handle Table */ - ExpInitializeHandleTables(); - - /* Create the Basic Object Manager Types to allow new Object Types */ - ObInit(); + if (!SeInit2()) KEBUGCHECK(SECURITY1_INITIALIZATION_FAILED);
/* Set up Region Maps, Sections and the Paging File */ MmInit2();
- /* Initialize Tokens now that the Object Manager is ready */ - if (!SeInit2()) KEBUGCHECK(SECURITY1_INITIALIZATION_FAILED); - - /* Initalize the Process Manager */ + /* Call OB initialization again */ + if (!ObInit()) KEBUGCHECK(OBJECT_INITIALIZATION_FAILED); + + /* Initialize the Process Manager */ PspInitPhase0();
/* Break into the Debugger if requested */ @@ -602,7 +679,7 @@ /* Initialize all processors */ HalAllProcessorsStarted();
- /* Do Phase 1 HAL Initalization */ + /* Do Phase 1 HAL Initialization */ HalInitSystem(1, KeLoaderBlock); }
Modified: trunk/reactos/ntoskrnl/include/internal/ntoskrnl.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/n... ============================================================================== --- trunk/reactos/ntoskrnl/include/internal/ntoskrnl.h (original) +++ trunk/reactos/ntoskrnl/include/internal/ntoskrnl.h Mon Oct 2 19:05:03 2006 @@ -63,7 +63,7 @@ VOID IoInit(VOID); VOID IoInit2(BOOLEAN BootLog); VOID NTAPI IoInit3(VOID); -VOID ObInit(VOID); +BOOLEAN NTAPI ObInit(VOID); VOID PsInit(VOID); VOID CmInitializeRegistry(VOID); VOID NTAPI CmInitHives(BOOLEAN SetupBoot);
Modified: trunk/reactos/ntoskrnl/ke/krnlinit.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/krnlinit.c?rev=... ============================================================================== --- trunk/reactos/ntoskrnl/ke/krnlinit.c (original) +++ trunk/reactos/ntoskrnl/ke/krnlinit.c Mon Oct 2 19:05:03 2006 @@ -14,6 +14,9 @@ #include <internal/napi.h>
/* GLOBALS *******************************************************************/ + +/* System call count */ +ULONG KiServiceLimit = NUMBER_OF_SYSCALLS;
/* ARC Loader Block */ PLOADER_PARAMETER_BLOCK KeLoaderBlock; @@ -96,7 +99,7 @@ /* Initialize the syscall table */ KeServiceDescriptorTable[0].Base = MainSSDT; KeServiceDescriptorTable[0].Count = NULL; - KeServiceDescriptorTable[0].Limit = NUMBER_OF_SYSCALLS; + KeServiceDescriptorTable[0].Limit = KiServiceLimit; KeServiceDescriptorTable[1].Limit = 0; KeServiceDescriptorTable[0].Number = MainSSPT;
Modified: trunk/reactos/ntoskrnl/ob/obinit.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ob/obinit.c?rev=24... ============================================================================== --- trunk/reactos/ntoskrnl/ob/obinit.c (original) +++ trunk/reactos/ntoskrnl/ob/obinit.c Mon Oct 2 19:05:03 2006 @@ -44,33 +44,18 @@ NTAPI PsInitializeQuotaSystem(VOID);
+ULONG ObpInitializationPhase; + /* PRIVATE FUNCTIONS *********************************************************/
-VOID +BOOLEAN INIT_FUNCTION +NTAPI ObInit2(VOID) { ULONG i; PKPRCB Prcb; PNPAGED_LOOKASIDE_LIST CurrentList = NULL; - - /* Initialize the OBJECT_CREATE_INFORMATION List */ - ExInitializeNPagedLookasideList(&ObpCiLookasideList, - NULL, - NULL, - 0, - sizeof(OBJECT_CREATE_INFORMATION), - TAG('O', 'b', 'C', 'I'), - 32); - - /* Set the captured UNICODE_STRING Object Name List */ - ExInitializeNPagedLookasideList(&ObpNmLookasideList, - NULL, - NULL, - 0, - 248, - TAG('O', 'b', 'N', 'M'), - 16);
/* Now allocate the per-processor lists */ for (i = 0; i < KeNumberProcessors; i++) @@ -128,10 +113,13 @@ /* Link it */ Prcb->PPLookasideList[LookasideNameBufferList].P = &CurrentList->L; } + + return TRUE; }
-VOID +BOOLEAN INIT_FUNCTION +NTAPI ObInit(VOID) { OBJECT_ATTRIBUTES ObjectAttributes; @@ -139,6 +127,34 @@ SECURITY_DESCRIPTOR SecurityDescriptor; OBJECT_TYPE_INITIALIZER ObjectTypeInitializer; OBP_LOOKUP_CONTEXT Context; + PKPRCB Prcb = KeGetCurrentPrcb(); + + /* Check if this is actually Phase 1 initialization */ + if (ObpInitializationPhase != 0) goto ObPostPhase0; + + /* Initialize the OBJECT_CREATE_INFORMATION List */ + ExInitializeNPagedLookasideList(&ObpCiLookasideList, + NULL, + NULL, + 0, + sizeof(OBJECT_CREATE_INFORMATION), + TAG('O', 'b', 'C', 'I'), + 32); + + /* Set the captured UNICODE_STRING Object Name List */ + ExInitializeNPagedLookasideList(&ObpNmLookasideList, + NULL, + NULL, + 0, + 248, + TAG('O', 'b', 'N', 'M'), + 16); + + /* Temporarily setup both pointers to the shared list */ + Prcb->PPLookasideList[LookasideCreateInfoList].L = &ObpCiLookasideList.L; + Prcb->PPLookasideList[LookasideCreateInfoList].P = &ObpCiLookasideList.L; + Prcb->PPLookasideList[LookasideNameBufferList].L = &ObpNmLookasideList.L; + Prcb->PPLookasideList[LookasideNameBufferList].P = &ObpNmLookasideList.L;
/* Initialize the security descriptor cache */ ObpInitSdCache(); @@ -148,9 +164,6 @@
/* Setup the Object Reaper */ ExInitializeWorkItem(&ObpReaperWorkItem, ObpReapObject, NULL); - - /* Initialize lookaside lists */ - ObInit2();
/* Initialize default Quota block */ PsInitializeQuotaSystem(); @@ -160,7 +173,6 @@ ObpKernelHandleTable = PsGetCurrentProcess()->ObjectTable;
/* Create the Type Type */ - DPRINT("Creating Type Type\n"); RtlZeroMemory(&ObjectTypeInitializer, sizeof(ObjectTypeInitializer)); RtlInitUnicodeString(&Name, L"Type"); ObjectTypeInitializer.Length = sizeof(ObjectTypeInitializer); @@ -173,7 +185,6 @@ ObCreateObjectType(&Name, &ObjectTypeInitializer, NULL, &ObTypeObjectType);
/* Create the Directory Type */ - DPRINT("Creating Directory Type\n"); RtlZeroMemory(&ObjectTypeInitializer, sizeof(ObjectTypeInitializer)); RtlInitUnicodeString(&Name, L"Directory"); ObjectTypeInitializer.Length = sizeof(ObjectTypeInitializer); @@ -183,6 +194,15 @@ ObjectTypeInitializer.GenericMapping = ObpDirectoryMapping; ObjectTypeInitializer.DefaultNonPagedPoolCharge = sizeof(OBJECT_DIRECTORY); ObCreateObjectType(&Name, &ObjectTypeInitializer, NULL, &ObDirectoryType); + + /* Phase 0 initialization complete */ + ObpInitializationPhase++; + return TRUE; + +ObPostPhase0: + + /* Re-initialize lookaside lists */ + ObInit2();
/* Create security descriptor */ RtlCreateSecurityDescriptor(&SecurityDescriptor, @@ -199,7 +219,6 @@ FALSE);
/* Create root directory */ - DPRINT("Creating Root Directory\n"); InitializeObjectAttributes(&ObjectAttributes, NULL, OBJ_PERMANENT, @@ -271,5 +290,7 @@ /* FIXME: Hack Hack! */ ObSystemDeviceMap = ExAllocatePoolWithTag(NonPagedPool, sizeof(*ObSystemDeviceMap), TAG('O', 'b', 'D', 'm')); RtlZeroMemory(ObSystemDeviceMap, sizeof(*ObSystemDeviceMap)); + return TRUE; } + /* EOF */