ReactOS 0.4.17-dev-1218-gfae4549
init.c File Reference
#include <ntoskrnl.h>
#include <reactos/buildno.h>
#include "inbv/logo.h"
#include <debug.h>
Include dependency graph for init.c:

Go to the source code of this file.

Classes

struct  _INIT_BUFFER
 

Macros

#define NDEBUG
 
#define LOADER_PARAMETER_EXTENSION_MIN_SIZE    RTL_SIZEOF_THROUGH_FIELD(LOADER_PARAMETER_EXTENSION, AcpiTableSize)
 

Typedefs

typedef struct _INIT_BUFFER INIT_BUFFER
 
typedef struct _INIT_BUFFER * PINIT_BUFFER
 

Functions

BOOLEAN NTAPI MmArmInitSystem (IN ULONG Phase, IN PLOADER_PARAMETER_BLOCK LoaderBlock)
 
NTSTATUS NTAPI RtlpInitializeLocaleTable (VOID)
 Initializes the locale index table, that maps the LCIDs to their indexes in the alphabetical table, and is sorted by LCID.
 
NTSTATUS NTAPI ExpCreateSystemRootLink (IN PLOADER_PARAMETER_BLOCK LoaderBlock)
 
VOID NTAPI ExpInitNls (IN PLOADER_PARAMETER_BLOCK LoaderBlock)
 
VOID NTAPI ExpLoadInitialProcess (IN PINIT_BUFFER InitBuffer, OUT PRTL_USER_PROCESS_PARAMETERS *ProcessParameters, OUT PCHAR *ProcessEnvironment)
 
ULONG NTAPI ExComputeTickCountMultiplier (IN ULONG ClockIncrement)
 
BOOLEAN NTAPI ExpInitSystemPhase0 (VOID)
 
BOOLEAN NTAPI ExpInitSystemPhase1 (VOID)
 
BOOLEAN NTAPI ExInitSystem (VOID)
 
BOOLEAN NTAPI ExpIsLoaderValid (IN PLOADER_PARAMETER_BLOCK LoaderBlock)
 
static CODE_SEG ("INIT")
 
VOID NTAPI ExBurnMemory (IN PLOADER_PARAMETER_BLOCK LoaderBlock, IN ULONG_PTR PagesToDestroy, IN TYPE_OF_MEMORY MemoryType)
 
VOID NTAPI ExpInitializeExecutive (IN ULONG Cpu, IN PLOADER_PARAMETER_BLOCK LoaderBlock)
 
VOID NTAPI MmFreeLoaderBlock (IN PLOADER_PARAMETER_BLOCK LoaderBlock)
 
VOID NTAPI Phase1InitializationDiscard (IN PVOID Context)
 
VOID NTAPI Phase1Initialization (IN PVOID Context)
 

Variables

ULONG NtMajorVersion = VER_PRODUCTMAJORVERSION
 
ULONG NtMinorVersion = VER_PRODUCTMINORVERSION
 
ULONG NtBuildNumber = VER_PRODUCTBUILD
 
ULONG NtGlobalFlag = 0
 
ULONG ExSuiteMask
 
ULONG CmNtSpBuildNumber
 
ULONG CmNtCSDVersion
 
ULONG CmNtCSDReleaseType
 
UNICODE_STRING CmVersionString
 
UNICODE_STRING CmCSDVersionString
 
CHAR NtBuildLab []
 
ULONG ExpInitializationPhase
 
BOOLEAN ExpInTextModeSetup
 
BOOLEAN IoRemoteBootClient
 
ULONG InitSafeBootMode
 
BOOLEAN InitIsWinPEMode
 
BOOLEAN InitWinPEModeType
 
BOOLEAN SosEnabled
 
UNICODE_STRING NtSystemRoot
 
WCHAR NtInitialUserProcessBuffer [128] = L"\\SystemRoot\\System32\\smss.exe"
 
ULONG NtInitialUserProcessBufferLength
 
ULONG NtInitialUserProcessBufferType = REG_SZ
 
PVOID ExpNlsTableBase
 
ULONG ExpAnsiCodePageDataOffset
 
ULONG ExpOemCodePageDataOffset
 
ULONG ExpUnicodeCaseTableDataOffset
 
NLSTABLEINFO ExpNlsTableInfo
 
SIZE_T ExpNlsTableSize
 
PVOID ExpNlsSectionPointer
 
BOOLEAN ExCmosClockIsSane = TRUE
 
BOOLEAN ExpRealTimeIsUniversal
 

Macro Definition Documentation

◆ LOADER_PARAMETER_EXTENSION_MIN_SIZE

#define LOADER_PARAMETER_EXTENSION_MIN_SIZE    RTL_SIZEOF_THROUGH_FIELD(LOADER_PARAMETER_EXTENSION, AcpiTableSize)

Definition at line 20 of file init.c.

◆ NDEBUG

#define NDEBUG

Definition at line 16 of file init.c.

Typedef Documentation

◆ INIT_BUFFER

◆ PINIT_BUFFER

Function Documentation

◆ CODE_SEG()

static CODE_SEG ( "INIT"  )
static

Definition at line 797 of file init.c.

