ReactOS 0.4.16-dev-424-ge4748fe
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_BUFFERPINIT_BUFFER
 

Functions

BOOLEAN NTAPI MmArmInitSystem (IN ULONG Phase, IN PLOADER_PARAMETER_BLOCK LoaderBlock)
 
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 793 of file init.c.

797{
798 PLIST_ENTRY NextEntry;
799 PLDR_DATA_TABLE_ENTRY LdrEntry;
801 ULONG i;
803 PWCHAR Name;
805 CHAR NameBuffer[256];
806
807 /* Loop over the boot modules list */
808 for (NextEntry = LoaderBlock->LoadOrderListHead.Flink, i = 0;
809 NextEntry != &LoaderBlock->LoadOrderListHead;
810 NextEntry = NextEntry->Flink, ++i)
811 {
812 /* Skip the first two images: HAL and kernel */
813 if (i < 2)
814 continue;
815
816 /* Get the entry */
817 LdrEntry = CONTAINING_RECORD(NextEntry,
819 InLoadOrderLinks);
820 if (LdrEntry->FullDllName.Buffer[0] == L'\\')
821 {
822 /* We have a name, read its data */
823 Name = LdrEntry->FullDllName.Buffer;
824 Length = LdrEntry->FullDllName.Length / sizeof(WCHAR);
825
826 /* Check if our buffer can hold it */
827 if (sizeof(NameBuffer) < Length + sizeof(ANSI_NULL))
828 {
829 /* It's too long */
831 }
832 else
833 {
834 /* Copy the name */
835 Count = 0;
836 do
837 {
838 /* Do cheap Unicode to ANSI conversion */
839 NameBuffer[Count++] = (CHAR)*Name++;
840 } while (Count < Length);
841
842 /* Null-terminate */
843 NameBuffer[Count] = ANSI_NULL;
845 }
846 }
847 else
848 {
849 /* Safely print the string into our buffer */
850 Status = RtlStringCbPrintfA(NameBuffer,
851 sizeof(NameBuffer),
852 "%S\\System32\\Drivers\\%wZ",
853 &SharedUserData->NtSystemRoot[2],
854 &LdrEntry->BaseDllName);
855 }
856
857 /* Check if the buffer is OK */
858 if (NT_SUCCESS(Status))
859 {
860 /* Load the symbols */
861 RtlInitString(&ImageName, NameBuffer);
863 LdrEntry->DllBase,
865 }
866 }
867}
struct NameRec_ * Name
Definition: cdprocs.h:460
LONG NTSTATUS
Definition: precomp.h:26
#define CHAR(Char)
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
std::wstring STRING
Definition: fontsub.cpp:33
Status
Definition: gdiplustypes.h:25
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
static const char * ImageName
Definition: image.c:34
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:1123
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
#define L(x)
Definition: ntvdm.h:50
#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:145
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
__wchar_t WCHAR
Definition: xmlstorage.h:180
char CHAR
Definition: xmlstorage.h:175

◆ ExBurnMemory()

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

Definition at line 872 of file init.c.

875{
876 PLIST_ENTRY ListEntry;
877 PMEMORY_ALLOCATION_DESCRIPTOR MemDescriptor;
878
879 DPRINT1("Burn RAM amount: %lu pages\n", PagesToDestroy);
880
881 /* Loop the memory descriptors, beginning at the end */
882 for (ListEntry = LoaderBlock->MemoryDescriptorListHead.Blink;
883 ListEntry != &LoaderBlock->MemoryDescriptorListHead;
884 ListEntry = ListEntry->Blink)
885 {
886 /* Get the memory descriptor structure */
887 MemDescriptor = CONTAINING_RECORD(ListEntry,
889 ListEntry);
890
891 /* Is memory free there or is it temporary? */
892 if (MemDescriptor->MemoryType == LoaderFree ||
893 MemDescriptor->MemoryType == LoaderFirmwareTemporary)
894 {
895 /* Check if the descriptor has more pages than we want */
896 if (MemDescriptor->PageCount > PagesToDestroy)
897 {
898 /* Change block's page count, ntoskrnl doesn't care much */
899 MemDescriptor->PageCount -= PagesToDestroy;
900 break;
901 }
902 else
903 {
904 /* Change block type */
905 MemDescriptor->MemoryType = MemoryType;
906 PagesToDestroy -= MemDescriptor->PageCount;
907
908 /* Check if we are done */
909 if (PagesToDestroy == 0) break;
910 }
911 }
912 }
913}
#define DPRINT1
Definition: precomp.h:8
@ LoaderFree
Definition: arc.h:176
@ LoaderFirmwareTemporary
Definition: arc.h:179
struct _LIST_ENTRY * Blink
Definition: typedefs.h:122
TYPE_OF_MEMORY MemoryType
Definition: arc.h:240

Referenced by ExpInitializeExecutive().

◆ ExComputeTickCountMultiplier()

ULONG NTAPI ExComputeTickCountMultiplier ( IN ULONG  ClockIncrement)

Definition at line 606 of file init.c.

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

Referenced by ExpInitializeExecutive().

◆ ExInitSystem()

BOOLEAN NTAPI ExInitSystem ( VOID  )

Definition at line 744 of file init.c.

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

Referenced by ExpInitializeExecutive(), and Phase1InitializationDiscard().

◆ ExpCreateSystemRootLink()

NTSTATUS NTAPI ExpCreateSystemRootLink ( IN PLOADER_PARAMETER_BLOCK  LoaderBlock)

Definition at line 101 of file init.c.

102{
103 UNICODE_STRING LinkName;
105 HANDLE LinkHandle;
107 ANSI_STRING AnsiName;
108 CHAR Buffer[256];
111
112 /* Initialize the ArcName tree */
113 RtlInitUnicodeString(&LinkName, L"\\ArcName");
115 &LinkName,
117 NULL,
119
120 /* Create it */
121 Status = NtCreateDirectoryObject(&LinkHandle,
124 if (!NT_SUCCESS(Status))
125 {
126 /* Failed */
127 KeBugCheckEx(SYMBOLIC_INITIALIZATION_FAILED, Status, 1, 0, 0);
128 }
129
130 /* Close the LinkHandle */
131 NtClose(LinkHandle);
132
133 /* Initialize the Device tree */
134 RtlInitUnicodeString(&LinkName, L"\\Device");
136 &LinkName,
138 NULL,
140
141 /* Create it */
142 Status = NtCreateDirectoryObject(&LinkHandle,
145 if (!NT_SUCCESS(Status))
146 {
147 /* Failed */
148 KeBugCheckEx(SYMBOLIC_INITIALIZATION_FAILED, Status, 2, 0, 0);
149 }
150
151 /* Close the LinkHandle */
152 ObCloseHandle(LinkHandle, KernelMode);
153
154 /* Create the system root symlink name */
155 RtlInitAnsiString(&AnsiName, "\\SystemRoot");
156 Status = RtlAnsiStringToUnicodeString(&LinkName, &AnsiName, TRUE);
157 if (!NT_SUCCESS(Status))
158 {
159 /* Failed */
160 KeBugCheckEx(SYMBOLIC_INITIALIZATION_FAILED, Status, 3, 0, 0);
161 }
162
163 /* Initialize the attributes for the link */
165 &LinkName,
167 NULL,
169
170 /* Build the ARC name */
172 "\\ArcName\\%s%s",
173 LoaderBlock->ArcBootDeviceName,
174 LoaderBlock->NtBootPathName);
176
177 /* Convert it to Unicode */
181 TRUE);
182 if (!NT_SUCCESS(Status))
183 {
184 /* We failed, bugcheck */
185 KeBugCheckEx(SYMBOLIC_INITIALIZATION_FAILED, Status, 4, 0, 0);
186 }
187
188 /* Create it */
192 &TargetName);
193
194 /* Free the strings */
195 RtlFreeUnicodeString(&LinkName);
197
198 /* Check if creating the link failed */
199 if (!NT_SUCCESS(Status))
200 {
201 /* Failed */
202 KeBugCheckEx(SYMBOLIC_INITIALIZATION_FAILED, Status, 5, 0, 0);
203 }
204
205 /* Close the handle and return success */
206 ObCloseHandle(LinkHandle, KernelMode);
207 return STATUS_SUCCESS;
208}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
_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
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define OBJ_PERMANENT
Definition: winternl.h:226
#define sprintf(buf, format,...)
Definition: sprintf.c:55
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define KernelMode
Definition: asm.h:38
#define SYMBOLIC_LINK_ALL_ACCESS
Definition: nt_native.h:1267
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:3402
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
#define DIRECTORY_ALL_ACCESS
Definition: nt_native.h:1259
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:3379
static PCWSTR TargetName
Definition: ping.c:67
VOID NTAPI KeBugCheckEx(_In_ ULONG BugCheckCode, _In_ ULONG_PTR BugCheckParameter1, _In_ ULONG_PTR BugCheckParameter2, _In_ ULONG_PTR BugCheckParameter3, _In_ ULONG_PTR BugCheckParameter4)
Definition: rtlcompat.c:108

Referenced by Phase1InitializationDiscard().

◆ ExpInitializeExecutive()

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

Definition at line 918 of file init.c.

