ReactOS 0.4.15-dev-5893-g1bb4167
init.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Kernel
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: ntoskrnl/ex/init.c
5 * PURPOSE: Executive Initialization Code
6 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
7 * Eric Kohl
8 */
9
10/* INCLUDES ******************************************************************/
11
12#include <ntoskrnl.h>
13#include <reactos/buildno.h>
14#include "inbv/logo.h"
15
16#define NDEBUG
17#include <debug.h>
18
19/* This is the size that we can expect from the win 2003 loader */
20#define LOADER_PARAMETER_EXTENSION_MIN_SIZE \
21 RTL_SIZEOF_THROUGH_FIELD(LOADER_PARAMETER_EXTENSION, AcpiTableSize)
22
23/* Temporary hack */
24CODE_SEG("INIT")
28 IN ULONG Phase,
29 IN PLOADER_PARAMETER_BLOCK LoaderBlock
30);
31
33{
34 WCHAR DebugBuffer[256];
35 CHAR VersionBuffer[256];
36 CHAR BootlogHeader[256];
37 CHAR VersionNumber[24];
39 WCHAR RegistryBuffer[256];
41
42/* DATA **********************************************************************/
43
44/* NT Version Info */
47#if DBG /* Checked Build */
49#else /* Free Build */
51#endif
52
53/* NT System Info */
56
57/* Cm Version Info */
63
64CHAR NtBuildLab[] = KERNEL_VERSION_BUILD_STR "."
65 REACTOS_COMPILER_NAME "_" REACTOS_COMPILER_VERSION;
66
67/* Init flags and settings */
73
74/* NT Boot Path */
76
77/* NT Initial User Application */
78WCHAR NtInitialUserProcessBuffer[128] = L"\\SystemRoot\\System32\\smss.exe";
80 sizeof(WCHAR);
82
83/* Boot NLS information */
90
91/* CMOS Timer Sanity */
94
95/* FUNCTIONS ****************************************************************/
96
97CODE_SEG("INIT")
101{
102 UNICODE_STRING LinkName;
104 HANDLE LinkHandle;
106 ANSI_STRING AnsiName;
107 CHAR Buffer[256];
110
111 /* Initialize the ArcName tree */
112 RtlInitUnicodeString(&LinkName, L"\\ArcName");
114 &LinkName,
116 NULL,
118
119 /* Create it */
120 Status = NtCreateDirectoryObject(&LinkHandle,
123 if (!NT_SUCCESS(Status))
124 {
125 /* Failed */
126 KeBugCheckEx(SYMBOLIC_INITIALIZATION_FAILED, Status, 1, 0, 0);
127 }
128
129 /* Close the LinkHandle */
130 NtClose(LinkHandle);
131
132 /* Initialize the Device tree */
133 RtlInitUnicodeString(&LinkName, L"\\Device");
135 &LinkName,
137 NULL,
139
140 /* Create it */
141 Status = NtCreateDirectoryObject(&LinkHandle,
144 if (!NT_SUCCESS(Status))
145 {
146 /* Failed */
147 KeBugCheckEx(SYMBOLIC_INITIALIZATION_FAILED, Status, 2, 0, 0);
148 }
149
150 /* Close the LinkHandle */
151 ObCloseHandle(LinkHandle, KernelMode);
152
153 /* Create the system root symlink name */
154 RtlInitAnsiString(&AnsiName, "\\SystemRoot");
155 Status = RtlAnsiStringToUnicodeString(&LinkName, &AnsiName, TRUE);
156 if (!NT_SUCCESS(Status))
157 {
158 /* Failed */
159 KeBugCheckEx(SYMBOLIC_INITIALIZATION_FAILED, Status, 3, 0, 0);
160 }
161
162 /* Initialize the attributes for the link */
164 &LinkName,
166 NULL,
168
169 /* Build the ARC name */
171 "\\ArcName\\%s%s",
172 LoaderBlock->ArcBootDeviceName,
173 LoaderBlock->NtBootPathName);
175
176 /* Convert it to Unicode */
180 TRUE);
181 if (!NT_SUCCESS(Status))
182 {
183 /* We failed, bugcheck */
184 KeBugCheckEx(SYMBOLIC_INITIALIZATION_FAILED, Status, 4, 0, 0);
185 }
186
187 /* Create it */
191 &TargetName);
192
193 /* Free the strings */
194 RtlFreeUnicodeString(&LinkName);
196
197 /* Check if creating the link failed */
198 if (!NT_SUCCESS(Status))
199 {
200 /* Failed */
201 KeBugCheckEx(SYMBOLIC_INITIALIZATION_FAILED, Status, 5, 0, 0);
202 }
203
204 /* Close the handle and return success */
205 ObCloseHandle(LinkHandle, KernelMode);
206 return STATUS_SUCCESS;
207}
208
209CODE_SEG("INIT")
210VOID
211NTAPI
213{
214 LARGE_INTEGER SectionSize;
216 HANDLE NlsSection;
217 PVOID SectionBase = NULL;
218 SIZE_T ViewSize = 0;
219 LARGE_INTEGER SectionOffset = {{0, 0}};
220 PLIST_ENTRY ListHead, NextEntry;
222 ULONG NlsTablesEncountered = 0;
223 SIZE_T NlsTableSizes[3] = {0, 0, 0}; /* 3 NLS tables */
224
225 /* Check if this is boot-time phase 0 initialization */
227 {
228 /* Loop the memory descriptors */
229 ListHead = &LoaderBlock->MemoryDescriptorListHead;
230 NextEntry = ListHead->Flink;
231 while (NextEntry != ListHead)
232 {
233 /* Get the current block */
234 MdBlock = CONTAINING_RECORD(NextEntry,
236 ListEntry);
237
238 /* Check if this is an NLS block */
239 if (MdBlock->MemoryType == LoaderNlsData)
240 {
241 /* Increase the table size */
242 ExpNlsTableSize += MdBlock->PageCount * PAGE_SIZE;
243
244 /* FreeLdr-specific */
245 NlsTableSizes[NlsTablesEncountered] = MdBlock->PageCount * PAGE_SIZE;
246 NlsTablesEncountered++;
247 ASSERT(NlsTablesEncountered < 4);
248 }
249
250 /* Go to the next block */
251 NextEntry = MdBlock->ListEntry.Flink;
252 }
253
254 /* Allocate the a new buffer since loader memory will be freed */
257 TAG_RTLI);
258 if (!ExpNlsTableBase) KeBugCheck(PHASE0_INITIALIZATION_FAILED);
259
260 /* Copy the codepage data in its new location. */
261 if (NlsTablesEncountered == 1)
262 {
263 /* Ntldr-way boot process */
265 LoaderBlock->NlsData->AnsiCodePageData,
267 }
268 else
269 {
270 /*
271 * In NT, the memory blocks are contiguous, but in ReactOS they aren't,
272 * so unless someone fixes FreeLdr, we'll have to use this icky hack.
273 */
275 LoaderBlock->NlsData->AnsiCodePageData,
276 NlsTableSizes[0]);
277
278 RtlCopyMemory((PVOID)((ULONG_PTR)ExpNlsTableBase + NlsTableSizes[0]),
279 LoaderBlock->NlsData->OemCodePageData,
280 NlsTableSizes[1]);
281
282 RtlCopyMemory((PVOID)((ULONG_PTR)ExpNlsTableBase + NlsTableSizes[0] +
283 NlsTableSizes[1]),
284 LoaderBlock->NlsData->UnicodeCodePageData,
285 NlsTableSizes[2]);
286 /* End of Hack */
287 }
288
289 /* Initialize and reset the NLS TAbles */
298 return;
299 }
300
301 /* Set the section size */
302 SectionSize.QuadPart = ExpNlsTableSize;
303
304 /* Create the NLS Section */
305 Status = ZwCreateSection(&NlsSection,
307 NULL,
308 &SectionSize,
310 SEC_COMMIT | 0x1,
311 NULL);
312 if (!NT_SUCCESS(Status))
313 {
314 /* Failed */
315 KeBugCheckEx(PHASE1_INITIALIZATION_FAILED, Status, 1, 0, 0);
316 }
317
318 /* Get a pointer to the section */
324 NULL);
325 ObCloseHandle(NlsSection, KernelMode);
326 if (!NT_SUCCESS(Status))
327 {
328 /* Failed */
329 KeBugCheckEx(PHASE1_INITIALIZATION_FAILED, Status, 2, 0, 0);
330 }
331
332 /* Map the NLS Section in system space */
334 &SectionBase,
336 if (!NT_SUCCESS(Status))
337 {
338 /* Failed */
339 KeBugCheckEx(PHASE1_INITIALIZATION_FAILED, Status, 3, 0, 0);
340 }
341
342 /* Copy the codepage data in its new location. */
343 ASSERT(SectionBase >= MmSystemRangeStart);
345
346 /* Free the previously allocated buffer and set the new location */
348 ExpNlsTableBase = SectionBase;
349
350 /* Initialize the NLS Tables */
359
360 /* Reset the base to 0 */
361 SectionBase = NULL;
362
363 /* Map the section in the system process */
366 &SectionBase,
367 0L,
368 0L,
370 &ViewSize,
371 ViewShare,
372 0L,
374 if (!NT_SUCCESS(Status))
375 {
376 /* Failed */
377 KeBugCheckEx(PHASE1_INITIALIZATION_FAILED, Status, 5, 0, 0);
378 }
379
380 /* Copy the table into the system process and set this as the base */
382 ExpNlsTableBase = SectionBase;
383}
384
385CODE_SEG("INIT")
386VOID
387NTAPI
389 OUT PRTL_USER_PROCESS_PARAMETERS *ProcessParameters,
390 OUT PCHAR *ProcessEnvironment)
391{
393 SIZE_T Size;
394 PWSTR p;
395 UNICODE_STRING NullString = RTL_CONSTANT_STRING(L"");
396 UNICODE_STRING SmssName, Environment, SystemDriveString, DebugString;
397 PVOID EnvironmentPtr = NULL;
398 PRTL_USER_PROCESS_INFORMATION ProcessInformation;
399 PRTL_USER_PROCESS_PARAMETERS ProcessParams = NULL;
400
401 NullString.Length = sizeof(WCHAR);
402
403 /* Use the initial buffer, after the strings */
404 ProcessInformation = &InitBuffer->ProcessInfo;
405
406 /* Allocate memory for the process parameters */
407 Size = sizeof(*ProcessParams) + ((MAX_WIN32_PATH * 6) * sizeof(WCHAR));
408 Status = ZwAllocateVirtualMemory(NtCurrentProcess(),
409 (PVOID*)&ProcessParams,
410 0,
411 &Size,
414 if (!NT_SUCCESS(Status))
415 {
416 /* Failed, display error */
417 _snwprintf(InitBuffer->DebugBuffer,
418 sizeof(InitBuffer->DebugBuffer)/sizeof(WCHAR),
419 L"INIT: Unable to allocate Process Parameters. 0x%lx",
420 Status);
421 RtlInitUnicodeString(&DebugString, InitBuffer->DebugBuffer);
423
424 /* Bugcheck the system */
425 KeBugCheckEx(SESSION1_INITIALIZATION_FAILED, Status, 0, 0, 0);
426 }
427
428 /* Setup the basic header, and give the process the low 1MB to itself */
429 ProcessParams->Length = (ULONG)Size;
430 ProcessParams->MaximumLength = (ULONG)Size;
433
434 /* Allocate a page for the environment */
435 Size = PAGE_SIZE;
436 Status = ZwAllocateVirtualMemory(NtCurrentProcess(),
437 &EnvironmentPtr,
438 0,
439 &Size,
442 if (!NT_SUCCESS(Status))
443 {
444 /* Failed, display error */
445 _snwprintf(InitBuffer->DebugBuffer,
446 sizeof(InitBuffer->DebugBuffer)/sizeof(WCHAR),
447 L"INIT: Unable to allocate Process Environment. 0x%lx",
448 Status);
449 RtlInitUnicodeString(&DebugString, InitBuffer->DebugBuffer);
451
452 /* Bugcheck the system */
453 KeBugCheckEx(SESSION2_INITIALIZATION_FAILED, Status, 0, 0, 0);
454 }
455
456 /* Write the pointer */
457 ProcessParams->Environment = EnvironmentPtr;
458
459 /* Make a buffer for the DOS path */
460 p = (PWSTR)(ProcessParams + 1);
461 ProcessParams->CurrentDirectory.DosPath.Buffer = p;
463 sizeof(WCHAR);
464
465 /* Copy the DOS path */
467 &NtSystemRoot);
468
469 /* Make a buffer for the DLL Path */
470 p = (PWSTR)((PCHAR)ProcessParams->CurrentDirectory.DosPath.Buffer +
471 ProcessParams->CurrentDirectory.DosPath.MaximumLength);
472 ProcessParams->DllPath.Buffer = p;
473 ProcessParams->DllPath.MaximumLength = MAX_WIN32_PATH * sizeof(WCHAR);
474
475 /* Copy the DLL path and append the system32 directory */
476 RtlCopyUnicodeString(&ProcessParams->DllPath,
477 &ProcessParams->CurrentDirectory.DosPath);
478 RtlAppendUnicodeToString(&ProcessParams->DllPath, L"\\System32");
479
480 /* Make a buffer for the image name */
481 p = (PWSTR)((PCHAR)ProcessParams->DllPath.Buffer +
482 ProcessParams->DllPath.MaximumLength);
483 ProcessParams->ImagePathName.Buffer = p;
484 ProcessParams->ImagePathName.MaximumLength = MAX_WIN32_PATH * sizeof(WCHAR);
485
486 /* Make sure the buffer is a valid string which within the given length */
491 sizeof(NtInitialUserProcessBuffer) - sizeof(WCHAR)))))
492 {
493 /* Invalid initial process string, bugcheck */
494 KeBugCheckEx(SESSION2_INITIALIZATION_FAILED,
499 }
500
501 /* Cut out anything after a space */
503 while ((*p) && (*p != L' ')) p++;
504
505 /* Set the image path length */
506 ProcessParams->ImagePathName.Length =
508
509 /* Copy the actual buffer */
510 RtlCopyMemory(ProcessParams->ImagePathName.Buffer,
512 ProcessParams->ImagePathName.Length);
513
514 /* Null-terminate it */
515 ProcessParams->ImagePathName.Buffer[ProcessParams->ImagePathName.Length /
516 sizeof(WCHAR)] = UNICODE_NULL;
517
518 /* Make a buffer for the command line */
519 p = (PWSTR)((PCHAR)ProcessParams->ImagePathName.Buffer +
520 ProcessParams->ImagePathName.MaximumLength);
521 ProcessParams->CommandLine.Buffer = p;
522 ProcessParams->CommandLine.MaximumLength = MAX_WIN32_PATH * sizeof(WCHAR);
523
524 /* Add the image name to the command line */
527
528 /* Create the environment string */
529 RtlInitEmptyUnicodeString(&Environment,
530 ProcessParams->Environment,
531 (USHORT)Size);
532
533 /* Append the DLL path to it */
537
538 /* Create the system drive string */
539 SystemDriveString = NtSystemRoot;
540 SystemDriveString.Length = 2 * sizeof(WCHAR);
541
542 /* Append it to the environment */
543 RtlAppendUnicodeToString(&Environment, L"SystemDrive=");
544 RtlAppendUnicodeStringToString(&Environment, &SystemDriveString);
546
547 /* Append the system root to the environment */
548 RtlAppendUnicodeToString(&Environment, L"SystemRoot=");
551
552 /* Prepare the prefetcher */
553 //CcPfBeginBootPhase(150);
554
555 /* Create SMSS process */
556 SmssName = ProcessParams->ImagePathName;
557 Status = RtlCreateUserProcess(&SmssName,
559 RtlDeNormalizeProcessParams(ProcessParams),
560 NULL,
561 NULL,
562 NULL,
563 FALSE,
564 NULL,
565 NULL,
566 ProcessInformation);
567 if (!NT_SUCCESS(Status))
568 {
569 /* Failed, display error */
570 _snwprintf(InitBuffer->DebugBuffer,
571 sizeof(InitBuffer->DebugBuffer)/sizeof(WCHAR),
572 L"INIT: Unable to create Session Manager. 0x%lx",
573 Status);
574 RtlInitUnicodeString(&DebugString, InitBuffer->DebugBuffer);
576
577 /* Bugcheck the system */
578 KeBugCheckEx(SESSION3_INITIALIZATION_FAILED, Status, 0, 0, 0);
579 }
580
581 /* Resume the thread */
582 Status = ZwResumeThread(ProcessInformation->ThreadHandle, NULL);
583 if (!NT_SUCCESS(Status))
584 {
585 /* Failed, display error */
586 _snwprintf(InitBuffer->DebugBuffer,
587 sizeof(InitBuffer->DebugBuffer)/sizeof(WCHAR),
588 L"INIT: Unable to resume Session Manager. 0x%lx",
589 Status);
590 RtlInitUnicodeString(&DebugString, InitBuffer->DebugBuffer);
592
593 /* Bugcheck the system */
594 KeBugCheckEx(SESSION4_INITIALIZATION_FAILED, Status, 0, 0, 0);
595 }
596
597 /* Return success */
598 *ProcessParameters = ProcessParams;
599 *ProcessEnvironment = EnvironmentPtr;
600}
601
602CODE_SEG("INIT")
603ULONG
604NTAPI
606{
607 ULONG MsRemainder = 0, MsIncrement;
608 ULONG IncrementRemainder;
609 ULONG i;
610
611 /* Count the number of milliseconds for each clock interrupt */
612 MsIncrement = ClockIncrement / (10 * 1000);
613
614 /* Count the remainder from the division above, with 24-bit precision */
615 IncrementRemainder = ClockIncrement - (MsIncrement * (10 * 1000));
616 for (i= 0; i < 24; i++)
617 {
618 /* Shift the remainders */
619 MsRemainder <<= 1;
620 IncrementRemainder <<= 1;
621
622 /* Check if we've went past 1 ms */
623 if (IncrementRemainder >= (10 * 1000))
624 {
625 /* Increase the remainder by one, and substract from increment */
626 IncrementRemainder -= (10 * 1000);
627 MsRemainder |= 1;
628 }
629 }
630
631 /* Return the increment */
632 return (MsIncrement << 24) | MsRemainder;
633}
634
635CODE_SEG("INIT")
637NTAPI
639{
640 /* Initialize EXRESOURCE Support */
642
643 /* Initialize the environment lock */
645
646 /* Initialize the lookaside lists and locks */
648
649 /* Initialize the Firmware Table resource and listhead */
653
654 /* Set the suite mask to maximum and return */
655 ExSuiteMask = 0xFFFFFFFF;
656 return TRUE;
657}
658
659CODE_SEG("INIT")
661NTAPI
663{
664 /* Initialize worker threads */
666
667 /* Initialize pushlocks */
669
670 /* Initialize events and event pairs */
672 {
673 DPRINT1("Executive: Event initialization failed\n");
674 return FALSE;
675 }
677 {
678 DPRINT1("Executive: Event Pair initialization failed\n");
679 return FALSE;
680 }
681
682 /* Initialize mutants */
684 {
685 DPRINT1("Executive: Mutant initialization failed\n");
686 return FALSE;
687 }
688
689 /* Initialize callbacks */
691 {
692 DPRINT1("Executive: Callback initialization failed\n");
693 return FALSE;
694 }
695
696 /* Initialize semaphores */
698 {
699 DPRINT1("Executive: Semaphore initialization failed\n");
700 return FALSE;
701 }
702
703 /* Initialize timers */
705 {
706 DPRINT1("Executive: Timer initialization failed\n");
707 return FALSE;
708 }
709
710 /* Initialize profiling */
712 {
713 DPRINT1("Executive: Profile initialization failed\n");
714 return FALSE;
715 }
716
717 /* Initialize UUIDs */
719 {
720 DPRINT1("Executive: Uuid initialization failed\n");
721 return FALSE;
722 }
723
724 /* Initialize keyed events */
726 {
727 DPRINT1("Executive: Keyed event initialization failed\n");
728 return FALSE;
729 }
730
731 /* Initialize Win32K */
732 if (ExpWin32kInit() == FALSE)
733 {
734 DPRINT1("Executive: Win32 initialization failed\n");
735 return FALSE;
736 }
737 return TRUE;
738}
739
740CODE_SEG("INIT")
742NTAPI
744{
745 /* Check the initialization phase */
747 {
748 case 0:
749
750 /* Do Phase 0 */
751 return ExpInitSystemPhase0();
752
753 case 1:
754
755 /* Do Phase 1 */
756 return ExpInitSystemPhase1();
757
758 default:
759
760 /* Don't know any other phase! Bugcheck! */
761 KeBugCheck(UNEXPECTED_INITIALIZATION_CALL);
762 return FALSE;
763 }
764}
765
766CODE_SEG("INIT")
768NTAPI
770{
772
773 /* Get the loader extension */
774 Extension = LoaderBlock->Extension;
775
776 /* Validate the size (Windows 2003 loader doesn't provide more) */
778
779 /* Don't validate upper versions */
780 if (Extension->MajorVersion > VER_PRODUCTMAJORVERSION) return TRUE;
781
782 /* Fail if this is NT 4 */
783 if (Extension->MajorVersion < VER_PRODUCTMAJORVERSION) return FALSE;
784
785 /* Fail if this is XP */
786 if (Extension->MinorVersion < VER_PRODUCTMINORVERSION) return FALSE;
787
788 /* This is 2003 or newer, approve it */
789 return TRUE;
790}
791
792CODE_SEG("INIT")
793VOID
794NTAPI
796{
797 ULONG i = 0;
798 PLIST_ENTRY NextEntry;
800 PWCHAR Name;
801 PLDR_DATA_TABLE_ENTRY LdrEntry;
802 CHAR NameBuffer[256];
803 STRING SymbolString;
805
806 /* Loop the driver list */
807 NextEntry = LoaderBlock->LoadOrderListHead.Flink;
808 while (NextEntry != &LoaderBlock->LoadOrderListHead)
809 {
810 /* Skip the first two images */
811 if (i >= 2)
812 {
813 /* Get the entry */
814 LdrEntry = CONTAINING_RECORD(NextEntry,
816 InLoadOrderLinks);
817 if (LdrEntry->FullDllName.Buffer[0] == L'\\')
818 {
819 /* We have a name, read its data */
820 Name = LdrEntry->FullDllName.Buffer;
821 Length = LdrEntry->FullDllName.Length / sizeof(WCHAR);
822
823 /* Check if our buffer can hold it */
824 if (sizeof(NameBuffer) < Length + sizeof(ANSI_NULL))
825 {
826 /* It's too long */
828 }
829 else
830 {
831 /* Copy the name */
832 Count = 0;
833 do
834 {
835 /* Copy the character */
836 NameBuffer[Count++] = (CHAR)*Name++;
837 } while (Count < Length);
838
839 /* Null-terminate */
840 NameBuffer[Count] = ANSI_NULL;
842 }
843 }
844 else
845 {
846 /* Safely print the string into our buffer */
847 Status = RtlStringCbPrintfA(NameBuffer,
848 sizeof(NameBuffer),
849 "%S\\System32\\Drivers\\%wZ",
850 &SharedUserData->NtSystemRoot[2],
851 &LdrEntry->BaseDllName);
852 }
853
854 /* Check if the buffer was ok */
855 if (NT_SUCCESS(Status))
856 {
857 /* Initialize the STRING for the debugger */
858 RtlInitString(&SymbolString, NameBuffer);
859
860 /* Load the symbols */
861 DbgLoadImageSymbols(&SymbolString,
862 LdrEntry->DllBase,
864 }
865 }
866
867 /* Go to the next entry */
868 i++;
869 NextEntry = NextEntry->Flink;
870 }
871}
872
873CODE_SEG("INIT")
874VOID
875NTAPI
877 IN ULONG_PTR PagesToDestroy,
878 IN TYPE_OF_MEMORY MemoryType)
879{
880 PLIST_ENTRY ListEntry;
881 PMEMORY_ALLOCATION_DESCRIPTOR MemDescriptor;
882
883 DPRINT1("Burn RAM amount: %lu pages\n", PagesToDestroy);
884
885 /* Loop the memory descriptors, beginning at the end */
886 for (ListEntry = LoaderBlock->MemoryDescriptorListHead.Blink;
887 ListEntry != &LoaderBlock->MemoryDescriptorListHead;
888 ListEntry = ListEntry->Blink)
889 {
890 /* Get the memory descriptor structure */
891 MemDescriptor = CONTAINING_RECORD(ListEntry,
893 ListEntry);
894
895 /* Is memory free there or is it temporary? */
896 if (MemDescriptor->MemoryType == LoaderFree ||
897 MemDescriptor->MemoryType == LoaderFirmwareTemporary)
898 {
899 /* Check if the descriptor has more pages than we want */
900 if (MemDescriptor->PageCount > PagesToDestroy)
901 {
902 /* Change block's page count, ntoskrnl doesn't care much */
903 MemDescriptor->PageCount -= PagesToDestroy;
904 break;
905 }
906 else
907 {
908 /* Change block type */
909 MemDescriptor->MemoryType = MemoryType;
910 PagesToDestroy -= MemDescriptor->PageCount;
911
912 /* Check if we are done */
913 if (PagesToDestroy == 0) break;
914 }
915 }
916 }
917}
918
919CODE_SEG("INIT")
920VOID
921NTAPI
923 IN PLOADER_PARAMETER_BLOCK LoaderBlock)
924{
925 PNLS_DATA_BLOCK NlsData;
926 CHAR Buffer[256];
927 ANSI_STRING AnsiPath;
929 PCHAR CommandLine, PerfMem;
930 ULONG PerfMemUsed;
931 PLDR_DATA_TABLE_ENTRY NtosEntry;
933 ANSI_STRING CSDString;
934 size_t Remaining = 0;
935 PCHAR RcEnd = NULL;
936 CHAR VersionBuffer[65];
937
938 /* Validate Loader */
939 if (!ExpIsLoaderValid(LoaderBlock))
940 {
941 /* Invalid loader version */
942 KeBugCheckEx(MISMATCHED_HAL,
943 3,
944 LoaderBlock->Extension->Size,
945 LoaderBlock->Extension->MajorVersion,
946 LoaderBlock->Extension->MinorVersion);
947 }
948
949 /* Initialize PRCB pool lookaside pointers */
951
952 /* Check if this is an application CPU */
953 if (Cpu)
954 {
955 /* Then simply initialize it with HAL */
956 if (!HalInitSystem(ExpInitializationPhase, LoaderBlock))
957 {
958 /* Initialization failed */
959 KeBugCheck(HAL_INITIALIZATION_FAILED);
960 }
961
962 /* We're done */
963 return;
964 }
965
966 /* Assume no text-mode or remote boot */
969
970 /* Check if we have a setup loader block */
971 if (LoaderBlock->SetupLdrBlock)
972 {
973 /* Check if this is text-mode setup */
974 if (LoaderBlock->SetupLdrBlock->Flags & SETUPLDR_TEXT_MODE)
976
977 /* Check if this is network boot */
978 if (LoaderBlock->SetupLdrBlock->Flags & SETUPLDR_REMOTE_BOOT)
979 {
980 /* Set variable */
982
983 /* Make sure we're actually booting off the network */
984 ASSERT(!_memicmp(LoaderBlock->ArcBootDeviceName, "net(0)", 6));
985 }
986 }
987
988 /* Set phase to 0 */
990
991 /* Get boot command line */
992 CommandLine = LoaderBlock->LoadOptions;
993 if (CommandLine)
994 {
995 /* Upcase it for comparison and check if we're in performance mode */
996 _strupr(CommandLine);
997 PerfMem = strstr(CommandLine, "PERFMEM");
998 if (PerfMem)
999 {
1000 /* Check if the user gave a number of bytes to use */
1001 PerfMem = strstr(PerfMem, "=");
1002 if (PerfMem)
1003 {
1004 /* Read the number of pages we'll use */
1005 PerfMemUsed = atol(PerfMem + 1) * (1024 * 1024 / PAGE_SIZE);
1006 if (PerfMemUsed)
1007 {
1008 /* FIXME: TODO */
1009 DPRINT1("BBT performance mode not yet supported."
1010 "/PERFMEM option ignored.\n");
1011 }
1012 }
1013 }
1014
1015 /* Check if we're burning memory */
1016 PerfMem = strstr(CommandLine, "BURNMEMORY");
1017 if (PerfMem)
1018 {
1019 /* Check if the user gave a number of bytes to use */
1020 PerfMem = strstr(PerfMem, "=");
1021 if (PerfMem)
1022 {
1023 /* Read the number of pages we'll use */
1024 PerfMemUsed = atol(PerfMem + 1) * (1024 * 1024 / PAGE_SIZE);
1025 if (PerfMemUsed) ExBurnMemory(LoaderBlock, PerfMemUsed, LoaderBad);
1026 }
1027 }
1028 }
1029
1030 /* Setup NLS Base and offsets */
1031 NlsData = LoaderBlock->NlsData;
1035 (ULONG_PTR)NlsData->AnsiCodePageData);
1037 (ULONG_PTR)NlsData->AnsiCodePageData);
1038
1039 /* Initialize the NLS Tables */
1048
1049 /* Now initialize the HAL */
1050 if (!HalInitSystem(ExpInitializationPhase, LoaderBlock))
1051 {
1052 /* HAL failed to initialize, bugcheck */
1053 KeBugCheck(HAL_INITIALIZATION_FAILED);
1054 }
1055
1056 /* Make sure interrupts are active now */
1057 _enable();
1058
1059 /* Clear the crypto exponent */
1060 SharedUserData->CryptoExponent = 0;
1061
1062 /* Set global flags for the checked build */
1063#if DBG
1066#endif
1067
1068 /* Setup NT System Root Path */
1069 sprintf(Buffer, "C:%s", LoaderBlock->NtBootPathName);
1070
1071 /* Convert to ANSI_STRING and null-terminate it */
1072 RtlInitString(&AnsiPath, Buffer);
1073 Buffer[--AnsiPath.Length] = ANSI_NULL;
1074
1075 /* Get the string from KUSER_SHARED_DATA's buffer */
1076 RtlInitEmptyUnicodeString(&NtSystemRoot,
1077 SharedUserData->NtSystemRoot,
1078 sizeof(SharedUserData->NtSystemRoot));
1079
1080 /* Now fill it in */
1082 if (!NT_SUCCESS(Status)) KeBugCheck(SESSION3_INITIALIZATION_FAILED);
1083
1084 /* Setup bugcheck messages */
1086
1087 /* Setup initial system settings */
1088 CmGetSystemControlValues(LoaderBlock->RegistryBase, CmControlVector);
1089
1090 /* Set the Service Pack Number and add it to the CSD Version number if needed */
1092 if (((CmNtCSDVersion & 0xFFFF0000) == 0) && (CmNtCSDReleaseType == 1))
1093 {
1095 }
1096
1097 /* Add loaded CmNtGlobalFlag value */
1099
1100 /* Initialize the executive at phase 0 */
1101 if (!ExInitSystem()) KeBugCheck(PHASE0_INITIALIZATION_FAILED);
1102
1103 /* Initialize the memory manager at phase 0 */
1104 if (!MmArmInitSystem(0, LoaderBlock)) KeBugCheck(PHASE0_INITIALIZATION_FAILED);
1105
1106 /* Load boot symbols */
1107 ExpLoadBootSymbols(LoaderBlock);
1108
1109 /* Check if we should break after symbol load */
1111
1112 /* Check if this loader is compatible with NT 5.2 */
1113 if (LoaderBlock->Extension->Size >= sizeof(LOADER_PARAMETER_EXTENSION))
1114 {
1115 /* Setup headless terminal settings */
1116 HeadlessInit(LoaderBlock);
1117 }
1118
1119 /* Set system ranges */
1120#ifdef _M_AMD64
1123#else
1126#endif
1127
1128 /* Make a copy of the NLS Tables */
1129 ExpInitNls(LoaderBlock);
1130
1131 /* Get the kernel's load entry */
1132 NtosEntry = CONTAINING_RECORD(LoaderBlock->LoadOrderListHead.Flink,
1134 InLoadOrderLinks);
1135
1136 /* Check if this is a service pack */
1137 if (CmNtCSDVersion & 0xFFFF)
1138 {
1139 /* Get the service pack string */
1140 Status = RtlFindMessage(NtosEntry->DllBase,
1141 11,
1142 0,
1143 WINDOWS_NT_CSD_STRING,
1144 &MsgEntry);
1145 if (NT_SUCCESS(Status))
1146 {
1147 /* Setup the string */
1148 RtlInitAnsiString(&CSDString, (PCHAR)MsgEntry->Text);
1149
1150 /* Remove trailing newline */
1151 while ((CSDString.Length > 0) &&
1152 ((CSDString.Buffer[CSDString.Length - 1] == '\r') ||
1153 (CSDString.Buffer[CSDString.Length - 1] == '\n')))
1154 {
1155 /* Skip the trailing character */
1156 CSDString.Length--;
1157 }
1158
1159 /* Fill the buffer with version information */
1161 sizeof(Buffer),
1162 "%Z %u%c",
1163 &CSDString,
1164 (CmNtCSDVersion & 0xFF00) >> 8,
1165 (CmNtCSDVersion & 0xFF) ?
1166 'A' + (CmNtCSDVersion & 0xFF) - 1 :
1167 ANSI_NULL);
1168 }
1169 else
1170 {
1171 /* Build default string */
1173 sizeof(Buffer),
1174 "CSD %04x",
1176 }
1177
1178 /* Check for success */
1179 if (!NT_SUCCESS(Status))
1180 {
1181 /* Fail */
1182 KeBugCheckEx(PHASE0_INITIALIZATION_FAILED, Status, 0, 0, 0);
1183 }
1184 }
1185 else
1186 {
1187 /* Then this is a beta */
1189 sizeof(Buffer),
1191 NULL,
1192 &Remaining,
1193 0);
1194 if (!NT_SUCCESS(Status))
1195 {
1196 /* Fail */
1197 KeBugCheckEx(PHASE0_INITIALIZATION_FAILED, Status, 0, 0, 0);
1198 }
1199
1200 /* Update length */
1201 CmCSDVersionString.MaximumLength = sizeof(Buffer) - (USHORT)Remaining;
1202 }
1203
1204 /* Check if we have an RC number */
1205 if ((CmNtCSDVersion & 0xFFFF0000) && (CmNtCSDReleaseType == 1))
1206 {
1207 /* Check if we have no version data yet */
1208 if (!(*Buffer))
1209 {
1210 /* Set defaults */
1211 Remaining = sizeof(Buffer);
1212 RcEnd = Buffer;
1213 }
1214 else
1215 {
1216 /* Add comma and space */
1218 sizeof(Buffer),
1219 ", ",
1220 &RcEnd,
1221 &Remaining,
1222 0);
1223 if (!NT_SUCCESS(Status))
1224 {
1225 /* Fail */
1226 KeBugCheckEx(PHASE0_INITIALIZATION_FAILED, Status, 0, 0, 0);
1227 }
1228 }
1229
1230 /* Add the version format string */
1231 Status = RtlStringCbPrintfA(RcEnd,
1232 Remaining,
1233 "v.%u",
1234 (CmNtCSDVersion & 0xFFFF0000) >> 16);
1235 if (!NT_SUCCESS(Status))
1236 {
1237 /* Fail */
1238 KeBugCheckEx(PHASE0_INITIALIZATION_FAILED, Status, 0, 0, 0);
1239 }
1240 }
1241
1242 /* Now setup the final string */
1243 RtlInitAnsiString(&CSDString, Buffer);
1245 &CSDString,
1246 TRUE);
1247 if (!NT_SUCCESS(Status))
1248 {
1249 /* Fail */
1250 KeBugCheckEx(PHASE0_INITIALIZATION_FAILED, Status, 0, 0, 0);
1251 }
1252
1253 /* Add our version */
1254 Status = RtlStringCbPrintfA(VersionBuffer,
1255 sizeof(VersionBuffer),
1256 "%u.%u",
1259 if (!NT_SUCCESS(Status))
1260 {
1261 /* Fail */
1262 KeBugCheckEx(PHASE0_INITIALIZATION_FAILED, Status, 0, 0, 0);
1263 }
1264
1265 /* Build the final version string */
1267
1268 /* Check if the user wants a kernel stack trace database */
1270 {
1271 /* FIXME: TODO */
1272 DPRINT1("Kernel-mode stack trace support not yet present."
1273 "FLG_KERNEL_STACK_TRACE_DB flag ignored.\n");
1274 }
1275
1276 /* Check if he wanted exception logging */
1278 {
1279 /* FIXME: TODO */
1280 DPRINT1("Kernel-mode exception logging support not yet present."
1281 "FLG_ENABLE_EXCEPTION_LOGGING flag ignored.\n");
1282 }
1283
1284 /* Initialize the Handle Table */
1286
1287#if DBG
1288 /* On checked builds, allocate the system call count table */
1291 KiServiceLimit * sizeof(ULONG),
1292 'llaC');
1293
1294 /* Use it for the shadow table too */
1296
1297 /* Make sure allocation succeeded */
1299 {
1300 /* Zero the call counts to 0 */
1302 KiServiceLimit * sizeof(ULONG));
1303 }
1304#endif
1305
1306 /* Create the Basic Object Manager Types to allow new Object Types */
1307 if (!ObInitSystem()) KeBugCheck(OBJECT_INITIALIZATION_FAILED);
1308
1309 /* Load basic Security for other Managers */
1310 if (!SeInitSystem()) KeBugCheck(SECURITY_INITIALIZATION_FAILED);
1311
1312 /* Initialize the Process Manager */
1313 if (!PsInitSystem(LoaderBlock)) KeBugCheck(PROCESS_INITIALIZATION_FAILED);
1314
1315 /* Initialize the PnP Manager */
1316 if (!PpInitSystem()) KeBugCheck(PP0_INITIALIZATION_FAILED);
1317
1318 /* Initialize the User-Mode Debugging Subsystem */
1320
1321 /* Calculate the tick count multiplier */
1323 SharedUserData->TickCountMultiplier = ExpTickCountMultiplier;
1324
1325 /* Set the OS Version */
1326 SharedUserData->NtMajorVersion = NtMajorVersion;
1327 SharedUserData->NtMinorVersion = NtMinorVersion;
1328
1329 /* Set the machine type */
1330 SharedUserData->ImageNumberLow = IMAGE_FILE_MACHINE_NATIVE;
1331 SharedUserData->ImageNumberHigh = IMAGE_FILE_MACHINE_NATIVE;
1332}
1333
1334VOID
1335NTAPI
1337
1338CODE_SEG("INIT")
1339VOID
1340NTAPI
1342{
1343 PLOADER_PARAMETER_BLOCK LoaderBlock = Context;
1344 NTSTATUS Status, MsgStatus;
1346 LARGE_INTEGER SystemBootTime, UniversalBootTime, OldTime, Timeout;
1347 BOOLEAN SosEnabled, 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 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 */
1553 KeSetSystemTime(&UniversalBootTime, &OldTime, FALSE, NULL);
1554
1555 /* Do system callback */
1557
1558 /* Remember this as the boot time */
1559 KeBootTime = UniversalBootTime;
1560 KeBootTimeBias = 0;
1561 }
1562
1563 /* Initialize all processors */
1564 if (!HalAllProcessorsStarted()) KeBugCheck(HAL1_INITIALIZATION_FAILED);
1565
1566#ifdef CONFIG_SMP
1567 /* HACK: We should use RtlFindMessage and not only fallback to this */
1568 MpString = "MultiProcessor Kernel\r\n";
1569#endif
1570
1571 /* Setup the "MP" String */
1572 RtlInitAnsiString(&TempString, MpString);
1573
1574 /* Make sure to remove the \r\n if we actually have a string */
1575 while ((TempString.Length > 0) &&
1576 ((TempString.Buffer[TempString.Length - 1] == '\r') ||
1577 (TempString.Buffer[TempString.Length - 1] == '\n')))
1578 {
1579 /* Skip the trailing character */
1580 TempString.Length--;
1581 }
1582
1583 /* Get the information string from our resource file */
1584 MsgStatus = RtlFindMessage(NtosEntry->DllBase,
1585 11,
1586 0,
1587 KeNumberProcessors > 1 ?
1588 WINDOWS_NT_INFO_STRING_PLURAL :
1589 WINDOWS_NT_INFO_STRING,
1590 &MsgEntry);
1591
1592 /* Get total RAM size, in MiB */
1593 /* Round size up. Assumed to better match actual physical RAM size */
1594 Size = ALIGN_UP_BY(MmNumberOfPhysicalPages * PAGE_SIZE, 1024 * 1024) / (1024 * 1024);
1595
1596 /* Create the string */
1597 StringBuffer = InitBuffer->VersionBuffer;
1599 sizeof(InitBuffer->VersionBuffer),
1600 NT_SUCCESS(MsgStatus) ?
1601 (PCHAR)MsgEntry->Text :
1602 "%u System Processor [%Iu MB Memory] %Z\r\n",
1604 Size,
1605 &TempString);
1606 if (!NT_SUCCESS(Status))
1607 {
1608 /* Bugcheck */
1609 KeBugCheckEx(PHASE1_INITIALIZATION_FAILED, Status, 4, 0, 0);
1610 }
1611
1612 /* Display RAM and CPU count */
1614
1615 /* Update the progress bar */
1617
1618 /* Call OB initialization again */
1619 if (!ObInitSystem()) KeBugCheck(OBJECT1_INITIALIZATION_FAILED);
1620
1621 /* Initialize Basic System Objects and Worker Threads */
1622 if (!ExInitSystem()) KeBugCheckEx(PHASE1_INITIALIZATION_FAILED, 0, 0, 1, 0);
1623
1624 /* Initialize the later stages of the kernel */
1625 if (!KeInitSystem()) KeBugCheckEx(PHASE1_INITIALIZATION_FAILED, 0, 0, 2, 0);
1626
1627 /* Call KD Providers at Phase 1 */
1629 {
1630 /* Failed, bugcheck */
1631 KeBugCheckEx(PHASE1_INITIALIZATION_FAILED, 0, 0, 3, 0);
1632 }
1633
1634 /* Initialize the SRM in Phase 1 */
1635 if (!SeInitSystem()) KeBugCheck(SECURITY1_INITIALIZATION_FAILED);
1636
1637 /* Update the progress bar */
1639
1640 /* Create SystemRoot Link */
1641 Status = ExpCreateSystemRootLink(LoaderBlock);
1642 if (!NT_SUCCESS(Status))
1643 {
1644 /* Failed to create the system root link */
1645 KeBugCheckEx(SYMBOLIC_INITIALIZATION_FAILED, Status, 0, 0, 0);
1646 }
1647
1648 /* Set up Region Maps, Sections and the Paging File */
1649 if (!MmInitSystem(1, LoaderBlock)) KeBugCheck(MEMORY1_INITIALIZATION_FAILED);
1650
1651 /* Create NLS section */
1652 ExpInitNls(LoaderBlock);
1653
1654 /* Initialize Cache Views */
1655 if (!CcInitializeCacheManager()) KeBugCheck(CACHE_INITIALIZATION_FAILED);
1656
1657 /* Initialize the Registry */
1658 if (!CmInitSystem1()) KeBugCheck(CONFIG_INITIALIZATION_FAILED);
1659
1660 /* Initialize Prefetcher */
1662
1663 /* Update progress bar */
1665
1666 /* Update timezone information */
1667 LastTzBias = ExpLastTimeZoneBias;
1668 ExRefreshTimeZoneInformation(&SystemBootTime);
1669
1670 /* Check if we're resetting timezone data */
1671 if (ResetBias)
1672 {
1673 /* Convert the local time to system time */
1674 ExLocalTimeToSystemTime(&SystemBootTime, &UniversalBootTime);
1675 KeBootTime = UniversalBootTime;
1676 KeBootTimeBias = 0;
1677
1678 /* Set the new time */
1679 KeSetSystemTime(&UniversalBootTime, &OldTime, FALSE, NULL);
1680 }
1681 else
1682 {
1683 /* Check if the timezone switched and update the time */
1684 if (LastTzBias != ExpLastTimeZoneBias) ZwSetSystemTime(NULL, NULL);
1685 }
1686
1687 /* Initialize the File System Runtime Library */
1688 if (!FsRtlInitSystem()) KeBugCheck(FILE_INITIALIZATION_FAILED);
1689
1690 /* Initialize range lists */
1692
1693 /* Report all resources used by HAL */
1695
1696 /* Call the debugger DLL */
1697 KdDebuggerInitialize1(LoaderBlock);
1698
1699 /* Setup PnP Manager in phase 1 */
1700 if (!PpInitSystem()) KeBugCheck(PP1_INITIALIZATION_FAILED);
1701
1702 /* Update progress bar */
1704
1705 /* Initialize LPC */
1706 if (!LpcInitSystem()) KeBugCheck(LPC_INITIALIZATION_FAILED);
1707
1708 /* Make sure we have a command line */
1709 if (CommandLine)
1710 {
1711 /* Check if this is a safe mode boot */
1712 SafeBoot = strstr(CommandLine, "SAFEBOOT:");
1713 if (SafeBoot)
1714 {
1715 /* Check what kind of boot this is */
1716 SafeBoot += 9;
1717 if (!strncmp(SafeBoot, "MINIMAL", 7))
1718 {
1719 /* Minimal mode */
1720 InitSafeBootMode = 1;
1721 SafeBoot += 7;
1722 MessageCode = BOOTING_IN_SAFEMODE_MINIMAL;
1723 }
1724 else if (!strncmp(SafeBoot, "NETWORK", 7))
1725 {
1726 /* With Networking */
1727 InitSafeBootMode = 2;
1728 SafeBoot += 7;
1729 MessageCode = BOOTING_IN_SAFEMODE_NETWORK;
1730 }
1731 else if (!strncmp(SafeBoot, "DSREPAIR", 8))
1732 {
1733 /* Domain Server Repair */
1734 InitSafeBootMode = 3;
1735 SafeBoot += 8;
1736 MessageCode = BOOTING_IN_SAFEMODE_DSREPAIR;
1737
1738 }
1739 else
1740 {
1741 /* Invalid */
1742 InitSafeBootMode = 0;
1743 }
1744
1745 /* Check if there's any settings left */
1746 if (*SafeBoot)
1747 {
1748 /* Check if an alternate shell was requested */
1749 if (!strncmp(SafeBoot, "(ALTERNATESHELL)", 16))
1750 {
1751 /* Remember this for later */
1752 AlternateShell = TRUE;
1753 }
1754 }
1755
1756 /* Find the message to print out */
1757 Status = RtlFindMessage(NtosEntry->DllBase,
1758 11,
1759 0,
1760 MessageCode,
1761 &MsgEntry);
1762 if (NT_SUCCESS(Status))
1763 {
1764 /* Display it */
1765 InbvDisplayString((PCHAR)MsgEntry->Text);
1766 }
1767 }
1768 }
1769
1770 /* Make sure we have a command line */
1771 if (CommandLine)
1772 {
1773 /* Check if bootlogging is enabled */
1774 if (strstr(CommandLine, "BOOTLOG"))
1775 {
1776 /* Find the message to print out */
1777 Status = RtlFindMessage(NtosEntry->DllBase,
1778 11,
1779 0,
1780 BOOTLOG_ENABLED,
1781 &MsgEntry);
1782 if (NT_SUCCESS(Status))
1783 {
1784 /* Display it */
1785 InbvDisplayString((PCHAR)MsgEntry->Text);
1786 }
1787
1788 /* Setup boot logging */
1789 //IopInitializeBootLogging(LoaderBlock, InitBuffer->BootlogHeader);
1790 }
1791 }
1792
1793 /* Setup the Executive in Phase 2 */
1794 //ExInitSystemPhase2();
1795
1796 /* Update progress bar */
1798
1799 /* No KD Time Slip is pending */
1801
1802 /* Initialize in-place execution support */
1803 XIPInit(LoaderBlock);
1804
1805 /* Set maximum update to 75% */
1807
1808 /* Initialize the I/O Subsystem */
1809 if (!IoInitSystem(LoaderBlock)) KeBugCheck(IO1_INITIALIZATION_FAILED);
1810
1811 /* Set maximum update to 100% */
1813
1814 /* Are we in safe mode? */
1815 if (InitSafeBootMode)
1816 {
1817 /* Open the safe boot key */
1819 L"\\REGISTRY\\MACHINE\\SYSTEM\\CURRENTCONTROLSET"
1820 L"\\CONTROL\\SAFEBOOT");
1822 &KeyName,
1824 NULL,
1825 NULL);
1827 if (NT_SUCCESS(Status))
1828 {
1829 /* First check if we have an alternate shell */
1830 if (AlternateShell)
1831 {
1832 /* Make sure that the registry has one setup */
1833 RtlInitUnicodeString(&KeyName, L"AlternateShell");
1835 &KeyName,
1837 &KeyPartialInfo,
1838 sizeof(KeyPartialInfo),
1839 &Length);
1841 {
1842 AlternateShell = FALSE;
1843 }
1844 }
1845
1846 /* Create the option key */
1847 RtlInitUnicodeString(&KeyName, L"Option");
1849 &KeyName,
1851 KeyHandle,
1852 NULL);
1853 Status = ZwCreateKey(&OptionHandle,
1856 0,
1857 NULL,
1859 &Disposition);
1861
1862 /* Check if the key create worked */
1863 if (NT_SUCCESS(Status))
1864 {
1865 /* Write the safe boot type */
1866 RtlInitUnicodeString(&KeyName, L"OptionValue");
1867 NtSetValueKey(OptionHandle,
1868 &KeyName,
1869 0,
1870 REG_DWORD,
1872 sizeof(InitSafeBootMode));
1873
1874 /* Check if we have to use an alternate shell */
1875 if (AlternateShell)
1876 {
1877 /* Remember this for later */
1878 Disposition = TRUE;
1879 RtlInitUnicodeString(&KeyName, L"UseAlternateShell");
1880 NtSetValueKey(OptionHandle,
1881 &KeyName,
1882 0,
1883 REG_DWORD,
1884 &Disposition,
1885 sizeof(Disposition));
1886 }
1887
1888 /* Close the options key handle */
1889 NtClose(OptionHandle);
1890 }
1891 }
1892 }
1893
1894 /* Are we in Win PE mode? */
1895 if (InitIsWinPEMode)
1896 {
1897 /* Open the safe control key */
1899 L"\\REGISTRY\\MACHINE\\SYSTEM\\CURRENTCONTROLSET"
1900 L"\\CONTROL");
1902 &KeyName,
1904 NULL,
1905 NULL);
1907 if (!NT_SUCCESS(Status))
1908 {
1909 /* Bugcheck */
1910 KeBugCheckEx(PHASE1_INITIALIZATION_FAILED, Status, 6, 0, 0);
1911 }
1912
1913 /* Create the MiniNT key */
1914 RtlInitUnicodeString(&KeyName, L"MiniNT");
1916 &KeyName,
1918 KeyHandle,
1919 NULL);
1920 Status = ZwCreateKey(&OptionHandle,
1923 0,
1924 NULL,
1926 &Disposition);
1927 if (!NT_SUCCESS(Status))
1928 {
1929 /* Bugcheck */
1930 KeBugCheckEx(PHASE1_INITIALIZATION_FAILED, Status, 6, 0, 0);
1931 }
1932
1933 /* Close the handles */
1935 NtClose(OptionHandle);
1936 }
1937
1938 /* FIXME: This doesn't do anything for now */
1939 MmArmInitSystem(2, LoaderBlock);
1940
1941 /* Update progress bar */
1943
1944 /* Initialize VDM support */
1945#if defined(_M_IX86)
1947#endif
1948
1949 /* Initialize Power Subsystem in Phase 1*/
1950 if (!PoInitSystem(1)) KeBugCheck(INTERNAL_POWER_ERROR);
1951
1952 /* Update progress bar */
1954
1955 /* Initialize the Process Manager at Phase 1 */
1956 if (!PsInitSystem(LoaderBlock)) KeBugCheck(PROCESS1_INITIALIZATION_FAILED);
1957
1958 /* Make sure nobody touches the loader block again */
1959 if (LoaderBlock == KeLoaderBlock) KeLoaderBlock = NULL;
1960 MmFreeLoaderBlock(LoaderBlock);
1961 LoaderBlock = Context = NULL;
1962
1963 /* Initialize the SRM in phase 1 */
1964 if (!SeRmInitPhase1()) KeBugCheck(PROCESS1_INITIALIZATION_FAILED);
1965
1966 /* Update progress bar */
1968
1969 /* Clear the screen */
1971
1972 /* Allow strings to be displayed */
1974
1975 /* Launch initial process */
1976 ProcessInfo = &InitBuffer->ProcessInfo;
1977 ExpLoadInitialProcess(InitBuffer, &ProcessParameters, &Environment);
1978
1979 /* Wait 5 seconds for initial process to initialize */
1980 Timeout.QuadPart = Int32x32To64(5, -10000000);
1981 Status = ZwWaitForSingleObject(ProcessInfo->ProcessHandle, FALSE, &Timeout);
1982 if (Status == STATUS_SUCCESS)
1983 {
1984 /* Failed, display error */
1985 DPRINT1("INIT: Session Manager terminated.\n");
1986
1987 /* Bugcheck the system if SMSS couldn't initialize */
1988 KeBugCheck(SESSION5_INITIALIZATION_FAILED);
1989 }
1990
1991 /* Close process handles */
1992 ZwClose(ProcessInfo->ThreadHandle);
1993 ZwClose(ProcessInfo->ProcessHandle);
1994
1995 /* Free the initial process environment */
1996 Size = 0;
1997 ZwFreeVirtualMemory(NtCurrentProcess(),
1998 (PVOID*)&Environment,
1999 &Size,
2000 MEM_RELEASE);
2001
2002 /* Free the initial process parameters */
2003 Size = 0;
2004 ZwFreeVirtualMemory(NtCurrentProcess(),
2005 (PVOID*)&ProcessParameters,
2006 &Size,
2007 MEM_RELEASE);
2008
2009 /* Increase init phase */
2011
2012 /* Free the boot buffer */
2013 ExFreePoolWithTag(InitBuffer, TAG_INIT);
2014}
2015
2016VOID
2017NTAPI
2019{
2020 /* Do the .INIT part of Phase 1 which we can free later */
2022
2023 /* Jump into zero page thread */
2025}
#define ALIGN_UP_BY(size, align)
unsigned char BOOLEAN
char * strstr(char *String1, char *String2)
Definition: utclib.c:653
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
struct NameRec_ * Name
Definition: cdprocs.h:460
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
#define CHAR(Char)
VOID NTAPI FinalizeBootLogo(VOID)
Definition: bootanim.c:754
VOID NTAPI DisplayBootBitmap(_In_ BOOLEAN TextMode)
Definition: bootanim.c:471
DECLSPEC_NORETURN VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1427
_In_z_ PCHAR TargetString
Definition: cdrom.h:954
Definition: bufpool.h:45
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
CCHAR DebugString[256]
Definition: cmdline.c:22
BOOLEAN NTAPI CmInitSystem1(VOID)
Definition: cmsysini.c:1511
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
VOID NTAPI DbgkInitialize(VOID)
Definition: dbgkobj.c:1498
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ULONG_PTR
Definition: config.h:101
BOOLEAN RtlTimeFieldsToTime(IN PTIME_FIELDS TimeFields, IN PLARGE_INTEGER Time)
#define ExLocalTimeToSystemTime(LocTime, SysTime)
Definition: env_spec_w32.h:738
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
NTSTATUS ExInitializeResourceLite(PULONG res)
Definition: env_spec_w32.h:641
#define PAGE_SIZE
Definition: env_spec_w32.h:49
NTSTATUS RtlAppendUnicodeToString(IN PUNICODE_STRING Str1, IN PWSTR Str2)
Definition: string_lib.cpp:62
#define NonPagedPool
Definition: env_spec_w32.h:307
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
BOOLEAN NTAPI ExpInitializeEventPairImplementation(VOID)
Definition: evtpair.c:33
BOOLEAN NTAPI ExpInitializeKeyedEventImplementation(VOID)
_Inout_opt_ PUNICODE_STRING Extension
Definition: fltkernel.h:1092
std::wstring STRING
Definition: fontsub.cpp:33
BOOLEAN NTAPI FsRtlInitSystem(VOID)
Definition: fsrtlpc.c:161
BOOLEAN NTAPI CcInitializeCacheManager(VOID)
Definition: fssup.c:83
VOID NTAPI CcPfInitializePrefetcher(VOID)
Definition: fssup.c:114
Status
Definition: gdiplustypes.h:25
GLfloat GLfloat p
Definition: glext.h:8902
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
BOOLEAN NTAPI HalAllProcessorsStarted(VOID)
Definition: processor.c:60
VOID NTAPI HalReportResourceUsage(VOID)
Definition: usage.c:67
#define KeGetCurrentThread
Definition: hal.h:55
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
#define VER_PRODUCTBUILD
Definition: ieverp.h:6
VOID NTAPI InbvNotifyDisplayOwnershipLost(_In_ INBV_RESET_DISPLAY_PARAMETERS Callback)
Definition: inbv.c:403
BOOLEAN InbvBootDriverInstalled
Definition: inbv.c:39
VOID NTAPI InbvEnableBootDriver(_In_ BOOLEAN Enable)
Definition: inbv.c:257
VOID NTAPI InbvSetProgressBarSubset(_In_ ULONG Floor, _In_ ULONG Ceiling)
Specifies a progress percentage sub-range. Further calls to InbvIndicateProgress() or InbvUpdateProgr...
Definition: inbv.c:663
BOOLEAN NTAPI InbvEnableDisplayString(_In_ BOOLEAN Enable)
Definition: inbv.c:369
BOOLEAN NTAPI InbvDisplayString(_In_ PCHAR String)
Definition: inbv.c:331
BOOLEAN NTAPI InbvDriverInitialize(_In_ PLOADER_PARAMETER_BLOCK LoaderBlock, _In_ ULONG Count)
Definition: inbv.c:175
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:689
_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
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define OBJ_PERMANENT
Definition: winternl.h:226
#define HIGH_PRIORITY
void __cdecl _enable(void)
Definition: intrin_arm.h:373
VOID ExpInitLookasideLists()
static CODE_SEG("PAGE")
Definition: isapnp.c:1482
BOOLEAN NTAPI KdInitSystem(_In_ ULONG BootPhase, _In_opt_ PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: kdinit.c:142
BOOLEAN KdBreakAfterSymbolLoad
Definition: kddata.c:80
LONG KdpTimeSlipPending
Definition: kddata.c:119
NTSTATUS NTAPI KdDebuggerInitialize1(IN PLOADER_PARAMETER_BLOCK LoaderBlock OPTIONAL)
Definition: kdcom.c:283
CCHAR KeNumberProcessors
Definition: krnlinit.c:35
PLOADER_PARAMETER_BLOCK KeLoaderBlock
Definition: krnlinit.c:29
#define REG_SZ
Definition: layer.c:22
WCHAR StringBuffer[156]
Definition: ldrinit.c:41
VOID NTAPI ExInitPoolLookasidePointers(VOID)
Definition: lookas.c:59
BOOLEAN NTAPI LpcInitSystem(VOID)
Definition: port.c:37
#define PCHAR
Definition: match.c:90
#define ASSERT(a)
Definition: mode.c:44
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
int _snwprintf(wchar_t *buffer, size_t count, const wchar_t *format,...)
PVOID PVOID PWCHAR PVOID Environment
Definition: env.c:47
#define sprintf(buf, format,...)
Definition: sprintf.c:55
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
static PTIME_FIELDS TimeFields
Definition: time.c:104
BOOLEAN NTAPI ExpInitializeMutantImplementation(VOID)
Definition: mutant.c:52
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4715
#define KernelMode
Definition: asm.h:34
_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 ZwDisplayString(_In_ PUNICODE_STRING DisplayString)
#define DBG_STATUS_CONTROL_C
Definition: kdtypes.h:39
NTSYSAPI NTSTATUS NTAPI ZwSetSystemTime(_In_ PLARGE_INTEGER SystemTime, _In_opt_ PLARGE_INTEGER NewSystemTime)
_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:99
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
NTSYSAPI NTSTATUS NTAPI ZwResumeThread(_In_ HANDLE ThreadHandle, _Out_opt_ PULONG SuspendCount)
NTSYSAPI VOID NTAPI RtlInitNlsTables(_In_ PUSHORT AnsiTableBase, _In_ PUSHORT OemTableBase, _In_ PUSHORT CaseTableBase, _Out_ PNLSTABLEINFO NlsTable)
NTSYSAPI VOID NTAPI RtlResetRtlTranslations(_In_ PNLSTABLEINFO NlsTable)
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 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)
NTSYSAPI PRTL_USER_PROCESS_PARAMETERS NTAPI RtlDeNormalizeProcessParams(_In_ PRTL_USER_PROCESS_PARAMETERS ProcessParameters)
VOID NTAPI DbgLoadImageSymbols(_In_ PSTRING Name, _In_ PVOID Base, _In_ ULONG_PTR ProcessId)
#define RTL_USER_PROCESS_PARAMETERS_RESERVE_1MB
Definition: rtltypes.h:46
#define RTL_USER_PROCESS_PARAMETERS_NORMALIZED
Definition: rtltypes.h:41
int Count
Definition: noreturn.cpp:7
NTSYSAPI VOID NTAPI RtlCopyUnicodeString(PUNICODE_STRING DestinationString, PUNICODE_STRING SourceString)
#define SYMBOLIC_LINK_ALL_ACCESS
Definition: nt_native.h:1267
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
NTSYSAPI NTSTATUS NTAPI RtlAppendUnicodeStringToString(PUNICODE_STRING Destination, PUNICODE_STRING Source)
NTSYSAPI VOID NTAPI RtlInitString(PSTRING DestinationString, PCSZ SourceString)
#define PAGE_READWRITE
Definition: nt_native.h:1304
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
#define SECTION_ALL_ACCESS
Definition: nt_native.h:1293
NTSYSAPI NTSTATUS NTAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, PANSI_STRING SourceString, BOOLEAN AllocateDestinationString)
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define NtCurrentProcess()
Definition: nt_native.h:1657
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)
@ ViewShare
Definition: nt_native.h:1278
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
#define MEM_RESERVE
Definition: nt_native.h:1314
#define MEM_RELEASE
Definition: nt_native.h:1316
#define DIRECTORY_ALL_ACCESS
Definition: nt_native.h:1259
#define MEM_COMMIT
Definition: nt_native.h:1313
#define REG_OPTION_VOLATILE
Definition: nt_native.h:1060
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
#define Int32x32To64(a, b)
#define UNICODE_NULL
#define ANSI_NULL
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
BOOLEAN NTAPI ExpInitializeCallbacks(VOID)
Definition: callback.c:256
BOOLEAN NTAPI ExpInitializeEventImplementation(VOID)
Definition: event.c:39
VOID NTAPI ExpInitializeHandleTables(VOID)
Definition: handle.c:34
SIZE_T ExpNlsTableSize
Definition: init.c:88
ULONG ExpInitializationPhase
Definition: init.c:68
VOID NTAPI ExBurnMemory(IN PLOADER_PARAMETER_BLOCK LoaderBlock, IN ULONG_PTR PagesToDestroy, IN TYPE_OF_MEMORY MemoryType)
Definition: init.c:876
ULONG CmNtCSDReleaseType
Definition: init.c:60
PVOID ExpNlsTableBase
Definition: init.c:84
ULONG NTAPI ExComputeTickCountMultiplier(IN ULONG ClockIncrement)
Definition: init.c:605
BOOLEAN InitWinPEModeType
Definition: init.c:72
BOOLEAN IoRemoteBootClient
Definition: init.c:70
BOOLEAN NTAPI ExpInitSystemPhase0(VOID)
Definition: init.c:638
BOOLEAN ExCmosClockIsSane
Definition: init.c:92
UNICODE_STRING NtSystemRoot
Definition: init.c:75
ULONG NtBuildNumber
Definition: init.c:50
NTSTATUS NTAPI ExpCreateSystemRootLink(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: init.c:100
ULONG ExpOemCodePageDataOffset
Definition: init.c:85
NLSTABLEINFO ExpNlsTableInfo
Definition: init.c:87
struct _INIT_BUFFER INIT_BUFFER
BOOLEAN NTAPI ExpIsLoaderValid(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: init.c:769
ULONG NtMajorVersion
Definition: init.c:45
ULONG ExpUnicodeCaseTableDataOffset
Definition: init.c:86
WCHAR NtInitialUserProcessBuffer[128]
Definition: init.c:78
BOOLEAN NTAPI MmArmInitSystem(IN ULONG Phase, IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: mminit.c:2046
struct _INIT_BUFFER * PINIT_BUFFER
CHAR NtBuildLab[]
Definition: init.c:64
ULONG NtGlobalFlag
Definition: init.c:54
#define LOADER_PARAMETER_EXTENSION_MIN_SIZE
Definition: init.c:20
VOID NTAPI MmFreeLoaderBlock(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: mminit.c:1093
UNICODE_STRING CmVersionString
Definition: init.c:61
ULONG ExSuiteMask
Definition: init.c:55
PVOID ExpNlsSectionPointer
Definition: init.c:89
ULONG CmNtSpBuildNumber
Definition: init.c:58
BOOLEAN NTAPI ExpInitSystemPhase1(VOID)
Definition: init.c:662
BOOLEAN ExpInTextModeSetup
Definition: init.c:69
ULONG NtInitialUserProcessBufferType
Definition: init.c:81
ULONG ExpAnsiCodePageDataOffset
Definition: init.c:85
ULONG NtMinorVersion
Definition: init.c:46
VOID NTAPI ExpLoadInitialProcess(IN PINIT_BUFFER InitBuffer, OUT PRTL_USER_PROCESS_PARAMETERS *ProcessParameters, OUT PCHAR *ProcessEnvironment)
Definition: init.c:388
VOID NTAPI ExpLoadBootSymbols(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: init.c:795
ULONG CmNtCSDVersion
Definition: init.c:59
VOID NTAPI ExpInitNls(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: init.c:212
VOID NTAPI ExpInitializeExecutive(IN ULONG Cpu, IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: init.c:922
VOID NTAPI Phase1Initialization(IN PVOID Context)
Definition: init.c:2018
UNICODE_STRING CmCSDVersionString
Definition: init.c:62
VOID NTAPI Phase1InitializationDiscard(IN PVOID Context)
Definition: init.c:1341
BOOLEAN NTAPI ExInitSystem(VOID)
Definition: init.c:743
BOOLEAN ExpRealTimeIsUniversal
Definition: init.c:93
ULONG NtInitialUserProcessBufferLength
Definition: init.c:79
ULONG InitSafeBootMode
Definition: init.c:71
BOOLEAN InitIsWinPEMode
Definition: init.c:72
BOOLEAN NTAPI ExpInitializeProfileImplementation(VOID)
Definition: profile.c:62
VOID NTAPI ExpResourceInitialization(VOID)
Definition: resource.c:169
LIST_ENTRY ExpFirmwareTableProviderListHead
Definition: sysinfo.c:31
FAST_MUTEX ExpEnvironmentLock
Definition: sysinfo.c:29
ERESOURCE ExpFirmwareTableResource
Definition: sysinfo.c:30
LARGE_INTEGER ExpTimeZoneBias
Definition: time.c:23
ERESOURCE ExpTimeRefreshLock
Definition: time.c:27
ULONG ExpAltTimeZoneBias
Definition: time.c:24
ULONG ExpTickCountMultiplier
Definition: time.c:26
ULONG ExpLastTimeZoneBias
Definition: time.c:22
BOOLEAN NTAPI ExRefreshTimeZoneInformation(IN PLARGE_INTEGER CurrentBootTime)
Definition: time.c:226
BOOLEAN NTAPI ExpInitializeTimerImplementation(VOID)
Definition: timer.c:223
BOOLEAN NTAPI ExpUuidInitialization(VOID)
Definition: uuid.c:53
#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
VOID NTAPI KeI386VdmInitialize(VOID)
Definition: vdmmain.c:42
BOOLEAN NTAPI IoInitSystem(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: iomgr.c:465
BOOLEAN NTAPI PpInitSystem(VOID)
Definition: pnpmgr.c:1712
VOID NTAPI KeSetSystemTime(IN PLARGE_INTEGER NewSystemTime, OUT PLARGE_INTEGER OldSystemTime, IN BOOLEAN FixInterruptTime, IN PLARGE_INTEGER HalTime)
Definition: clock.c:28
VOID NTAPI KiInitializeBugCheck(VOID)
Definition: bug.c:296
ULONGLONG KeBootTimeBias
Definition: clock.c:18
BOOLEAN NTAPI KeInitSystem(VOID)
Definition: krnlinit.c:296
ULONG KiServiceLimit
Definition: krnlinit.c:26
LARGE_INTEGER KeBootTime
Definition: clock.c:17
PFN_COUNT MmNumberOfPhysicalPages
Definition: init.c:48
VOID NTAPI MmZeroPageThread(VOID)
Definition: zeropage.c:36
BOOLEAN NTAPI MmInitSystem(IN ULONG Phase, IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: mminit.c:202
VOID NTAPI RtlInitializeRangeListPackage(VOID)
Definition: libsupp.c:62
BOOLEAN NTAPI SeInitSystem(VOID)
Main security manager initialization function.
Definition: semgr.c:285
PSECURITY_DESCRIPTOR SePublicDefaultUnrestrictedSd
Definition: sd.c:17
BOOLEAN NTAPI SeRmInitPhase1(VOID)
Manages the phase 1 initialization of the security reference monitoring module of the kernel.
Definition: srm.c:211
#define MAX_WIN32_PATH
Definition: ntoskrnl.h:119
#define IDB_MAX_RESOURCE
Definition: resource.h:46
ULONG KeMaximumIncrement
Definition: clock.c:20
HANDLE NTAPI PsGetCurrentProcessId(VOID)
Definition: process.c:1123
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
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
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
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 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
NTSTRSAFEAPI RtlStringCbCopyA(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PSTR pszDest, _In_ size_t cbDest, _In_ NTSTRSAFE_PCSTR pszSrc)
Definition: ntstrsafe.h:156
#define L(x)
Definition: ntvdm.h:50
#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
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
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
unsigned short USHORT
Definition: pedump.c:61
static ULONG Timeout
Definition: ping.c:61
static PCWSTR TargetName
Definition: ping.c:67
BOOLEAN NTAPI PoInitSystem(IN ULONG BootPhase)
Definition: power.c:397
VOID NTAPI PoNotifySystemTimeSet(VOID)
Definition: events.c:39
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:624
VOID NTAPI ExpInitializePushLocks(VOID)
Definition: pushlock.c:45
BOOLEAN NTAPI HalQueryRealTimeClock(IN PTIME_FIELDS Time)
Definition: rtc.c:24
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
PVOID MmHighestUserAddress
Definition: rtlcompat.c:29
#define REG_DWORD
Definition: sdbapi.c:596
_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:130
@ LoaderFree
Definition: arc.h:129
@ LoaderFirmwareTemporary
Definition: arc.h:132
@ LoaderNlsData
Definition: arc.h:148
enum _TYPE_OF_MEMORY TYPE_OF_MEMORY
#define SharedUserData
NTSTATUS NTAPI MmMapViewInSystemSpace(IN PVOID SectionObject, OUT PVOID *MappedBase, IN OUT PSIZE_T ViewSize)
Definition: section.c:4348
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:3918
POBJECT_TYPE MmSectionObjectType
Definition: section.c:195
BOOLEAN NTAPI ExpInitializeSemaphoreImplementation(VOID)
Definition: sem.c:43
#define SETUPLDR_REMOTE_BOOT
Definition: setupblk.h:8
#define SETUPLDR_TEXT_MODE
Definition: setupblk.h:7
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
UNICODE_STRING DosPath
Definition: rtltypes.h:1368
RTL_USER_PROCESS_INFORMATION ProcessInfo
Definition: init.c:38
CHAR VersionBuffer[256]
Definition: init.c:35
CHAR VersionNumber[24]
Definition: init.c:37
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 * Blink
Definition: typedefs.h:122
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
LIST_ENTRY LoadOrderListHead
Definition: arc.h:493
TYPE_OF_MEMORY MemoryType
Definition: arc.h:193
Definition: rtltypes.h:1896
UCHAR Text[ANYSIZE_ARRAY]
Definition: rtltypes.h:1899
PVOID UnicodeCodePageData
Definition: arc.h:278
PVOID AnsiCodePageData
Definition: arc.h:276
PVOID OemCodePageData
Definition: arc.h:277
UNICODE_STRING CommandLine
Definition: btrfs_drv.h:1902
UNICODE_STRING ImagePathName
Definition: btrfs_drv.h:1901
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define TAG_RTLI
Definition: tag.h:28
#define TAG_INIT
Definition: tag.h:27
KPRIORITY NTAPI KeSetPriorityThread(IN PKTHREAD Thread, IN KPRIORITY Priority)
Definition: thrdobj.c:1327
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
uint16_t * PWSTR
Definition: typedefs.h:56
#define MAXULONG
Definition: typedefs.h:251
#define NTAPI
Definition: typedefs.h:36
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define IN
Definition: typedefs.h:39
uint16_t * PWCHAR
Definition: typedefs.h:56
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
char * PCHAR
Definition: typedefs.h:51
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
__analysis_noreturn NTSYSAPI VOID NTAPI DbgBreakPointWithStatus(_In_ ULONG Status)
short CSHORT
Definition: umtypes.h:127
LONGLONG QuadPart
Definition: typedefs.h:114
ULONG LowPart
Definition: typedefs.h:106
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING KeyName
Definition: wdfdevice.h:2699
BOOLEAN NTAPI ExpWin32kInit(VOID)
Definition: win32k.c:259
BOOLEAN SafeBoot
Definition: winldr.c:34
BOOLEAN SosEnabled
Definition: winldr.c:33
VOID NTAPI ExpInitializeWorkerThreads(VOID)
Definition: work.c:522
FORCEINLINE VOID ExInitializeFastMutex(_Out_ PFAST_MUTEX FastMutex)
Definition: exfuncs.h:274
#define PsGetCurrentProcess
Definition: psfuncs.h:17
VOID NTAPI XIPInit(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: xipdisp.c:55
__wchar_t WCHAR
Definition: xmlstorage.h:180
char CHAR
Definition: xmlstorage.h:175