Author: ion
Date: Mon Oct 2 17:23:03 2006
New Revision: 24360
URL:
http://svn.reactos.org/svn/reactos?rev=24360&view=rev
Log:
- Implement Phase 0 Ex initialization (Resource, Lookaside initialization) and generic Ex
initialization routine.
- Clear the crypto exponent on boot-up.
- Set default global flags for checked builds.
- Set NtSystemRoot (SharedUserData) to C:<NT BOOT PATH> on startup.
- Cleanup lookas.c file and implement routines to initialize the system lookaside list in
phase 0.
Modified:
trunk/reactos/ntoskrnl/ex/init.c
trunk/reactos/ntoskrnl/ex/lookas.c
trunk/reactos/ntoskrnl/ex/sysinfo.c
trunk/reactos/ntoskrnl/include/internal/ex.h
Modified: trunk/reactos/ntoskrnl/ex/init.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ex/init.c?rev=243…
==============================================================================
--- trunk/reactos/ntoskrnl/ex/init.c (original)
+++ trunk/reactos/ntoskrnl/ex/init.c Mon Oct 2 17:23:03 2006
@@ -22,7 +22,8 @@
ULONG NtMinorVersion = 0;
ULONG NtOSCSDVersion = BUILD_OSCSDVERSION(4, 0);
ULONG NtBuildNumber = KERNEL_VERSION_BUILD;
-ULONG NtGlobalFlag = 0;
+ULONG NtGlobalFlag;
+ULONG ExSuiteMask;
extern ULONG MmCoreDumpType;
extern LOADER_MODULE KeLoaderModules[64];
@@ -35,6 +36,9 @@
BOOLEAN ExpInTextModeSetup;
BOOLEAN IoRemoteBootClient;
ULONG InitSafeBootMode;
+
+/* NT Boot Path */
+UNICODE_STRING NtSystemRoot;
/* Boot NLS information */
PVOID ExpNlsTableBase;
@@ -350,14 +354,6 @@
VOID
NTAPI
-ExInit2(VOID)
-{
- ExpInitLookasideLists();
- ExpInitializeHandleTables();
-}
-
-VOID
-NTAPI
ExInit3(VOID)
{
ExpInitializeEventImplementation();
@@ -373,6 +369,61 @@
BOOLEAN
NTAPI
+ExpInitSystemPhase0(VOID)
+{
+ /* Initialize EXRESOURCE Support */
+ ExpResourceInitialization();
+
+ /* Initialize the environment lock */
+ ExInitializeFastMutex(&ExpEnvironmentLock);
+
+ /* Initialize the lookaside lists and locks */
+ ExpInitLookasideLists();
+
+ /* Initialize the Firmware Table resource and listhead */
+ InitializeListHead(&ExpFirmwareTableProviderListHead);
+ ExInitializeResourceLite(&ExpFirmwareTableResource);
+
+ /* Set the suite mask to maximum and return */
+ ExSuiteMask = 0xFFFFFFFF;
+ return TRUE;
+}
+
+BOOLEAN
+NTAPI
+ExpInitSystemPhase1(VOID)
+{
+ /* Not yet done */
+ return FALSE;
+}
+
+BOOLEAN
+NTAPI
+ExInitSystem(VOID)
+{
+ /* Check the initialization phase */
+ switch (ExpInitializationPhase)
+ {
+ case 0:
+
+ /* Do Phase 0 */
+ return ExpInitSystemPhase0();
+
+ case 1:
+
+ /* Do Phase 1 */
+ return ExpInitSystemPhase1();
+
+ default:
+
+ /* Don't know any other phase! Bugcheck! */
+ KeBugCheck(UNEXPECTED_INITIALIZATION_CALL);
+ return FALSE;
+ }
+}
+
+BOOLEAN
+NTAPI
ExpIsLoaderValid(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
{
PLOADER_PARAMETER_EXTENSION Extension;
@@ -402,6 +453,9 @@
IN PLOADER_PARAMETER_BLOCK LoaderBlock)
{
PNLS_DATA_BLOCK NlsData;
+ CHAR Buffer[256];
+ ANSI_STRING AnsiPath;
+ NTSTATUS Status;
/* FIXME: Deprecate soon */
ParseAndCacheLoadedModules();
@@ -487,6 +541,31 @@
/* Make sure interrupts are active now */
_enable();
+ /* Clear the crypto exponent */
+ SharedUserData->CryptoExponent = 0;
+
+ /* Set global flags for the checked build */
+#if DBG
+ NtGlobalFlag |= FLG_ENABLE_CLOSE_EXCEPTIONS |
+ FLG_ENABLE_KDEBUG_SYMBOL_LOAD;
+#endif
+
+ /* Setup NT System Root Path */
+ sprintf(Buffer, "C:%s", LoaderBlock->NtBootPathName);
+
+ /* Convert to ANSI_STRING and null-terminate it */
+ RtlInitString(&AnsiPath, Buffer );
+ Buffer[--AnsiPath.Length] = UNICODE_NULL;
+
+ /* Get the string from KUSER_SHARED_DATA's buffer */
+ NtSystemRoot.Buffer = SharedUserData->NtSystemRoot;
+ NtSystemRoot.MaximumLength = sizeof(SharedUserData->NtSystemRoot) /
sizeof(WCHAR);
+ NtSystemRoot.Length = 0;
+
+ /* Now fill it in */
+ Status = RtlAnsiStringToUnicodeString(&NtSystemRoot, &AnsiPath, FALSE);
+ if (!NT_SUCCESS(Status)) KEBUGCHECK(SESSION3_INITIALIZATION_FAILED);
+
/* Setup bugcheck messages */
KiInitializeBugCheck();
@@ -496,14 +575,14 @@
/* Initialize the second stage of the kernel */
KeInit2();
- /* Initialize resources */
- ExpResourceInitialization();
+ /* Initialize the executive at phase 0 */
+ if (!ExInitSystem()) KEBUGCHECK(PHASE0_INITIALIZATION_FAILED);
/* Load basic Security for other Managers */
if (!SeInit1()) KEBUGCHECK(SECURITY_INITIALIZATION_FAILED);
- /* Initialize Lookaside Lists and Handle Table */
- ExInit2();
+ /* Initialize the Handle Table */
+ ExpInitializeHandleTables();
/* Create the Basic Object Manager Types to allow new Object Types */
ObInit();
Modified: trunk/reactos/ntoskrnl/ex/lookas.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ex/lookas.c?rev=2…
==============================================================================
--- trunk/reactos/ntoskrnl/ex/lookas.c (original)
+++ trunk/reactos/ntoskrnl/ex/lookas.c Mon Oct 2 17:23:03 2006
@@ -1,18 +1,16 @@
/*
- * COPYRIGHT: See COPYING in the top level directory
- * PROJECT: ReactOS kernel
- * FILE: ntoskrnl/ex/lookas.c
- * PURPOSE: Lookaside lists
- * PROGRAMMERS: Alex Ionescu (alex(a)relsoft.net)
- * David Welch (welch(a)mcmail.com)
- * Casper S. Hornstrup (chorns(a)users.sourceforge.net)
- */
-
-/* INCLUDES *****************************************************************/
+* PROJECT: ReactOS Kernel
+* LICENSE: GPL - See COPYING in the top level directory
+* FILE: ntoskrnl/ex/lookas.c
+* PURPOSE: Lookaside Lists
+* PROGRAMMERS: Alex Ionescu (alex.ionescu(a)reactos.org)
+*/
+
+/* INCLUDES ******************************************************************/
#include <ntoskrnl.h>
#define NDEBUG
-#include <internal/debug.h>
+#include <debug.h>
#if defined (ALLOC_PRAGMA)
#pragma alloc_text(INIT, ExpInitLookasideLists)
@@ -24,10 +22,41 @@
KSPIN_LOCK ExpNonPagedLookasideListLock;
LIST_ENTRY ExpPagedLookasideListHead;
KSPIN_LOCK ExpPagedLookasideListLock;
+LIST_ENTRY ExSystemLookasideListHead;
+LIST_ENTRY ExPoolLookasideListHead;
NPAGED_LOOKASIDE_LIST ExpSmallNPagedPoolLookasideLists[MAXIMUM_PROCESSORS];
PAGED_LOOKASIDE_LIST ExpSmallPagedPoolLookasideLists[MAXIMUM_PROCESSORS];
-/* FUNCTIONS *****************************************************************/
+/* PRIVATE FUNCTIONS *********************************************************/
+
+VOID
+NTAPI
+ExInitializeSystemLookasideList(IN PGENERAL_LOOKASIDE List,
+ IN POOL_TYPE Type,
+ IN ULONG Size,
+ IN ULONG Tag,
+ IN USHORT MaximumDepth,
+ IN PLIST_ENTRY ListHead)
+{
+ /* Initialize the list */
+ List->Tag = Tag;
+ List->Type = Type;
+ List->Size = Size;
+ InsertHeadList(ListHead, &List->ListEntry);
+ List->MaximumDepth = MaximumDepth;
+ List->Depth = 2;
+ List->Allocate = ExAllocatePoolWithTag;
+ List->Free = ExFreePool;
+ List->ListHead.Next.Next = NULL;
+ List->ListHead.Depth = 0;
+ List->ListHead.Sequence = 0;
+ List->TotalAllocates = 0;
+ List->AllocateHits = 0;
+ List->TotalFrees = 0;
+ List->FreeHits = 0;
+ List->LastTotalAllocates = 0;
+ List->LastAllocateHits = 0;
+}
VOID
NTAPI
@@ -60,23 +89,49 @@
Entry->P = &PagedListEntry->L;
}
}
-VOID
-INIT_FUNCTION
-STDCALL
+
+VOID
+NTAPI
ExpInitLookasideLists()
{
- /* Initialize Lock and Listhead */
+ ULONG i, j;
+
+ /* Initialize locks and lists */
InitializeListHead(&ExpNonPagedLookasideListHead);
+ InitializeListHead(&ExpPagedLookasideListHead);
+ InitializeListHead(&ExSystemLookasideListHead);
+ InitializeListHead(&ExPoolLookasideListHead);
KeInitializeSpinLock(&ExpNonPagedLookasideListLock);
- InitializeListHead(&ExpPagedLookasideListHead);
KeInitializeSpinLock(&ExpPagedLookasideListLock);
-}
+
+ /* Initialize the system lookaside lists */
+ for (i = 0, j = 1; i < (MAXIMUM_PROCESSORS - 1); j++, i++)
+ {
+ /* Initialize the non-paged list */
+ ExInitializeSystemLookasideList(&ExpSmallNPagedPoolLookasideLists[i].L,
+ NonPagedPool,
+ j * 8,
+ TAG('P', 'o', 'o',
'l'),
+ 256,
+ &ExPoolLookasideListHead);
+
+ /* Initialize the paged list */
+ ExInitializeSystemLookasideList(&ExpSmallPagedPoolLookasideLists[i].L,
+ PagedPool,
+ j * 8,
+ TAG('P', 'o', 'o',
'l'),
+ 256,
+ &ExPoolLookasideListHead);
+ }
+}
+
+/* PUBLIC FUNCTIONS **********************************************************/
/*
* @implemented
*/
PVOID
-STDCALL
+NTAPI
ExiAllocateFromPagedLookasideList(IN PPAGED_LOOKASIDE_LIST Lookaside)
{
PVOID Entry;
@@ -87,7 +142,7 @@
{
Lookaside->L.AllocateMisses++;
Entry = (Lookaside->L.Allocate)(Lookaside->L.Type,
- Lookaside->L.Size,
+ Lookaside->L.Size,
Lookaside->L.Tag);
}
return Entry;
@@ -97,7 +152,7 @@
* @implemented
*/
VOID
-STDCALL
+NTAPI
ExiFreeToPagedLookasideList(IN PPAGED_LOOKASIDE_LIST Lookaside,
IN PVOID Entry)
{
@@ -117,21 +172,20 @@
* @implemented
*/
VOID
-STDCALL
-ExDeleteNPagedLookasideList(PNPAGED_LOOKASIDE_LIST Lookaside)
+NTAPI
+ExDeleteNPagedLookasideList(IN PNPAGED_LOOKASIDE_LIST Lookaside)
{
KIRQL OldIrql;
PVOID Entry;
- /* Pop all entries off the stack and release the resources allocated
- for them */
+ /* Pop all entries off the stack and release their resources */
for (;;)
{
Entry = InterlockedPopEntrySList(&Lookaside->L.ListHead);
if (!Entry) break;
(*Lookaside->L.Free)(Entry);
}
-
+
/* Remove from list */
KeAcquireSpinLock(&ExpNonPagedLookasideListLock, &OldIrql);
RemoveEntryList(&Lookaside->L.ListEntry);
@@ -142,21 +196,20 @@
* @implemented
*/
VOID
-STDCALL
-ExDeletePagedLookasideList(PPAGED_LOOKASIDE_LIST Lookaside)
+NTAPI
+ExDeletePagedLookasideList(IN PPAGED_LOOKASIDE_LIST Lookaside)
{
KIRQL OldIrql;
PVOID Entry;
- /* Pop all entries off the stack and release the resources allocated
- for them */
+ /* Pop all entries off the stack and release their resources */
for (;;)
{
Entry = InterlockedPopEntrySList(&Lookaside->L.ListHead);
if (!Entry) break;
(*Lookaside->L.Free)(Entry);
}
-
+
/* Remove from list */
KeAcquireSpinLock(&ExpPagedLookasideListLock, &OldIrql);
RemoveEntryList(&Lookaside->L.ListEntry);
@@ -167,17 +220,15 @@
* @implemented
*/
VOID
-STDCALL
-ExInitializeNPagedLookasideList(PNPAGED_LOOKASIDE_LIST Lookaside,
- PALLOCATE_FUNCTION Allocate,
- PFREE_FUNCTION Free,
- ULONG Flags,
- ULONG Size,
- ULONG Tag,
- USHORT Depth)
-{
- DPRINT("Initializing nonpaged lookaside list at 0x%p\n", Lookaside);
-
+NTAPI
+ExInitializeNPagedLookasideList(IN PNPAGED_LOOKASIDE_LIST Lookaside,
+ IN PALLOCATE_FUNCTION Allocate OPTIONAL,
+ IN PFREE_FUNCTION Free OPTIONAL,
+ IN ULONG Flags,
+ IN ULONG Size,
+ IN ULONG Tag,
+ IN USHORT Depth)
+{
/* Initialize the Header */
ExInitializeSListHead(&Lookaside->L.ListHead);
Lookaside->L.TotalAllocates = 0;
@@ -221,17 +272,15 @@
* @implemented
*/
VOID
-STDCALL
-ExInitializePagedLookasideList (PPAGED_LOOKASIDE_LIST Lookaside,
- PALLOCATE_FUNCTION Allocate,
- PFREE_FUNCTION Free,
- ULONG Flags,
- ULONG Size,
- ULONG Tag,
- USHORT Depth)
-{
- DPRINT("Initializing paged lookaside list at 0x%p\n", Lookaside);
-
+NTAPI
+ExInitializePagedLookasideList(IN PPAGED_LOOKASIDE_LIST Lookaside,
+ IN PALLOCATE_FUNCTION Allocate OPTIONAL,
+ IN PFREE_FUNCTION Free OPTIONAL,
+ IN ULONG Flags,
+ IN ULONG Size,
+ IN ULONG Tag,
+ IN USHORT Depth)
+{
/* Initialize the Header */
ExInitializeSListHead(&Lookaside->L.ListHead);
Lookaside->L.TotalAllocates = 0;
@@ -264,7 +313,7 @@
{
Lookaside->L.Free = ExFreePool;
}
-
+
/* Insert it into the list */
ExInterlockedInsertTailList(&ExpNonPagedLookasideListHead,
&Lookaside->L.ListEntry,
Modified: trunk/reactos/ntoskrnl/ex/sysinfo.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ex/sysinfo.c?rev=…
==============================================================================
--- trunk/reactos/ntoskrnl/ex/sysinfo.c (original)
+++ trunk/reactos/ntoskrnl/ex/sysinfo.c Mon Oct 2 17:23:03 2006
@@ -20,6 +20,10 @@
ULONGLONG STDCALL KeQueryInterruptTime(VOID);
VOID MmPrintMemoryStatistic(VOID);
+
+FAST_MUTEX ExpEnvironmentLock;
+ERESOURCE ExpFirmwareTableResource;
+LIST_ENTRY ExpFirmwareTableProviderListHead;
/* FUNCTIONS *****************************************************************/
Modified: trunk/reactos/ntoskrnl/include/internal/ex.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/…
==============================================================================
--- trunk/reactos/ntoskrnl/include/internal/ex.h (original)
+++ trunk/reactos/ntoskrnl/include/internal/ex.h Mon Oct 2 17:23:03 2006
@@ -10,6 +10,9 @@
extern ULONG NtBuildNumber;
extern ULONG NtMajorVersion;
extern ULONG NtMinorVersion;
+extern FAST_MUTEX ExpEnvironmentLock;
+extern ERESOURCE ExpFirmwareTableResource;
+extern LIST_ENTRY ExpFirmwareTableProviderListHead;
#define MAX_FAST_REFS 7
@@ -65,6 +68,17 @@
VOID
NTAPI
ExpInitLookasideLists(VOID);
+
+VOID
+NTAPI
+ExInitializeSystemLookasideList(
+ IN PGENERAL_LOOKASIDE List,
+ IN POOL_TYPE Type,
+ IN ULONG Size,
+ IN ULONG Tag,
+ IN USHORT MaximumDepth,
+ IN PLIST_ENTRY ListHead
+);
VOID
NTAPI