920{
921 PNLS_DATA_BLOCK NlsData;
922 CHAR Buffer[256];
923 ANSI_STRING AnsiPath;
925 PCHAR CommandLine, PerfMem;
926 ULONG PerfMemUsed;
927 PLDR_DATA_TABLE_ENTRY NtosEntry;
929 ANSI_STRING CSDString;
930 size_t Remaining = 0;
931 PCHAR RcEnd = NULL;
932 CHAR VersionBuffer[65];
933
934 /* Validate Loader */
935 if (!ExpIsLoaderValid(LoaderBlock))
936 {
937 /* Invalid loader version */
938 KeBugCheckEx(MISMATCHED_HAL,
939 3,
940 LoaderBlock->Extension->Size,
941 LoaderBlock->Extension->MajorVersion,
942 LoaderBlock->Extension->MinorVersion);
943 }
944
945 /* Initialize PRCB pool lookaside pointers */
947
948 /* Check if this is an application CPU */
949 if (Cpu)
950 {
951 /* Then simply initialize it with HAL */
952 if (!HalInitSystem(ExpInitializationPhase, LoaderBlock))
953 {
954 /* Initialization failed */
955 KeBugCheck(HAL_INITIALIZATION_FAILED);
956 }
957
958 /* We're done */
959 return;
960 }
961
962 /* Assume no text-mode or remote boot */
965
966 /* Check if we have a setup loader block */
967 if (LoaderBlock->SetupLdrBlock)
968 {
969 /* Check if this is text-mode setup */
970 if (LoaderBlock->SetupLdrBlock->Flags & SETUPLDR_TEXT_MODE)
972
973 /* Check if this is network boot */
974 if (LoaderBlock->SetupLdrBlock->Flags & SETUPLDR_REMOTE_BOOT)
975 {
976 /* Set variable */
978
979 /* Make sure we're actually booting off the network */
980 ASSERT(!_memicmp(LoaderBlock->ArcBootDeviceName, "net(0)", 6));
981 }
982 }
983
984 /* Set phase to 0 */
986
987 /* Get boot command line */
988 CommandLine = LoaderBlock->LoadOptions;
989 if (CommandLine)
990 {
991 /* Upcase it for comparison and check if we're in performance mode */
992 _strupr(CommandLine);
993 PerfMem = strstr(CommandLine, "PERFMEM");
994 if (PerfMem)
995 {
996 /* Check if the user gave a number of bytes to use */
997 PerfMem = strstr(PerfMem, "=");
998 if (PerfMem)
999 {
1000 /* Read the number of pages we'll use */
1001 PerfMemUsed = atol(PerfMem + 1) * (1024 * 1024 / PAGE_SIZE);
1002 if (PerfMemUsed)
1003 {
1004 /* FIXME: TODO */
1005 DPRINT1("BBT performance mode not yet supported."
1006 "/PERFMEM option ignored.\n");
1007 }
1008 }
1009 }
1010
1011 /* Check if we're burning memory */
1012 PerfMem = strstr(CommandLine, "BURNMEMORY");
1013 if (PerfMem)
1014 {
1015 /* Check if the user gave a number of bytes to use */
1016 PerfMem = strstr(PerfMem, "=");
1017 if (PerfMem)
1018 {
1019 /* Read the number of pages we'll use */
1020 PerfMemUsed = atol(PerfMem + 1) * (1024 * 1024 / PAGE_SIZE);
1021 if (PerfMemUsed) ExBurnMemory(LoaderBlock, PerfMemUsed, LoaderBad);
1022 }
1023 }
1024 }
1025
1026 /* Setup NLS Base and offsets */
1027 NlsData = LoaderBlock->NlsData;
1031 (ULONG_PTR)NlsData->AnsiCodePageData);
1033 (ULONG_PTR)NlsData->AnsiCodePageData);
1034
1035 /* Initialize the NLS Tables */
1044
1045 /* Now initialize the HAL */
1046 if (!HalInitSystem(ExpInitializationPhase, LoaderBlock))
1047 {
1048 /* HAL failed to initialize, bugcheck */
1049 KeBugCheck(HAL_INITIALIZATION_FAILED);
1050 }
1051
1052 /* Make sure interrupts are active now */
1053 _enable();
1054
1055 /* Clear the crypto exponent */
1056 SharedUserData->CryptoExponent = 0;
1057
1058 /* Set global flags for the checked build */
1059#if DBG
1062#endif
1063
1064 /* Setup NT System Root Path */
1065 sprintf(Buffer, "C:%s", LoaderBlock->NtBootPathName);
1066
1067 /* Convert to ANSI_STRING and null-terminate it */
1068 RtlInitString(&AnsiPath, Buffer);
1069 Buffer[--AnsiPath.Length] = ANSI_NULL;
1070
1071 /* Get the string from KUSER_SHARED_DATA's buffer */
1072 RtlInitEmptyUnicodeString(&NtSystemRoot,
1073 SharedUserData->NtSystemRoot,
1074 sizeof(SharedUserData->NtSystemRoot));
1075
1076 /* Now fill it in */
1078 if (!NT_SUCCESS(Status)) KeBugCheck(SESSION3_INITIALIZATION_FAILED);
1079
1080 /* Setup bugcheck messages */
1082
1083 /* Setup initial system settings */
1084 CmGetSystemControlValues(LoaderBlock->RegistryBase, CmControlVector);
1085
1086 /* Set the Service Pack Number and add it to the CSD Version number if needed */
1088 if (((CmNtCSDVersion & 0xFFFF0000) == 0) && (CmNtCSDReleaseType == 1))
1089 {
1091 }
1092
1093 /* Add loaded CmNtGlobalFlag value */
1095
1096 /* Initialize the executive at phase 0 */
1097 if (!ExInitSystem()) KeBugCheck(PHASE0_INITIALIZATION_FAILED);
1098
1099 /* Initialize the memory manager at phase 0 */
1100 if (!MmArmInitSystem(0, LoaderBlock)) KeBugCheck(PHASE0_INITIALIZATION_FAILED);
1101
1102 /* Load boot symbols */
1103 ExpLoadBootSymbols(LoaderBlock);
1104
1105 /* Check if we should break after symbol load */
1108
1109 /* Check if this loader is compatible with NT 5.2 */
1110 if (LoaderBlock->Extension->Size >= sizeof(LOADER_PARAMETER_EXTENSION))
1111 {
1112 /* Setup headless terminal settings */
1113 HeadlessInit(LoaderBlock);
1114 }
1115
1116 /* Set system ranges */
1117#ifdef _M_AMD64
1120#else
1123#endif
1124
1125 /* Make a copy of the NLS Tables */
1126 ExpInitNls(LoaderBlock);
1127
1128 /* Get the kernel's load entry */
1129 NtosEntry = CONTAINING_RECORD(LoaderBlock->LoadOrderListHead.Flink,
1131 InLoadOrderLinks);
1132
1133 /* Check if this is a service pack */
1134 if (CmNtCSDVersion & 0xFFFF)
1135 {
1136 /* Get the service pack string */
1137 Status = RtlFindMessage(NtosEntry->DllBase,
1138 11,
1139 0,
1140 WINDOWS_NT_CSD_STRING,
1141 &MsgEntry);
1142 if (NT_SUCCESS(Status))
1143 {
1144 /* Setup the string */
1145 RtlInitAnsiString(&CSDString, (PCHAR)MsgEntry->Text);
1146
1147 /* Remove trailing newline */
1148 while ((CSDString.Length > 0) &&
1149 ((CSDString.Buffer[CSDString.Length - 1] == '\r') ||
1150 (CSDString.Buffer[CSDString.Length - 1] == '\n')))
1151 {
1152 /* Skip the trailing character */
1153 CSDString.Length--;
1154 }
1155
1156 /* Fill the buffer with version information */
1158 sizeof(Buffer),
1159 "%Z %u%c",
1160 &CSDString,
1161 (CmNtCSDVersion & 0xFF00) >> 8,
1162 (CmNtCSDVersion & 0xFF) ?
1163 'A' + (CmNtCSDVersion & 0xFF) - 1 :
1164 ANSI_NULL);
1165 }
1166 else
1167 {
1168 /* Build default string */
1170 sizeof(Buffer),
1171 "CSD %04x",
1173 }
1174
1175 /* Check for success */
1176 if (!NT_SUCCESS(Status))
1177 {
1178 /* Fail */
1179 KeBugCheckEx(PHASE0_INITIALIZATION_FAILED, Status, 0, 0, 0);
1180 }
1181 }
1182 else
1183 {
1184 /* Then this is a beta */
1186 sizeof(Buffer),
1188 NULL,
1189 &Remaining,
1190 0);
1191 if (!NT_SUCCESS(Status))
1192 {
1193 /* Fail */
1194 KeBugCheckEx(PHASE0_INITIALIZATION_FAILED, Status, 0, 0, 0);
1195 }
1196
1197 /* Update length */
1198 CmCSDVersionString.MaximumLength = sizeof(Buffer) - (USHORT)Remaining;
1199 }
1200
1201 /* Check if we have an RC number */
1202 if ((CmNtCSDVersion & 0xFFFF0000) && (CmNtCSDReleaseType == 1))
1203 {
1204 /* Check if we have no version data yet */
1205 if (!(*Buffer))
1206 {
1207 /* Set defaults */
1208 Remaining = sizeof(Buffer);
1209 RcEnd = Buffer;
1210 }
1211 else
1212 {
1213 /* Add comma and space */
1215 sizeof(Buffer),
1216 ", ",
1217 &RcEnd,
1218 &Remaining,
1219 0);
1220 if (!NT_SUCCESS(Status))
1221 {
1222 /* Fail */
1223 KeBugCheckEx(PHASE0_INITIALIZATION_FAILED, Status, 0, 0, 0);
1224 }
1225 }
1226
1227 /* Add the version format string */
1228 Status = RtlStringCbPrintfA(RcEnd,
1229 Remaining,
1230 "v.%u",
1231 (CmNtCSDVersion & 0xFFFF0000) >> 16);
1232 if (!NT_SUCCESS(Status))
1233 {
1234 /* Fail */
1235 KeBugCheckEx(PHASE0_INITIALIZATION_FAILED, Status, 0, 0, 0);
1236 }
1237 }
1238
1239 /* Now setup the final string */
1240 RtlInitAnsiString(&CSDString, Buffer);
1242 &CSDString,
1243 TRUE);
1244 if (!NT_SUCCESS(Status))
1245 {
1246 /* Fail */
1247 KeBugCheckEx(PHASE0_INITIALIZATION_FAILED, Status, 0, 0, 0);
1248 }
1249
1250 /* Add our version */
1251 Status = RtlStringCbPrintfA(VersionBuffer,
1252 sizeof(VersionBuffer),
1253 "%u.%u",
1256 if (!NT_SUCCESS(Status))
1257 {
1258 /* Fail */
1259 KeBugCheckEx(PHASE0_INITIALIZATION_FAILED, Status, 0, 0, 0);
1260 }
1261
1262 /* Build the final version string */
1264
1265 /* Check if the user wants a kernel stack trace database */
1267 {
1268 /* FIXME: TODO */
1269 DPRINT1("Kernel-mode stack trace support not yet present."
1270 "FLG_KERNEL_STACK_TRACE_DB flag ignored.\n");
1271 }
1272
1273 /* Check if he wanted exception logging */
1275 {
1276 /* FIXME: TODO */
1277 DPRINT1("Kernel-mode exception logging support not yet present."
1278 "FLG_ENABLE_EXCEPTION_LOGGING flag ignored.\n");
1279 }
1280
1281 /* Initialize the Handle Table */
1283
1284#if DBG
1285 /* On checked builds, allocate the system call count table */
1288 KiServiceLimit * sizeof(ULONG),
1289 'llaC');
1290
1291 /* Use it for the shadow table too */
1293
1294 /* Make sure allocation succeeded */
1296 {
1297 /* Zero the call counts to 0 */
1299 KiServiceLimit * sizeof(ULONG));
1300 }
1301#endif
1302
1303 /* Create the Basic Object Manager Types to allow new Object Types */
1304 if (!ObInitSystem()) KeBugCheck(OBJECT_INITIALIZATION_FAILED);
1305
1306 /* Load basic Security for other Managers */
1307 if (!SeInitSystem()) KeBugCheck(SECURITY_INITIALIZATION_FAILED);
1308
1309 /* Initialize the Process Manager */
1310 if (!PsInitSystem(LoaderBlock)) KeBugCheck(PROCESS_INITIALIZATION_FAILED);
1311
1312 /* Initialize the PnP Manager */
1313 if (!PpInitSystem()) KeBugCheck(PP0_INITIALIZATION_FAILED);
1314
1315 /* Initialize the User-Mode Debugging Subsystem */
1317
1318 /* Calculate the tick count multiplier */
1320 SharedUserData->TickCountMultiplier = ExpTickCountMultiplier;
1321
1322 /* Set the OS Version */
1323 SharedUserData->NtMajorVersion = NtMajorVersion;
1324 SharedUserData->NtMinorVersion = NtMinorVersion;
1325
1326 /* Set the machine type */
1327 SharedUserData->ImageNumberLow = IMAGE_FILE_MACHINE_NATIVE;
1328 SharedUserData->ImageNumberHigh = IMAGE_FILE_MACHINE_NATIVE;
1329
1330 /* ReactOS magic */
1331 *(PULONG)(KI_USER_SHARED_DATA + PAGE_SIZE - sizeof(ULONG)) = 0x8eac705;
1332}
char * strstr(char *String1, char *String2)
Definition: utclib.c:653
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
#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:43
VOID NTAPI HeadlessInit(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: hdlsterm.c:189
#define VER_PRODUCTBETA_STR
Definition: ieverp.h:10
_Check_return_ long __cdecl atol(_In_z_ const char *_Str)
#define FLG_KERNEL_STACK_TRACE_DB
Definition: pstypes.h:68
#define FLG_ENABLE_EXCEPTION_LOGGING
Definition: pstypes.h:82
#define FLG_ENABLE_CLOSE_EXCEPTIONS
Definition: pstypes.h:81
#define FLG_ENABLE_KDEBUG_SYMBOL_LOAD
Definition: pstypes.h:73
void __cdecl _enable(void)
Definition: intrin_arm.h:373
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:872
ULONG CmNtCSDReleaseType
Definition: init.c:60
PVOID ExpNlsTableBase
Definition: init.c:85
ULONG NTAPI ExComputeTickCountMultiplier(IN ULONG ClockIncrement)
Definition: init.c:606
BOOLEAN IoRemoteBootClient
Definition: init.c:70
UNICODE_STRING NtSystemRoot
Definition: init.c:76
ULONG ExpOemCodePageDataOffset
Definition: init.c:86
NLSTABLEINFO ExpNlsTableInfo
Definition: init.c:88
BOOLEAN NTAPI ExpIsLoaderValid(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: init.c:770
ULONG NtMajorVersion
Definition: init.c:45
ULONG ExpUnicodeCaseTableDataOffset
Definition: init.c:87
BOOLEAN NTAPI MmArmInitSystem(IN ULONG Phase, IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: mminit.c:2037
ULONG NtGlobalFlag
Definition: init.c:54
UNICODE_STRING CmVersionString
Definition: init.c:61
ULONG CmNtSpBuildNumber
Definition: init.c:58
BOOLEAN ExpInTextModeSetup
Definition: init.c:69
ULONG ExpAnsiCodePageDataOffset
Definition: init.c:86
ULONG NtMinorVersion
Definition: init.c:46
ULONG CmNtCSDVersion
Definition: init.c:59
VOID NTAPI ExpInitNls(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: init.c:213
UNICODE_STRING CmCSDVersionString
Definition: init.c:62
BOOLEAN NTAPI ExInitSystem(VOID)
Definition: init.c:744
ULONG ExpTickCountMultiplier
Definition: time.c:26
#define MM_HIGHEST_USER_ADDRESS_WOW64
Definition: mm.h:35
#define MM_SYSTEM_RANGE_START_WOW64
Definition: mm.h:36
#define MmSystemRangeStart
Definition: mm.h:32
BOOLEAN NTAPI PpInitSystem(VOID)
Definition: pnpmgr.c:1142
VOID NTAPI KiInitializeBugCheck(VOID)
Definition: bug.c:300
ULONG KiServiceLimit
Definition: krnlinit.c:26
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
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:532
PVOID MmHighestUserAddress
Definition: rtlcompat.c:29
_Check_return_ _CRTIMP int __cdecl _memicmp(_In_reads_bytes_opt_(_Size) const void *_Buf1, _In_reads_bytes_opt_(_Size) const void *_Buf2, _In_ size_t _Size)
_CRTIMP char *__cdecl _strupr(_Inout_z_ char *_String)
@ LoaderBad
Definition: arc.h:177
#define KI_USER_SHARED_DATA
#define SETUPLDR_REMOTE_BOOT
Definition: setupblk.h:8
#define SETUPLDR_TEXT_MODE
Definition: setupblk.h:7
Definition: rtltypes.h:1896
UCHAR Text[ANYSIZE_ARRAY]
Definition: rtltypes.h:1899
PVOID UnicodeCodePageData
Definition: arc.h:325
PVOID AnsiCodePageData
Definition: arc.h:323
PVOID OemCodePageData
Definition: arc.h:324
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 213 of file init.c.

214{
215 LARGE_INTEGER SectionSize;
217 HANDLE NlsSection;
218 PVOID SectionBase = NULL;
219 SIZE_T ViewSize = 0;
220 LARGE_INTEGER SectionOffset = {{0, 0}};
221 PLIST_ENTRY ListHead, NextEntry;
223 ULONG NlsTablesEncountered = 0;
224 SIZE_T NlsTableSizes[3] = {0, 0, 0}; /* 3 NLS tables */
225
226 /* Check if this is boot-time phase 0 initialization */
228 {
229 /* Loop the memory descriptors */
230 ListHead = &LoaderBlock->MemoryDescriptorListHead;
231 NextEntry = ListHead->Flink;
232 while (NextEntry != ListHead)
233 {
234 /* Get the current block */
235 MdBlock = CONTAINING_RECORD(NextEntry,
237 ListEntry);
238
239 /* Check if this is an NLS block */
240 if (MdBlock->MemoryType == LoaderNlsData)
241 {
242 /* Increase the table size */
243 ExpNlsTableSize += MdBlock->PageCount * PAGE_SIZE;
244
245 /* FreeLdr-specific */
246 NlsTableSizes[NlsTablesEncountered] = MdBlock->PageCount * PAGE_SIZE;
247 NlsTablesEncountered++;
248 ASSERT(NlsTablesEncountered < 4);
249 }
250
251 /* Go to the next block */
252 NextEntry = MdBlock->ListEntry.Flink;
253 }
254
255 /* Allocate the a new buffer since loader memory will be freed */
258 TAG_RTLI);
259 if (!ExpNlsTableBase) KeBugCheck(PHASE0_INITIALIZATION_FAILED);
260
261 /* Copy the codepage data in its new location. */
262 if (NlsTablesEncountered == 1)
263 {
264 /* Ntldr-way boot process */
266 LoaderBlock->NlsData->AnsiCodePageData,
268 }
269 else
270 {
271 /*
272 * In NT, the memory blocks are contiguous, but in ReactOS they aren't,
273 * so unless someone fixes FreeLdr, we'll have to use this icky hack.
274 */
276 LoaderBlock->NlsData->AnsiCodePageData,
277 NlsTableSizes[0]);
278
279 RtlCopyMemory((PVOID)((ULONG_PTR)ExpNlsTableBase + NlsTableSizes[0]),
280 LoaderBlock->NlsData->OemCodePageData,
281 NlsTableSizes[1]);
282
283 RtlCopyMemory((PVOID)((ULONG_PTR)ExpNlsTableBase + NlsTableSizes[0] +
284 NlsTableSizes[1]),
285 LoaderBlock->NlsData->UnicodeCodePageData,
286 NlsTableSizes[2]);
287 /* End of Hack */
288 }
289
290 /* Initialize and reset the NLS TAbles */
299 return;
300 }
301
302 /* Set the section size */
303 SectionSize.QuadPart = ExpNlsTableSize;
304
305 /* Create the NLS Section */
306 Status = ZwCreateSection(&NlsSection,
308 NULL,
309 &SectionSize,
311 SEC_COMMIT | 0x1,
312 NULL);
313 if (!NT_SUCCESS(Status))
314 {
315 /* Failed */
316 KeBugCheckEx(PHASE1_INITIALIZATION_FAILED, Status, 1, 0, 0);
317 }
318
319 /* Get a pointer to the section */
325 NULL);
326 ObCloseHandle(NlsSection, KernelMode);
327 if (!NT_SUCCESS(Status))
328 {
329 /* Failed */
330 KeBugCheckEx(PHASE1_INITIALIZATION_FAILED, Status, 2, 0, 0);
331 }
332
333 /* Map the NLS Section in system space */
335 &SectionBase,
337 if (!NT_SUCCESS(Status))
338 {
339 /* Failed */
340 KeBugCheckEx(PHASE1_INITIALIZATION_FAILED, Status, 3, 0, 0);
341 }
342
343 /* Copy the codepage data in its new location. */
344 ASSERT(SectionBase >= MmSystemRangeStart);
346
347 /* Free the previously allocated buffer and set the new location */
349 ExpNlsTableBase = SectionBase;
350
351 /* Initialize the NLS Tables */
360
361 /* Reset the base to 0 */
362 SectionBase = NULL;
363
364 /* Map the section in the system process */
367 &SectionBase,
368 0L,
369 0L,
371 &ViewSize,
372 ViewShare,
373 0L,
375 if (!NT_SUCCESS(Status))
376 {
377 /* Failed */
378 KeBugCheckEx(PHASE1_INITIALIZATION_FAILED, Status, 5, 0, 0);
379 }
380
381 /* Copy the table into the system process and set this as the base */
383 ExpNlsTableBase = SectionBase;
384}
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR _In_ SIZE_T _Inout_opt_ PLARGE_INTEGER SectionOffset
Definition: mmfuncs.h:407
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR _In_ SIZE_T _Inout_opt_ PLARGE_INTEGER _Inout_ PSIZE_T ViewSize
Definition: mmfuncs.h:408
#define SEC_COMMIT
Definition: mmtypes.h:100
#define PAGE_READWRITE
Definition: nt_native.h:1304
#define SECTION_ALL_ACCESS
Definition: nt_native.h:1293
@ ViewShare
Definition: nt_native.h:1278
SIZE_T ExpNlsTableSize
Definition: init.c:89
PVOID ExpNlsSectionPointer
Definition: init.c:90
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:494
@ LoaderNlsData
Definition: arc.h:195
NTSTATUS NTAPI MmMapViewInSystemSpace(IN PVOID SectionObject, OUT PVOID *MappedBase, IN OUT PSIZE_T ViewSize)
Definition: section.c:4452
NTSTATUS NTAPI MmMapViewOfSection(IN PVOID SectionObject, IN PEPROCESS Process, IN OUT PVOID *BaseAddress, IN ULONG_PTR ZeroBits, IN SIZE_T CommitSize, IN OUT PLARGE_INTEGER SectionOffset OPTIONAL, IN OUT PSIZE_T ViewSize, IN SECTION_INHERIT InheritDisposition, IN ULONG AllocationType, IN ULONG Protect)
Definition: section.c:4001
POBJECT_TYPE MmSectionObjectType
Definition: section.c:194
#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 639 of file init.c.

640{
641 /* Initialize EXRESOURCE Support */
643
644 /* Initialize the environment lock */
646
647 /* Initialize the lookaside lists and locks */
649
650 /* Initialize the Firmware Table resource and listhead */
654
655 /* Set the suite mask to maximum and return */
656 ExSuiteMask = 0xFFFFFFFF;
657 return TRUE;
658}
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:55
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 663 of file init.c.

664{
665 /* Initialize worker threads */
667
668 /* Initialize pushlocks */
670
671 /* Initialize events and event pairs */
673 {
674 DPRINT1("Executive: Event initialization failed\n");
675 return FALSE;
676 }
678 {
679 DPRINT1("Executive: Event Pair initialization failed\n");
680 return FALSE;
681 }
682
683 /* Initialize mutants */
685 {
686 DPRINT1("Executive: Mutant initialization failed\n");
687 return FALSE;
688 }
689
690 /* Initialize callbacks */
692 {
693 DPRINT1("Executive: Callback initialization failed\n");
694 return FALSE;
695 }
696
697 /* Initialize semaphores */
699 {
700 DPRINT1("Executive: Semaphore initialization failed\n");
701 return FALSE;
702 }
703
704 /* Initialize timers */
706 {
707 DPRINT1("Executive: Timer initialization failed\n");
708 return FALSE;
709 }
710
711 /* Initialize profiling */
713 {
714 DPRINT1("Executive: Profile initialization failed\n");
715 return FALSE;
716 }
717
718 /* Initialize UUIDs */
720 {
721 DPRINT1("Executive: Uuid initialization failed\n");
722 return FALSE;
723 }
724
725 /* Initialize keyed events */
727 {
728 DPRINT1("Executive: Keyed event initialization failed\n");
729 return FALSE;
730 }
731
732 /* Initialize Win32K */
733 if (ExpWin32kInit() == FALSE)
734 {
735 DPRINT1("Executive: Win32 initialization failed\n");
736 return FALSE;
737 }
738 return TRUE;
739}
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:259
VOID NTAPI ExpInitializeWorkerThreads(VOID)
Definition: work.c:522

Referenced by ExInitSystem().

◆ ExpIsLoaderValid()

BOOLEAN NTAPI ExpIsLoaderValid ( IN PLOADER_PARAMETER_BLOCK  LoaderBlock)

Definition at line 770 of file init.c.

771{
773
774 /* Get the loader extension */
775 Extension = LoaderBlock->Extension;
776
777 /* Validate the size (Windows 2003 loader doesn't provide more) */
779
780 /* Don't validate upper versions */
781 if (Extension->MajorVersion > VER_PRODUCTMAJORVERSION) return TRUE;
782
783 /* Fail if this is NT 4 */
784 if (Extension->MajorVersion < VER_PRODUCTMAJORVERSION) return FALSE;
785
786 /* Fail if this is XP */
787 if (Extension->MinorVersion < VER_PRODUCTMINORVERSION) return FALSE;
788
789 /* This is 2003 or newer, approve it */
790 return TRUE;
791}
_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 389 of file init.c.

392{
394 SIZE_T Size;
395 PWSTR p;
396 UNICODE_STRING NullString = RTL_CONSTANT_STRING(L"");
397 UNICODE_STRING SmssName, Environment, SystemDriveString, DebugString;
398 PVOID EnvironmentPtr = NULL;
399 PRTL_USER_PROCESS_INFORMATION ProcessInformation;
400 PRTL_USER_PROCESS_PARAMETERS ProcessParams = NULL;
401
402 NullString.Length = sizeof(WCHAR);
403
404 /* Use the initial buffer, after the strings */
405 ProcessInformation = &InitBuffer->ProcessInfo;
406
407 /* Allocate memory for the process parameters */
408 Size = sizeof(*ProcessParams) + ((MAX_WIN32_PATH * 6) * sizeof(WCHAR));
409 Status = ZwAllocateVirtualMemory(NtCurrentProcess(),
410 (PVOID*)&ProcessParams,
411 0,
412 &Size,
415 if (!NT_SUCCESS(Status))
416 {
417 /* Failed, display error */
418 _snwprintf(InitBuffer->DebugBuffer,
419 sizeof(InitBuffer->DebugBuffer)/sizeof(WCHAR),
420 L"INIT: Unable to allocate Process Parameters. 0x%lx",
421 Status);
422 RtlInitUnicodeString(&DebugString, InitBuffer->DebugBuffer);
424
425 /* Bugcheck the system */
426 KeBugCheckEx(SESSION1_INITIALIZATION_FAILED, Status, 0, 0, 0);
427 }
428
429 /* Setup the basic header, and give the process the low 1MB to itself */
430 ProcessParams->Length = (ULONG)Size;
431 ProcessParams->MaximumLength = (ULONG)Size;
434
435 /* Allocate a page for the environment */
436 Size = PAGE_SIZE;
437 Status = ZwAllocateVirtualMemory(NtCurrentProcess(),
438 &EnvironmentPtr,
439 0,
440 &Size,
443 if (!NT_SUCCESS(Status))
444 {
445 /* Failed, display error */
446 _snwprintf(InitBuffer->DebugBuffer,
447 sizeof(InitBuffer->DebugBuffer)/sizeof(WCHAR),
448 L"INIT: Unable to allocate Process Environment. 0x%lx",
449 Status);
450 RtlInitUnicodeString(&DebugString, InitBuffer->DebugBuffer);
452
453 /* Bugcheck the system */
454 KeBugCheckEx(SESSION2_INITIALIZATION_FAILED, Status, 0, 0, 0);
455 }
456
457 /* Write the pointer */
458 ProcessParams->Environment = EnvironmentPtr;
459
460 /* Make a buffer for the DOS path */
461 p = (PWSTR)(ProcessParams + 1);
462 ProcessParams->CurrentDirectory.DosPath.Buffer = p;
464 sizeof(WCHAR);
465
466 /* Copy the DOS path */
468 &NtSystemRoot);
469
470 /* Make a buffer for the DLL Path */
471 p = (PWSTR)((PCHAR)ProcessParams->CurrentDirectory.DosPath.Buffer +
472 ProcessParams->CurrentDirectory.DosPath.MaximumLength);
473 ProcessParams->DllPath.Buffer = p;
474 ProcessParams->DllPath.MaximumLength = MAX_WIN32_PATH * sizeof(WCHAR);
475
476 /* Copy the DLL path and append the system32 directory */
477 RtlCopyUnicodeString(&ProcessParams->DllPath,
478 &ProcessParams->CurrentDirectory.DosPath);
479 RtlAppendUnicodeToString(&ProcessParams->DllPath, L"\\System32");
480
481 /* Make a buffer for the image name */
482 p = (PWSTR)((PCHAR)ProcessParams->DllPath.Buffer +
483 ProcessParams->DllPath.MaximumLength);
484 ProcessParams->ImagePathName.Buffer = p;
485 ProcessParams->ImagePathName.MaximumLength = MAX_WIN32_PATH * sizeof(WCHAR);
486
487 /* Make sure the buffer is a valid string which within the given length */
492 sizeof(NtInitialUserProcessBuffer) - sizeof(WCHAR)))))
493 {
494 /* Invalid initial process string, bugcheck */
495 KeBugCheckEx(SESSION2_INITIALIZATION_FAILED,
500 }
501
502 /* Cut out anything after a space */
504 while ((*p) && (*p != L' ')) p++;
505
506 /* Set the image path length */
507 ProcessParams->ImagePathName.Length =
509
510 /* Copy the actual buffer */
511 RtlCopyMemory(ProcessParams->ImagePathName.Buffer,
513 ProcessParams->ImagePathName.Length);
514
515 /* Null-terminate it */
516 ProcessParams->ImagePathName.Buffer[ProcessParams->ImagePathName.Length /
517 sizeof(WCHAR)] = UNICODE_NULL;
518
519 /* Make a buffer for the command line */
520 p = (PWSTR)((PCHAR)ProcessParams->ImagePathName.Buffer +
521 ProcessParams->ImagePathName.MaximumLength);
522 ProcessParams->CommandLine.Buffer = p;
523 ProcessParams->CommandLine.MaximumLength = MAX_WIN32_PATH * sizeof(WCHAR);
524
525 /* Add the image name to the command line */
528
529 /* Create the environment string */
530 RtlInitEmptyUnicodeString(&Environment,
531 ProcessParams->Environment,
532 (USHORT)Size);
533
534 /* Append the DLL path to it */
538
539 /* Create the system drive string */
540 SystemDriveString = NtSystemRoot;
541 SystemDriveString.Length = 2 * sizeof(WCHAR);
542
543 /* Append it to the environment */
544 RtlAppendUnicodeToString(&Environment, L"SystemDrive=");
545 RtlAppendUnicodeStringToString(&Environment, &SystemDriveString);
547
548 /* Append the system root to the environment */
549 RtlAppendUnicodeToString(&Environment, L"SystemRoot=");
552
553 /* Prepare the prefetcher */
554 //CcPfBeginBootPhase(150);
555
556 /* Create SMSS process */
557 SmssName = ProcessParams->ImagePathName;
558 Status = RtlCreateUserProcess(&SmssName,
560 RtlDeNormalizeProcessParams(ProcessParams),
561 NULL,
562 NULL,
563 NULL,
564 FALSE,
565 NULL,
566 NULL,
567 ProcessInformation);
568 if (!NT_SUCCESS(Status))
569 {
570 /* Failed, display error */
571 _snwprintf(InitBuffer->DebugBuffer,
572 sizeof(InitBuffer->DebugBuffer)/sizeof(WCHAR),
573 L"INIT: Unable to create Session Manager. 0x%lx",
574 Status);
575 RtlInitUnicodeString(&DebugString, InitBuffer->DebugBuffer);
577
578 /* Bugcheck the system */
579 KeBugCheckEx(SESSION3_INITIALIZATION_FAILED, Status, 0, 0, 0);
580 }
581
582 /* Resume the thread */
583 Status = ZwResumeThread(ProcessInformation->ThreadHandle, NULL);
584 if (!NT_SUCCESS(Status))
585 {
586 /* Failed, display error */
587 _snwprintf(InitBuffer->DebugBuffer,
588 sizeof(InitBuffer->DebugBuffer)/sizeof(WCHAR),
589 L"INIT: Unable to resume Session Manager. 0x%lx",
590 Status);
591 RtlInitUnicodeString(&DebugString, InitBuffer->DebugBuffer);
593
594 /* Bugcheck the system */
595 KeBugCheckEx(SESSION4_INITIALIZATION_FAILED, Status, 0, 0, 0);
596 }
597
598 /* Return success */
599 *ProcessParameters = ProcessParams;
600 *ProcessEnvironment = EnvironmentPtr;
601}
static CCHAR DebugString[256]
Definition: settings.c:16
NTSTATUS RtlAppendUnicodeToString(IN PUNICODE_STRING Str1, IN PWSTR Str2)
Definition: string_lib.cpp:62
GLfloat GLfloat p
Definition: glext.h:8902
#define REG_SZ
Definition: layer.c:22
#define PCHAR
Definition: match.c:90
int _snwprintf(wchar_t *buffer, size_t count, const wchar_t *format,...)
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:1657
#define MEM_RESERVE
Definition: nt_native.h:1314
#define MEM_COMMIT
Definition: nt_native.h:1313
#define UNICODE_NULL
WCHAR NtInitialUserProcessBuffer[128]
Definition: init.c:79
ULONG NtInitialUserProcessBufferType
Definition: init.c:82
ULONG NtInitialUserProcessBufferLength
Definition: init.c:80
#define MAX_WIN32_PATH
Definition: ntoskrnl.h:125
UNICODE_STRING DosPath
Definition: rtltypes.h:1368
UNICODE_STRING CommandLine
Definition: btrfs_drv.h:1902
UNICODE_STRING ImagePathName
Definition: btrfs_drv.h:1901
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
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:4533