801{
802 PLIST_ENTRY NextEntry;
803 PLDR_DATA_TABLE_ENTRY LdrEntry;
805 ULONG i;
807 PWCHAR Name;
808 STRING ImageName;
809 CHAR NameBuffer[256];
810
811 /* Loop over the boot modules list */
812 for (NextEntry = LoaderBlock->LoadOrderListHead.Flink, i = 0;
813 NextEntry != &LoaderBlock->LoadOrderListHead;
814 NextEntry = NextEntry->Flink, ++i)
815 {
816 /* Skip the first two images: HAL and kernel */
817 if (i < 2)
818 continue;
819
820 /* Get the entry */
821 LdrEntry = CONTAINING_RECORD(NextEntry,
823 InLoadOrderLinks);
824 if (LdrEntry->FullDllName.Buffer[0] == L'\\')
825 {
826 /* We have a name, read its data */
827 Name = LdrEntry->FullDllName.Buffer;
828 Length = LdrEntry->FullDllName.Length / sizeof(WCHAR);
829
830 /* Check if our buffer can hold it */
831 if (sizeof(NameBuffer) < Length + sizeof(ANSI_NULL))
832 {
833 /* It's too long */
835 }
836 else
837 {
838 /* Copy the name */
839 Count = 0;
840 do
841 {
842 /* Do cheap Unicode to ANSI conversion */
843 NameBuffer[Count++] = (CHAR)*Name++;
844 } while (Count < Length);
845
846 /* Null-terminate */
847 NameBuffer[Count] = ANSI_NULL;
849 }
850 }
851 else
852 {
853 /* Safely print the string into our buffer */
854 Status = RtlStringCbPrintfA(NameBuffer,
855 sizeof(NameBuffer),
856 "%S\\System32\\Drivers\\%wZ",
857 &SharedUserData->NtSystemRoot[2],
858 &LdrEntry->BaseDllName);
859 }
860
861 /* Check if the buffer is OK */
862 if (NT_SUCCESS(Status))
863 {
864 /* Load the symbols */
865 RtlInitString(&ImageName, NameBuffer);
866 DbgLoadImageSymbols(&ImageName,
867 LdrEntry->DllBase,
869 }
870
871#ifdef CONFIG_SMP
872 /* Check that the image is safe to use if we have more than one CPU */
873 if (!MmVerifyImageIsOkForMpUse(LdrEntry->DllBase))
874 {
875 KeBugCheckEx(UP_DRIVER_ON_MP_SYSTEM,
876 (ULONG_PTR)LdrEntry->DllBase,
877 0, 0, 0);
878 }
879#endif // CONFIG_SMP
880 }
881}
LONG NTSTATUS
Definition: precomp.h:26
#define CHAR(Char)
DECLSPEC_NORETURN VOID NTAPI KeBugCheckEx(IN ULONG BugCheckCode, IN ULONG_PTR BugCheckParameter1, IN ULONG_PTR BugCheckParameter2, IN ULONG_PTR BugCheckParameter3, IN ULONG_PTR BugCheckParameter4)
Definition: debug.c:485
LPWSTR Name
Definition: desk.c:124
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define L(x)
Definition: resources.c:13
std::wstring STRING
Definition: fontsub.cpp:33
Status
Definition: gdiplustypes.h:24
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
VOID NTAPI DbgLoadImageSymbols(_In_ PSTRING Name, _In_ PVOID Base, _In_ ULONG_PTR ProcessId)
int Count
Definition: noreturn.cpp:7
NTSYSAPI VOID NTAPI RtlInitString(PSTRING DestinationString, PCSZ SourceString)
#define ANSI_NULL
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
HANDLE NTAPI PsGetCurrentProcessId(VOID)
Definition: process.c:1163
NTSTRSAFEVAPI RtlStringCbPrintfA(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PSTR pszDest, _In_ size_t cbDest, _In_ _Printf_format_string_ NTSTRSAFE_PCSTR pszFormat,...)
Definition: ntstrsafe.h:1148
short WCHAR
Definition: pedump.c:58
char CHAR
Definition: pedump.c:57
#define SharedUserData
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
Definition: btrfs_drv.h:1876
UNICODE_STRING FullDllName
Definition: btrfs_drv.h:1882
PVOID DllBase
Definition: btrfs_drv.h:1880
UNICODE_STRING BaseDllName
Definition: ldrtypes.h:149
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint16_t * PWCHAR
Definition: typedefs.h:56
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59

◆ ExBurnMemory()

VOID NTAPI ExBurnMemory ( IN PLOADER_PARAMETER_BLOCK  LoaderBlock,
IN ULONG_PTR  PagesToDestroy,
IN TYPE_OF_MEMORY  MemoryType 
)

Definition at line 886 of file init.c.

889{
890 PLIST_ENTRY ListEntry;
891 PMEMORY_ALLOCATION_DESCRIPTOR MemDescriptor;
892
893 DPRINT1("Burn RAM amount: %lu pages\n", PagesToDestroy);
894
895 /* Loop the memory descriptors, beginning at the end */
896 for (ListEntry = LoaderBlock->MemoryDescriptorListHead.Blink;
897 ListEntry != &LoaderBlock->MemoryDescriptorListHead;
898 ListEntry = ListEntry->Blink)
899 {
900 /* Get the memory descriptor structure */
901 MemDescriptor = CONTAINING_RECORD(ListEntry,
903 ListEntry);
904
905 /* Is memory free there or is it temporary? */
906 if (MemDescriptor->MemoryType == LoaderFree ||
907 MemDescriptor->MemoryType == LoaderFirmwareTemporary)
908 {
909 /* Check if the descriptor has more pages than we want */
910 if (MemDescriptor->PageCount > PagesToDestroy)
911 {
912 /* Change block's page count, ntoskrnl doesn't care much */
913 MemDescriptor->PageCount -= PagesToDestroy;
914 break;
915 }
916 else
917 {
918 /* Change block type */
919 MemDescriptor->MemoryType = MemoryType;
920 PagesToDestroy -= MemDescriptor->PageCount;
921
922 /* Check if we are done */
923 if (PagesToDestroy == 0) break;
924 }
925 }
926 }
927}
#define DPRINT1
Definition: precomp.h:8
@ LoaderFree
Definition: arc.h:295
@ LoaderFirmwareTemporary
Definition: arc.h:298
struct _LIST_ENTRY * Blink
Definition: typedefs.h:122
TYPE_OF_MEMORY MemoryType
Definition: arc.h:328

Referenced by ExpInitializeExecutive().

◆ ExComputeTickCountMultiplier()

ULONG NTAPI ExComputeTickCountMultiplier ( IN ULONG  ClockIncrement)

Definition at line 610 of file init.c.

611{
612 ULONG MsRemainder = 0, MsIncrement;
613 ULONG IncrementRemainder;
614 ULONG i;
615
616 /* Count the number of milliseconds for each clock interrupt */
617 MsIncrement = ClockIncrement / (10 * 1000);
618
619 /* Count the remainder from the division above, with 24-bit precision */
620 IncrementRemainder = ClockIncrement - (MsIncrement * (10 * 1000));
621 for (i= 0; i < 24; i++)
622 {
623 /* Shift the remainders */
624 MsRemainder <<= 1;
625 IncrementRemainder <<= 1;
626
627 /* Check if we've went past 1 ms */
628 if (IncrementRemainder >= (10 * 1000))
629 {
630 /* Increase the remainder by one, and substract from increment */
631 IncrementRemainder -= (10 * 1000);
632 MsRemainder |= 1;
633 }
634 }
635
636 /* Return the increment */
637 return (MsIncrement << 24) | MsRemainder;
638}

Referenced by ExpInitializeExecutive().

◆ ExInitSystem()

BOOLEAN NTAPI ExInitSystem ( VOID  )

Definition at line 748 of file init.c.

749{
750 /* Check the initialization phase */
752 {
753 case 0:
754
755 /* Do Phase 0 */
756 return ExpInitSystemPhase0();
757
758 case 1:
759
760 /* Do Phase 1 */
761 return ExpInitSystemPhase1();
762
763 default:
764
765 /* Don't know any other phase! Bugcheck! */
766 KeBugCheck(UNEXPECTED_INITIALIZATION_CALL);
767 return FALSE;
768 }
769}
DECLSPEC_NORETURN VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1434
#define FALSE
Definition: types.h:117
ULONG ExpInitializationPhase
Definition: init.c:72
BOOLEAN NTAPI ExpInitSystemPhase0(VOID)
Definition: init.c:643
BOOLEAN NTAPI ExpInitSystemPhase1(VOID)
Definition: init.c:667

Referenced by ExpInitializeExecutive(), and Phase1InitializationDiscard().

◆ ExpCreateSystemRootLink()

NTSTATUS NTAPI ExpCreateSystemRootLink ( IN PLOADER_PARAMETER_BLOCK  LoaderBlock)

Definition at line 105 of file init.c.

106{
107 UNICODE_STRING LinkName;
109 HANDLE LinkHandle;
111 ANSI_STRING AnsiName;
112 CHAR Buffer[256];
115
116 /* Initialize the ArcName tree */
117 RtlInitUnicodeString(&LinkName, L"\\ArcName");
119 &LinkName,
121 NULL,
123
124 /* Create it */
125 Status = NtCreateDirectoryObject(&LinkHandle,
128 if (!NT_SUCCESS(Status))
129 {
130 /* Failed */
131 KeBugCheckEx(SYMBOLIC_INITIALIZATION_FAILED, Status, 1, 0, 0);
132 }
133
134 /* Close the LinkHandle */
135 NtClose(LinkHandle);
136
137 /* Initialize the Device tree */
138 RtlInitUnicodeString(&LinkName, L"\\Device");
140 &LinkName,
142 NULL,
144
145 /* Create it */
146 Status = NtCreateDirectoryObject(&LinkHandle,
149 if (!NT_SUCCESS(Status))
150 {
151 /* Failed */
152 KeBugCheckEx(SYMBOLIC_INITIALIZATION_FAILED, Status, 2, 0, 0);
153 }
154
155 /* Close the LinkHandle */
156 ObCloseHandle(LinkHandle, KernelMode);
157
158 /* Create the system root symlink name */
159 RtlInitAnsiString(&AnsiName, "\\SystemRoot");
160 Status = RtlAnsiStringToUnicodeString(&LinkName, &AnsiName, TRUE);
161 if (!NT_SUCCESS(Status))
162 {
163 /* Failed */
164 KeBugCheckEx(SYMBOLIC_INITIALIZATION_FAILED, Status, 3, 0, 0);
165 }
166
167 /* Initialize the attributes for the link */
169 &LinkName,
171 NULL,
173
174 /* Build the ARC name */
176 "\\ArcName\\%s%s",
177 LoaderBlock->ArcBootDeviceName,
178 LoaderBlock->NtBootPathName);
180
181 /* Convert it to Unicode */
185 TRUE);
186 if (!NT_SUCCESS(Status))
187 {
188 /* We failed, bugcheck */
189 KeBugCheckEx(SYMBOLIC_INITIALIZATION_FAILED, Status, 4, 0, 0);
190 }
191
192 /* Create it */
196 &TargetName);
197
198 /* Free the strings */
199 RtlFreeUnicodeString(&LinkName);
201
202 /* Check if creating the link failed */
203 if (!NT_SUCCESS(Status))
204 {
205 /* Failed */
206 KeBugCheckEx(SYMBOLIC_INITIALIZATION_FAILED, Status, 5, 0, 0);
207 }
208
209 /* Close the handle and return success */
210 ObCloseHandle(LinkHandle, KernelMode);
211 return STATUS_SUCCESS;
212}
_In_z_ PCHAR TargetString
Definition: cdrom.h:954
Definition: bufpool.h:45
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
_ACRTIMP size_t __cdecl strlen(const char *)
Definition: string.c:1597
#define sprintf
Definition: sprintf.c:45
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:115
#define KernelMode
Definition: asm.h:38
#define SYMBOLIC_LINK_ALL_ACCESS
Definition: nt_native.h:1270
NTSYSAPI NTSTATUS NTAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, PANSI_STRING SourceString, BOOLEAN AllocateDestinationString)
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3434
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
#define DIRECTORY_ALL_ACCESS
Definition: nt_native.h:1262
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
PSECURITY_DESCRIPTOR SePublicDefaultUnrestrictedSd
Definition: sd.c:17
NTSTATUS NTAPI NtCreateDirectoryObject(OUT PHANDLE DirectoryHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
Definition: obdir.c:765
NTSTATUS NTAPI ObCloseHandle(IN HANDLE Handle, IN KPROCESSOR_MODE AccessMode)
Definition: obhandle.c:3411
static PCWSTR TargetName
Definition: ping.c:67
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define OBJ_PERMANENT
Definition: winternl.h:226

Referenced by Phase1InitializationDiscard().

◆ ExpInitializeExecutive()

VOID NTAPI ExpInitializeExecutive ( IN ULONG  Cpu,
IN PLOADER_PARAMETER_BLOCK  LoaderBlock 
)

Definition at line 932 of file init.c.

934{
935 PNLS_DATA_BLOCK NlsData;
936 CHAR Buffer[256];
937 ANSI_STRING AnsiPath;
939 PCHAR CommandLine, PerfMem;
940 ULONG PerfMemUsed;
941 PLDR_DATA_TABLE_ENTRY NtosEntry;
943 ANSI_STRING CSDString;
944 size_t Remaining = 0;
945 PCHAR RcEnd = NULL;
946 CHAR VersionBuffer[65];
947
948 /* Validate Loader */
949 if (!ExpIsLoaderValid(LoaderBlock))
950 {
951 /* Invalid loader version */
952 KeBugCheckEx(MISMATCHED_HAL,
953 3,
954 LoaderBlock->Extension->Size,
955 LoaderBlock->Extension->MajorVersion,
956 LoaderBlock->Extension->MinorVersion);
957 }
958
959 /* Initialize PRCB pool lookaside pointers */
961
962 /* Check if this is an application CPU */
963 if (Cpu)
964 {
965 /* Then simply initialize it with HAL */
966 if (!HalInitSystem(ExpInitializationPhase, LoaderBlock))
967 {
968 /* Initialization failed */
969 KeBugCheck(HAL_INITIALIZATION_FAILED);
970 }
971
972 /* We're done */
973 return;
974 }
975
976 /* Assume no text-mode or remote boot */
979
980 /* Check if we have a setup loader block */
981 if (LoaderBlock->SetupLdrBlock)
982 {
983 /* Check if this is text-mode setup */
984 if (LoaderBlock->SetupLdrBlock->Flags & SETUPLDR_TEXT_MODE)
986
987 /* Check if this is network boot */
988 if (LoaderBlock->SetupLdrBlock->Flags & SETUPLDR_REMOTE_BOOT)
989 {
990 /* Set variable */
992
993 /* Make sure we're actually booting off the network */
994 ASSERT(!_memicmp(LoaderBlock->ArcBootDeviceName, "net(0)", 6));
995 }
996 }
997
998 /* Set phase to 0 */
1000
1001 /* Get boot command line */
1002 CommandLine = LoaderBlock->LoadOptions;
1003 if (CommandLine)
1004 {
1005 /* Upcase it for comparison and check if we're in performance mode */
1006 _strupr(CommandLine);
1007 PerfMem = strstr(CommandLine, "PERFMEM");
1008 if (PerfMem)
1009 {
1010 /* Check if the user gave a number of bytes to use */
1011 PerfMem = strstr(PerfMem, "=");
1012 if (PerfMem)
1013 {
1014 /* Read the number of pages we'll use */
1015 PerfMemUsed = atol(PerfMem + 1) * (1024 * 1024 / PAGE_SIZE);
1016 if (PerfMemUsed)
1017 {
1018 /* FIXME: TODO */
1019 DPRINT1("BBT performance mode not yet supported."
1020 "/PERFMEM option ignored.\n");
1021 }
1022 }
1023 }
1024
1025 /* Check if we're burning memory */
1026 PerfMem = strstr(CommandLine, "BURNMEMORY");
1027 if (PerfMem)
1028 {
1029 /* Check if the user gave a number of bytes to use */
1030 PerfMem = strstr(PerfMem, "=");
1031 if (PerfMem)
1032 {
1033 /* Read the number of pages we'll use */
1034 PerfMemUsed = atol(PerfMem + 1) * (1024 * 1024 / PAGE_SIZE);
1035 if (PerfMemUsed) ExBurnMemory(LoaderBlock, PerfMemUsed, LoaderBad);
1036 }
1037 }
1038 }
1039
1040 /* Setup NLS Base and offsets */
1041 NlsData = LoaderBlock->NlsData;
1045 (ULONG_PTR)NlsData->AnsiCodePageData);
1047 (ULONG_PTR)NlsData->AnsiCodePageData);
1048
1049 /* Initialize the NLS Tables */
1058
1059 /* Now initialize the HAL */
1060 if (!HalInitSystem(ExpInitializationPhase, LoaderBlock))
1061 {
1062 /* HAL failed to initialize, bugcheck */
1063 KeBugCheck(HAL_INITIALIZATION_FAILED);
1064 }
1065
1066 /* Make sure interrupts are active now */
1067 _enable();
1068
1069 /* Clear the crypto exponent */
1070 SharedUserData->CryptoExponent = 0;
1071
1072 /* Set global flags for the checked build */
1073#if DBG
1076#endif
1077
1078 /* Setup NT System Root Path */
1079 sprintf(Buffer, "C:%s", LoaderBlock->NtBootPathName);
1080
1081 /* Convert to ANSI_STRING and null-terminate it */
1082 RtlInitString(&AnsiPath, Buffer);
1083 Buffer[--AnsiPath.Length] = ANSI_NULL;
1084
1085 /* Get the string from KUSER_SHARED_DATA's buffer */
1086 RtlInitEmptyUnicodeString(&NtSystemRoot,
1087 SharedUserData->NtSystemRoot,
1088 sizeof(SharedUserData->NtSystemRoot));
1089
1090 /* Now fill it in */
1092 if (!NT_SUCCESS(Status)) KeBugCheck(SESSION3_INITIALIZATION_FAILED);
1093
1094 /* Setup bugcheck messages */
1096
1097 /* Setup initial system settings */
1098 CmGetSystemControlValues(LoaderBlock->RegistryBase, CmControlVector);
1099
1100 /* Set the Service Pack Number and add it to the CSD Version number if needed */
1102 if (((CmNtCSDVersion & 0xFFFF0000) == 0) && (CmNtCSDReleaseType == 1))
1103 {
1105 }
1106
1107 /* Add loaded CmNtGlobalFlag value */
1109
1110 /* Initialize the executive at phase 0 */
1111 if (!ExInitSystem()) KeBugCheck(PHASE0_INITIALIZATION_FAILED);
1112
1113 /* Initialize the memory manager at phase 0 */
1114 if (!MmArmInitSystem(0, LoaderBlock)) KeBugCheck(PHASE0_INITIALIZATION_FAILED);
1115
1116 /* Load boot symbols */
1117 ExpLoadBootSymbols(LoaderBlock);
1118
1119 /* Check if we should break after symbol load */
1122
1123 /* Check if this loader is compatible with NT 5.2 */
1124 if (LoaderBlock->Extension->Size >= sizeof(LOADER_PARAMETER_EXTENSION))
1125 {
1126 /* Setup headless terminal settings */
1127 HeadlessInit(LoaderBlock);
1128 }
1129
1130 /* Set system ranges */
1131#ifdef _M_AMD64
1134#else
1137#endif
1138
1139 /* Make a copy of the NLS Tables */
1140 ExpInitNls(LoaderBlock);
1141
1142 /* Get the kernel's load entry */
1143 NtosEntry = CONTAINING_RECORD(LoaderBlock->LoadOrderListHead.Flink,
1145 InLoadOrderLinks);
1146
1147 /* Check if this is a service pack */
1148 if (CmNtCSDVersion & 0xFFFF)
1149 {
1150 /* Get the service pack string */
1151 Status = RtlFindMessage(NtosEntry->DllBase,
1154 WINDOWS_NT_CSD_STRING,
1155 &MsgEntry);
1156 if (NT_SUCCESS(Status))
1157 {
1158 /* Setup the string */
1159 RtlInitAnsiString(&CSDString, (PCHAR)MsgEntry->Text);
1160
1161 /* Remove trailing newline */
1162 while ((CSDString.Length > 0) &&
1163 ((CSDString.Buffer[CSDString.Length - 1] == '\r') ||
1164 (CSDString.Buffer[CSDString.Length - 1] == '\n')))
1165 {
1166 /* Skip the trailing character */
1167 CSDString.Length--;
1168 }
1169
1170 /* Fill the buffer with version information */
1172 sizeof(Buffer),
1173 "%Z %u%c",
1174 &CSDString,
1175 (CmNtCSDVersion & 0xFF00) >> 8,
1176 (CmNtCSDVersion & 0xFF) ?
1177 'A' + (CmNtCSDVersion & 0xFF) - 1 :
1178 ANSI_NULL);
1179 }
1180 else
1181 {
1182 /* Build default string */
1184 sizeof(Buffer),
1185 "CSD %04x",
1187 }
1188
1189 /* Check for success */
1190 if (!NT_SUCCESS(Status))
1191 {
1192 /* Fail */
1193 KeBugCheckEx(PHASE0_INITIALIZATION_FAILED, Status, 0, 0, 0);
1194 }
1195 }
1196 else
1197 {
1198 /* Then this is a beta */
1200 sizeof(Buffer),
1202 NULL,
1203 &Remaining,
1204 0);
1205 if (!NT_SUCCESS(Status))
1206 {
1207 /* Fail */
1208 KeBugCheckEx(PHASE0_INITIALIZATION_FAILED, Status, 0, 0, 0);
1209 }
1210
1211 /* Update length */
1212 CmCSDVersionString.MaximumLength = sizeof(Buffer) - (USHORT)Remaining;
1213 }
1214
1215 /* Check if we have an RC number */
1216 if ((CmNtCSDVersion & 0xFFFF0000) && (CmNtCSDReleaseType == 1))
1217 {
1218 /* Check if we have no version data yet */
1219 if (!(*Buffer))
1220 {
1221 /* Set defaults */
1222 Remaining = sizeof(Buffer);
1223 RcEnd = Buffer;
1224 }
1225 else
1226 {
1227 /* Add comma and space */
1229 sizeof(Buffer),
1230 ", ",
1231 &RcEnd,
1232 &Remaining,
1233 0);
1234 if (!NT_SUCCESS(Status))
1235 {
1236 /* Fail */
1237 KeBugCheckEx(PHASE0_INITIALIZATION_FAILED, Status, 0, 0, 0);
1238 }
1239 }
1240
1241 /* Add the version format string */
1242 Status = RtlStringCbPrintfA(RcEnd,
1243 Remaining,
1244 "v.%u",
1245 (CmNtCSDVersion & 0xFFFF0000) >> 16);
1246 if (!NT_SUCCESS(Status))
1247 {
1248 /* Fail */
1249 KeBugCheckEx(PHASE0_INITIALIZATION_FAILED, Status, 0, 0, 0);
1250 }
1251 }
1252
1253 /* Now setup the final string */
1254 RtlInitAnsiString(&CSDString, Buffer);
1256 &CSDString,
1257 TRUE);
1258 if (!NT_SUCCESS(Status))
1259 {
1260 /* Fail */
1261 KeBugCheckEx(PHASE0_INITIALIZATION_FAILED, Status, 0, 0, 0);
1262 }
1263
1264 /* Add our version */
1265 Status = RtlStringCbPrintfA(VersionBuffer,
1266 sizeof(VersionBuffer),
1267 "%u.%u",
1270 if (!NT_SUCCESS(Status))
1271 {
1272 /* Fail */
1273 KeBugCheckEx(PHASE0_INITIALIZATION_FAILED, Status, 0, 0, 0);
1274 }
1275
1276 /* Build the final version string */
1278
1279 /* Check if the user wants a kernel stack trace database */
1281 {
1282 /* FIXME: TODO */
1283 DPRINT1("Kernel-mode stack trace support not yet present."
1284 "FLG_KERNEL_STACK_TRACE_DB flag ignored.\n");
1285 }
1286
1287 /* Check if he wanted exception logging */
1289 {
1290 /* FIXME: TODO */
1291 DPRINT1("Kernel-mode exception logging support not yet present."
1292 "FLG_ENABLE_EXCEPTION_LOGGING flag ignored.\n");
1293 }
1294
1295 /* Initialize the Handle Table */
1297
1298#if DBG
1299 /* On checked builds, allocate the system call count table */
1302 KiServiceLimit * sizeof(ULONG),
1303 'llaC');
1304
1305 /* Use it for the shadow table too */
1307
1308 /* Make sure allocation succeeded */
1310 {
1311 /* Zero the call counts to 0 */
1313 KiServiceLimit * sizeof(ULONG));
1314 }
1315#endif
1316
1317 /* Create the Basic Object Manager Types to allow new Object Types */
1318 if (!ObInitSystem()) KeBugCheck(OBJECT_INITIALIZATION_FAILED);
1319
1320 /* Load basic Security for other Managers */
1321 if (!SeInitSystem()) KeBugCheck(SECURITY_INITIALIZATION_FAILED);
1322
1323 /* Initialize the Process Manager */
1324 if (!PsInitSystem(LoaderBlock)) KeBugCheck(PROCESS_INITIALIZATION_FAILED);
1325
1326 /* Initialize the PnP Manager */
1327 if (!PpInitSystem()) KeBugCheck(PP0_INITIALIZATION_FAILED);
1328
1329 /* Initialize the User-Mode Debugging Subsystem */
1331
1332 /* Calculate the tick count multiplier */
1334 SharedUserData->TickCountMultiplier = ExpTickCountMultiplier;
1335
1336 /* Set the OS Version */
1337 SharedUserData->NtMajorVersion = NtMajorVersion;
1338 SharedUserData->NtMinorVersion = NtMinorVersion;
1339
1340 /* Set the machine type */
1341 SharedUserData->ImageNumberLow = IMAGE_FILE_MACHINE_NATIVE;
1342 SharedUserData->ImageNumberHigh = IMAGE_FILE_MACHINE_NATIVE;
1343
1344 /* ReactOS magic */
1345 *(PULONG)(KI_USER_SHARED_DATA + PAGE_SIZE - sizeof(ULONG)) = 0x8eac705;
1346}
PVOID MmHighestUserAddress
Definition: libsupp.c:23
CM_SYSTEM_CONTROL_VECTOR CmControlVector[]
VOID NTAPI CmGetSystemControlValues(IN PVOID SystemHiveData, IN PCM_SYSTEM_CONTROL_VECTOR ControlVector)
Definition: cmcontrl.c:104
ULONG CmNtGlobalFlag
Definition: cmdata.c:19
VOID NTAPI DbgkInitialize(VOID)
Definition: dbgkobj.c:1498
_ACRTIMP int __cdecl _memicmp(const void *, const void *, size_t)
Definition: string.c:3490
_ACRTIMP __msvcrt_long __cdecl atol(const char *)
Definition: string.c:1787
_ACRTIMP char *__cdecl strstr(const char *, const char *)
Definition: string.c:3420
#define ULONG_PTR
Definition: config.h:101
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define NonPagedPool
Definition: env_spec_w32.h:307
BOOLEAN NTAPI HalInitSystem(_In_ ULONG BootPhase, _In_ PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: halinit.c:45
VOID NTAPI HeadlessInit(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: hdlsterm.c:189
#define VER_PRODUCTBETA_STR
Definition: ieverp.h:10
#define FLG_KERNEL_STACK_TRACE_DB
Definition: pstypes.h:63
#define FLG_ENABLE_EXCEPTION_LOGGING
Definition: pstypes.h:77
#define FLG_ENABLE_CLOSE_EXCEPTIONS
Definition: pstypes.h:76
#define FLG_ENABLE_KDEBUG_SYMBOL_LOAD
Definition: pstypes.h:68
BOOLEAN KdBreakAfterSymbolLoad
Definition: kddata.c:79
VOID NTAPI ExInitPoolLookasidePointers(VOID)
Definition: lookas.c:59
#define ASSERT(a)
Definition: mode.c:44
#define DBG_STATUS_CONTROL_C
Definition: kdtypes.h:39
NTSYSAPI VOID NTAPI RtlInitNlsTables(_In_ PUSHORT AnsiTableBase, _In_ PUSHORT OemTableBase, _In_ PUSHORT CaseTableBase, _Out_ PNLSTABLEINFO NlsTable)
NTSYSAPI VOID NTAPI RtlResetRtlTranslations(_In_ PNLSTABLEINFO NlsTable)
NTSYSAPI BOOLEAN NTAPI RtlCreateUnicodeStringFromAsciiz(_Out_ PUNICODE_STRING Destination, _In_ PCSZ Source)
NTSYSAPI NTSTATUS NTAPI RtlFindMessage(_In_ PVOID BaseAddress, _In_ ULONG Type, _In_ ULONG Language, _In_ ULONG MessageId, _Out_ PMESSAGE_RESOURCE_ENTRY *MessageResourceEntry)
VOID NTAPI ExpInitializeHandleTables(VOID)
Definition: handle.c:34
VOID NTAPI ExBurnMemory(IN PLOADER_PARAMETER_BLOCK LoaderBlock, IN ULONG_PTR PagesToDestroy, IN TYPE_OF_MEMORY MemoryType)
Definition: init.c:886
ULONG CmNtCSDReleaseType
Definition: init.c:64
PVOID ExpNlsTableBase
Definition: init.c:89
ULONG NTAPI ExComputeTickCountMultiplier(IN ULONG ClockIncrement)
Definition: init.c:610
BOOLEAN IoRemoteBootClient
Definition: init.c:74
UNICODE_STRING NtSystemRoot
Definition: init.c:80
ULONG ExpOemCodePageDataOffset
Definition: init.c:90
NLSTABLEINFO ExpNlsTableInfo
Definition: init.c:92
BOOLEAN NTAPI ExpIsLoaderValid(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: init.c:774
ULONG NtMajorVersion
Definition: init.c:49
ULONG ExpUnicodeCaseTableDataOffset
Definition: init.c:91
BOOLEAN NTAPI MmArmInitSystem(IN ULONG Phase, IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: mminit.c:2049
ULONG NtGlobalFlag
Definition: init.c:58
UNICODE_STRING CmVersionString
Definition: init.c:65
ULONG CmNtSpBuildNumber
Definition: init.c:62
BOOLEAN ExpInTextModeSetup
Definition: init.c:73
ULONG ExpAnsiCodePageDataOffset
Definition: init.c:90
ULONG NtMinorVersion
Definition: init.c:50
ULONG CmNtCSDVersion
Definition: init.c:63
VOID NTAPI ExpInitNls(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: init.c:217
UNICODE_STRING CmCSDVersionString
Definition: init.c:66
BOOLEAN NTAPI ExInitSystem(VOID)
Definition: init.c:748
ULONG ExpTickCountMultiplier
Definition: time.c:26
#define MM_HIGHEST_USER_ADDRESS_WOW64
Definition: mm.h:37
#define MM_SYSTEM_RANGE_START_WOW64
Definition: mm.h:38
#define MmSystemRangeStart
Definition: mm.h:34
BOOLEAN NTAPI PpInitSystem(VOID)
Definition: pnpmgr.c:1142
VOID NTAPI KiInitializeBugCheck(VOID)
Definition: bug.c:300
ULONG KiServiceLimit
Definition: krnlinit.c:25
BOOLEAN NTAPI SeInitSystem(VOID)
Main security manager initialization function.
Definition: semgr.c:285
ULONG KeMaximumIncrement
Definition: clock.c:20
NTSTRSAFEAPI RtlStringCbCatExA(_Inout_updates_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PSTR pszDest, _In_ size_t cbDest, _In_ NTSTRSAFE_PCSTR pszSrc, _Outptr_opt_result_bytebuffer_(*pcbRemaining) NTSTRSAFE_PSTR *ppszDestEnd, _Out_opt_ size_t *pcbRemaining, _In_ STRSAFE_DWORD dwFlags)
Definition: ntstrsafe.h:718
NTSTRSAFEAPI RtlStringCbCopyExA(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PSTR pszDest, _In_ size_t cbDest, _In_ NTSTRSAFE_PCSTR pszSrc, _Outptr_opt_result_bytebuffer_(*pcbRemaining) STRSAFE_LPSTR *ppszDestEnd, _Out_opt_ size_t *pcbRemaining, _In_ STRSAFE_DWORD dwFlags)
Definition: ntstrsafe.h:270
#define VER_PRODUCTMAJORVERSION
Definition: ntverp.h:25
#define VER_PRODUCTBUILD_QFE
Definition: ntverp.h:20
#define VER_PRODUCTMINORVERSION
Definition: ntverp.h:26
BOOLEAN NTAPI ObInitSystem(VOID)
Definition: obinit.c:203
#define RT_MESSAGETABLE
Definition: pedump.c:373
unsigned short USHORT
Definition: pedump.c:61
KSERVICE_TABLE_DESCRIPTOR KeServiceDescriptorTable[SSDT_MAX_ENTRIES]
Definition: procobj.c:23
KSERVICE_TABLE_DESCRIPTOR KeServiceDescriptorTableShadow[SSDT_MAX_ENTRIES]
Definition: procobj.c:24
BOOLEAN NTAPI PsInitSystem(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: psmgr.c:536
#define LANG_NEUTRAL
Definition: nls.h:22
#define MAKELANGID(p, s)
Definition: nls.h:15
#define SUBLANG_NEUTRAL
Definition: nls.h:167
@ LoaderBad
Definition: arc.h:296
_strupr
Definition: string.h:453
void __cdecl _enable(void)
Definition: intrin_arm.h:373
#define KI_USER_SHARED_DATA
#define SETUPLDR_REMOTE_BOOT
Definition: setupblk.h:8
#define SETUPLDR_TEXT_MODE
Definition: setupblk.h:7
Definition: rtltypes.h:1958
UCHAR Text[ANYSIZE_ARRAY]
Definition: rtltypes.h:1961
PVOID UnicodeCodePageData
Definition: arc.h:401
PVOID AnsiCodePageData
Definition: arc.h:399
PVOID OemCodePageData
Definition: arc.h:400
USHORT MaximumLength
Definition: env_spec_w32.h:370
uint32_t * PULONG
Definition: typedefs.h:59
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
char * PCHAR
Definition: typedefs.h:51
__analysis_noreturn NTSYSAPI VOID NTAPI DbgBreakPointWithStatus(_In_ ULONG Status)

Referenced by KiInitializeKernel().

◆ ExpInitNls()

VOID NTAPI ExpInitNls ( IN PLOADER_PARAMETER_BLOCK  LoaderBlock)

Definition at line 217 of file init.c.

218{
219 LARGE_INTEGER SectionSize;
221 HANDLE NlsSection;
222 PVOID SectionBase = NULL;
223 SIZE_T ViewSize = 0;
224 LARGE_INTEGER SectionOffset = {{0, 0}};
225 PLIST_ENTRY ListHead, NextEntry;
227 ULONG NlsTablesEncountered = 0;
228 SIZE_T NlsTableSizes[3] = {0, 0, 0}; /* 3 NLS tables */
229
230 /* Check if this is boot-time phase 0 initialization */
232 {
233 /* Loop the memory descriptors */
234 ListHead = &LoaderBlock->MemoryDescriptorListHead;
235 NextEntry = ListHead->Flink;
236 while (NextEntry != ListHead)
237 {
238 /* Get the current block */
239 MdBlock = CONTAINING_RECORD(NextEntry,
241 ListEntry);
242
243 /* Check if this is an NLS block */
244 if (MdBlock->MemoryType == LoaderNlsData)
245 {
246 /* Increase the table size */
247 ExpNlsTableSize += MdBlock->PageCount * PAGE_SIZE;
248
249 /* FreeLdr-specific */
250 NlsTableSizes[NlsTablesEncountered] = MdBlock->PageCount * PAGE_SIZE;
251 NlsTablesEncountered++;
252 ASSERT(NlsTablesEncountered < 4);
253 }
254
255 /* Go to the next block */
256 NextEntry = MdBlock->ListEntry.Flink;
257 }
258
259 /* Allocate the a new buffer since loader memory will be freed */
262 TAG_RTLI);
263 if (!ExpNlsTableBase) KeBugCheck(PHASE0_INITIALIZATION_FAILED);
264
265 /* Copy the codepage data in its new location. */
266 if (NlsTablesEncountered == 1)
267 {
268 /* Ntldr-way boot process */
270 LoaderBlock->NlsData->AnsiCodePageData,
272 }
273 else
274 {
275 /*
276 * In NT, the memory blocks are contiguous, but in ReactOS they aren't,
277 * so unless someone fixes FreeLdr, we'll have to use this icky hack.
278 */
280 LoaderBlock->NlsData->AnsiCodePageData,
281 NlsTableSizes[0]);
282
283 RtlCopyMemory((PVOID)((ULONG_PTR)ExpNlsTableBase + NlsTableSizes[0]),
284 LoaderBlock->NlsData->OemCodePageData,
285 NlsTableSizes[1]);
286
287 RtlCopyMemory((PVOID)((ULONG_PTR)ExpNlsTableBase + NlsTableSizes[0] +
288 NlsTableSizes[1]),
289 LoaderBlock->NlsData->UnicodeCodePageData,
290 NlsTableSizes[2]);
291 /* End of Hack */
292 }
293
294 /* Initialize and reset the NLS TAbles */
303 return;
304 }
305
306 /* Set the section size */
307 SectionSize.QuadPart = ExpNlsTableSize;
308
309 /* Create the NLS Section */
310 Status = ZwCreateSection(&NlsSection,
312 NULL,
313 &SectionSize,
315 SEC_COMMIT | 0x1,
316 NULL);
317 if (!NT_SUCCESS(Status))
318 {
319 /* Failed */
320 KeBugCheckEx(PHASE1_INITIALIZATION_FAILED, Status, 1, 0, 0);
321 }
322
323 /* Get a pointer to the section */
329 NULL);
330 ObCloseHandle(NlsSection, KernelMode);
331 if (!NT_SUCCESS(Status))
332 {
333 /* Failed */
334 KeBugCheckEx(PHASE1_INITIALIZATION_FAILED, Status, 2, 0, 0);
335 }
336
337 /* Map the NLS Section in system space */
339 &SectionBase,
341 if (!NT_SUCCESS(Status))
342 {
343 /* Failed */
344 KeBugCheckEx(PHASE1_INITIALIZATION_FAILED, Status, 3, 0, 0);
345 }
346
347 /* Copy the codepage data in its new location. */
348 ASSERT(SectionBase >= MmSystemRangeStart);
350
351 /* Free the previously allocated buffer and set the new location */
353 ExpNlsTableBase = SectionBase;
354
355 /* Initialize the NLS Tables */
364
365 /* Reset the base to 0 */
366 SectionBase = NULL;
367
368 /* Map the section in the system process */
371 &SectionBase,
372 0L,
373 0L,
375 &ViewSize,
376 ViewShare,
377 0L,
379 if (!NT_SUCCESS(Status))
380 {
381 /* Failed */
382 KeBugCheckEx(PHASE1_INITIALIZATION_FAILED, Status, 5, 0, 0);
383 }
384
385 /* Copy the table into the system process and set this as the base */
387 ExpNlsTableBase = SectionBase;
388}
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize _Pre_valid_ PVOID _In_ ULONG_PTR _In_ SIZE_T _Inout_opt_ PLARGE_INTEGER SectionOffset
Definition: mmfuncs.h:411
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize _Pre_valid_ PVOID _In_ ULONG_PTR _In_ SIZE_T _Inout_opt_ PLARGE_INTEGER _Inout_ PSIZE_T ViewSize
Definition: mmfuncs.h:412
#define SEC_COMMIT
Definition: mmtypes.h:100
#define PAGE_READWRITE
Definition: nt_native.h:1307
#define SECTION_ALL_ACCESS
Definition: nt_native.h:1296
@ ViewShare
Definition: nt_native.h:1281
SIZE_T ExpNlsTableSize
Definition: init.c:93
PVOID ExpNlsSectionPointer
Definition: init.c:94
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:493
@ LoaderNlsData
Definition: arc.h:314
NTSTATUS NTAPI MmMapViewInSystemSpace(IN PVOID SectionObject, OUT PVOID *MappedBase, IN OUT PSIZE_T ViewSize)
Definition: section.c:4504
POBJECT_TYPE MmSectionObjectType
Definition: section.c:196
NTSTATUS NTAPI MmMapViewOfSection(_In_ PVOID SectionObject, _In_ PEPROCESS Process, _Outptr_result_bytebuffer_(*ViewSize) _Pre_opt_valid_ PVOID *BaseAddress, _In_ ULONG_PTR ZeroBits, _In_ SIZE_T CommitSize, _Inout_opt_ PLARGE_INTEGER SectionOffset, _Inout_ PSIZE_T ViewSize, _In_range_(ViewShare, ViewUnmap) SECTION_INHERIT InheritDisposition, _In_ ULONG AllocationType, _In_ ULONG Protect)
Definition: section.c:4031
#define TAG_RTLI
Definition: tag.h:28
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
LONGLONG QuadPart
Definition: typedefs.h:114
#define PsGetCurrentProcess
Definition: psfuncs.h:17

Referenced by ExpInitializeExecutive(), and Phase1InitializationDiscard().

◆ ExpInitSystemPhase0()

BOOLEAN NTAPI ExpInitSystemPhase0 ( VOID  )

Definition at line 643 of file init.c.

644{
645 /* Initialize EXRESOURCE Support */
647
648 /* Initialize the environment lock */
650
651 /* Initialize the lookaside lists and locks */
653
654 /* Initialize the Firmware Table resource and listhead */
658
659 /* Set the suite mask to maximum and return */
660 ExSuiteMask = 0xFFFFFFFF;
661 return TRUE;
662}
NTSTATUS ExInitializeResourceLite(PULONG res)
Definition: env_spec_w32.h:641
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
VOID ExpInitLookasideLists()
ULONG ExSuiteMask
Definition: init.c:59
VOID NTAPI ExpResourceInitialization(VOID)
Definition: resource.c:173
LIST_ENTRY ExpFirmwareTableProviderListHead
Definition: sysinfo.c:31
FAST_MUTEX ExpEnvironmentLock
Definition: sysinfo.c:29
ERESOURCE ExpFirmwareTableResource
Definition: sysinfo.c:30
ERESOURCE ExpTimeRefreshLock
Definition: time.c:27
FORCEINLINE VOID ExInitializeFastMutex(_Out_ PFAST_MUTEX FastMutex)
Definition: exfuncs.h:274

Referenced by ExInitSystem().

◆ ExpInitSystemPhase1()

BOOLEAN NTAPI ExpInitSystemPhase1 ( VOID  )

Definition at line 667 of file init.c.

668{
669 /* Initialize worker threads */
671
672 /* Initialize pushlocks */
674
675 /* Initialize events and event pairs */
677 {
678 DPRINT1("Executive: Event initialization failed\n");
679 return FALSE;
680 }
682 {
683 DPRINT1("Executive: Event Pair initialization failed\n");
684 return FALSE;
685 }
686
687 /* Initialize mutants */
689 {
690 DPRINT1("Executive: Mutant initialization failed\n");
691 return FALSE;
692 }
693
694 /* Initialize callbacks */
696 {
697 DPRINT1("Executive: Callback initialization failed\n");
698 return FALSE;
699 }
700
701 /* Initialize semaphores */
703 {
704 DPRINT1("Executive: Semaphore initialization failed\n");
705 return FALSE;
706 }
707
708 /* Initialize timers */
710 {
711 DPRINT1("Executive: Timer initialization failed\n");
712 return FALSE;
713 }
714
715 /* Initialize profiling */
717 {
718 DPRINT1("Executive: Profile initialization failed\n");
719 return FALSE;
720 }
721
722 /* Initialize UUIDs */
724 {
725 DPRINT1("Executive: Uuid initialization failed\n");
726 return FALSE;
727 }
728
729 /* Initialize keyed events */
731 {
732 DPRINT1("Executive: Keyed event initialization failed\n");
733 return FALSE;
734 }
735
736 /* Initialize Win32K */
737 if (ExpWin32kInit() == FALSE)
738 {
739 DPRINT1("Executive: Win32 initialization failed\n");
740 return FALSE;
741 }
742 return TRUE;
743}
BOOLEAN NTAPI ExpInitializeEventPairImplementation(VOID)
Definition: evtpair.c:33
BOOLEAN NTAPI ExpInitializeKeyedEventImplementation(VOID)
BOOLEAN NTAPI ExpInitializeMutantImplementation(VOID)
Definition: mutant.c:52
BOOLEAN NTAPI ExpInitializeCallbacks(VOID)
Definition: callback.c:256
BOOLEAN NTAPI ExpInitializeEventImplementation(VOID)
Definition: event.c:39
BOOLEAN NTAPI ExpInitializeProfileImplementation(VOID)
Definition: profile.c:62
BOOLEAN NTAPI ExpInitializeTimerImplementation(VOID)
Definition: timer.c:223
BOOLEAN NTAPI ExpUuidInitialization(VOID)
Definition: uuid.c:53
VOID NTAPI ExpInitializePushLocks(VOID)
Definition: pushlock.c:45
BOOLEAN NTAPI ExpInitializeSemaphoreImplementation(VOID)
Definition: sem.c:43
BOOLEAN NTAPI ExpWin32kInit(VOID)
Definition: win32k.c:269
VOID NTAPI ExpInitializeWorkerThreads(VOID)
Definition: work.c:521

Referenced by ExInitSystem().

◆ ExpIsLoaderValid()

BOOLEAN NTAPI ExpIsLoaderValid ( IN PLOADER_PARAMETER_BLOCK  LoaderBlock)

Definition at line 774 of file init.c.

775{
777
778 /* Get the loader extension */
779 Extension = LoaderBlock->Extension;
780
781 /* Validate the size (Windows 2003 loader doesn't provide more) */
783
784 /* Don't validate upper versions */
785 if (Extension->MajorVersion > VER_PRODUCTMAJORVERSION) return TRUE;
786
787 /* Fail if this is NT 4 */
788 if (Extension->MajorVersion < VER_PRODUCTMAJORVERSION) return FALSE;
789
790 /* Fail if this is XP */
791 if (Extension->MinorVersion < VER_PRODUCTMINORVERSION) return FALSE;
792
793 /* This is 2003 or newer, approve it */
794 return TRUE;
795}
_Inout_opt_ PUNICODE_STRING Extension
Definition: fltkernel.h:1092
#define LOADER_PARAMETER_EXTENSION_MIN_SIZE
Definition: init.c:20

Referenced by ExpInitializeExecutive().

◆ ExpLoadInitialProcess()

VOID NTAPI ExpLoadInitialProcess ( IN PINIT_BUFFER  InitBuffer,
OUT PRTL_USER_PROCESS_PARAMETERS *  ProcessParameters,
OUT PCHAR *  ProcessEnvironment 
)

Definition at line 393 of file init.c.

396{
398 SIZE_T Size;
399 PWSTR p;
400 UNICODE_STRING NullString = RTL_CONSTANT_STRING(L"");
401 UNICODE_STRING SmssName, Environment, SystemDriveString, DebugString;
402 PVOID EnvironmentPtr = NULL;
403 PRTL_USER_PROCESS_INFORMATION ProcessInformation;
404 PRTL_USER_PROCESS_PARAMETERS ProcessParams = NULL;
405
406 NullString.Length = sizeof(WCHAR);
407
408 /* Use the initial buffer, after the strings */
409 ProcessInformation = &InitBuffer->ProcessInfo;
410
411 /* Allocate memory for the process parameters */
412 Size = sizeof(*ProcessParams) + ((MAX_WIN32_PATH * 6) * sizeof(WCHAR));
413 Status = ZwAllocateVirtualMemory(NtCurrentProcess(),
414 (PVOID*)&ProcessParams,
415 0,
416 &Size,
419 if (!NT_SUCCESS(Status))
420 {
421 /* Failed, display error */
422 _snwprintf(InitBuffer->DebugBuffer,
423 sizeof(InitBuffer->DebugBuffer)/sizeof(WCHAR),
424 L"INIT: Unable to allocate Process Parameters. 0x%lx",
425 Status);
426 RtlInitUnicodeString(&DebugString, InitBuffer->DebugBuffer);
428
429 /* Bugcheck the system */
430 KeBugCheckEx(SESSION1_INITIALIZATION_FAILED, Status, 0, 0, 0);
431 }
432
433 /* Setup the basic header, and give the process the low 1MB to itself */
434 ProcessParams->Length = (ULONG)Size;
435 ProcessParams->MaximumLength = (ULONG)Size;
438
439 /* Allocate a page for the environment */
440 Size = PAGE_SIZE;
441 Status = ZwAllocateVirtualMemory(NtCurrentProcess(),
442 &EnvironmentPtr,
443 0,
444 &Size,
447 if (!NT_SUCCESS(Status))
448 {
449 /* Failed, display error */
450 _snwprintf(InitBuffer->DebugBuffer,
451 sizeof(InitBuffer->DebugBuffer)/sizeof(WCHAR),
452 L"INIT: Unable to allocate Process Environment. 0x%lx",
453 Status);
454 RtlInitUnicodeString(&DebugString, InitBuffer->DebugBuffer);
456
457 /* Bugcheck the system */
458 KeBugCheckEx(SESSION2_INITIALIZATION_FAILED, Status, 0, 0, 0);
459 }
460
461 /* Write the pointer */
462 ProcessParams->Environment = EnvironmentPtr;
463
464 /* Make a buffer for the DOS path */
465 p = (PWSTR)(ProcessParams + 1);
466 ProcessParams->CurrentDirectory.DosPath.Buffer = p;
468 sizeof(WCHAR);
469
470 /* Copy the DOS path */
472 &NtSystemRoot);
473
474 /* Make a buffer for the DLL Path */
475 p = (PWSTR)((PCHAR)ProcessParams->CurrentDirectory.DosPath.Buffer +
476 ProcessParams->CurrentDirectory.DosPath.MaximumLength);
477 ProcessParams->DllPath.Buffer = p;
478 ProcessParams->DllPath.MaximumLength = MAX_WIN32_PATH * sizeof(WCHAR);
479
480 /* Copy the DLL path and append the system32 directory */
481 RtlCopyUnicodeString(&ProcessParams->DllPath,
482 &ProcessParams->CurrentDirectory.DosPath);
483 RtlAppendUnicodeToString(&ProcessParams->DllPath, L"\\System32");
484
485 /* Make a buffer for the image name */
486 p = (PWSTR)((PCHAR)ProcessParams->DllPath.Buffer +
487 ProcessParams->DllPath.MaximumLength);
488 ProcessParams->ImagePathName.Buffer = p;
489 ProcessParams->ImagePathName.MaximumLength = MAX_WIN32_PATH * sizeof(WCHAR);
490
491 /* Make sure the buffer is a valid string which within the given length */
496 sizeof(NtInitialUserProcessBuffer) - sizeof(WCHAR)))))
497 {
498 /* Invalid initial process string, bugcheck */
499 KeBugCheckEx(SESSION2_INITIALIZATION_FAILED,
504 }
505
506 /* Cut out anything after a space */
508 while ((*p) && (*p != L' ')) p++;
509
510 /* Set the image path length */
511 ProcessParams->ImagePathName.Length =
513
514 /* Copy the actual buffer */
515 RtlCopyMemory(ProcessParams->ImagePathName.Buffer,
517 ProcessParams->ImagePathName.Length);
518
519 /* Null-terminate it */
520 ProcessParams->ImagePathName.Buffer[ProcessParams->ImagePathName.Length /
521 sizeof(WCHAR)] = UNICODE_NULL;
522
523 /* Make a buffer for the command line */
524 p = (PWSTR)((PCHAR)ProcessParams->ImagePathName.Buffer +
525 ProcessParams->ImagePathName.MaximumLength);
526 ProcessParams->CommandLine.Buffer = p;
527 ProcessParams->CommandLine.MaximumLength = MAX_WIN32_PATH * sizeof(WCHAR);
528
529 /* Add the image name to the command line */
532
533 /* Create the environment string */
534 RtlInitEmptyUnicodeString(&Environment,
535 ProcessParams->Environment,
536 (USHORT)Size);
537
538 /* Append the DLL path to it */
542
543 /* Create the system drive string */
544 SystemDriveString = NtSystemRoot;
545 SystemDriveString.Length = 2 * sizeof(WCHAR);
546
547 /* Append it to the environment */
548 RtlAppendUnicodeToString(&Environment, L"SystemDrive=");
549 RtlAppendUnicodeStringToString(&Environment, &SystemDriveString);
551
552 /* Append the system root to the environment */
553 RtlAppendUnicodeToString(&Environment, L"SystemRoot=");
556
557 /* Prepare the prefetcher */
558 //CcPfBeginBootPhase(150);
559
560 /* Create SMSS process */
561 SmssName = ProcessParams->ImagePathName;
562 Status = RtlCreateUserProcess(&SmssName,
564 RtlDeNormalizeProcessParams(ProcessParams),
565 NULL,
566 NULL,
567 NULL,
568 FALSE,
569 NULL,
570 NULL,
571 ProcessInformation);
572 if (!NT_SUCCESS(Status))
573 {
574 /* Failed, display error */
575 _snwprintf(InitBuffer->DebugBuffer,
576 sizeof(InitBuffer->DebugBuffer)/sizeof(WCHAR),
577 L"INIT: Unable to create Session Manager. 0x%lx",
578 Status);
579 RtlInitUnicodeString(&DebugString, InitBuffer->DebugBuffer);
581
582 /* Bugcheck the system */
583 KeBugCheckEx(SESSION3_INITIALIZATION_FAILED, Status, 0, 0, 0);
584 }
585
586 /* Resume the thread */
587 Status = ZwResumeThread(ProcessInformation->ThreadHandle, NULL);
588 if (!NT_SUCCESS(Status))
589 {
590 /* Failed, display error */
591 _snwprintf(InitBuffer->DebugBuffer,
592 sizeof(InitBuffer->DebugBuffer)/sizeof(WCHAR),
593 L"INIT: Unable to resume Session Manager. 0x%lx",
594 Status);
595 RtlInitUnicodeString(&DebugString, InitBuffer->DebugBuffer);
597
598 /* Bugcheck the system */
599 KeBugCheckEx(SESSION4_INITIALIZATION_FAILED, Status, 0, 0, 0);
600 }
601
602 /* Return success */
603 *ProcessParameters = ProcessParams;
604 *ProcessEnvironment = EnvironmentPtr;
605}
#define REG_SZ
Definition: layer.c:22
static CCHAR DebugString[256]
Definition: settings.c:16
#define RTL_CONSTANT_STRING(s)
Definition: combase.c:35
_ACRTIMP int __cdecl _snwprintf(wchar_t *, size_t, const wchar_t *,...)
Definition: wcs.c:1498
NTSTATUS RtlAppendUnicodeToString(IN PUNICODE_STRING Str1, IN PWSTR Str2)
Definition: string_lib.cpp:62
GLfloat GLfloat p
Definition: glext.h:8902
#define PCHAR
Definition: match.c:90
PVOID PVOID PWCHAR PVOID Environment
Definition: env.c:47
NTSYSAPI NTSTATUS NTAPI ZwDisplayString(_In_ PUNICODE_STRING DisplayString)
NTSYSAPI NTSTATUS NTAPI ZwResumeThread(_In_ HANDLE ThreadHandle, _Out_opt_ PULONG SuspendCount)
NTSYSAPI NTSTATUS NTAPI RtlCreateUserProcess(_In_ PUNICODE_STRING ImageFileName, _In_ ULONG Attributes, _In_ PRTL_USER_PROCESS_PARAMETERS ProcessParameters, _In_opt_ PSECURITY_DESCRIPTOR ProcessSecutityDescriptor, _In_opt_ PSECURITY_DESCRIPTOR ThreadSecurityDescriptor, _In_opt_ HANDLE ParentProcess, _In_ BOOLEAN CurrentDirectory, _In_opt_ HANDLE DebugPort, _In_opt_ HANDLE ExceptionPort, _Out_ PRTL_USER_PROCESS_INFORMATION ProcessInfo)
NTSYSAPI PRTL_USER_PROCESS_PARAMETERS NTAPI RtlDeNormalizeProcessParams(_In_ PRTL_USER_PROCESS_PARAMETERS ProcessParameters)
#define RTL_USER_PROCESS_PARAMETERS_RESERVE_1MB
Definition: rtltypes.h:46
#define RTL_USER_PROCESS_PARAMETERS_NORMALIZED
Definition: rtltypes.h:41
NTSYSAPI VOID NTAPI RtlCopyUnicodeString(PUNICODE_STRING DestinationString, PUNICODE_STRING SourceString)
NTSYSAPI NTSTATUS NTAPI RtlAppendUnicodeStringToString(PUNICODE_STRING Destination, PUNICODE_STRING Source)
#define NtCurrentProcess()
Definition: nt_native.h:1660
#define MEM_RESERVE
Definition: nt_native.h:1317
#define MEM_COMMIT
Definition: nt_native.h:1316
#define UNICODE_NULL
WCHAR NtInitialUserProcessBuffer[128]
Definition: init.c:83
ULONG NtInitialUserProcessBufferType
Definition: init.c:86
ULONG NtInitialUserProcessBufferLength
Definition: init.c:84
#define MAX_WIN32_PATH
Definition: ntoskrnl.h:125
UNICODE_STRING DosPath
Definition: rtltypes.h:1390
UNICODE_STRING CommandLine
Definition: btrfs_drv.h:1902
UNICODE_STRING ImagePathName
Definition: btrfs_drv.h:1901
uint16_t * PWSTR
Definition: typedefs.h:56
#define MAXULONG
Definition: typedefs.h:251
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4539

Referenced by Phase1InitializationDiscard().

◆ MmArmInitSystem()

BOOLEAN NTAPI MmArmInitSystem ( IN ULONG  Phase,
IN PLOADER_PARAMETER_BLOCK  LoaderBlock 
)

Definition at line 2049 of file mminit.c.

2051{
2052 ULONG i;
2053 BOOLEAN IncludeType[LoaderMaximum];
2054 PVOID Bitmap;
2056 PFN_NUMBER PageCount;
2057#if DBG
2058 ULONG j;
2059 PMMPTE PointerPte, TestPte;
2060 MMPTE TempPte;
2061#endif
2062
2063 /* Dump memory descriptors */
2065
2066 //
2067 // Instantiate memory that we don't consider RAM/usable
2068 // We use the same exclusions that Windows does, in order to try to be
2069 // compatible with WinLDR-style booting
2070 //
2071 for (i = 0; i < LoaderMaximum; i++) IncludeType[i] = TRUE;
2072 IncludeType[LoaderBad] = FALSE;
2073 IncludeType[LoaderFirmwarePermanent] = FALSE;
2074 IncludeType[LoaderSpecialMemory] = FALSE;
2075 IncludeType[LoaderBBTMemory] = FALSE;
2076 if (Phase == 0)
2077 {
2078 /* Count physical pages on the system */
2079 MiScanMemoryDescriptors(LoaderBlock);
2080
2081 /* Initialize the phase 0 temporary event */
2083
2084 /* Set all the events to use the temporary event for now */
2091
2092 //
2093 // Default throttling limits for Cc
2094 // May be ajusted later on depending on system type
2095 //
2096 MmThrottleTop = 450;
2097 MmThrottleBottom = 127;
2098
2099 //
2100 // Define the basic user vs. kernel address space separation
2101 //
2105
2106 /* Highest PTE and PDE based on the addresses above */
2109#if (_MI_PAGING_LEVELS >= 3)
2110 MiHighestUserPpe = MiAddressToPpe(MmHighestUserAddress);
2111#if (_MI_PAGING_LEVELS >= 4)
2112 MiHighestUserPxe = MiAddressToPxe(MmHighestUserAddress);
2113#endif
2114#endif
2115 //
2116 // Get the size of the boot loader's image allocations and then round
2117 // that region up to a PDE size, so that any PDEs we might create for
2118 // whatever follows are separate from the PDEs that boot loader might've
2119 // already created (and later, we can blow all that away if we want to).
2120 //
2121 MmBootImageSize = KeLoaderBlock->Extension->LoaderPagesSpanned;
2125
2126 /* Initialize session space address layout */
2128
2129 /* Set the based section highest address */
2131
2132 /* Loop all 8 standby lists */
2133 for (i = 0; i < 8; i++)
2134 {
2135 /* Initialize them */
2140 }
2141
2142 /* Initialize the user mode image list */
2144
2145 /* Initalize the Working set list */
2147
2148 /* Initialize critical section timeout value (relative time is negative) */
2150
2151 /* Initialize the paged pool mutex and the section commit mutex */
2155
2156 /* Initialize the Loader Lock */
2158
2159 /* Set up the zero page event */
2161
2162 /* Initialize the dead stack S-LIST */
2164
2165 //
2166 // Check if this is a machine with less than 19MB of RAM
2167 //
2168 PageCount = MmNumberOfPhysicalPages;
2169 if (PageCount < MI_MIN_PAGES_FOR_SYSPTE_TUNING)
2170 {
2171 //
2172 // Use the very minimum of system PTEs
2173 //
2174 MmNumberOfSystemPtes = 7000;
2175 }
2176 else
2177 {
2178 //
2179 // Use the default
2180 //
2181 MmNumberOfSystemPtes = 11000;
2182 if (PageCount > MI_MIN_PAGES_FOR_SYSPTE_BOOST)
2183 {
2184 //
2185 // Double the amount of system PTEs
2186 //
2188 }
2190 {
2191 //
2192 // Double the amount of system PTEs
2193 //
2195 }
2196 if (MmSpecialPoolTag != 0 && MmSpecialPoolTag != -1)
2197 {
2198 //
2199 // Add some extra PTEs for special pool
2200 //
2201 MmNumberOfSystemPtes += 0x6000;
2202 }
2203 }
2204
2205 DPRINT("System PTE count has been tuned to %lu (%lu bytes)\n",
2207
2208 /* Check if no values are set for the heap limits */
2209 if (MmHeapSegmentReserve == 0)
2210 {
2212 }
2213
2214 if (MmHeapSegmentCommit == 0)
2215 {
2217 }
2218
2220 {
2222 }
2223
2225 {
2227 }
2228
2229 /* Initialize the working set lock */
2231
2232 /* Set commit limit */
2235
2236 /* Has the allocation fragment been setup? */
2238 {
2239 /* Use the default value */
2241 if (PageCount < ((256 * _1MB) / PAGE_SIZE))
2242 {
2243 /* On memory systems with less than 256MB, divide by 4 */
2245 }
2246 else if (PageCount < (_1GB / PAGE_SIZE))
2247 {
2248 /* On systems with less than 1GB, divide by 2 */
2250 }
2251 }
2252 else
2253 {
2254 /* Convert from 1KB fragments to pages */
2257
2258 /* Don't let it past the maximum */
2261
2262 /* Don't let it too small either */
2265 }
2266
2267 /* Check for kernel stack size that's too big */
2269 {
2270 /* Sanitize to default value */
2272 }
2273 else
2274 {
2275 /* Take the registry setting, and convert it into bytes */
2277
2278 /* Now align it to a page boundary */
2280
2281 /* Sanity checks */
2283 ASSERT((MmLargeStackSize & (PAGE_SIZE - 1)) == 0);
2284
2285 /* Make sure it's not too low */
2287 }
2288
2289 /* Compute color information (L2 cache-separated paging lists) */
2291
2292 // Calculate the number of bytes for the PFN database
2293 // then add the color tables and convert to pages
2297
2298 // We have to add one to the count here, because in the process of
2299 // shifting down to the page size, we actually ended up getting the
2300 // lower aligned size (so say, 0x5FFFF bytes is now 0x5F pages).
2301 // Later on, we'll shift this number back into bytes, which would cause
2302 // us to end up with only 0x5F000 bytes -- when we actually want to have
2303 // 0x60000 bytes.
2305
2306 /* Initialize the platform-specific parts */
2307 MiInitMachineDependent(LoaderBlock);
2308
2309 //
2310 // x86 uses the loader-gap region
2311 //
2314
2315#if DBG
2316 /* Prototype PTEs are assumed to be in paged pool, so check if the math works */
2317 PointerPte = (PMMPTE)MmPagedPoolStart;
2318 MI_MAKE_PROTOTYPE_PTE(&TempPte, PointerPte);
2319 TestPte = MiProtoPteToPte(&TempPte);
2320 ASSERT(PointerPte == TestPte);
2321
2322 /* Try the last nonpaged pool address */
2323 PointerPte = (PMMPTE)MI_NONPAGED_POOL_END;
2324 MI_MAKE_PROTOTYPE_PTE(&TempPte, PointerPte);
2325 TestPte = MiProtoPteToPte(&TempPte);
2326 ASSERT(PointerPte == TestPte);
2327
2328 /* Try a bunch of random addresses near the end of the address space */
2329 PointerPte = (PMMPTE)((ULONG_PTR)MI_HIGHEST_SYSTEM_ADDRESS - 0x37FFF);
2330 for (j = 0; j < 20; j += 1)
2331 {
2332 MI_MAKE_PROTOTYPE_PTE(&TempPte, PointerPte);
2333 TestPte = MiProtoPteToPte(&TempPte);
2334 ASSERT(PointerPte == TestPte);
2335 PointerPte++;
2336 }
2337
2338 /* Subsection PTEs are always in nonpaged pool, pick a random address to try */
2340 MI_MAKE_SUBSECTION_PTE(&TempPte, PointerPte);
2342 ASSERT(PointerPte == TestPte);
2343#endif
2344
2345 //
2346 // Build the physical memory block
2347 //
2349 IncludeType);
2350
2351 //
2352 // Allocate enough buffer for the PFN bitmap
2353 // Align it up to a 32-bit boundary
2354 //
2356 (((MmHighestPhysicalPage + 1) + 31) / 32) * 4,
2357 TAG_MM);
2358 if (!Bitmap)
2359 {
2360 //
2361 // This is critical
2362 //
2363 KeBugCheckEx(INSTALL_MORE_MEMORY,
2367 0x101);
2368 }
2369
2370 //
2371 // Initialize it and clear all the bits to begin with
2372 //
2374 Bitmap,
2377
2378 //
2379 // Loop physical memory runs
2380 //
2381 for (i = 0; i < MmPhysicalMemoryBlock->NumberOfRuns; i++)
2382 {
2383 //
2384 // Get the run
2385 //
2387 DPRINT("PHYSICAL RAM [0x%08p to 0x%08p]\n",
2388 Run->BasePage << PAGE_SHIFT,
2389 (Run->BasePage + Run->PageCount) << PAGE_SHIFT);
2390
2391 //
2392 // Make sure it has pages inside it
2393 //
2394 if (Run->PageCount)
2395 {
2396 //
2397 // Set the bits in the PFN bitmap
2398 //
2399 RtlSetBits(&MiPfnBitMap, (ULONG)Run->BasePage, (ULONG)Run->PageCount);
2400 }
2401 }
2402
2403 /* Look for large page cache entries that need caching */
2405
2406 /* Loop for HAL Heap I/O device mappings that need coherency tracking */
2408
2409 /* Set the initial resident page count */
2411
2412 /* Initialize large page structures on PAE/x64, and MmProcessList on x86 */
2414
2415 /* Check if the registry says any drivers should be loaded with large pages */
2417
2418 /* Relocate the boot drivers into system PTE space and fixup their PFNs */
2419 MiReloadBootLoadedDrivers(LoaderBlock);
2420
2421 /* FIXME: Call out into Driver Verifier for initialization */
2422
2423 /* Check how many pages the system has */
2424 if (MmNumberOfPhysicalPages <= ((13 * _1MB) / PAGE_SIZE))
2425 {
2426 /* Set small system */
2429 }
2430 else if (MmNumberOfPhysicalPages <= ((19 * _1MB) / PAGE_SIZE))
2431 {
2432 /* Set small system and add 100 pages for the cache */
2436 }
2437 else
2438 {
2439 /* Set medium system and add 400 pages for the cache */
2443 }
2444
2445 /* Check for less than 24MB */
2446 if (MmNumberOfPhysicalPages < ((24 * _1MB) / PAGE_SIZE))
2447 {
2448 /* No more than 32 pages */
2450 }
2451
2452 /* Check for more than 32MB */
2453 if (MmNumberOfPhysicalPages >= ((32 * _1MB) / PAGE_SIZE))
2454 {
2455 /* Check for product type being "Wi" for WinNT */
2456 if (MmProductType == '\0i\0W')
2457 {
2458 /* Then this is a large system */
2460 }
2461 else
2462 {
2463 /* For servers, we need 64MB to consider this as being large */
2464 if (MmNumberOfPhysicalPages >= ((64 * _1MB) / PAGE_SIZE))
2465 {
2466 /* Set it as large */
2468 }
2469 }
2470 }
2471
2472 /* Check for more than 33 MB */
2473 if (MmNumberOfPhysicalPages > ((33 * _1MB) / PAGE_SIZE))
2474 {
2475 /* Add another 500 pages to the cache */
2477 }
2478
2479 /* Now setup the shared user data fields */
2480 ASSERT(SharedUserData->NumberOfPhysicalPages == 0);
2481 SharedUserData->NumberOfPhysicalPages = MmNumberOfPhysicalPages;
2482 SharedUserData->LargePageMinimum = 0;
2483
2484 /* Check for workstation (Wi for WinNT) */
2485 if (MmProductType == '\0i\0W')
2486 {
2487 /* Set Windows NT Workstation product type */
2488 SharedUserData->NtProductType = NtProductWinNt;
2489 MmProductType = 0;
2490
2491 /* For this product, we wait till the last moment to throttle */
2492 MmThrottleTop = 250;
2493 MmThrottleBottom = 30;
2494 }
2495 else
2496 {
2497 /* Check for LanMan server (La for LanmanNT) */
2498 if (MmProductType == '\0a\0L')
2499 {
2500 /* This is a domain controller */
2501 SharedUserData->NtProductType = NtProductLanManNt;
2502 }
2503 else
2504 {
2505 /* Otherwise it must be a normal server (Se for ServerNT) */
2506 SharedUserData->NtProductType = NtProductServer;
2507 }
2508
2509 /* Set the product type, and make the system more aggressive with low memory */
2510 MmProductType = 1;
2511 MmMinimumFreePages = 81;
2512
2513 /* We will throttle earlier to preserve memory */
2514 MmThrottleTop = 450;
2515 MmThrottleBottom = 80;
2516 }
2517
2518 /* Update working set tuning parameters */
2520
2521 /* Finetune the page count by removing working set and NP expansion */
2525 if (MmResidentAvailablePages <= 0)
2526 {
2527 /* This should not happen */
2528 DPRINT1("System cache working set too big\n");
2529 return FALSE;
2530 }
2531
2532 /* Define limits for system cache */
2533#ifdef _M_AMD64
2535#else
2537#endif
2539#ifdef _M_AMD64
2541#else
2543#endif
2544
2545 /* Initialize the system cache */
2546 //MiInitializeSystemCache(MmSystemCacheWsMinimum, MmAvailablePages);
2547
2548 /* Update the commit limit */
2550 if (MmTotalCommitLimit > 1024) MmTotalCommitLimit -= 1024;
2552
2553 /* Size up paged pool and build the shadow system page directory */
2555
2556 /* Debugger physical memory support is now ready to be used */
2558
2559 /* Initialize the loaded module list */
2560 MiInitializeLoadedModuleList(LoaderBlock);
2561 }
2562
2563 //
2564 // Always return success for now
2565 //
2566 return TRUE;
2567}
PVOID MmSystemPteSpaceStart
Definition: mminit.c:97
SIZE_T MmHeapSegmentReserve
Definition: mminit.c:367
PMMPTE MiHighestUserPte
Definition: mminit.c:234
PVOID MmNonPagedSystemStart
Definition: mminit.c:96
PFN_NUMBER MmSystemCacheWsMinimum
Definition: mminit.c:337
SIZE_T MmHeapDeCommitFreeBlockThreshold
Definition: mminit.c:370
SIZE_T MmTotalCommitLimitMaximum
Definition: mminit.c:361
PVOID MmPagedPoolStart
Definition: mminit.c:105
SIZE_T MmTotalCommitLimit
Definition: mminit.c:360
MM_SYSTEMSIZE MmSystemSize
Definition: mminit.c:327
SIZE_T MmBootImageSize
Definition: mminit.c:223
PVOID MmSystemRangeStart
Definition: mminit.c:231
PMMPDE MiHighestUserPde
Definition: mminit.c:235
SIZE_T MmHeapDeCommitTotalFreeThreshold
Definition: mminit.c:369
PFN_COUNT MmNumberOfPhysicalPages
Definition: mminit.c:213
ULONG MmThrottleTop
Definition: mminit.c:397
PFN_NUMBER MmMinimumFreePages
Definition: mminit.c:315
SIZE_T MmSizeOfNonPagedPoolInBytes
Definition: mminit.c:26
KEVENT MiTempEvent
Definition: mminit.c:290
ULONG MmSecondaryColors
Definition: mminit.c:257
VOID NTAPI MiAdjustWorkingSetManagerParameters(IN BOOLEAN Client)
Definition: mminit.c:1195
VOID NTAPI MiBuildPagedPool(VOID)
Definition: mminit.c:1743
VOID NTAPI MiScanMemoryDescriptors(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: mminit.c:404
VOID NTAPI MiAddHalIoMappings(VOID)
Definition: mminit.c:1410
VOID NTAPI MiDbgDumpMemoryDescriptors(VOID)
Definition: mminit.c:1997
PFN_NUMBER MmLowestPhysicalPage
Definition: mminit.c:212
PKEVENT MiLowNonPagedPoolEvent
Definition: mminit.c:297
PKEVENT MiHighMemoryEvent
Definition: mminit.c:294
PKEVENT MiLowMemoryEvent
Definition: mminit.c:293
ULONG MmProductType
Definition: mminit.c:326
PPHYSICAL_MEMORY_DESCRIPTOR NTAPI MmInitializeMemoryLimits(IN PLOADER_PARAMETER_BLOCK LoaderBlock, IN PBOOLEAN IncludeType)
Definition: mminit.c:1614
PFN_NUMBER MmHighestPhysicalPage
Definition: mminit.c:212
ULONG_PTR MmSizeOfSystemCacheInPages
Definition: mminit.c:246
ULONG_PTR MmUserProbeAddress
Definition: mminit.c:229
RTL_BITMAP MiPfnBitMap
Definition: mminit.c:202
MMSUPPORT MmSystemCacheWs
Definition: mminit.c:247
ULONG MmLargeStackSize
Definition: mminit.c:263
VOID NTAPI MiComputeColorInformation(VOID)
Definition: mminit.c:500
PKEVENT MiHighPagedPoolEvent
Definition: mminit.c:296
PFN_NUMBER MxPfnAllocation
Definition: mminit.c:188
ULONG MmThrottleBottom
Definition: mminit.c:398
PVOID MmNonPagedPoolStart
Definition: mminit.c:98
BOOLEAN MiDbgEnableMdDump
Definition: mminit.c:374
SIZE_T MmHeapSegmentCommit
Definition: mminit.c:368
SIZE_T MmAllocationFragment
Definition: mminit.c:353
PKEVENT MiLowPagedPoolEvent
Definition: mminit.c:295
LARGE_INTEGER MmCriticalSectionTimeout
Definition: mminit.c:389
PFN_COUNT MmNumberOfSystemPtes
Definition: mminit.c:182
PPHYSICAL_MEMORY_DESCRIPTOR MmPhysicalMemoryBlock
Definition: mminit.c:207
PVOID MmSystemCacheStart
Definition: mminit.c:244
PVOID MmSystemCacheEnd
Definition: mminit.c:245
PKEVENT MiHighNonPagedPoolEvent
Definition: mminit.c:298
PVOID MmHighestUserAddress
Definition: mminit.c:230
ULONG MmCritsectTimeoutSeconds
Definition: mminit.c:388
ULONG_PTR PFN_NUMBER
unsigned char BOOLEAN
Definition: actypes.h:127
HARDWARE_PTE_ARMV6 TempPte
Definition: winldr.c:76
#define RtlInitializeBitMap
Definition: dbgbitmap.h:326
#define RtlClearAllBits
Definition: dbgbitmap.h:329
#define RtlSetBits
Definition: dbgbitmap.h:345
struct tagRun Run
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define PAGE_SHIFT
Definition: env_spec_w32.h:45
#define ExInitializePushLock
Definition: ex.h:1016
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
VOID FASTCALL KeInitializeGuardedMutex(OUT PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:31
VOID NTAPI MiInitializeDriverLargePageList(VOID)
Definition: largepag.c:68
VOID NTAPI MiInitializeLargePageSupport(VOID)
Definition: largepag.c:34
VOID NTAPI MiSyncCachedRanges(VOID)
Definition: largepag.c:54
PFN_COUNT MiExpansionPoolPagesInitialCharge
Definition: pool.c:21
KGUARDED_MUTEX MmSectionBasedMutex
Definition: section.c:110
SLIST_HEADER MmDeadStackSListHead
Definition: procsup.c:22
#define _1GB
Definition: miarm.h:20
struct _MMCOLOR_TABLES MMCOLOR_TABLES
KGUARDED_MUTEX MmPagedPoolMutex
Definition: pool.c:24
PFN_NUMBER MmResidentAvailableAtInit
Definition: freelist.c:28
#define _1MB
Definition: miarm.h:19
MMPFNLIST MmStandbyPageListByPriority[8]
Definition: pfnlist.c:44
PVOID MmHighSectionBase
Definition: section.c:111
ULONG MmSpecialPoolTag
Definition: pool.c:29
KGUARDED_MUTEX MmSectionCommitMutex
Definition: section.c:108
KEVENT MmZeroingPageEvent
Definition: zeropage.c:20
LIST_ENTRY MmWorkingSetExpansionHead
Definition: session.c:30
#define _1KB
Definition: miarm.h:18
ULONG MmMaximumDeadKernelStacks
Definition: procsup.c:21
#define min(a, b)
Definition: monoChain.cc:55
struct _MMPTE * PMMPTE
#define MI_HIGHEST_USER_ADDRESS
Definition: mmtypes.h:43
#define PAGE_ROUND_UP(x)
Definition: mmtypes.h:38
@ StandbyPageList
Definition: mmtypes.h:155
@ NotificationEvent
#define MiAddressToPte(x)
Definition: mm.h:144
#define MI_ALLOCATION_FRAGMENT
Definition: mm.h:73
#define MI_PAGED_POOL_START
Definition: mm.h:23
#define MI_USER_PROBE_ADDRESS
Definition: mm.h:12
#define MI_DEFAULT_SYSTEM_RANGE_START
Definition: mm.h:13
#define MiSubsectionPteToSubsection(x)
Definition: mm.h:322
FORCEINLINE VOID MI_MAKE_PROTOTYPE_PTE(IN PMMPTE NewPte, IN PMMPTE PointerPte)
Definition: mm.h:341
#define MI_MIN_PAGES_FOR_SYSPTE_BOOST
Definition: mm.h:58
#define MM_EMPTY_LIST
Definition: mm.h:90
#define MI_MIN_PAGES_FOR_SYSPTE_TUNING
Definition: mm.h:57
FORCEINLINE PMMPTE MiAddressToPpe(PVOID Address)
Definition: mm.h:160
#define MiProtoPteToPte(x)
Definition: mm.h:315
FORCEINLINE PMMPTE MiAddressToPxe(PVOID Address)
Definition: mm.h:170
#define MI_HIGHEST_SYSTEM_ADDRESS
Definition: mm.h:33
#define MI_NONPAGED_POOL_END
Definition: mm.h:31
#define MiAddressToPde(x)
Definition: mm.h:155
#define MI_MIN_ALLOCATION_FRAGMENT
Definition: mm.h:72
#define MI_SYSTEM_CACHE_END
Definition: mm.h:29
#define MI_MIN_PAGES_FOR_SYSPTE_BOOST_BOOST
Definition: mm.h:59
FORCEINLINE VOID MI_MAKE_SUBSECTION_PTE(_Out_ PMMPTE NewPte, _In_ PVOID Segment)
Definition: mm.h:327
#define PDE_MAPPED_VA
Definition: mm.h:41
#define MI_SYSTEM_CACHE_START
Definition: mm.h:28
#define MI_MAX_ALLOCATION_FRAGMENT
Definition: mm.h:74
PFN_NUMBER MmResidentAvailablePages
Definition: freelist.c:27
BOOLEAN NTAPI MiInitializeLoadedModuleList(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: sysldr.c:2284
PMMPTE MmDebugPte
Definition: mmdbg.c:31
LIST_ENTRY MmLoadedUserImageList
Definition: sysldr.c:22
VOID NTAPI MiReloadBootLoadedDrivers(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: sysldr.c:1773
PVOID MiDebugMapping
Definition: mmdbg.c:30
PFN_NUMBER MmAvailablePages
Definition: freelist.c:26
KMUTANT MmSystemLoadLock
Definition: sysldr.c:26
VOID NTAPI KeInitializeMutant(IN PKMUTANT Mutant, IN BOOLEAN InitialOwner)
Definition: mutex.c:22
VOID NTAPI MiInitializeSessionSpaceLayout(VOID)
Definition: init.c:63
NTSTATUS NTAPI MiInitMachineDependent(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: init.c:697
NTSYSAPI PLOADER_PARAMETER_BLOCK KeLoaderBlock
Definition: krnlinit.c:28
@ LoaderFirmwarePermanent
Definition: arc.h:299
@ LoaderSpecialMemory
Definition: arc.h:315
@ LoaderMaximum
Definition: arc.h:322
@ LoaderBBTMemory
Definition: arc.h:316
#define KERNEL_LARGE_STACK_SIZE
#define KERNEL_STACK_SIZE
#define DPRINT
Definition: sndvol32.h:73
PLOADER_PARAMETER_EXTENSION Extension
Definition: arc.h:857
PFN_NUMBER Total
Definition: mm.h:458
MMLISTS ListName
Definition: mm.h:459
PFN_NUMBER Blink
Definition: mm.h:461
PFN_NUMBER Flink
Definition: mm.h:460
Definition: mm.h:386
EX_PUSH_LOCK WorkingSetMutex
Definition: mmtypes.h:961
PHYSICAL_MEMORY_RUN Run[1]
Definition: miarm.h:430
Definition: bidi.c:435
#define max(a, b)
Definition: svc.c:63
#define TAG_MM
Definition: tag.h:113
void * PVOID
Definition: typedefs.h:50
@ NtProductWinNt
Definition: wdm.h:20
@ NtProductLanManNt
Definition: wdm.h:21
@ NtProductServer
Definition: wdm.h:22
#define ROUND_TO_PAGES(Size)
@ MmLargeSystem
Definition: mmtypes.h:147
@ MmMediumSystem
Definition: mmtypes.h:146
@ MmSmallSystem
Definition: mmtypes.h:145
FORCEINLINE VOID InitializeSListHead(_Out_ PSLIST_HEADER SListHead)
Definition: rtlfuncs.h:3375

Referenced by ExpInitializeExecutive(), and Phase1InitializationDiscard().

◆ MmFreeLoaderBlock()

VOID NTAPI MmFreeLoaderBlock ( IN PLOADER_PARAMETER_BLOCK  LoaderBlock)

Definition at line 1085 of file mminit.c.

1086{
1087 PLIST_ENTRY NextMd;
1089 ULONG_PTR i;
1090 PFN_NUMBER BasePage, LoaderPages;
1091 PMMPFN Pfn1;
1092 KIRQL OldIrql;
1094
1095 /* Loop the descriptors in order to count them */
1096 i = 0;
1097 NextMd = LoaderBlock->MemoryDescriptorListHead.Flink;
1098 while (NextMd != &LoaderBlock->MemoryDescriptorListHead)
1099 {
1100 MdBlock = CONTAINING_RECORD(NextMd,
1102 ListEntry);
1103 i++;
1104 NextMd = MdBlock->ListEntry.Flink;
1105 }
1106
1107 /* Allocate a structure to hold the physical runs */
1109 i * sizeof(PHYSICAL_MEMORY_RUN),
1110 'lMmM');
1111 ASSERT(Buffer != NULL);
1112 Entry = Buffer;
1113
1114 /* Loop the descriptors again */
1115 NextMd = LoaderBlock->MemoryDescriptorListHead.Flink;
1116 while (NextMd != &LoaderBlock->MemoryDescriptorListHead)
1117 {
1118 /* Check what kind this was */
1119 MdBlock = CONTAINING_RECORD(NextMd,
1121 ListEntry);
1122 switch (MdBlock->MemoryType)
1123 {
1124 /* Registry, NLS, and heap data */
1125 case LoaderRegistryData:
1126 case LoaderOsloaderHeap:
1127 case LoaderNlsData:
1128 /* Are all a candidate for deletion */
1129 Entry->BasePage = MdBlock->BasePage;
1130 Entry->PageCount = MdBlock->PageCount;
1131 Entry++;
1132
1133 /* We keep the rest */
1134 default:
1135 break;
1136 }
1137
1138 /* Move to the next descriptor */
1139 NextMd = MdBlock->ListEntry.Flink;
1140 }
1141
1142 /* Acquire the PFN lock */
1143 OldIrql = MiAcquirePfnLock();
1144
1145 /* Loop the runs */
1146 LoaderPages = 0;
1147 while (--Entry >= Buffer)
1148 {
1149 /* See how many pages are in this run */
1150 i = Entry->PageCount;
1151 BasePage = Entry->BasePage;
1152
1153 /* Loop each page */
1154 Pfn1 = MiGetPfnEntry(BasePage);
1155 while (i--)
1156 {
1157 /* Check if it has references or is in any kind of list */
1158 if (!(Pfn1->u3.e2.ReferenceCount) && (!Pfn1->u1.Flink))
1159 {
1160 /* Set the new PTE address and put this page into the free list */
1161 Pfn1->PteAddress = (PMMPTE)(BasePage << PAGE_SHIFT);
1162 MiInsertPageInFreeList(BasePage);
1163 LoaderPages++;
1164 }
1165 else if (BasePage)
1166 {
1167 /* It has a reference, so simply drop it */
1169
1170 /* Drop a dereference on this page, which should delete it */
1171 Pfn1->PteAddress->u.Long = 0;
1172 MI_SET_PFN_DELETED(Pfn1);
1173 MiDecrementShareCount(Pfn1, BasePage);
1174 LoaderPages++;
1175 }
1176
1177 /* Move to the next page */
1178 Pfn1++;
1179 BasePage++;
1180 }
1181 }
1182
1183 /* Release the PFN lock and flush the TLB */
1184 DPRINT("Loader pages freed: %lx\n", LoaderPages);
1185 MiReleasePfnLock(OldIrql);
1187
1188 /* Free our run structure */
1189 ExFreePoolWithTag(Buffer, 'lMmM');
1190}
UCHAR KIRQL
Definition: env_spec_w32.h:591
FORCEINLINE BOOLEAN MI_IS_PHYSICAL_ADDRESS(IN PVOID Address)
Definition: miarm.h:953
#define MI_SET_PFN_DELETED(x)
Definition: miarm.h:208
VOID NTAPI MiInsertPageInFreeList(IN PFN_NUMBER PageFrameIndex)
Definition: pfnlist.c:611
VOID NTAPI MiDecrementShareCount(IN PMMPFN Pfn1, IN PFN_NUMBER PageFrameIndex)
Definition: pfnlist.c:1141
#define MiPteToAddress(_Pte)
Definition: mm.h:131
VOID NTAPI KeFlushCurrentTb(VOID)
Definition: cpu.c:361
FORCEINLINE PMMPFN MiGetPfnEntry(IN PFN_NUMBER Pfn)
Definition: mm.h:1042
@ LoaderOsloaderHeap
Definition: arc.h:300
@ LoaderRegistryData
Definition: arc.h:312
Entry
Definition: section.c:5216
PMMPTE PteAddress
Definition: mm.h:398
PFN_NUMBER Flink
Definition: mm.h:389
union _MMPFN::@2099 u1
struct _MMPFN::@2101::@2107 e2
union _MMPFN::@2101 u3
union _MMPTE::@2788 u
ULONG_PTR Long
Definition: mmtypes.h:215
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:778

Referenced by Phase1InitializationDiscard().

◆ Phase1Initialization()

VOID NTAPI Phase1Initialization ( IN PVOID  Context)

Definition at line 2065 of file init.c.

2066{
2067 /* Do the .INIT part of Phase 1 which we can free later */
2069
2070 /* Jump into zero page thread */
2072}
_In_ PIRP _In_ PIO_COMPLETION_ROUTINE _In_ PVOID Context
Definition: kse.h:81
VOID NTAPI Phase1InitializationDiscard(IN PVOID Context)
Definition: init.c:1355
VOID NTAPI MmZeroPageThread(VOID)
Definition: zeropage.c:36

Referenced by PspInitPhase0().

◆ Phase1InitializationDiscard()

VOID NTAPI Phase1InitializationDiscard ( IN PVOID  Context)

Definition at line 1355 of file init.c.

1356{
1357 PLOADER_PARAMETER_BLOCK LoaderBlock = Context;
1358 NTSTATUS Status, MsgStatus;
1360 LARGE_INTEGER SystemBootTime, UniversalBootTime, OldTime, Timeout;
1361 BOOLEAN NoGuiBoot, ResetBias = FALSE, AlternateShell = FALSE;
1362 PLDR_DATA_TABLE_ENTRY NtosEntry;
1363 PMESSAGE_RESOURCE_ENTRY MsgEntry;
1364 PCHAR CommandLine, Y2KHackRequired, SafeBoot, Environment;
1365 PCHAR StringBuffer, EndBuffer, BeginBuffer, MpString = "";
1366 PINIT_BUFFER InitBuffer;
1367 ANSI_STRING TempString;
1368 ULONG LastTzBias, Length, YearHack = 0, Disposition, MessageCode = 0;
1369 SIZE_T Size;
1370 size_t Remaining;
1372 KEY_VALUE_PARTIAL_INFORMATION KeyPartialInfo;
1375 HANDLE KeyHandle, OptionHandle;
1376 PRTL_USER_PROCESS_PARAMETERS ProcessParameters = NULL;
1377
1378 /* Allocate the initialization buffer */
1380 sizeof(INIT_BUFFER),
1381 TAG_INIT);
1382 if (!InitBuffer)
1383 {
1384 /* Bugcheck */
1385 KeBugCheckEx(PHASE1_INITIALIZATION_FAILED, STATUS_NO_MEMORY, 8, 0, 0);
1386 }
1387
1388 /* Set to phase 1 */
1390
1391 /* Set us at maximum priority */
1393
1394 /* Do Phase 1 HAL Initialization */
1395 if (!HalInitSystem(1, LoaderBlock)) KeBugCheck(HAL1_INITIALIZATION_FAILED);
1396
1397 /* Get the command line and upcase it */
1398 CommandLine = (LoaderBlock->LoadOptions ? _strupr(LoaderBlock->LoadOptions) : NULL);
1399
1400 /* Check if GUI Boot is enabled */
1401 NoGuiBoot = (CommandLine && strstr(CommandLine, "NOGUIBOOT") != NULL);
1402
1403 /* Get the SOS setting */
1404 SosEnabled = (CommandLine && strstr(CommandLine, "SOS") != NULL);
1405
1406 /* Setup the boot video driver */
1407 InbvEnableBootDriver(!NoGuiBoot);
1409
1410 /* Check if GUI boot is enabled */
1411 if (!NoGuiBoot)
1412 {
1413 /* It is, display the boot logo and enable printing strings */
1416 }
1417 else
1418 {
1419 /* Release display ownership if not using GUI boot */
1421
1422 /* Don't allow boot-time strings */
1424 }
1425
1426 /* Check if this is LiveCD (WinPE) mode */
1427 if (CommandLine && strstr(CommandLine, "MININT") != NULL)
1428 {
1429 /* Setup WinPE Settings */
1431 InitWinPEModeType |= (strstr(CommandLine, "INRAM") != NULL) ? 0x80000000 : 0x00000001;
1432 }
1433
1434 /* Get the kernel's load entry */
1435 NtosEntry = CONTAINING_RECORD(LoaderBlock->LoadOrderListHead.Flink,
1437 InLoadOrderLinks);
1438
1439 /* Find the banner message */
1440 MsgStatus = RtlFindMessage(NtosEntry->DllBase,
1443 WINDOWS_NT_BANNER,
1444 &MsgEntry);
1445
1446 /* Setup defaults and check if we have a version string */
1447 StringBuffer = InitBuffer->VersionBuffer;
1448 BeginBuffer = StringBuffer;
1449 EndBuffer = StringBuffer;
1450 Remaining = sizeof(InitBuffer->VersionBuffer);
1452 {
1453 /* Print the version string */
1455 Remaining,
1456 &EndBuffer,
1457 &Remaining,
1458 0,
1459 ": %wZ",
1461 if (!NT_SUCCESS(Status))
1462 {
1463 /* Bugcheck */
1464 KeBugCheckEx(PHASE1_INITIALIZATION_FAILED, Status, 7, 0, 0);
1465 }
1466 }
1467 else
1468 {
1469 /* No version */
1470 *EndBuffer = ANSI_NULL; /* Null-terminate the string */
1471 }
1472
1473 /* Skip over the null-terminator to start a new string */
1474 ++EndBuffer;
1475 --Remaining;
1476
1477 /* Build the version number */
1478 StringBuffer = InitBuffer->VersionNumber;
1480 sizeof(InitBuffer->VersionNumber),
1481 "%u.%u",
1484 if (!NT_SUCCESS(Status))
1485 {
1486 /* Bugcheck */
1487 KeBugCheckEx(PHASE1_INITIALIZATION_FAILED, Status, 7, 0, 0);
1488 }
1489
1490 /* Check if we had found a banner message */
1491 if (NT_SUCCESS(MsgStatus))
1492 {
1493 /* Create the banner message */
1494 /* ReactOS specific: Report ReactOS version, NtBuildLab information and reported NT kernel version */
1495 Status = RtlStringCbPrintfA(EndBuffer,
1496 Remaining,
1497 (PCHAR)MsgEntry->Text,
1498 KERNEL_VERSION_STR,
1499 NtBuildLab,
1501 NtBuildNumber & 0xFFFF,
1502 BeginBuffer);
1503 if (!NT_SUCCESS(Status))
1504 {
1505 /* Bugcheck */
1506 KeBugCheckEx(PHASE1_INITIALIZATION_FAILED, Status, 7, 0, 0);
1507 }
1508 }
1509 else
1510 {
1511 /* Use hard-coded banner message */
1512 Status = RtlStringCbCopyA(EndBuffer, Remaining, "REACTOS (R)\r\n");
1513 if (!NT_SUCCESS(Status))
1514 {
1515 /* Bugcheck */
1516 KeBugCheckEx(PHASE1_INITIALIZATION_FAILED, Status, 7, 0, 0);
1517 }
1518 }
1519
1520 /* Display the version string on-screen */
1521 InbvDisplayString(EndBuffer);
1522
1523 /* Initialize Power Subsystem in Phase 0 */
1524 if (!PoInitSystem(0)) KeBugCheck(INTERNAL_POWER_ERROR);
1525
1526 /* Check for Y2K hack */
1527 Y2KHackRequired = CommandLine ? strstr(CommandLine, "YEAR") : NULL;
1528 if (Y2KHackRequired) Y2KHackRequired = strstr(Y2KHackRequired, "=");
1529 if (Y2KHackRequired) YearHack = atol(Y2KHackRequired + 1);
1530
1531 /* Query the clock */
1533 {
1534 /* Check if we're using the Y2K hack */
1535 if (Y2KHackRequired) TimeFields.Year = (CSHORT)YearHack;
1536
1537 /* Convert to time fields */
1538 RtlTimeFieldsToTime(&TimeFields, &SystemBootTime);
1539 UniversalBootTime = SystemBootTime;
1540
1541 /* Check if real time is GMT */
1543 {
1544 /* Check if we don't have a valid bias */
1546 {
1547 /* Reset */
1548 ResetBias = TRUE;
1550 }
1551
1552 /* Calculate the bias in seconds */
1554 10000000);
1555
1556 /* Set the boot time-zone bias */
1558
1559 /* Convert the boot time to local time, and set it */
1560 UniversalBootTime.QuadPart = SystemBootTime.QuadPart +
1562 }
1563
1564 /* Update the system time and notify the system */
1565 KeSetSystemTime(&UniversalBootTime, &OldTime, FALSE, NULL);
1567
1568 /* Remember this as the boot time */
1569 KeBootTime = UniversalBootTime;
1570 KeBootTimeBias = 0;
1571 }
1572
1573#ifdef CONFIG_SMP
1574 /*
1575 * IMPORTANT NOTE:
1576 * Because ReactOS is a "nice" OS, we do not care _at all_
1577 * about any number of registered/licensed processors:
1578 * no usage of KeRegisteredProcessors nor KeLicensedProcessors.
1579 */
1580 if (CommandLine)
1581 {
1582 PSTR Option;
1583
1584 /* Check for NUMPROC: maximum number of logical processors
1585 * that can be started (including dynamically) at run-time */
1586 Option = strstr(CommandLine, "NUMPROC");
1587 if (Option) Option = strstr(Option, "=");
1588 if (Option) KeNumprocSpecified = atol(Option + 1);
1589
1590 /* Check for BOOTPROC (NT6+ and ReactOS): maximum number
1591 * of logical processors that can be started at boot-time */
1592 Option = strstr(CommandLine, "BOOTPROC");
1593 if (Option) Option = strstr(Option, "=");
1594 if (Option) KeBootprocSpecified = atol(Option + 1);
1595
1596 /* Check for MAXPROC (NT6+ and ReactOS): forces the kernel to report
1597 * as existing the maximum number of processors that can be handled */
1598 if (strstr(CommandLine, "MAXPROC"))
1599 KeMaximumProcessors = MAXIMUM_PROCESSORS;
1600 }
1601
1602 /* Start Application Processors */
1604#endif
1605
1606 /* Initialize all processors */
1607 if (!HalAllProcessorsStarted()) KeBugCheck(HAL1_INITIALIZATION_FAILED);
1608
1609#ifdef CONFIG_SMP
1610 /* HACK: We should use RtlFindMessage and not only fallback to this */
1611 MpString = "MultiProcessor Kernel\r\n";
1612#endif
1613
1614 /* Setup the "MP" String */
1615 RtlInitAnsiString(&TempString, MpString);
1616
1617 /* Make sure to remove the \r\n if we actually have a string */
1618 while ((TempString.Length > 0) &&
1619 ((TempString.Buffer[TempString.Length - 1] == '\r') ||
1620 (TempString.Buffer[TempString.Length - 1] == '\n')))
1621 {
1622 /* Skip the trailing character */
1623 TempString.Length--;
1624 }
1625
1626 /* Get the information string from our resource file */
1627 MsgStatus = RtlFindMessage(NtosEntry->DllBase,
1630 KeNumberProcessors > 1 ?
1631 WINDOWS_NT_INFO_STRING_PLURAL :
1632 WINDOWS_NT_INFO_STRING,
1633 &MsgEntry);
1634
1635 /* Get total RAM size, in MiB */
1636 /* Round size up. Assumed to better match actual physical RAM size */
1637 Size = ALIGN_UP_BY(MmNumberOfPhysicalPages * PAGE_SIZE, 1024 * 1024) / (1024 * 1024);
1638
1639 /* Create the string */
1640 StringBuffer = InitBuffer->VersionBuffer;
1642 sizeof(InitBuffer->VersionBuffer),
1643 NT_SUCCESS(MsgStatus) ?
1644 (PCHAR)MsgEntry->Text :
1645 "%u System Processor [%Iu MB Memory] %Z\r\n",
1647 Size,
1648 &TempString);
1649 if (!NT_SUCCESS(Status))
1650 {
1651 /* Bugcheck */
1652 KeBugCheckEx(PHASE1_INITIALIZATION_FAILED, Status, 4, 0, 0);
1653 }
1654
1655 /* Display RAM and CPU count */
1657
1658 /* Update the progress bar */
1660
1661 /* Call OB initialization again */
1662 if (!ObInitSystem()) KeBugCheck(OBJECT1_INITIALIZATION_FAILED);
1663
1664 /* Initialize Basic System Objects and Worker Threads */
1665 if (!ExInitSystem()) KeBugCheckEx(PHASE1_INITIALIZATION_FAILED, 0, 0, 1, 0);
1666
1667 /* Initialize the later stages of the kernel */
1668 if (!KeInitSystem()) KeBugCheckEx(PHASE1_INITIALIZATION_FAILED, 0, 0, 2, 0);
1669
1670 /* Call KD Providers at Phase 1 */
1672 {
1673 /* Failed, bugcheck */
1674 KeBugCheckEx(PHASE1_INITIALIZATION_FAILED, 0, 0, 3, 0);
1675 }
1676
1677 /* Initialize the SRM in Phase 1 */
1678 if (!SeInitSystem()) KeBugCheck(SECURITY1_INITIALIZATION_FAILED);
1679
1680 /* Update the progress bar */
1682
1683 /* Create SystemRoot Link */
1684 Status = ExpCreateSystemRootLink(LoaderBlock);
1685 if (!NT_SUCCESS(Status))
1686 {
1687 /* Failed to create the system root link */
1688 KeBugCheckEx(SYMBOLIC_INITIALIZATION_FAILED, Status, 0, 0, 0);
1689 }
1690
1691 /* Set up Region Maps, Sections and the Paging File */
1692 if (!MmInitSystem(1, LoaderBlock)) KeBugCheck(MEMORY1_INITIALIZATION_FAILED);
1693
1694 /* Create NLS section */
1695 ExpInitNls(LoaderBlock);
1696
1697 /* Initialize the Rtl locale table */
1699
1700 /* Initialize Cache Views */
1701 if (!CcInitializeCacheManager()) KeBugCheck(CACHE_INITIALIZATION_FAILED);
1702
1703 /* Initialize the Registry */
1704 if (!CmInitSystem1()) KeBugCheck(CONFIG_INITIALIZATION_FAILED);
1705
1706 /* Initialize Prefetcher */
1708
1709 /* Update progress bar */
1711
1712 /* Update timezone information */
1713 LastTzBias = ExpLastTimeZoneBias;
1714 ExRefreshTimeZoneInformation(&SystemBootTime);
1715
1716 /* Check if we're resetting timezone data */
1717 if (ResetBias)
1718 {
1719 /* Convert the local time to system time */
1720 ExLocalTimeToSystemTime(&SystemBootTime, &UniversalBootTime);
1721 KeBootTime = UniversalBootTime;
1722 KeBootTimeBias = 0;
1723
1724 /* Set the new time */
1725 KeSetSystemTime(&UniversalBootTime, &OldTime, FALSE, NULL);
1726 }
1727 else
1728 {
1729 /* Check if the timezone switched and update the time */
1730 if (LastTzBias != ExpLastTimeZoneBias)
1732 }
1733
1734 /* Initialize the File System Runtime Library */
1735 if (!FsRtlInitSystem()) KeBugCheck(FILE_INITIALIZATION_FAILED);
1736
1737 /* Initialize range lists */
1739
1740 /* Report all resources used by HAL */
1742
1743 /* Call the debugger DLL */
1744 KdDebuggerInitialize1(LoaderBlock);
1745
1746 /* Setup PnP Manager in phase 1 */
1747 if (!PpInitSystem()) KeBugCheck(PP1_INITIALIZATION_FAILED);
1748
1749 /* Update progress bar */
1751
1752 /* Initialize LPC */
1753 if (!LpcInitSystem()) KeBugCheck(LPC_INITIALIZATION_FAILED);
1754
1755 /* Make sure we have a command line */
1756 if (CommandLine)
1757 {
1758 /* Check if this is a safe mode boot */
1759 SafeBoot = strstr(CommandLine, "SAFEBOOT:");
1760 if (SafeBoot)
1761 {
1762 /* Check what kind of boot this is */
1763 SafeBoot += 9;
1764 if (!strncmp(SafeBoot, "MINIMAL", 7))
1765 {
1766 /* Minimal mode */
1767 InitSafeBootMode = 1;
1768 SafeBoot += 7;
1769 MessageCode = BOOTING_IN_SAFEMODE_MINIMAL;
1770 }
1771 else if (!strncmp(SafeBoot, "NETWORK", 7))
1772 {
1773 /* With Networking */
1774 InitSafeBootMode = 2;
1775 SafeBoot += 7;
1776 MessageCode = BOOTING_IN_SAFEMODE_NETWORK;
1777 }
1778 else if (!strncmp(SafeBoot, "DSREPAIR", 8))
1779 {
1780 /* Domain Server Repair */
1781 InitSafeBootMode = 3;
1782 SafeBoot += 8;
1783 MessageCode = BOOTING_IN_SAFEMODE_DSREPAIR;
1784
1785 }
1786 else
1787 {
1788 /* Invalid */
1789 InitSafeBootMode = 0;
1790 }
1791
1792 /* Check if there's any settings left */
1793 if (*SafeBoot)
1794 {
1795 /* Check if an alternate shell was requested */
1796 if (!strncmp(SafeBoot, "(ALTERNATESHELL)", 16))
1797 {
1798 /* Remember this for later */
1799 AlternateShell = TRUE;
1800 }
1801 }
1802
1803 /* Find the message to print out */
1804 Status = RtlFindMessage(NtosEntry->DllBase,
1807 MessageCode,
1808 &MsgEntry);
1809 if (NT_SUCCESS(Status))
1810 {
1811 /* Display it */
1812 InbvDisplayString((PCSTR)MsgEntry->Text);
1813 }
1814 }
1815 }
1816
1817 /* Make sure we have a command line */
1818 if (CommandLine)
1819 {
1820 /* Check if bootlogging is enabled */
1821 if (strstr(CommandLine, "BOOTLOG"))
1822 {
1823 /* Find the message to print out */
1824 Status = RtlFindMessage(NtosEntry->DllBase,
1827 BOOTLOG_ENABLED,
1828 &MsgEntry);
1829 if (NT_SUCCESS(Status))
1830 {
1831 /* Display it */
1832 InbvDisplayString((PCSTR)MsgEntry->Text);
1833 }
1834
1835 /* Setup boot logging */
1836 //IopInitializeBootLogging(LoaderBlock, InitBuffer->BootlogHeader);
1837 }
1838 }
1839
1840 /* Setup the Executive in Phase 2 */
1841 //ExInitSystemPhase2();
1842
1843 /* Update progress bar */
1845
1846 /* No KD Time Slip is pending */
1848
1849 /* Initialize in-place execution support */
1850 XIPInit(LoaderBlock);
1851
1852 /* Set maximum update to 75% */
1854
1855 /* Initialize the I/O Subsystem */
1856 if (!IoInitSystem(LoaderBlock)) KeBugCheck(IO1_INITIALIZATION_FAILED);
1857
1858 /* Set maximum update to 100% */
1860
1861 /* Are we in safe mode? */
1862 if (InitSafeBootMode)
1863 {
1864 /* Open the safe boot key */
1866 L"\\REGISTRY\\MACHINE\\SYSTEM\\CURRENTCONTROLSET"
1867 L"\\CONTROL\\SAFEBOOT");
1869 &KeyName,
1871 NULL,
1872 NULL);
1874 if (NT_SUCCESS(Status))
1875 {
1876 /* First check if we have an alternate shell */
1877 if (AlternateShell)
1878 {
1879 /* Make sure that the registry has one setup */
1880 RtlInitUnicodeString(&KeyName, L"AlternateShell");
1882 &KeyName,
1884 &KeyPartialInfo,
1885 sizeof(KeyPartialInfo),
1886 &Length);
1888 {
1889 AlternateShell = FALSE;
1890 }
1891 }
1892
1893 /* Create the option key */
1894 RtlInitUnicodeString(&KeyName, L"Option");
1896 &KeyName,
1898 KeyHandle,
1899 NULL);
1900 Status = ZwCreateKey(&OptionHandle,
1903 0,
1904 NULL,
1906 &Disposition);
1908
1909 /* Check if the key create worked */
1910 if (NT_SUCCESS(Status))
1911 {
1912 /* Write the safe boot type */
1913 RtlInitUnicodeString(&KeyName, L"OptionValue");
1914 NtSetValueKey(OptionHandle,
1915 &KeyName,
1916 0,
1917 REG_DWORD,
1919 sizeof(InitSafeBootMode));
1920
1921 /* Check if we have to use an alternate shell */
1922 if (AlternateShell)
1923 {
1924 /* Remember this for later */
1925 Disposition = TRUE;
1926 RtlInitUnicodeString(&KeyName, L"UseAlternateShell");
1927 NtSetValueKey(OptionHandle,
1928 &KeyName,
1929 0,
1930 REG_DWORD,
1931 &Disposition,
1932 sizeof(Disposition));
1933 }
1934
1935 /* Close the options key handle */
1936 NtClose(OptionHandle);
1937 }
1938 }
1939 }
1940
1941 /* Are we in Win PE mode? */
1942 if (InitIsWinPEMode)
1943 {
1944 /* Open the safe control key */
1946 L"\\REGISTRY\\MACHINE\\SYSTEM\\CURRENTCONTROLSET"
1947 L"\\CONTROL");
1949 &KeyName,
1951 NULL,
1952 NULL);
1954 if (!NT_SUCCESS(Status))
1955 {
1956 /* Bugcheck */
1957 KeBugCheckEx(PHASE1_INITIALIZATION_FAILED, Status, 6, 0, 0);
1958 }
1959
1960 /* Create the MiniNT key */
1961 RtlInitUnicodeString(&KeyName, L"MiniNT");
1963 &KeyName,
1965 KeyHandle,
1966 NULL);
1967 Status = ZwCreateKey(&OptionHandle,
1970 0,
1971 NULL,
1973 &Disposition);
1974 if (!NT_SUCCESS(Status))
1975 {
1976 /* Bugcheck */
1977 KeBugCheckEx(PHASE1_INITIALIZATION_FAILED, Status, 6, 0, 0);
1978 }
1979
1980 /* Close the handles */
1982 NtClose(OptionHandle);
1983 }
1984
1985 /* FIXME: This doesn't do anything for now */
1986 MmArmInitSystem(2, LoaderBlock);
1987
1988 /* Update progress bar */
1990
1991 /* Initialize VDM support */
1992#if defined(_M_IX86)
1994#endif
1995
1996 /* Initialize Power Subsystem in Phase 1*/
1997 if (!PoInitSystem(1)) KeBugCheck(INTERNAL_POWER_ERROR);
1998
1999 /* Update progress bar */
2001
2002 /* Initialize the Process Manager at Phase 1 */
2003 if (!PsInitSystem(LoaderBlock)) KeBugCheck(PROCESS1_INITIALIZATION_FAILED);
2004
2005 /* Make sure nobody touches the loader block again */
2006 if (LoaderBlock == KeLoaderBlock) KeLoaderBlock = NULL;
2007 MmFreeLoaderBlock(LoaderBlock);
2008 LoaderBlock = Context = NULL;
2009
2010 /* Initialize the SRM in phase 1 */
2011 if (!SeRmInitPhase1()) KeBugCheck(PROCESS1_INITIALIZATION_FAILED);
2012
2013 /* Update progress bar */
2015
2016 /* Clear the screen */
2018
2019 /* Allow strings to be displayed */
2021
2022 /* Launch initial process */
2023 ProcessInfo = &InitBuffer->ProcessInfo;
2024 ExpLoadInitialProcess(InitBuffer, &ProcessParameters, &Environment);
2025
2026 /* Wait 5 seconds for initial process to initialize */
2027 Timeout.QuadPart = Int32x32To64(5, -10000000);
2029 if (Status == STATUS_SUCCESS)
2030 {
2031 /* Failed, display error */
2032 DPRINT1("INIT: Session Manager terminated.\n");
2033
2034 /* Bugcheck the system if SMSS couldn't initialize */
2035 KeBugCheck(SESSION5_INITIALIZATION_FAILED);
2036 }
2037
2038 /* Close process handles */
2039 ZwClose(ProcessInfo->ThreadHandle);
2040 ZwClose(ProcessInfo->ProcessHandle);
2041
2042 /* Free the initial process environment */
2043 Size = 0;
2044 ZwFreeVirtualMemory(NtCurrentProcess(),
2045 (PVOID*)&Environment,
2046 &Size,
2047 MEM_RELEASE);
2048
2049 /* Free the initial process parameters */
2050 Size = 0;
2051 ZwFreeVirtualMemory(NtCurrentProcess(),
2052 (PVOID*)&ProcessParameters,
2053 &Size,
2054 MEM_RELEASE);
2055
2056 /* Increase init phase */
2058
2059 /* Free the boot buffer */
2060 ExFreePoolWithTag(InitBuffer, TAG_INIT);
2061}
#define ALIGN_UP_BY(size, align)
VOID NTAPI FinalizeBootLogo(VOID)
Definition: bootanim.c:799
VOID NTAPI DisplayBootBitmap(_In_ BOOLEAN TextMode)
Definition: bootanim.c:507
BOOLEAN NTAPI CmInitSystem1(VOID)
Definition: cmsysini.c:1642
#define STATUS_NO_MEMORY
Definition: d3dkmdt.h:51
_ACRTIMP int __cdecl strncmp(const char *, const char *, size_t)
Definition: string.c:3335
BOOLEAN RtlTimeFieldsToTime(IN PTIME_FIELDS TimeFields, IN PLARGE_INTEGER Time)
#define ExLocalTimeToSystemTime(LocTime, SysTime)
Definition: env_spec_w32.h:738
#define MAXIMUM_PROCESSORS
Definition: rwlock.h:5
NTSYSAPI NTSTATUS NTAPI ZwWaitForSingleObject(_In_ HANDLE Handle, _In_ BOOLEAN Alertable, _In_opt_ PLARGE_INTEGER Timeout)
BOOLEAN NTAPI FsRtlInitSystem(VOID)
Definition: fsrtlpc.c:161
BOOLEAN NTAPI CcInitializeCacheManager(VOID)
Definition: fssup.c:83
VOID NTAPI CcPfInitializePrefetcher(VOID)
Definition: fssup.c:114
BOOLEAN NTAPI HalAllProcessorsStarted(VOID)
Definition: processor.c:60
VOID NTAPI HalReportResourceUsage(VOID)
Definition: usage.c:67
#define KeGetCurrentThread
Definition: hal.h:55
VOID NTAPI InbvNotifyDisplayOwnershipLost(_In_ INBV_RESET_DISPLAY_PARAMETERS Callback)
Definition: inbv.c:410
BOOLEAN InbvBootDriverInstalled
Definition: inbv.c:39
VOID NTAPI InbvEnableBootDriver(_In_ BOOLEAN Enable)
Definition: inbv.c:261
VOID NTAPI InbvSetProgressBarSubset(_In_ ULONG Floor, _In_ ULONG Ceiling)
Specifies a progress percentage sub-range. Further calls to InbvIndicateProgress() or InbvUpdateProgr...
Definition: inbv.c:670
BOOLEAN NTAPI InbvEnableDisplayString(_In_ BOOLEAN Enable)
Definition: inbv.c:376
BOOLEAN NTAPI InbvDriverInitialize(_In_ PLOADER_PARAMETER_BLOCK LoaderBlock, _In_ ULONG Count)
Definition: inbv.c:179
VOID NTAPI InbvUpdateProgressBar(_In_ ULONG Percentage)
Updates the progress bar percentage, relative to the current percentage sub-range previously set by I...
Definition: inbv.c:696
BOOLEAN NTAPI InbvDisplayString(_In_ PCSTR String)
Definition: inbv.c:335
#define HIGH_PRIORITY
BOOLEAN NTAPI KdInitSystem(_In_ ULONG BootPhase, _In_opt_ PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: kdinit.c:164
LONG KdpTimeSlipPending
Definition: kddata.c:118
NTSTATUS NTAPI KdDebuggerInitialize1(IN PLOADER_PARAMETER_BLOCK LoaderBlock OPTIONAL)
Definition: kdcom.c:236
WCHAR StringBuffer[156]
Definition: ldrinit.c:41
BOOLEAN NTAPI LpcInitSystem(VOID)
Definition: port.c:37
static PTIME_FIELDS TimeFields
Definition: time.c:36
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4715
_In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Reserved_ ULONG _In_opt_ PUNICODE_STRING _In_ ULONG _Out_opt_ PULONG Disposition
Definition: cmfuncs.h:56
NTSYSAPI NTSTATUS NTAPI ZwSetSystemTime(_In_ PLARGE_INTEGER SystemTime, _In_opt_ PLARGE_INTEGER NewSystemTime)
FORCEINLINE VOID KiWriteSystemTime(_Out_ volatile KSYSTEM_TIME *SystemTime, _In_ LARGE_INTEGER NewTime)
Definition: kefuncs.h:429
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
NTSYSAPI NTSTATUS NTAPI NtSetValueKey(IN HANDLE KeyHandle, IN PUNICODE_STRING ValueName, IN ULONG TitleIndex OPTIONAL, IN ULONG Type, IN PVOID Data, IN ULONG DataSize)
Definition: ntapi.c:858
@ KeyValuePartialInformation
Definition: nt_native.h:1185
#define KEY_ALL_ACCESS
Definition: nt_native.h:1044
NTSYSAPI NTSTATUS NTAPI NtQueryValueKey(IN HANDLE KeyHandle, IN PUNICODE_STRING ValueName, IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass, IN PVOID KeyValueInformation, IN ULONG Length, IN PULONG ResultLength)
#define MEM_RELEASE
Definition: nt_native.h:1319
#define REG_OPTION_VOLATILE
Definition: nt_native.h:1063
#define Int32x32To64(a, b)
BOOLEAN InitWinPEModeType
Definition: init.c:76
BOOLEAN ExCmosClockIsSane
Definition: init.c:97
ULONG NtBuildNumber
Definition: init.c:54
NTSTATUS NTAPI ExpCreateSystemRootLink(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: init.c:105
CHAR NtBuildLab[]
Definition: init.c:68
NTSTATUS NTAPI RtlpInitializeLocaleTable(VOID)
Initializes the locale index table, that maps the LCIDs to their indexes in the alphabetical table,...
Definition: locale.c:515
VOID NTAPI MmFreeLoaderBlock(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: mminit.c:1085
VOID NTAPI ExpLoadInitialProcess(IN PINIT_BUFFER InitBuffer, OUT PRTL_USER_PROCESS_PARAMETERS *ProcessParameters, OUT PCHAR *ProcessEnvironment)
Definition: init.c:393
BOOLEAN ExpRealTimeIsUniversal
Definition: init.c:98
BOOLEAN SosEnabled
Definition: init.c:77
ULONG InitSafeBootMode
Definition: init.c:75
BOOLEAN InitIsWinPEMode
Definition: init.c:76
LARGE_INTEGER ExpTimeZoneBias
Definition: time.c:23
ULONG ExpAltTimeZoneBias
Definition: time.c:24
ULONG ExpLastTimeZoneBias
Definition: time.c:22
BOOLEAN NTAPI ExRefreshTimeZoneInformation(IN PLARGE_INTEGER CurrentBootTime)
Definition: time.c:320
VOID NTAPI KeI386VdmInitialize(VOID)
Definition: vdmmain.c:42
BOOLEAN NTAPI IoInitSystem(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: iomgr.c:542
VOID NTAPI KeSetSystemTime(IN PLARGE_INTEGER NewSystemTime, OUT PLARGE_INTEGER OldSystemTime, IN BOOLEAN FixInterruptTime, IN PLARGE_INTEGER HalTime)
Definition: clock.c:28
ULONGLONG KeBootTimeBias
Definition: clock.c:18
BOOLEAN NTAPI KeInitSystem(VOID)
Definition: krnlinit.c:292
VOID NTAPI KeStartAllProcessors(VOID)
Definition: mproc.c:20
LARGE_INTEGER KeBootTime
Definition: clock.c:17
PFN_COUNT MmNumberOfPhysicalPages
Definition: init.c:48
BOOLEAN NTAPI MmInitSystem(IN ULONG Phase, IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: mminit.c:217
VOID NTAPI RtlInitializeRangeListPackage(VOID)
Definition: libsupp.c:62
BOOLEAN NTAPI SeRmInitPhase1(VOID)
Manages the phase 1 initialization of the security reference monitoring module of the kernel.
Definition: srm.c:310
#define IDB_MAX_RESOURCES
Definition: resource.h:55
CCHAR KeNumberProcessors
Definition: processor.c:19
NTSTRSAFEVAPI RtlStringCbPrintfExA(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PSTR pszDest, _In_ size_t cbDest, _Outptr_opt_result_bytebuffer_(*pcbRemaining) NTSTRSAFE_PSTR *ppszDestEnd, _Out_opt_ size_t *pcbRemaining, _In_ STRSAFE_DWORD dwFlags, _In_ _Printf_format_string_ NTSTRSAFE_PCSTR pszFormat,...)
Definition: ntstrsafe.h:1294
NTSTRSAFEAPI RtlStringCbCopyA(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PSTR pszDest, _In_ size_t cbDest, _In_ NTSTRSAFE_PCSTR pszSrc)
Definition: ntstrsafe.h:156
static ULONG Timeout
Definition: ping.c:61
BOOLEAN NTAPI PoInitSystem(IN ULONG BootPhase)
Definition: power.c:397
VOID NTAPI PoNotifySystemTimeSet(VOID)
Definition: events.c:39
BOOLEAN NTAPI HalQueryRealTimeClock(IN PTIME_FIELDS Time)
Definition: rtc.c:24
#define REG_DWORD
Definition: sdbapi.c:615
RTL_USER_PROCESS_INFORMATION ProcessInfo
Definition: init.c:42
CHAR VersionBuffer[256]
Definition: init.c:39
CHAR VersionNumber[24]
Definition: init.c:41
LIST_ENTRY LoadOrderListHead
Definition: arc.h:820
#define TAG_INIT
Definition: tag.h:27
KPRIORITY NTAPI KeSetPriorityThread(IN PKTHREAD Thread, IN KPRIORITY Priority)
Definition: thrdobj.c:1300
char * PSTR
Definition: typedefs.h:51
const char * PCSTR
Definition: typedefs.h:52
short CSHORT
Definition: umtypes.h:127
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING KeyName
Definition: wdfdevice.h:2705
BOOLEAN SafeBoot
Definition: winldr.c:35
VOID NTAPI XIPInit(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: xipdisp.c:55

Referenced by Phase1Initialization().

◆ RtlpInitializeLocaleTable()

NTSTATUS NTAPI RtlpInitializeLocaleTable ( VOID  )

Initializes the locale index table, that maps the LCIDs to their indexes in the alphabetical table, and is sorted by LCID.

Definition at line 515 of file locale.c.

516{
519
520 for (USHORT i = 0; i < ARRAYSIZE(RtlpLocaleTable); i++)
521 {
523 USHORT j = i;
524
525 while ((j > 0) && (RtlpLocaleTable[RtlpLocaleIndexTable[j - 1]].Lcid > Lcid))
526 {
528 j--;
529 }
530
532 }
533
534 return STATUS_SUCCESS;
535}
#define ARRAYSIZE(a)
Definition: cat.c:25
_Out_ PLCID Lcid
Definition: rtlfuncs.h:5284
NTSTATUS NTAPI NtQueryDefaultLocale(IN BOOLEAN UserProfile, OUT PLCID DefaultLocaleId)
Definition: locale.c:392
DWORD LCID
Definition: nls.h:13
static USHORT RtlpLocaleIndexTable[_ARRAYSIZE(RtlpLocaleTable)]
Definition: locale.c:506
LCID RtlpUserDefaultLcid
Definition: locale.c:23
static const LOCALE_ENTRY RtlpLocaleTable[]
Definition: locale.c:34
LCID RtlpSystemDefaultLcid
Definition: locale.c:24
LCID Lcid
Definition: locale.c:29

Referenced by Phase1InitializationDiscard().

Variable Documentation

◆ CmCSDVersionString

UNICODE_STRING CmCSDVersionString

◆ CmNtCSDReleaseType

ULONG CmNtCSDReleaseType

Definition at line 64 of file init.c.

Referenced by ExpInitializeExecutive().

◆ CmNtCSDVersion

ULONG CmNtCSDVersion

Definition at line 63 of file init.c.

Referenced by ExpInitializeExecutive(), MmCreatePeb(), and RtlGetVersion().

◆ CmNtSpBuildNumber

ULONG CmNtSpBuildNumber

Definition at line 62 of file init.c.

Referenced by CmpSetVersionData(), and ExpInitializeExecutive().

◆ CmVersionString

UNICODE_STRING CmVersionString

Definition at line 65 of file init.c.

Referenced by CmpSetVersionData(), and ExpInitializeExecutive().

◆ ExCmosClockIsSane

BOOLEAN ExCmosClockIsSane = TRUE

Definition at line 97 of file init.c.

Referenced by KeSetSystemTime(), and Phase1InitializationDiscard().

◆ ExpAnsiCodePageDataOffset

ULONG ExpAnsiCodePageDataOffset

Definition at line 90 of file init.c.

Referenced by ExpInitializeExecutive(), ExpInitNls(), and MmCreatePeb().

◆ ExpInitializationPhase

◆ ExpInTextModeSetup

BOOLEAN ExpInTextModeSetup

Definition at line 73 of file init.c.

Referenced by CmpGetRegistryPath(), DisplayBootBitmap(), and ExpInitializeExecutive().

◆ ExpNlsSectionPointer

PVOID ExpNlsSectionPointer

Definition at line 94 of file init.c.

Referenced by ExpInitNls(), and MmCreatePeb().

◆ ExpNlsTableBase

PVOID ExpNlsTableBase

Definition at line 89 of file init.c.

Referenced by ExpInitializeExecutive(), and ExpInitNls().

◆ ExpNlsTableInfo

NLSTABLEINFO ExpNlsTableInfo

Definition at line 92 of file init.c.

Referenced by ExpInitializeExecutive(), and ExpInitNls().

◆ ExpNlsTableSize

SIZE_T ExpNlsTableSize

Definition at line 93 of file init.c.

Referenced by ExpInitNls().

◆ ExpOemCodePageDataOffset

ULONG ExpOemCodePageDataOffset

Definition at line 90 of file init.c.

Referenced by ExpInitializeExecutive(), ExpInitNls(), and MmCreatePeb().

◆ ExpRealTimeIsUniversal

BOOLEAN ExpRealTimeIsUniversal

Definition at line 98 of file init.c.

Referenced by Phase1InitializationDiscard().

◆ ExpUnicodeCaseTableDataOffset

ULONG ExpUnicodeCaseTableDataOffset

Definition at line 91 of file init.c.

Referenced by ExpInitializeExecutive(), ExpInitNls(), and MmCreatePeb().

◆ ExSuiteMask

ULONG ExSuiteMask

Definition at line 59 of file init.c.

Referenced by ExpInitSystemPhase0().

◆ InitIsWinPEMode

BOOLEAN InitIsWinPEMode

Definition at line 76 of file init.c.

Referenced by CmInitSystem1(), NtSystemDebugControl(), and Phase1InitializationDiscard().

◆ InitSafeBootMode

◆ InitWinPEModeType

BOOLEAN InitWinPEModeType

Definition at line 76 of file init.c.

Referenced by Phase1InitializationDiscard().

◆ IoRemoteBootClient

BOOLEAN IoRemoteBootClient

Definition at line 74 of file init.c.

Referenced by ExpInitializeExecutive(), IopCreateArcNames(), and xHalIoAssignDriveLetters().

◆ NtBuildLab

CHAR NtBuildLab[]
Initial value:
= KERNEL_VERSION_BUILD_STR "."
REACTOS_COMPILER_NAME "_" REACTOS_COMPILER_VERSION

Definition at line 68 of file init.c.

Referenced by CmpSetVersionData(), and Phase1InitializationDiscard().

◆ NtBuildNumber

◆ NtGlobalFlag

◆ NtInitialUserProcessBuffer

WCHAR NtInitialUserProcessBuffer[128] = L"\\SystemRoot\\System32\\smss.exe"

Definition at line 83 of file init.c.

Referenced by ExpLoadInitialProcess().

◆ NtInitialUserProcessBufferLength

ULONG NtInitialUserProcessBufferLength
Initial value:
sizeof(WCHAR)

Definition at line 84 of file init.c.

Referenced by ExpLoadInitialProcess().

◆ NtInitialUserProcessBufferType

ULONG NtInitialUserProcessBufferType = REG_SZ

Definition at line 86 of file init.c.

Referenced by ExpLoadInitialProcess().

◆ NtMajorVersion

ULONG NtMajorVersion = VER_PRODUCTMAJORVERSION

Definition at line 49 of file init.c.

Referenced by ExpInitializeExecutive(), MmCreatePeb(), PsGetVersion(), and RtlGetVersion().

◆ NtMinorVersion

ULONG NtMinorVersion = VER_PRODUCTMINORVERSION

Definition at line 50 of file init.c.

Referenced by ExpInitializeExecutive(), MmCreatePeb(), PsGetVersion(), and RtlGetVersion().

◆ NtSystemRoot

◆ SosEnabled

BOOLEAN SosEnabled

Definition at line 77 of file init.c.

Referenced by Phase1InitializationDiscard().