Referenced by Phase1InitializationDiscard().

◆ MmArmInitSystem()

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

Definition at line 2037 of file mminit.c.

2039{
2040 ULONG i;
2041 BOOLEAN IncludeType[LoaderMaximum];
2042 PVOID Bitmap;
2044 PFN_NUMBER PageCount;
2045#if DBG
2046 ULONG j;
2047 PMMPTE PointerPte, TestPte;
2048 MMPTE TempPte;
2049#endif
2050
2051 /* Dump memory descriptors */
2053
2054 //
2055 // Instantiate memory that we don't consider RAM/usable
2056 // We use the same exclusions that Windows does, in order to try to be
2057 // compatible with WinLDR-style booting
2058 //
2059 for (i = 0; i < LoaderMaximum; i++) IncludeType[i] = TRUE;
2060 IncludeType[LoaderBad] = FALSE;
2061 IncludeType[LoaderFirmwarePermanent] = FALSE;
2062 IncludeType[LoaderSpecialMemory] = FALSE;
2063 IncludeType[LoaderBBTMemory] = FALSE;
2064 if (Phase == 0)
2065 {
2066 /* Count physical pages on the system */
2067 MiScanMemoryDescriptors(LoaderBlock);
2068
2069 /* Initialize the phase 0 temporary event */
2071
2072 /* Set all the events to use the temporary event for now */
2079
2080 //
2081 // Default throttling limits for Cc
2082 // May be ajusted later on depending on system type
2083 //
2084 MmThrottleTop = 450;
2085 MmThrottleBottom = 127;
2086
2087 //
2088 // Define the basic user vs. kernel address space separation
2089 //
2093
2094 /* Highest PTE and PDE based on the addresses above */
2097#if (_MI_PAGING_LEVELS >= 3)
2098 MiHighestUserPpe = MiAddressToPpe(MmHighestUserAddress);
2099#if (_MI_PAGING_LEVELS >= 4)
2100 MiHighestUserPxe = MiAddressToPxe(MmHighestUserAddress);
2101#endif
2102#endif
2103 //
2104 // Get the size of the boot loader's image allocations and then round
2105 // that region up to a PDE size, so that any PDEs we might create for
2106 // whatever follows are separate from the PDEs that boot loader might've
2107 // already created (and later, we can blow all that away if we want to).
2108 //
2113
2114 /* Initialize session space address layout */
2116
2117 /* Set the based section highest address */
2119
2120 /* Loop all 8 standby lists */
2121 for (i = 0; i < 8; i++)
2122 {
2123 /* Initialize them */
2128 }
2129
2130 /* Initialize the user mode image list */
2132
2133 /* Initalize the Working set list */
2135
2136 /* Initialize critical section timeout value (relative time is negative) */
2138
2139 /* Initialize the paged pool mutex and the section commit mutex */
2143
2144 /* Initialize the Loader Lock */
2146
2147 /* Set up the zero page event */
2149
2150 /* Initialize the dead stack S-LIST */
2152
2153 //
2154 // Check if this is a machine with less than 19MB of RAM
2155 //
2156 PageCount = MmNumberOfPhysicalPages;
2157 if (PageCount < MI_MIN_PAGES_FOR_SYSPTE_TUNING)
2158 {
2159 //
2160 // Use the very minimum of system PTEs
2161 //
2162 MmNumberOfSystemPtes = 7000;
2163 }
2164 else
2165 {
2166 //
2167 // Use the default
2168 //
2169 MmNumberOfSystemPtes = 11000;
2170 if (PageCount > MI_MIN_PAGES_FOR_SYSPTE_BOOST)
2171 {
2172 //
2173 // Double the amount of system PTEs
2174 //
2176 }
2178 {
2179 //
2180 // Double the amount of system PTEs
2181 //
2183 }
2184 if (MmSpecialPoolTag != 0 && MmSpecialPoolTag != -1)
2185 {
2186 //
2187 // Add some extra PTEs for special pool
2188 //
2189 MmNumberOfSystemPtes += 0x6000;
2190 }
2191 }
2192
2193 DPRINT("System PTE count has been tuned to %lu (%lu bytes)\n",
2195
2196 /* Check if no values are set for the heap limits */
2197 if (MmHeapSegmentReserve == 0)
2198 {
2200 }
2201
2202 if (MmHeapSegmentCommit == 0)
2203 {
2205 }
2206
2208 {
2210 }
2211
2213 {
2215 }
2216
2217 /* Initialize the working set lock */
2219
2220 /* Set commit limit */
2223
2224 /* Has the allocation fragment been setup? */
2226 {
2227 /* Use the default value */
2229 if (PageCount < ((256 * _1MB) / PAGE_SIZE))
2230 {
2231 /* On memory systems with less than 256MB, divide by 4 */
2233 }
2234 else if (PageCount < (_1GB / PAGE_SIZE))
2235 {
2236 /* On systems with less than 1GB, divide by 2 */
2238 }
2239 }
2240 else
2241 {
2242 /* Convert from 1KB fragments to pages */
2245
2246 /* Don't let it past the maximum */
2249
2250 /* Don't let it too small either */
2253 }
2254
2255 /* Check for kernel stack size that's too big */
2257 {
2258 /* Sanitize to default value */
2260 }
2261 else
2262 {
2263 /* Take the registry setting, and convert it into bytes */
2265
2266 /* Now align it to a page boundary */
2268
2269 /* Sanity checks */
2271 ASSERT((MmLargeStackSize & (PAGE_SIZE - 1)) == 0);
2272
2273 /* Make sure it's not too low */
2275 }
2276
2277 /* Compute color information (L2 cache-separated paging lists) */
2279
2280 // Calculate the number of bytes for the PFN database
2281 // then add the color tables and convert to pages
2285
2286 // We have to add one to the count here, because in the process of
2287 // shifting down to the page size, we actually ended up getting the
2288 // lower aligned size (so say, 0x5FFFF bytes is now 0x5F pages).
2289 // Later on, we'll shift this number back into bytes, which would cause
2290 // us to end up with only 0x5F000 bytes -- when we actually want to have
2291 // 0x60000 bytes.
2293
2294 /* Initialize the platform-specific parts */
2295 MiInitMachineDependent(LoaderBlock);
2296
2297#if DBG
2298 /* Prototype PTEs are assumed to be in paged pool, so check if the math works */
2299 PointerPte = (PMMPTE)MmPagedPoolStart;
2300 MI_MAKE_PROTOTYPE_PTE(&TempPte, PointerPte);
2301 TestPte = MiProtoPteToPte(&TempPte);
2302 ASSERT(PointerPte == TestPte);
2303
2304 /* Try the last nonpaged pool address */
2305 PointerPte = (PMMPTE)MI_NONPAGED_POOL_END;
2306 MI_MAKE_PROTOTYPE_PTE(&TempPte, PointerPte);
2307 TestPte = MiProtoPteToPte(&TempPte);
2308 ASSERT(PointerPte == TestPte);
2309
2310 /* Try a bunch of random addresses near the end of the address space */
2311 PointerPte = (PMMPTE)((ULONG_PTR)MI_HIGHEST_SYSTEM_ADDRESS - 0x37FFF);
2312 for (j = 0; j < 20; j += 1)
2313 {
2314 MI_MAKE_PROTOTYPE_PTE(&TempPte, PointerPte);
2315 TestPte = MiProtoPteToPte(&TempPte);
2316 ASSERT(PointerPte == TestPte);
2317 PointerPte++;
2318 }
2319
2320 /* Subsection PTEs are always in nonpaged pool, pick a random address to try */
2322 MI_MAKE_SUBSECTION_PTE(&TempPte, PointerPte);
2324 ASSERT(PointerPte == TestPte);
2325#endif
2326
2327 //
2328 // Build the physical memory block
2329 //
2331 IncludeType);
2332
2333 //
2334 // Allocate enough buffer for the PFN bitmap
2335 // Align it up to a 32-bit boundary
2336 //
2338 (((MmHighestPhysicalPage + 1) + 31) / 32) * 4,
2339 TAG_MM);
2340 if (!Bitmap)
2341 {
2342 //
2343 // This is critical
2344 //
2345 KeBugCheckEx(INSTALL_MORE_MEMORY,
2349 0x101);
2350 }
2351
2352 //
2353 // Initialize it and clear all the bits to begin with
2354 //
2356 Bitmap,
2359
2360 //
2361 // Loop physical memory runs
2362 //
2363 for (i = 0; i < MmPhysicalMemoryBlock->NumberOfRuns; i++)
2364 {
2365 //
2366 // Get the run
2367 //
2369 DPRINT("PHYSICAL RAM [0x%08p to 0x%08p]\n",
2370 Run->BasePage << PAGE_SHIFT,
2371 (Run->BasePage + Run->PageCount) << PAGE_SHIFT);
2372
2373 //
2374 // Make sure it has pages inside it
2375 //
2376 if (Run->PageCount)
2377 {
2378 //
2379 // Set the bits in the PFN bitmap
2380 //
2381 RtlSetBits(&MiPfnBitMap, (ULONG)Run->BasePage, (ULONG)Run->PageCount);
2382 }
2383 }
2384
2385 /* Look for large page cache entries that need caching */
2387
2388 /* Loop for HAL Heap I/O device mappings that need coherency tracking */
2390
2391 /* Set the initial resident page count */
2393
2394 /* Initialize large page structures on PAE/x64, and MmProcessList on x86 */
2396
2397 /* Check if the registry says any drivers should be loaded with large pages */
2399
2400 /* Relocate the boot drivers into system PTE space and fixup their PFNs */
2401 MiReloadBootLoadedDrivers(LoaderBlock);
2402
2403 /* FIXME: Call out into Driver Verifier for initialization */
2404
2405 /* Check how many pages the system has */
2406 if (MmNumberOfPhysicalPages <= ((13 * _1MB) / PAGE_SIZE))
2407 {
2408 /* Set small system */
2411 }
2412 else if (MmNumberOfPhysicalPages <= ((19 * _1MB) / PAGE_SIZE))
2413 {
2414 /* Set small system and add 100 pages for the cache */
2418 }
2419 else
2420 {
2421 /* Set medium system and add 400 pages for the cache */
2425 }
2426
2427 /* Check for less than 24MB */
2428 if (MmNumberOfPhysicalPages < ((24 * _1MB) / PAGE_SIZE))
2429 {
2430 /* No more than 32 pages */
2432 }
2433
2434 /* Check for more than 32MB */
2435 if (MmNumberOfPhysicalPages >= ((32 * _1MB) / PAGE_SIZE))
2436 {
2437 /* Check for product type being "Wi" for WinNT */
2438 if (MmProductType == '\0i\0W')
2439 {
2440 /* Then this is a large system */
2442 }
2443 else
2444 {
2445 /* For servers, we need 64MB to consider this as being large */
2446 if (MmNumberOfPhysicalPages >= ((64 * _1MB) / PAGE_SIZE))
2447 {
2448 /* Set it as large */
2450 }
2451 }
2452 }
2453
2454 /* Check for more than 33 MB */
2455 if (MmNumberOfPhysicalPages > ((33 * _1MB) / PAGE_SIZE))
2456 {
2457 /* Add another 500 pages to the cache */
2459 }
2460
2461 /* Now setup the shared user data fields */
2462 ASSERT(SharedUserData->NumberOfPhysicalPages == 0);
2463 SharedUserData->NumberOfPhysicalPages = MmNumberOfPhysicalPages;
2464 SharedUserData->LargePageMinimum = 0;
2465
2466 /* Check for workstation (Wi for WinNT) */
2467 if (MmProductType == '\0i\0W')
2468 {
2469 /* Set Windows NT Workstation product type */
2470 SharedUserData->NtProductType = NtProductWinNt;
2471 MmProductType = 0;
2472
2473 /* For this product, we wait till the last moment to throttle */
2474 MmThrottleTop = 250;
2475 MmThrottleBottom = 30;
2476 }
2477 else
2478 {
2479 /* Check for LanMan server (La for LanmanNT) */
2480 if (MmProductType == '\0a\0L')
2481 {
2482 /* This is a domain controller */
2483 SharedUserData->NtProductType = NtProductLanManNt;
2484 }
2485 else
2486 {
2487 /* Otherwise it must be a normal server (Se for ServerNT) */
2488 SharedUserData->NtProductType = NtProductServer;
2489 }
2490
2491 /* Set the product type, and make the system more aggressive with low memory */
2492 MmProductType = 1;
2493 MmMinimumFreePages = 81;
2494
2495 /* We will throttle earlier to preserve memory */
2496 MmThrottleTop = 450;
2497 MmThrottleBottom = 80;
2498 }
2499
2500 /* Update working set tuning parameters */
2502
2503 /* Finetune the page count by removing working set and NP expansion */
2507 if (MmResidentAvailablePages <= 0)
2508 {
2509 /* This should not happen */
2510 DPRINT1("System cache working set too big\n");
2511 return FALSE;
2512 }
2513
2514 /* Define limits for system cache */
2515#ifdef _M_AMD64
2517#else
2519#endif
2521#ifdef _M_AMD64
2523#else
2525#endif
2526
2527 /* Initialize the system cache */
2528 //MiInitializeSystemCache(MmSystemCacheWsMinimum, MmAvailablePages);
2529
2530 /* Update the commit limit */
2532 if (MmTotalCommitLimit > 1024) MmTotalCommitLimit -= 1024;
2534
2535 /* Size up paged pool and build the shadow system page directory */
2537
2538 /* Debugger physical memory support is now ready to be used */
2540
2541 /* Initialize the loaded module list */
2542 MiInitializeLoadedModuleList(LoaderBlock);
2543 }
2544
2545 //
2546 // Always return success for now
2547 //
2548 return TRUE;
2549}
SIZE_T MmHeapSegmentReserve
Definition: mminit.c:366
PMMPTE MiHighestUserPte
Definition: mminit.c:233
PFN_NUMBER MmSystemCacheWsMinimum
Definition: mminit.c:336
SIZE_T MmHeapDeCommitFreeBlockThreshold
Definition: mminit.c:369
SIZE_T MmTotalCommitLimitMaximum
Definition: mminit.c:360
PVOID MmPagedPoolStart
Definition: mminit.c:104
SIZE_T MmTotalCommitLimit
Definition: mminit.c:359
MM_SYSTEMSIZE MmSystemSize
Definition: mminit.c:326
SIZE_T MmBootImageSize
Definition: mminit.c:222
PVOID MmSystemRangeStart
Definition: mminit.c:230
PMMPDE MiHighestUserPde
Definition: mminit.c:234
SIZE_T MmHeapDeCommitTotalFreeThreshold
Definition: mminit.c:368
PFN_COUNT MmNumberOfPhysicalPages
Definition: mminit.c:212
ULONG MmThrottleTop
Definition: mminit.c:396
PFN_NUMBER MmMinimumFreePages
Definition: mminit.c:314
SIZE_T MmSizeOfNonPagedPoolInBytes
Definition: mminit.c:26
KEVENT MiTempEvent
Definition: mminit.c:289
ULONG MmSecondaryColors
Definition: mminit.c:256
VOID NTAPI MiAdjustWorkingSetManagerParameters(IN BOOLEAN Client)
Definition: mminit.c:1194
VOID NTAPI MiBuildPagedPool(VOID)
Definition: mminit.c:1742
VOID NTAPI MiScanMemoryDescriptors(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: mminit.c:403
VOID NTAPI MiAddHalIoMappings(VOID)
Definition: mminit.c:1409
VOID NTAPI MiDbgDumpMemoryDescriptors(VOID)
Definition: mminit.c:1985
PFN_NUMBER MmLowestPhysicalPage
Definition: mminit.c:211
PKEVENT MiLowNonPagedPoolEvent
Definition: mminit.c:296
PKEVENT MiHighMemoryEvent
Definition: mminit.c:293
PKEVENT MiLowMemoryEvent
Definition: mminit.c:292
ULONG MmProductType
Definition: mminit.c:325
PPHYSICAL_MEMORY_DESCRIPTOR NTAPI MmInitializeMemoryLimits(IN PLOADER_PARAMETER_BLOCK LoaderBlock, IN PBOOLEAN IncludeType)
Definition: mminit.c:1613
PFN_NUMBER MmHighestPhysicalPage
Definition: mminit.c:211
ULONG_PTR MmSizeOfSystemCacheInPages
Definition: mminit.c:245
ULONG_PTR MmUserProbeAddress
Definition: mminit.c:228
RTL_BITMAP MiPfnBitMap
Definition: mminit.c:201
MMSUPPORT MmSystemCacheWs
Definition: mminit.c:246
ULONG MmLargeStackSize
Definition: mminit.c:262
VOID NTAPI MiComputeColorInformation(VOID)
Definition: mminit.c:499
PKEVENT MiHighPagedPoolEvent
Definition: mminit.c:295
PFN_NUMBER MxPfnAllocation
Definition: mminit.c:187
ULONG MmThrottleBottom
Definition: mminit.c:397
PVOID MmNonPagedPoolStart
Definition: mminit.c:97
BOOLEAN MiDbgEnableMdDump
Definition: mminit.c:373
SIZE_T MmHeapSegmentCommit
Definition: mminit.c:367
SIZE_T MmAllocationFragment
Definition: mminit.c:352
PKEVENT MiLowPagedPoolEvent
Definition: mminit.c:294
LARGE_INTEGER MmCriticalSectionTimeout
Definition: mminit.c:388
PFN_COUNT MmNumberOfSystemPtes
Definition: mminit.c:181
PPHYSICAL_MEMORY_DESCRIPTOR MmPhysicalMemoryBlock
Definition: mminit.c:206
PVOID MmSystemCacheStart
Definition: mminit.c:243
PVOID MmSystemCacheEnd
Definition: mminit.c:244
PKEVENT MiHighNonPagedPoolEvent
Definition: mminit.c:297
PVOID MmHighestUserAddress
Definition: mminit.c:229
ULONG MmCritsectTimeoutSeconds
Definition: mminit.c:387
unsigned char BOOLEAN
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
@ NtProductWinNt
Definition: shellpath.c:64
@ NtProductLanManNt
Definition: shellpath.c:65
@ NtProductServer
Definition: shellpath.c:66
#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
PLOADER_PARAMETER_BLOCK KeLoaderBlock
Definition: krnlinit.c:29
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 MiAddressToPte(x)
Definition: mmx86.c:19
#define MiAddressToPde(x)
Definition: mmx86.c:20
#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 MI_ALLOCATION_FRAGMENT
Definition: mm.h:71
#define MI_PAGED_POOL_START
Definition: mm.h:21
#define MI_USER_PROBE_ADDRESS
Definition: mm.h:10
#define MI_DEFAULT_SYSTEM_RANGE_START
Definition: mm.h:11
#define MiSubsectionPteToSubsection(x)
Definition: mm.h:323
FORCEINLINE VOID MI_MAKE_PROTOTYPE_PTE(IN PMMPTE NewPte, IN PMMPTE PointerPte)
Definition: mm.h:342
#define MI_MIN_PAGES_FOR_SYSPTE_BOOST
Definition: mm.h:56
#define MM_EMPTY_LIST
Definition: mm.h:88
#define MI_MIN_PAGES_FOR_SYSPTE_TUNING
Definition: mm.h:55
FORCEINLINE PMMPTE MiAddressToPpe(PVOID Address)
Definition: mm.h:161
#define MiProtoPteToPte(x)
Definition: mm.h:316
FORCEINLINE PMMPTE MiAddressToPxe(PVOID Address)
Definition: mm.h:171
#define MI_HIGHEST_SYSTEM_ADDRESS
Definition: mm.h:31
#define MI_NONPAGED_POOL_END
Definition: mm.h:29
#define MI_MIN_ALLOCATION_FRAGMENT
Definition: mm.h:70
#define MI_SYSTEM_CACHE_END
Definition: mm.h:27
#define MI_MIN_PAGES_FOR_SYSPTE_BOOST_BOOST
Definition: mm.h:57
FORCEINLINE VOID MI_MAKE_SUBSECTION_PTE(_Out_ PMMPTE NewPte, _In_ PVOID Segment)
Definition: mm.h:328
#define PDE_MAPPED_VA
Definition: mm.h:39
#define MI_SYSTEM_CACHE_START
Definition: mm.h:26
#define MI_MAX_ALLOCATION_FRAGMENT
Definition: mm.h:72
PFN_NUMBER MmResidentAvailablePages
Definition: freelist.c:27
BOOLEAN NTAPI MiInitializeLoadedModuleList(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: sysldr.c:2242
PMMPTE MmDebugPte
Definition: mmdbg.c:31
LIST_ENTRY MmLoadedUserImageList
Definition: sysldr.c:22
VOID NTAPI MiReloadBootLoadedDrivers(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: sysldr.c:1731
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
@ LoaderFirmwarePermanent
Definition: arc.h:180
@ LoaderSpecialMemory
Definition: arc.h:196
@ LoaderMaximum
Definition: arc.h:203
@ LoaderBBTMemory
Definition: arc.h:197
#define KERNEL_LARGE_STACK_SIZE
#define KERNEL_STACK_SIZE
ULONG PFN_NUMBER
Definition: ke.h:9
#define DPRINT
Definition: sndvol32.h:73
PLOADER_PARAMETER_EXTENSION Extension
Definition: arc.h:559
ULONG_PTR LoaderPagesSpanned
Definition: arc.h:403
PFN_NUMBER Total
Definition: mm.h:443
MMLISTS ListName
Definition: mm.h:444
PFN_NUMBER Blink
Definition: mm.h:446
PFN_NUMBER Flink
Definition: mm.h:445
Definition: mm.h:374
EX_PUSH_LOCK WorkingSetMutex
Definition: mmtypes.h:961
PHYSICAL_MEMORY_RUN Run[1]
Definition: miarm.h:440
Definition: bidi.c:434
#define max(a, b)
Definition: svc.c:63
#define TAG_MM
Definition: tag.h:112
void * PVOID
Definition: typedefs.h:50
struct tagRun Run
#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:3368

Referenced by ExpInitializeExecutive(), and Phase1InitializationDiscard().

◆ MmFreeLoaderBlock()

VOID NTAPI MmFreeLoaderBlock ( IN PLOADER_PARAMETER_BLOCK  LoaderBlock)

Definition at line 1084 of file mminit.c.

1085{
1086 PLIST_ENTRY NextMd;
1088 ULONG_PTR i;
1089 PFN_NUMBER BasePage, LoaderPages;
1090 PMMPFN Pfn1;
1091 KIRQL OldIrql;
1093
1094 /* Loop the descriptors in order to count them */
1095 i = 0;
1096 NextMd = LoaderBlock->MemoryDescriptorListHead.Flink;
1097 while (NextMd != &LoaderBlock->MemoryDescriptorListHead)
1098 {
1099 MdBlock = CONTAINING_RECORD(NextMd,
1101 ListEntry);
1102 i++;
1103 NextMd = MdBlock->ListEntry.Flink;
1104 }
1105
1106 /* Allocate a structure to hold the physical runs */
1108 i * sizeof(PHYSICAL_MEMORY_RUN),
1109 'lMmM');
1110 ASSERT(Buffer != NULL);
1111 Entry = Buffer;
1112
1113 /* Loop the descriptors again */
1114 NextMd = LoaderBlock->MemoryDescriptorListHead.Flink;
1115 while (NextMd != &LoaderBlock->MemoryDescriptorListHead)
1116 {
1117 /* Check what kind this was */
1118 MdBlock = CONTAINING_RECORD(NextMd,
1120 ListEntry);
1121 switch (MdBlock->MemoryType)
1122 {
1123 /* Registry, NLS, and heap data */
1124 case LoaderRegistryData:
1125 case LoaderOsloaderHeap:
1126 case LoaderNlsData:
1127 /* Are all a candidate for deletion */
1128 Entry->BasePage = MdBlock->BasePage;
1129 Entry->PageCount = MdBlock->PageCount;
1130 Entry++;
1131
1132 /* We keep the rest */
1133 default:
1134 break;
1135 }
1136
1137 /* Move to the next descriptor */
1138 NextMd = MdBlock->ListEntry.Flink;
1139 }
1140
1141 /* Acquire the PFN lock */
1142 OldIrql = MiAcquirePfnLock();
1143
1144 /* Loop the runs */
1145 LoaderPages = 0;
1146 while (--Entry >= Buffer)
1147 {
1148 /* See how many pages are in this run */
1149 i = Entry->PageCount;
1150 BasePage = Entry->BasePage;
1151
1152 /* Loop each page */
1153 Pfn1 = MiGetPfnEntry(BasePage);
1154 while (i--)
1155 {
1156 /* Check if it has references or is in any kind of list */
1157 if (!(Pfn1->u3.e2.ReferenceCount) && (!Pfn1->u1.Flink))
1158 {
1159 /* Set the new PTE address and put this page into the free list */
1160 Pfn1->PteAddress = (PMMPTE)(BasePage << PAGE_SHIFT);
1161 MiInsertPageInFreeList(BasePage);
1162 LoaderPages++;
1163 }
1164 else if (BasePage)
1165 {
1166 /* It has a reference, so simply drop it */
1168
1169 /* Drop a dereference on this page, which should delete it */
1170 Pfn1->PteAddress->u.Long = 0;
1171 MI_SET_PFN_DELETED(Pfn1);
1172 MiDecrementShareCount(Pfn1, BasePage);
1173 LoaderPages++;
1174 }
1175
1176 /* Move to the next page */
1177 Pfn1++;
1178 BasePage++;
1179 }
1180 }
1181
1182 /* Release the PFN lock and flush the TLB */
1183 DPRINT("Loader pages freed: %lx\n", LoaderPages);
1184 MiReleasePfnLock(OldIrql);
1186
1187 /* Free our run structure */
1188 ExFreePoolWithTag(Buffer, 'lMmM');
1189}
UCHAR KIRQL
Definition: env_spec_w32.h:591
FORCEINLINE BOOLEAN MI_IS_PHYSICAL_ADDRESS(IN PVOID Address)
Definition: miarm.h:959
#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:116
VOID NTAPI KeFlushCurrentTb(VOID)
Definition: cpu.c:526
FORCEINLINE PMMPFN MiGetPfnEntry(IN PFN_NUMBER Pfn)
Definition: mm.h:1047
@ LoaderOsloaderHeap
Definition: arc.h:181
@ LoaderRegistryData
Definition: arc.h:193
base of all file and directory entries
Definition: entries.h:83
PMMPTE PteAddress
Definition: mm.h:386
PFN_NUMBER Flink
Definition: mm.h:377
union _MMPFN::@1806 u1
struct _MMPFN::@1808::@1814 e2
union _MMPFN::@1808 u3
union _MMPTE::@2342 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 2022 of file init.c.

2023{
2024 /* Do the .INIT part of Phase 1 which we can free later */
2026
2027 /* Jump into zero page thread */
2029}
VOID NTAPI Phase1InitializationDiscard(IN PVOID Context)
Definition: init.c:1341
VOID NTAPI MmZeroPageThread(VOID)
Definition: zeropage.c:36

Referenced by PspInitPhase0().

◆ Phase1InitializationDiscard()

VOID NTAPI Phase1InitializationDiscard ( IN PVOID  Context)

Definition at line 1341 of file init.c.

1342{
1343 PLOADER_PARAMETER_BLOCK LoaderBlock = Context;
1344 NTSTATUS Status, MsgStatus;
1346 LARGE_INTEGER SystemBootTime, UniversalBootTime, OldTime, Timeout;
1347 BOOLEAN NoGuiBoot, ResetBias = FALSE, AlternateShell = FALSE;
1348 PLDR_DATA_TABLE_ENTRY NtosEntry;
1349 PMESSAGE_RESOURCE_ENTRY MsgEntry;
1350 PCHAR CommandLine, Y2KHackRequired, SafeBoot, Environment;
1351 PCHAR StringBuffer, EndBuffer, BeginBuffer, MpString = "";
1352 PINIT_BUFFER InitBuffer;
1353 ANSI_STRING TempString;
1354 ULONG LastTzBias, Length, YearHack = 0, Disposition, MessageCode = 0;
1355 SIZE_T Size;
1356 size_t Remaining;
1358 KEY_VALUE_PARTIAL_INFORMATION KeyPartialInfo;
1361 HANDLE KeyHandle, OptionHandle;
1362 PRTL_USER_PROCESS_PARAMETERS ProcessParameters = NULL;
1363
1364 /* Allocate the initialization buffer */
1366 sizeof(INIT_BUFFER),
1367 TAG_INIT);
1368 if (!InitBuffer)
1369 {
1370 /* Bugcheck */
1371 KeBugCheckEx(PHASE1_INITIALIZATION_FAILED, STATUS_NO_MEMORY, 8, 0, 0);
1372 }
1373
1374 /* Set to phase 1 */
1376
1377 /* Set us at maximum priority */
1379
1380 /* Do Phase 1 HAL Initialization */
1381 if (!HalInitSystem(1, LoaderBlock)) KeBugCheck(HAL1_INITIALIZATION_FAILED);
1382
1383 /* Get the command line and upcase it */
1384 CommandLine = (LoaderBlock->LoadOptions ? _strupr(LoaderBlock->LoadOptions) : NULL);
1385
1386 /* Check if GUI Boot is enabled */
1387 NoGuiBoot = (CommandLine && strstr(CommandLine, "NOGUIBOOT") != NULL);
1388
1389 /* Get the SOS setting */
1390 SosEnabled = (CommandLine && strstr(CommandLine, "SOS") != NULL);
1391
1392 /* Setup the boot video driver */
1393 InbvEnableBootDriver(!NoGuiBoot);
1395
1396 /* Check if GUI boot is enabled */
1397 if (!NoGuiBoot)
1398 {
1399 /* It is, display the boot logo and enable printing strings */
1402 }
1403 else
1404 {
1405 /* Release display ownership if not using GUI boot */
1407
1408 /* Don't allow boot-time strings */
1410 }
1411
1412 /* Check if this is LiveCD (WinPE) mode */
1413 if (CommandLine && strstr(CommandLine, "MININT") != NULL)
1414 {
1415 /* Setup WinPE Settings */
1417 InitWinPEModeType |= (strstr(CommandLine, "INRAM") != NULL) ? 0x80000000 : 0x00000001;
1418 }
1419
1420 /* Get the kernel's load entry */
1421 NtosEntry = CONTAINING_RECORD(LoaderBlock->LoadOrderListHead.Flink,
1423 InLoadOrderLinks);
1424
1425 /* Find the banner message */
1426 MsgStatus = RtlFindMessage(NtosEntry->DllBase,
1427 11,
1428 0,
1429 WINDOWS_NT_BANNER,
1430 &MsgEntry);
1431
1432 /* Setup defaults and check if we have a version string */
1433 StringBuffer = InitBuffer->VersionBuffer;
1434 BeginBuffer = StringBuffer;
1435 EndBuffer = StringBuffer;
1436 Remaining = sizeof(InitBuffer->VersionBuffer);
1438 {
1439 /* Print the version string */
1441 Remaining,
1442 &EndBuffer,
1443 &Remaining,
1444 0,
1445 ": %wZ",
1447 if (!NT_SUCCESS(Status))
1448 {
1449 /* Bugcheck */
1450 KeBugCheckEx(PHASE1_INITIALIZATION_FAILED, Status, 7, 0, 0);
1451 }
1452 }
1453 else
1454 {
1455 /* No version */
1456 *EndBuffer = ANSI_NULL; /* Null-terminate the string */
1457 }
1458
1459 /* Skip over the null-terminator to start a new string */
1460 ++EndBuffer;
1461 --Remaining;
1462
1463 /* Build the version number */
1464 StringBuffer = InitBuffer->VersionNumber;
1466 sizeof(InitBuffer->VersionNumber),
1467 "%u.%u",
1470 if (!NT_SUCCESS(Status))
1471 {
1472 /* Bugcheck */
1473 KeBugCheckEx(PHASE1_INITIALIZATION_FAILED, Status, 7, 0, 0);
1474 }
1475
1476 /* Check if we had found a banner message */
1477 if (NT_SUCCESS(MsgStatus))
1478 {
1479 /* Create the banner message */
1480 /* ReactOS specific: Report ReactOS version, NtBuildLab information and reported NT kernel version */
1481 Status = RtlStringCbPrintfA(EndBuffer,
1482 Remaining,
1483 (PCHAR)MsgEntry->Text,
1484 KERNEL_VERSION_STR,
1485 NtBuildLab,
1487 NtBuildNumber & 0xFFFF,
1488 BeginBuffer);
1489 if (!NT_SUCCESS(Status))
1490 {
1491 /* Bugcheck */
1492 KeBugCheckEx(PHASE1_INITIALIZATION_FAILED, Status, 7, 0, 0);
1493 }
1494 }
1495 else
1496 {
1497 /* Use hard-coded banner message */
1498 Status = RtlStringCbCopyA(EndBuffer, Remaining, "REACTOS (R)\r\n");
1499 if (!NT_SUCCESS(Status))
1500 {
1501 /* Bugcheck */
1502 KeBugCheckEx(PHASE1_INITIALIZATION_FAILED, Status, 7, 0, 0);
1503 }
1504 }
1505
1506 /* Display the version string on-screen */
1507 InbvDisplayString(EndBuffer);
1508
1509 /* Initialize Power Subsystem in Phase 0 */
1510 if (!PoInitSystem(0)) KeBugCheck(INTERNAL_POWER_ERROR);
1511
1512 /* Check for Y2K hack */
1513 Y2KHackRequired = CommandLine ? strstr(CommandLine, "YEAR") : NULL;
1514 if (Y2KHackRequired) Y2KHackRequired = strstr(Y2KHackRequired, "=");
1515 if (Y2KHackRequired) YearHack = atol(Y2KHackRequired + 1);
1516
1517 /* Query the clock */
1519 {
1520 /* Check if we're using the Y2K hack */
1521 if (Y2KHackRequired) TimeFields.Year = (CSHORT)YearHack;
1522
1523 /* Convert to time fields */
1524 RtlTimeFieldsToTime(&TimeFields, &SystemBootTime);
1525 UniversalBootTime = SystemBootTime;
1526
1527 /* Check if real time is GMT */
1529 {
1530 /* Check if we don't have a valid bias */
1532 {
1533 /* Reset */
1534 ResetBias = TRUE;
1536 }
1537
1538 /* Calculate the bias in seconds */
1540 10000000);
1541
1542 /* Set the boot time-zone bias */
1543 SharedUserData->TimeZoneBias.High2Time = ExpTimeZoneBias.HighPart;
1544 SharedUserData->TimeZoneBias.LowPart = ExpTimeZoneBias.LowPart;
1545 SharedUserData->TimeZoneBias.High1Time = ExpTimeZoneBias.HighPart;
1546
1547 /* Convert the boot time to local time, and set it */
1548 UniversalBootTime.QuadPart = SystemBootTime.QuadPart +
1550 }
1551
1552 /* Update the system time and notify the system */
1553 KeSetSystemTime(&UniversalBootTime, &OldTime, FALSE, NULL);
1555
1556 /* Remember this as the boot time */
1557 KeBootTime = UniversalBootTime;
1558 KeBootTimeBias = 0;
1559 }
1560
1561#ifdef CONFIG_SMP
1562 /* Start Application Processors */
1564#endif
1565
1566 /* Initialize all processors */
1567 if (!HalAllProcessorsStarted()) KeBugCheck(HAL1_INITIALIZATION_FAILED);
1568
1569#ifdef CONFIG_SMP
1570 /* HACK: We should use RtlFindMessage and not only fallback to this */
1571 MpString = "MultiProcessor Kernel\r\n";
1572#endif
1573
1574 /* Setup the "MP" String */
1575 RtlInitAnsiString(&TempString, MpString);
1576
1577 /* Make sure to remove the \r\n if we actually have a string */
1578 while ((TempString.Length > 0) &&
1579 ((TempString.Buffer[TempString.Length - 1] == '\r') ||
1580 (TempString.Buffer[TempString.Length - 1] == '\n')))
1581 {
1582 /* Skip the trailing character */
1583 TempString.Length--;
1584 }
1585
1586 /* Get the information string from our resource file */
1587 MsgStatus = RtlFindMessage(NtosEntry->DllBase,
1588 11,
1589 0,
1590 KeNumberProcessors > 1 ?
1591 WINDOWS_NT_INFO_STRING_PLURAL :
1592 WINDOWS_NT_INFO_STRING,
1593 &MsgEntry);
1594
1595 /* Get total RAM size, in MiB */
1596 /* Round size up. Assumed to better match actual physical RAM size */
1597 Size = ALIGN_UP_BY(MmNumberOfPhysicalPages * PAGE_SIZE, 1024 * 1024) / (1024 * 1024);
1598
1599 /* Create the string */
1600 StringBuffer = InitBuffer->VersionBuffer;
1602 sizeof(InitBuffer->VersionBuffer),
1603 NT_SUCCESS(MsgStatus) ?
1604 (PCHAR)MsgEntry->Text :
1605 "%u System Processor [%Iu MB Memory] %Z\r\n",
1607 Size,
1608 &TempString);
1609 if (!NT_SUCCESS(Status))
1610 {
1611 /* Bugcheck */
1612 KeBugCheckEx(PHASE1_INITIALIZATION_FAILED, Status, 4, 0, 0);
1613 }
1614
1615 /* Display RAM and CPU count */
1617
1618 /* Update the progress bar */
1620
1621 /* Call OB initialization again */
1622 if (!ObInitSystem()) KeBugCheck(OBJECT1_INITIALIZATION_FAILED);
1623
1624 /* Initialize Basic System Objects and Worker Threads */
1625 if (!ExInitSystem()) KeBugCheckEx(PHASE1_INITIALIZATION_FAILED, 0, 0, 1, 0);
1626
1627 /* Initialize the later stages of the kernel */
1628 if (!KeInitSystem()) KeBugCheckEx(PHASE1_INITIALIZATION_FAILED, 0, 0, 2, 0);
1629
1630 /* Call KD Providers at Phase 1 */
1632 {
1633 /* Failed, bugcheck */
1634 KeBugCheckEx(PHASE1_INITIALIZATION_FAILED, 0, 0, 3, 0);
1635 }
1636
1637 /* Initialize the SRM in Phase 1 */
1638 if (!SeInitSystem()) KeBugCheck(SECURITY1_INITIALIZATION_FAILED);
1639
1640 /* Update the progress bar */
1642
1643 /* Create SystemRoot Link */
1644 Status = ExpCreateSystemRootLink(LoaderBlock);
1645 if (!NT_SUCCESS(Status))
1646 {
1647 /* Failed to create the system root link */
1648 KeBugCheckEx(SYMBOLIC_INITIALIZATION_FAILED, Status, 0, 0, 0);
1649 }
1650
1651 /* Set up Region Maps, Sections and the Paging File */
1652 if (!MmInitSystem(1, LoaderBlock)) KeBugCheck(MEMORY1_INITIALIZATION_FAILED);
1653
1654 /* Create NLS section */
1655 ExpInitNls(LoaderBlock);
1656
1657 /* Initialize Cache Views */
1658 if (!CcInitializeCacheManager()) KeBugCheck(CACHE_INITIALIZATION_FAILED);
1659
1660 /* Initialize the Registry */
1661 if (!CmInitSystem1()) KeBugCheck(CONFIG_INITIALIZATION_FAILED);
1662
1663 /* Initialize Prefetcher */
1665
1666 /* Update progress bar */
1668
1669 /* Update timezone information */
1670 LastTzBias = ExpLastTimeZoneBias;
1671 ExRefreshTimeZoneInformation(&SystemBootTime);
1672
1673 /* Check if we're resetting timezone data */
1674 if (ResetBias)
1675 {
1676 /* Convert the local time to system time */
1677 ExLocalTimeToSystemTime(&SystemBootTime, &UniversalBootTime);
1678 KeBootTime = UniversalBootTime;
1679 KeBootTimeBias = 0;
1680
1681 /* Set the new time */
1682 KeSetSystemTime(&UniversalBootTime, &OldTime, FALSE, NULL);
1683 }
1684 else
1685 {
1686 /* Check if the timezone switched and update the time */
1687 if (LastTzBias != ExpLastTimeZoneBias)
1689 }
1690
1691 /* Initialize the File System Runtime Library */
1692 if (!FsRtlInitSystem()) KeBugCheck(FILE_INITIALIZATION_FAILED);
1693
1694 /* Initialize range lists */
1696
1697 /* Report all resources used by HAL */
1699
1700 /* Call the debugger DLL */
1701 KdDebuggerInitialize1(LoaderBlock);
1702
1703 /* Setup PnP Manager in phase 1 */
1704 if (!PpInitSystem()) KeBugCheck(PP1_INITIALIZATION_FAILED);
1705
1706 /* Update progress bar */
1708
1709 /* Initialize LPC */
1710 if (!LpcInitSystem()) KeBugCheck(LPC_INITIALIZATION_FAILED);
1711
1712 /* Make sure we have a command line */
1713 if (CommandLine)
1714 {
1715 /* Check if this is a safe mode boot */
1716 SafeBoot = strstr(CommandLine, "SAFEBOOT:");
1717 if (SafeBoot)
1718 {
1719 /* Check what kind of boot this is */
1720 SafeBoot += 9;
1721 if (!strncmp(SafeBoot, "MINIMAL", 7))
1722 {
1723 /* Minimal mode */
1724 InitSafeBootMode = 1;
1725 SafeBoot += 7;
1726 MessageCode = BOOTING_IN_SAFEMODE_MINIMAL;
1727 }
1728 else if (!strncmp(SafeBoot, "NETWORK", 7))
1729 {
1730 /* With Networking */
1731 InitSafeBootMode = 2;
1732 SafeBoot += 7;
1733 MessageCode = BOOTING_IN_SAFEMODE_NETWORK;
1734 }
1735 else if (!strncmp(SafeBoot, "DSREPAIR", 8))
1736 {
1737 /* Domain Server Repair */
1738 InitSafeBootMode = 3;
1739 SafeBoot += 8;
1740 MessageCode = BOOTING_IN_SAFEMODE_DSREPAIR;
1741
1742 }
1743 else
1744 {
1745 /* Invalid */
1746 InitSafeBootMode = 0;
1747 }
1748
1749 /* Check if there's any settings left */
1750 if (*SafeBoot)
1751 {
1752 /* Check if an alternate shell was requested */
1753 if (!strncmp(SafeBoot, "(ALTERNATESHELL)", 16))
1754 {
1755 /* Remember this for later */
1756 AlternateShell = TRUE;
1757 }
1758 }
1759
1760 /* Find the message to print out */
1761 Status = RtlFindMessage(NtosEntry->DllBase,
1762 11,
1763 0,
1764 MessageCode,
1765 &MsgEntry);
1766 if (NT_SUCCESS(Status))
1767 {
1768 /* Display it */
1769 InbvDisplayString((PCHAR)MsgEntry->Text);
1770 }
1771 }
1772 }
1773
1774 /* Make sure we have a command line */
1775 if (CommandLine)
1776 {
1777 /* Check if bootlogging is enabled */
1778 if (strstr(CommandLine, "BOOTLOG"))
1779 {
1780 /* Find the message to print out */
1781 Status = RtlFindMessage(NtosEntry->DllBase,
1782 11,
1783 0,
1784 BOOTLOG_ENABLED,
1785 &MsgEntry);
1786 if (NT_SUCCESS(Status))
1787 {
1788 /* Display it */
1789 InbvDisplayString((PCHAR)MsgEntry->Text);
1790 }
1791
1792 /* Setup boot logging */
1793 //IopInitializeBootLogging(LoaderBlock, InitBuffer->BootlogHeader);
1794 }
1795 }
1796
1797 /* Setup the Executive in Phase 2 */
1798 //ExInitSystemPhase2();
1799
1800 /* Update progress bar */
1802
1803 /* No KD Time Slip is pending */
1805
1806 /* Initialize in-place execution support */
1807 XIPInit(LoaderBlock);
1808
1809 /* Set maximum update to 75% */
1811
1812 /* Initialize the I/O Subsystem */
1813 if (!IoInitSystem(LoaderBlock)) KeBugCheck(IO1_INITIALIZATION_FAILED);
1814
1815 /* Set maximum update to 100% */
1817
1818 /* Are we in safe mode? */
1819 if (InitSafeBootMode)
1820 {
1821 /* Open the safe boot key */
1823 L"\\REGISTRY\\MACHINE\\SYSTEM\\CURRENTCONTROLSET"
1824 L"\\CONTROL\\SAFEBOOT");
1826 &KeyName,
1828 NULL,
1829 NULL);
1831 if (NT_SUCCESS(Status))
1832 {
1833 /* First check if we have an alternate shell */
1834 if (AlternateShell)
1835 {
1836 /* Make sure that the registry has one setup */
1837 RtlInitUnicodeString(&KeyName, L"AlternateShell");
1839 &KeyName,
1841 &KeyPartialInfo,
1842 sizeof(KeyPartialInfo),
1843 &Length);
1845 {
1846 AlternateShell = FALSE;
1847 }
1848 }
1849
1850 /* Create the option key */
1851 RtlInitUnicodeString(&KeyName, L"Option");
1853 &KeyName,
1855 KeyHandle,
1856 NULL);
1857 Status = ZwCreateKey(&OptionHandle,
1860 0,
1861 NULL,
1863 &Disposition);
1865
1866 /* Check if the key create worked */
1867 if (NT_SUCCESS(Status))
1868 {
1869 /* Write the safe boot type */
1870 RtlInitUnicodeString(&KeyName, L"OptionValue");
1871 NtSetValueKey(OptionHandle,
1872 &KeyName,
1873 0,
1874 REG_DWORD,
1876 sizeof(InitSafeBootMode));
1877
1878 /* Check if we have to use an alternate shell */
1879 if (AlternateShell)
1880 {
1881 /* Remember this for later */
1882 Disposition = TRUE;
1883 RtlInitUnicodeString(&KeyName, L"UseAlternateShell");
1884 NtSetValueKey(OptionHandle,
1885 &KeyName,
1886 0,
1887 REG_DWORD,
1888 &Disposition,
1889 sizeof(Disposition));
1890 }
1891
1892 /* Close the options key handle */
1893 NtClose(OptionHandle);
1894 }
1895 }
1896 }
1897
1898 /* Are we in Win PE mode? */
1899 if (InitIsWinPEMode)
1900 {
1901 /* Open the safe control key */
1903 L"\\REGISTRY\\MACHINE\\SYSTEM\\CURRENTCONTROLSET"
1904 L"\\CONTROL");
1906 &KeyName,
1908 NULL,
1909 NULL);
1911 if (!NT_SUCCESS(Status))
1912 {
1913 /* Bugcheck */
1914 KeBugCheckEx(PHASE1_INITIALIZATION_FAILED, Status, 6, 0, 0);
1915 }
1916
1917 /* Create the MiniNT key */
1918 RtlInitUnicodeString(&KeyName, L"MiniNT");
1920 &KeyName,
1922 KeyHandle,
1923 NULL);
1924 Status = ZwCreateKey(&OptionHandle,
1927 0,
1928 NULL,
1930 &Disposition);
1931 if (!NT_SUCCESS(Status))
1932 {
1933 /* Bugcheck */
1934 KeBugCheckEx(PHASE1_INITIALIZATION_FAILED, Status, 6, 0, 0);
1935 }
1936
1937 /* Close the handles */
1939 NtClose(OptionHandle);
1940 }
1941
1942 /* FIXME: This doesn't do anything for now */
1943 MmArmInitSystem(2, LoaderBlock);
1944
1945 /* Update progress bar */
1947
1948 /* Initialize VDM support */
1949#if defined(_M_IX86)
1951#endif
1952
1953 /* Initialize Power Subsystem in Phase 1*/
1954 if (!PoInitSystem(1)) KeBugCheck(INTERNAL_POWER_ERROR);
1955
1956 /* Update progress bar */
1958
1959 /* Initialize the Process Manager at Phase 1 */
1960 if (!PsInitSystem(LoaderBlock)) KeBugCheck(PROCESS1_INITIALIZATION_FAILED);
1961
1962 /* Make sure nobody touches the loader block again */
1963 if (LoaderBlock == KeLoaderBlock) KeLoaderBlock = NULL;
1964 MmFreeLoaderBlock(LoaderBlock);
1965 LoaderBlock = Context = NULL;
1966
1967 /* Initialize the SRM in phase 1 */
1968 if (!SeRmInitPhase1()) KeBugCheck(PROCESS1_INITIALIZATION_FAILED);
1969
1970 /* Update progress bar */
1972
1973 /* Clear the screen */
1975
1976 /* Allow strings to be displayed */
1978
1979 /* Launch initial process */
1980 ProcessInfo = &InitBuffer->ProcessInfo;
1981 ExpLoadInitialProcess(InitBuffer, &ProcessParameters, &Environment);
1982
1983 /* Wait 5 seconds for initial process to initialize */
1984 Timeout.QuadPart = Int32x32To64(5, -10000000);
1985 Status = ZwWaitForSingleObject(ProcessInfo->ProcessHandle, FALSE, &Timeout);
1986 if (Status == STATUS_SUCCESS)
1987 {
1988 /* Failed, display error */
1989 DPRINT1("INIT: Session Manager terminated.\n");
1990
1991 /* Bugcheck the system if SMSS couldn't initialize */
1992 KeBugCheck(SESSION5_INITIALIZATION_FAILED);
1993 }
1994
1995 /* Close process handles */
1996 ZwClose(ProcessInfo->ThreadHandle);
1997 ZwClose(ProcessInfo->ProcessHandle);
1998
1999 /* Free the initial process environment */
2000 Size = 0;
2001 ZwFreeVirtualMemory(NtCurrentProcess(),
2002 (PVOID*)&Environment,
2003 &Size,
2004 MEM_RELEASE);
2005
2006 /* Free the initial process parameters */
2007 Size = 0;
2008 ZwFreeVirtualMemory(NtCurrentProcess(),
2009 (PVOID*)&ProcessParameters,
2010 &Size,
2011 MEM_RELEASE);
2012
2013 /* Increase init phase */
2015
2016 /* Free the boot buffer */
2017 ExFreePoolWithTag(InitBuffer, TAG_INIT);
2018}
#define ALIGN_UP_BY(size, align)
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
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:1621
#define STATUS_NO_MEMORY
Definition: d3dkmdt.h:51
BOOLEAN RtlTimeFieldsToTime(IN PTIME_FIELDS TimeFields, IN PLARGE_INTEGER Time)
#define ExLocalTimeToSystemTime(LocTime, SysTime)
Definition: env_spec_w32.h:738
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:404
BOOLEAN InbvBootDriverInstalled
Definition: inbv.c:39
VOID NTAPI InbvEnableBootDriver(_In_ BOOLEAN Enable)
Definition: inbv.c:258
VOID NTAPI InbvSetProgressBarSubset(_In_ ULONG Floor, _In_ ULONG Ceiling)
Specifies a progress percentage sub-range. Further calls to InbvIndicateProgress() or InbvUpdateProgr...
Definition: inbv.c:664
BOOLEAN NTAPI InbvEnableDisplayString(_In_ BOOLEAN Enable)
Definition: inbv.c:370
BOOLEAN NTAPI InbvDisplayString(_In_ PCHAR String)
Definition: inbv.c:332
BOOLEAN NTAPI InbvDriverInitialize(_In_ PLOADER_PARAMETER_BLOCK LoaderBlock, _In_ ULONG Count)
Definition: inbv.c:176
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:690
#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:283
CCHAR KeNumberProcessors
Definition: krnlinit.c:35
WCHAR StringBuffer[156]
Definition: ldrinit.c:41
BOOLEAN NTAPI LpcInitSystem(VOID)
Definition: port.c:37
static PTIME_FIELDS TimeFields
Definition: time.c:104
_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)
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:859
@ KeyValuePartialInformation
Definition: nt_native.h:1182
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
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:1316
#define REG_OPTION_VOLATILE
Definition: nt_native.h:1060
#define Int32x32To64(a, b)
BOOLEAN InitWinPEModeType
Definition: init.c:72
BOOLEAN ExCmosClockIsSane
Definition: init.c:93
ULONG NtBuildNumber
Definition: init.c:50
NTSTATUS NTAPI ExpCreateSystemRootLink(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: init.c:101
CHAR NtBuildLab[]
Definition: init.c:64
VOID NTAPI MmFreeLoaderBlock(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: mminit.c:1084
VOID NTAPI ExpLoadInitialProcess(IN PINIT_BUFFER InitBuffer, OUT PRTL_USER_PROCESS_PARAMETERS *ProcessParameters, OUT PCHAR *ProcessEnvironment)
Definition: init.c:389
BOOLEAN ExpRealTimeIsUniversal
Definition: init.c:94
BOOLEAN SosEnabled
Definition: init.c:73
ULONG InitSafeBootMode
Definition: init.c:71
BOOLEAN InitIsWinPEMode
Definition: init.c:72
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:466
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:296
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:206
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:211
#define IDB_MAX_RESOURCES
Definition: resource.h:55
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:596
RTL_USER_PROCESS_INFORMATION ProcessInfo
Definition: init.c:38
CHAR VersionBuffer[256]
Definition: init.c:35
CHAR VersionNumber[24]
Definition: init.c:37
LIST_ENTRY LoadOrderListHead
Definition: arc.h:540
#define TAG_INIT
Definition: tag.h:27
KPRIORITY NTAPI KeSetPriorityThread(IN PKTHREAD Thread, IN KPRIORITY Priority)
Definition: thrdobj.c:1319
short CSHORT
Definition: umtypes.h:127
ULONG LowPart
Definition: typedefs.h:106
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING KeyName
Definition: wdfdevice.h:2699
BOOLEAN SafeBoot
Definition: winldr.c:34
VOID NTAPI XIPInit(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: xipdisp.c:55

Referenced by Phase1Initialization().

Variable Documentation

◆ CmCSDVersionString

UNICODE_STRING CmCSDVersionString

◆ CmNtCSDReleaseType

ULONG CmNtCSDReleaseType

Definition at line 60 of file init.c.

Referenced by ExpInitializeExecutive().

◆ CmNtCSDVersion

ULONG CmNtCSDVersion

Definition at line 59 of file init.c.

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

◆ CmNtSpBuildNumber

ULONG CmNtSpBuildNumber

Definition at line 58 of file init.c.

Referenced by CmpSetVersionData(), and ExpInitializeExecutive().

◆ CmVersionString

UNICODE_STRING CmVersionString

Definition at line 61 of file init.c.

Referenced by CmpSetVersionData(), and ExpInitializeExecutive().

◆ ExCmosClockIsSane

BOOLEAN ExCmosClockIsSane = TRUE

Definition at line 93 of file init.c.

Referenced by KeSetSystemTime(), and Phase1InitializationDiscard().

◆ ExpAnsiCodePageDataOffset

ULONG ExpAnsiCodePageDataOffset

Definition at line 86 of file init.c.

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

◆ ExpInitializationPhase

◆ ExpInTextModeSetup

BOOLEAN ExpInTextModeSetup

Definition at line 69 of file init.c.

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

◆ ExpNlsSectionPointer

PVOID ExpNlsSectionPointer

Definition at line 90 of file init.c.

Referenced by ExpInitNls(), and MmCreatePeb().

◆ ExpNlsTableBase

PVOID ExpNlsTableBase

Definition at line 85 of file init.c.

Referenced by ExpInitializeExecutive(), and ExpInitNls().

◆ ExpNlsTableInfo

NLSTABLEINFO ExpNlsTableInfo

Definition at line 88 of file init.c.

Referenced by ExpInitializeExecutive(), and ExpInitNls().

◆ ExpNlsTableSize

SIZE_T ExpNlsTableSize

Definition at line 89 of file init.c.

Referenced by ExpInitNls().

◆ ExpOemCodePageDataOffset

ULONG ExpOemCodePageDataOffset

Definition at line 86 of file init.c.

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

◆ ExpRealTimeIsUniversal

BOOLEAN ExpRealTimeIsUniversal

Definition at line 94 of file init.c.

Referenced by Phase1InitializationDiscard().

◆ ExpUnicodeCaseTableDataOffset

ULONG ExpUnicodeCaseTableDataOffset

Definition at line 87 of file init.c.

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

◆ ExSuiteMask

ULONG ExSuiteMask

Definition at line 55 of file init.c.

Referenced by ExpInitSystemPhase0().

◆ InitIsWinPEMode

BOOLEAN InitIsWinPEMode

Definition at line 72 of file init.c.

Referenced by CmInitSystem1(), and Phase1InitializationDiscard().

◆ InitSafeBootMode

◆ InitWinPEModeType

BOOLEAN InitWinPEModeType

Definition at line 72 of file init.c.

Referenced by Phase1InitializationDiscard().

◆ IoRemoteBootClient

BOOLEAN IoRemoteBootClient

Definition at line 70 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 64 of file init.c.

Referenced by CmpSetVersionData(), and Phase1InitializationDiscard().

◆ NtBuildNumber

◆ NtGlobalFlag

◆ NtInitialUserProcessBuffer

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

Definition at line 79 of file init.c.

Referenced by ExpLoadInitialProcess().

◆ NtInitialUserProcessBufferLength

ULONG NtInitialUserProcessBufferLength
Initial value:
sizeof(WCHAR)

Definition at line 80 of file init.c.

Referenced by ExpLoadInitialProcess().

◆ NtInitialUserProcessBufferType

ULONG NtInitialUserProcessBufferType = REG_SZ

Definition at line 82 of file init.c.

Referenced by ExpLoadInitialProcess().

◆ NtMajorVersion

ULONG NtMajorVersion = VER_PRODUCTMAJORVERSION

Definition at line 45 of file init.c.

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

◆ NtMinorVersion

ULONG NtMinorVersion = VER_PRODUCTMINORVERSION

Definition at line 46 of file init.c.

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

◆ NtSystemRoot

◆ SosEnabled

BOOLEAN SosEnabled

Definition at line 73 of file init.c.

Referenced by Phase1InitializationDiscard().