ReactOS  0.4.15-dev-4570-g4f8bbd1
winldr.h File Reference
#include <arc/setupblk.h>
Include dependency graph for winldr.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _LOADER_SYSTEM_BLOCK
 

Macros

#define NUM_GDT   128
 
#define NUM_IDT   0x100
 
#define MAX_OPTIONS_LENGTH   255
 

Typedefs

typedef VOID(NTAPIKERNEL_ENTRY_POINT) (PLOADER_PARAMETER_BLOCK LoaderBlock)
 
typedef struct _LOADER_SYSTEM_BLOCK LOADER_SYSTEM_BLOCK
 
typedef struct _LOADER_SYSTEM_BLOCKPLOADER_SYSTEM_BLOCK
 

Functions

VOID ConvertConfigToVA (PCONFIGURATION_COMPONENT_DATA Start)
 
FORCEINLINE VOID UiResetForSOS (VOID)
 
VOID NtLdrOutputLoadMsg (_In_ PCSTR FileName, _In_opt_ PCSTR Description)
 
PVOID WinLdrLoadModule (PCSTR ModuleName, PULONG Size, TYPE_OF_MEMORY MemoryType)
 
BOOLEAN WinLdrSetupMemoryLayout (IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock)
 
BOOLEAN WinLdrInitSystemHive (IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock, IN PCSTR SystemRoot, IN BOOLEAN Setup)
 
BOOLEAN WinLdrScanSystemHive (IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock, IN PCSTR SystemRoot)
 
BOOLEAN WinLdrLoadNLSData (_Inout_ PLOADER_PARAMETER_BLOCK LoaderBlock, _In_ PCSTR DirectoryPath, _In_ PCUNICODE_STRING AnsiFileName, _In_ PCUNICODE_STRING OemFileName, _In_ PCUNICODE_STRING LangFileName, _In_ PCUNICODE_STRING OemHalFileName)
 
BOOLEAN WinLdrAddDriverToList (_Inout_ PLIST_ENTRY DriverListHead, _In_ BOOLEAN InsertAtHead, _In_ PCWSTR DriverName, _In_opt_ PCWSTR ImagePath, _In_opt_ PCWSTR GroupName, _In_ ULONG ErrorControl, _In_ ULONG Tag)
 Inserts the specified driver entry into the driver list, or updates an existing entry with new ImagePath, ErrorControl, Group and Tag values. More...
 
VOID WinLdrInitializePhase1 (PLOADER_PARAMETER_BLOCK LoaderBlock, PCSTR Options, PCSTR SystemPath, PCSTR BootPath, USHORT VersionToBoot)
 
VOID WinLdrpDumpMemoryDescriptors (PLOADER_PARAMETER_BLOCK LoaderBlock)
 
VOID WinLdrpDumpBootDriver (PLOADER_PARAMETER_BLOCK LoaderBlock)
 
VOID WinLdrpDumpArcDisks (PLOADER_PARAMETER_BLOCK LoaderBlock)
 
ARC_STATUS LoadAndBootWindowsCommon (IN USHORT OperatingSystemVersion, IN PLOADER_PARAMETER_BLOCK LoaderBlock, IN PCSTR BootOptions, IN PCSTR BootPath)
 
VOID WinLdrSetupMachineDependent (PLOADER_PARAMETER_BLOCK LoaderBlock)
 
VOID WinLdrSetProcessorContext (VOID)
 
BOOLEAN MempSetupPaging (IN PFN_NUMBER StartPage, IN PFN_NUMBER NumberOfPages, IN BOOLEAN KernelMapping)
 
VOID MempUnmapPage (PFN_NUMBER Page)
 
VOID MempDump (VOID)
 

Variables

PLOADER_SYSTEM_BLOCK WinLdrSystemBlock
 
PCWSTR BootFileSystem
 
BOOLEAN SosEnabled
 

Macro Definition Documentation

◆ MAX_OPTIONS_LENGTH

#define MAX_OPTIONS_LENGTH   255

Definition at line 44 of file winldr.h.

◆ NUM_GDT

#define NUM_GDT   128

Definition at line 16 of file winldr.h.

◆ NUM_IDT

#define NUM_IDT   0x100

Definition at line 17 of file winldr.h.

Typedef Documentation

◆ KERNEL_ENTRY_POINT

typedef VOID(NTAPI * KERNEL_ENTRY_POINT) (PLOADER_PARAMETER_BLOCK LoaderBlock)

Definition at line 13 of file winldr.h.

◆ LOADER_SYSTEM_BLOCK

◆ PLOADER_SYSTEM_BLOCK

Function Documentation

◆ ConvertConfigToVA()

VOID ConvertConfigToVA ( PCONFIGURATION_COMPONENT_DATA  Start)

Definition at line 51 of file conversion.c.

52 {
55 
56  TRACE("ConvertConfigToVA(Start 0x%X)\n", Start);
57  Child = Start;
58 
59  while (Child != NULL)
60  {
61  if (Child->ConfigurationData)
62  Child->ConfigurationData = PaToVa(Child->ConfigurationData);
63 
64  if (Child->Child)
65  Child->Child = PaToVa(Child->Child);
66 
67  if (Child->Parent)
68  Child->Parent = PaToVa(Child->Parent);
69 
70  if (Child->Sibling)
71  Child->Sibling = PaToVa(Child->Sibling);
72 
73  if (Child->ComponentEntry.Identifier)
74  Child->ComponentEntry.Identifier = PaToVa(Child->ComponentEntry.Identifier);
75 
76  TRACE("Device 0x%X class %d type %d id '%s', parent %p\n", Child,
77  Child->ComponentEntry.Class, Child->ComponentEntry.Type, VaToPa(Child->ComponentEntry.Identifier), Child->Parent);
78 
79  // Go through siblings list
80  Sibling = VaToPa(Child->Sibling);
81  while (Sibling != NULL)
82  {
83  if (Sibling->ConfigurationData)
84  Sibling->ConfigurationData = PaToVa(Sibling->ConfigurationData);
85 
86  if (Sibling->Child)
87  Sibling->Child = PaToVa(Sibling->Child);
88 
89  if (Sibling->Parent)
90  Sibling->Parent = PaToVa(Sibling->Parent);
91 
92  if (Sibling->Sibling)
93  Sibling->Sibling = PaToVa(Sibling->Sibling);
94 
95  if (Sibling->ComponentEntry.Identifier)
97 
98  TRACE("Device 0x%X class %d type %d id '%s', parent %p\n", Sibling,
99  Sibling->ComponentEntry.Class, Sibling->ComponentEntry.Type, VaToPa(Sibling->ComponentEntry.Identifier), Sibling->Parent);
100 
101  // Recurse into the Child tree
102  if (VaToPa(Sibling->Child) != NULL)
103  ConvertConfigToVA(VaToPa(Sibling->Child));
104 
105  Sibling = VaToPa(Sibling->Sibling);
106  }
107 
108  // Go to the next child
109  Child = VaToPa(Child->Child);
110  }
111 }
struct _CONFIGURATION_COMPONENT_DATA * Parent
Definition: arc.h:118
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFDEVICE Child
Definition: wdffdo.h:533
struct _CONFIGURATION_COMPONENT_DATA * Child
Definition: arc.h:119
CONFIGURATION_TYPE Type
Definition: arc.h:105
#define TRACE(s)
Definition: solgame.cpp:4
CONFIGURATION_CLASS Class
Definition: arc.h:104
Definition: partlist.h:33
CONFIGURATION_COMPONENT ComponentEntry
Definition: arc.h:121
struct _CONFIGURATION_COMPONENT_DATA * Sibling
Definition: arc.h:120
#define NULL
Definition: types.h:112
VOID ConvertConfigToVA(PCONFIGURATION_COMPONENT_DATA Start)
Definition: conversion.c:51
FORCEINLINE PVOID PaToVa(PVOID Pa)
Definition: conversion.h:22
FORCEINLINE PVOID VaToPa(PVOID Va)
Definition: conversion.h:15

Referenced by ConvertConfigToVA(), and WinLdrInitializePhase1().

◆ LoadAndBootWindowsCommon()

ARC_STATUS LoadAndBootWindowsCommon ( IN USHORT  OperatingSystemVersion,
IN PLOADER_PARAMETER_BLOCK  LoaderBlock,
IN PCSTR  BootOptions,
IN PCSTR  BootPath 
)

Definition at line 1150 of file winldr.c.

1155 {
1156  PLOADER_PARAMETER_BLOCK LoaderBlockVA;
1157  BOOLEAN Success;
1158  PLDR_DATA_TABLE_ENTRY KernelDTE;
1160  PCSTR SystemRoot;
1161 
1162  TRACE("LoadAndBootWindowsCommon()\n");
1163 
1164  ASSERT(OperatingSystemVersion != 0);
1165 
1166 #ifdef _M_IX86
1167  /* Setup redirection support */
1169 #endif
1170 
1171  /* Convert BootPath to SystemRoot */
1172  SystemRoot = strstr(BootPath, "\\");
1173 
1174  /* Detect hardware */
1175  UiUpdateProgressBar(20, "Detecting hardware...");
1176  LoaderBlock->ConfigurationRoot = MachHwDetect();
1177 
1178  /* Initialize the PE loader import-DLL callback, so that we can obtain
1179  * feedback (for example during SOS) on the PE images that get loaded. */
1181 
1182  /* Load the operating system core: the Kernel, the HAL and the Kernel Debugger Transport DLL */
1183  Success = LoadWindowsCore(OperatingSystemVersion,
1184  LoaderBlock,
1185  BootOptions,
1186  BootPath,
1187  &KernelDTE);
1188  if (!Success)
1189  {
1190  /* Reset the PE loader import-DLL callback */
1192 
1193  UiMessageBox("Error loading NTOS core.");
1194  return ENOEXEC;
1195  }
1196 
1197  /* Cleanup INI file */
1198  IniCleanup();
1199 
1200 /****
1201  **** WE HAVE NOW REACHED THE POINT OF NO RETURN !!
1202  ****/
1203 
1204  UiSetProgressBarSubset(40, 90); // NTOS goes from 25 to 75%
1205 
1206  /* Load boot drivers */
1207  UiSetProgressBarText("Loading boot drivers...");
1208  Success = WinLdrLoadBootDrivers(LoaderBlock, BootPath);
1209  TRACE("Boot drivers loading %s\n", Success ? "successful" : "failed");
1210 
1211  UiSetProgressBarSubset(0, 100);
1212 
1213  /* Reset the PE loader import-DLL callback */
1215 
1216  /* Initialize Phase 1 - no drivers loading anymore */
1217  WinLdrInitializePhase1(LoaderBlock,
1218  BootOptions,
1219  SystemRoot,
1220  BootPath,
1221  OperatingSystemVersion);
1222 
1223  UiUpdateProgressBar(100, NULL);
1224 
1225  /* Save entry-point pointer and Loader block VAs */
1227  LoaderBlockVA = PaToVa(LoaderBlock);
1228 
1229  /* "Stop all motors", change videomode */
1231 
1232  /* Debugging... */
1233  //DumpMemoryAllocMap();
1234 
1235  /* Do the machine specific initialization */
1236  WinLdrSetupMachineDependent(LoaderBlock);
1237 
1238  /* Map pages and create memory descriptors */
1239  WinLdrSetupMemoryLayout(LoaderBlock);
1240 
1241  /* Set processor context */
1243 
1244  /* Save final value of LoaderPagesSpanned */
1245  LoaderBlock->Extension->LoaderPagesSpanned = LoaderPagesSpanned;
1246 
1247  TRACE("Hello from paged mode, KiSystemStartup %p, LoaderBlockVA %p!\n",
1248  KiSystemStartup, LoaderBlockVA);
1249 
1250  /* Zero KI_USER_SHARED_DATA page */
1251  RtlZeroMemory((PVOID)KI_USER_SHARED_DATA, MM_PAGE_SIZE);
1252 
1253  WinLdrpDumpMemoryDescriptors(LoaderBlockVA);
1254  WinLdrpDumpBootDriver(LoaderBlockVA);
1255 #ifndef _M_AMD64
1256  WinLdrpDumpArcDisks(LoaderBlockVA);
1257 #endif
1258 
1259  /* Pass control */
1260  (*KiSystemStartup)(LoaderBlockVA);
1261 
1262  UNREACHABLE; // return ESUCCESS;
1263 }
VOID UiUpdateProgressBar(_In_ ULONG Percentage, _In_opt_ PCSTR ProgressText)
Definition: ui.c:462
#define MachHwDetect()
Definition: machine.h:136
VOID(NTAPI * KERNEL_ENTRY_POINT)(PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: winldr.h:13
BOOLEAN WinLdrLoadBootDrivers(PLOADER_PARAMETER_BLOCK LoaderBlock, PCSTR BootPath)
Definition: winldr.c:364
VOID WinLdrpDumpArcDisks(PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: winldr.c:1304
VOID UiSetProgressBarSubset(_In_ ULONG Floor, _In_ ULONG Ceiling)
Definition: ui.c:447
VOID WinLdrSetProcessorContext(void)
Definition: winldr.c:348
char * strstr(char *String1, char *String2)
Definition: utclib.c:653
static BOOLEAN LoadWindowsCore(IN USHORT OperatingSystemVersion, IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock, IN PCSTR BootOptions, IN PCSTR BootPath, IN OUT PLDR_DATA_TABLE_ENTRY *KernelDTE)
Definition: winldr.c:603
static VOID NTAPI NtLdrImportDllLoadCallback(_In_ PCSTR FileName)
Definition: winldr.c:47
BOOLEAN WinLdrSetupMemoryLayout(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: wlmemory.c:181
PVOID EntryPoint
Definition: ntddk_ex.h:203
VOID UiMessageBox(PCSTR Format,...)
Definition: ui.c:363
unsigned char BOOLEAN
void WinLdrSetupMachineDependent(PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: winldr.c:379
VOID WinLdrpDumpBootDriver(PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: winldr.c:1285
#define TRACE(s)
Definition: solgame.cpp:4
#define ASSERT(a)
Definition: mode.c:44
static const WCHAR SystemRoot[]
Definition: reg.c:38
PELDR_IMPORTDLL_LOAD_CALLBACK PeLdrImportDllLoadCallback
Definition: peloader.c:28
ULONG LoaderPagesSpanned
Definition: mm.c:29
VOID IniCleanup(VOID)
Definition: inifile.c:235
VOID UiSetProgressBarText(_In_ PCSTR ProgressText)
Definition: ui.c:488
#define KI_USER_SHARED_DATA
#define MachPrepareForReactOS()
Definition: machine.h:120
Definition: btrfs_drv.h:1866
VOID WinLdrpDumpMemoryDescriptors(PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: winldr.c:1266
VOID WinLdrSetupEms(IN PCSTR BootOptions)
Definition: headless.c:302
VOID WinLdrInitializePhase1(PLOADER_PARAMETER_BLOCK LoaderBlock, PCSTR Options, PCSTR SystemRoot, PCSTR BootPath, USHORT VersionToBoot)
Definition: winldr.c:117
#define NULL
Definition: types.h:112
DECLSPEC_NORETURN VOID NTAPI KiSystemStartup(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: kiinit.c:372
FORCEINLINE PVOID PaToVa(PVOID Pa)
Definition: conversion.h:22
#define UNREACHABLE
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
Definition: arc.h:47
const char * PCSTR
Definition: typedefs.h:52

Referenced by LoadAndBootWindows(), and LoadReactOSSetup().

◆ MempDump()

VOID MempDump ( VOID  )

Definition at line 429 of file winldr.c.

430 {
431 }

Referenced by WinLdrSetupMemoryLayout().

◆ MempSetupPaging()

BOOLEAN MempSetupPaging ( IN PFN_NUMBER  StartPage,
IN PFN_NUMBER  NumberOfPages,
IN BOOLEAN  KernelMapping 
)

Definition at line 170 of file winldr.c.

173 {
174  TRACE(">>> MempSetupPaging(0x%lx, %ld, %p)\n",
175  StartPage, NumberOfPages, StartPage * PAGE_SIZE + KSEG0_BASE);
176 
177  /* Identity mapping */
180  NumberOfPages) != NumberOfPages)
181  {
182  ERR("Failed to map pages %ld, %ld\n",
183  StartPage, NumberOfPages);
184  return FALSE;
185  }
186 
187  /* Kernel mapping */
188  if (KernelMapping)
189  {
192  NumberOfPages) != NumberOfPages)
193  {
194  ERR("Failed to map pages %ld, %ld\n",
195  StartPage, NumberOfPages);
196  return FALSE;
197  }
198  }
199 
200  return TRUE;
201 }
#define TRUE
Definition: types.h:120
int WINAPI StartPage(_In_ HDC)
#define FALSE
Definition: types.h:117
#define KSEG0_BASE
Definition: ketypes.h:278
static PFN_NUMBER MempMapRangeOfPages(ULONG64 VirtualAddress, ULONG64 PhysicalAddress, PFN_NUMBER cPages)
Definition: winldr.c:151
#define TRACE(s)
Definition: solgame.cpp:4
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define ERR(fmt,...)
Definition: debug.h:110

Referenced by MempSetupPagingForRegion(), and WinLdrSetupMemoryLayout().

◆ MempUnmapPage()

VOID MempUnmapPage ( PFN_NUMBER  Page)

Definition at line 204 of file winldr.c.

205 {
206  // TRACE(">>> MempUnmapPage\n");
207 }

◆ NtLdrOutputLoadMsg()

VOID NtLdrOutputLoadMsg ( _In_ PCSTR  FileName,
_In_opt_ PCSTR  Description 
)

Definition at line 54 of file winldr.c.

57 {
58  if (SosEnabled)
59  {
60  printf(" %s\n", FileName);
61  TRACE("Loading: %s\n", FileName);
62  }
63  else
64  {
65  /* Inform the user we load a file */
66  CHAR ProgressString[256];
67 
68  RtlStringCbPrintfA(ProgressString, sizeof(ProgressString),
69  "Loading %s...",
71  // UiSetProgressBarText(ProgressString);
72  // UiIndicateProgress();
73  UiDrawStatusText(ProgressString);
74  }
75 }
BOOLEAN SosEnabled
Definition: winldr.c:33
char CHAR
Definition: xmlstorage.h:175
static const WCHAR Description[]
Definition: oid.c:1266
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 TRACE(s)
Definition: solgame.cpp:4
#define printf
Definition: freeldr.h:94
VOID UiDrawStatusText(PCSTR StatusText)
Definition: ui.c:292

Referenced by LoadModule(), NtLdrImportDllLoadCallback(), WinLdrLoadDeviceDriver(), WinLdrLoadModule(), WinLdrLoadNLSData(), and WinLdrLoadSystemHive().

◆ UiResetForSOS()

FORCEINLINE VOID UiResetForSOS ( VOID  )

Definition at line 83 of file winldr.h.

84 {
85 #ifdef _M_ARM
86  /* Re-initialize the UI */
88 #else
89  /* Reset the UI and switch to MiniTui */
93 #endif
94  /* Disable the progress bar */
96 }
const UIVTBL MiniTuiVtbl
Definition: minitui.c:249
#define TRUE
Definition: types.h:120
UIVTBL UiVtbl
Definition: ui.c:70
#define FALSE
Definition: types.h:117
BOOLEAN(* Initialize)(VOID)
Definition: ui.h:247
BOOLEAN Show
Definition: ui.h:129
BOOLEAN UiInitialize(BOOLEAN ShowUi)
Definition: ui.c:98
VOID(* UnInitialize)(VOID)
Definition: ui.h:248
UI_PROGRESS_BAR UiProgressBar
Definition: ui.c:66

Referenced by LoadAndBootWindows(), and LoadReactOSSetup().

◆ WinLdrAddDriverToList()

BOOLEAN WinLdrAddDriverToList ( _Inout_ PLIST_ENTRY  DriverListHead,
_In_ BOOLEAN  InsertAtHead,
_In_ PCWSTR  DriverName,
_In_opt_ PCWSTR  ImagePath,
_In_opt_ PCWSTR  GroupName,
_In_ ULONG  ErrorControl,
_In_ ULONG  Tag 
)

Inserts the specified driver entry into the driver list, or updates an existing entry with new ImagePath, ErrorControl, Group and Tag values.

Parameters
[in,out]DriverListHeadThe driver list where to insert the driver entry.
[in]InsertAtHeadWhether to insert the driver at the head (TRUE) or at the tail (FALSE) of the driver list.
[in]DriverNameThe driver's name.
[in]ImagePathOptional path the the driver's image. If none is specified, a default path is constructed out of the driver's name.
[in]GroupNameOptional driver group name.
[in]ErrorControl
[in]TagThe ErrorControl and group Tag values for the driver.
Returns
TRUE if the driver has been inserted into the list or updated, FALSE if not.

Definition at line 575 of file wlregistry.c.

583 {
584  PBOOT_DRIVER_NODE DriverNode;
586  BOOLEAN AlreadyInserted;
588  UNICODE_STRING DriverNameU;
590  UNICODE_STRING FilePath = {0};
591  UNICODE_STRING RegistryString = {0};
592  UNICODE_STRING GroupString = {0};
593 
594  /* Check whether the driver is already in the list */
595  RtlInitUnicodeString(&DriverNameU, DriverName);
596  AlreadyInserted = CmpIsDriverInList(DriverListHead,
597  &DriverNameU,
598  &DriverNode);
599  if (AlreadyInserted)
600  {
601  /* If so, we have obtained its node */
602  ASSERT(DriverNode);
603  DriverEntry = &DriverNode->ListEntry;
604  }
605  else
606  {
607  /* Allocate a driver node and initialize it */
608  DriverNode = CmpAllocate(sizeof(BOOT_DRIVER_NODE), FALSE, TAG_CM);
609  if (!DriverNode)
610  return FALSE;
611 
612  RtlZeroMemory(DriverNode, sizeof(BOOT_DRIVER_NODE));
613  DriverEntry = &DriverNode->ListEntry;
614 
615  /* Driver Name */
616  RtlInitEmptyUnicodeString(&DriverNode->Name,
617  CmpAllocate(DriverNameU.Length, FALSE, TAG_CM),
618  DriverNameU.Length);
619  if (!DriverNode->Name.Buffer)
620  goto Failure;
621 
622  if (!NT_SUCCESS(RtlAppendUnicodeStringToString(&DriverNode->Name, &DriverNameU)))
623  goto Failure;
624  }
625 
626  /* Check whether we have a valid ImagePath. If not, we need
627  * to build it like "System32\\Drivers\\blah.sys" */
628  if (ImagePath && *ImagePath)
629  {
630  /* Just copy ImagePath to the corresponding field in the structure */
631  PathLength = (USHORT)(wcslen(ImagePath)) * sizeof(WCHAR);
632  RtlInitEmptyUnicodeString(&FilePath,
634  PathLength);
635  if (!FilePath.Buffer)
636  goto Failure;
637 
638  if (!NT_SUCCESS(RtlAppendUnicodeToString(&FilePath, ImagePath)))
639  goto Failure;
640  }
641  else
642  {
643  /* We have to construct ImagePath ourselves */
644  PathLength = DriverNode->Name.Length + sizeof(L"system32\\drivers\\.sys");
645  RtlInitEmptyUnicodeString(&FilePath,
647  PathLength);
648  if (!FilePath.Buffer)
649  goto Failure;
650 
651  if (!NT_SUCCESS(RtlAppendUnicodeToString(&FilePath, L"system32\\drivers\\")) ||
654  {
655  goto Failure;
656  }
657  }
658 
659  /* Registry path */
661  L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\");
662  PathLength = RegistryPath.Length + DriverNode->Name.Length;
663  RtlInitEmptyUnicodeString(&RegistryString,
665  PathLength);
666  if (!RegistryString.Buffer)
667  goto Failure;
668 
669  if (!NT_SUCCESS(RtlAppendUnicodeStringToString(&RegistryString, &RegistryPath)) ||
670  !NT_SUCCESS(RtlAppendUnicodeStringToString(&RegistryString, &DriverNode->Name)))
671  {
672  goto Failure;
673  }
674 
675  /* Group */
676  if (GroupName && *GroupName)
677  {
678  /*
679  * NOTE: Here we can use our own allocator as we alone maintain the
680  * group string. This is different from the other allocated strings,
681  * where we instead need to use the same (hive) allocator as the
682  * one used by CmpAddDriverToList(), for interoperability purposes.
683  */
684  RtlCreateUnicodeString(&GroupString, GroupName);
685  if (!GroupString.Buffer)
686  goto Failure;
687  }
688  else
689  {
690  RtlInitEmptyUnicodeString(&GroupString, NULL, 0);
691  }
692 
693  /* Set or replace the driver node's file path */
694  if (DriverEntry->FilePath.Buffer)
695  {
696  CmpFree(DriverEntry->FilePath.Buffer,
697  DriverEntry->FilePath.MaximumLength);
698  }
699  DriverEntry->FilePath = FilePath;
700  FilePath.Buffer = NULL;
701 
702  /* Set or replace the driver node's registry path */
703  if (DriverEntry->RegistryPath.Buffer)
704  {
705  CmpFree(DriverEntry->RegistryPath.Buffer,
706  DriverEntry->RegistryPath.MaximumLength);
707  }
708  DriverEntry->RegistryPath = RegistryString;
709  RegistryString.Buffer = NULL;
710 
711  /* Set or replace the driver node's group */
712  if (DriverNode->Group.Buffer)
713  {
714  /*
715  * If the buffer is inside the registry hive's memory, this means that
716  * it has been set by CmpAddDriverToList() to point to some data within
717  * the hive; thus we should not free the buffer but just replace it.
718  * Otherwise, this is a buffer previously allocated by ourselves, that
719  * we can free.
720  *
721  * NOTE: This function does not have an explicit LoaderBlock input
722  * parameter pointer, since it does not need it, except for this
723  * very place. So instead, use the global WinLdrSystemBlock pointer.
724  */
725  PLOADER_PARAMETER_BLOCK LoaderBlock =
727 
728  if (!LoaderBlock || !LoaderBlock->RegistryBase || !LoaderBlock->RegistryLength ||
729  ((ULONG_PTR)DriverNode->Group.Buffer <
730  (ULONG_PTR)VaToPa(LoaderBlock->RegistryBase)) ||
731  ((ULONG_PTR)DriverNode->Group.Buffer >=
732  (ULONG_PTR)VaToPa(LoaderBlock->RegistryBase) + LoaderBlock->RegistryLength))
733  {
734  RtlFreeUnicodeString(&DriverNode->Group);
735  }
736  }
737  DriverNode->Group = GroupString;
738  GroupString.Buffer = NULL;
739 
740  /* ErrorControl and Tag */
741  DriverNode->ErrorControl = ErrorControl;
742  DriverNode->Tag = Tag;
743 
744  /* Insert the entry into the list if it does not exist there already */
745  if (!AlreadyInserted)
746  {
747  if (InsertAtHead)
748  InsertHeadList(DriverListHead, &DriverEntry->Link);
749  else
750  InsertTailList(DriverListHead, &DriverEntry->Link);
751  }
752 
753  return TRUE;
754 
755 Failure:
756  if (GroupString.Buffer)
757  RtlFreeUnicodeString(&GroupString);
758  if (RegistryString.Buffer)
759  CmpFree(RegistryString.Buffer, RegistryString.MaximumLength);
760  if (FilePath.Buffer)
761  CmpFree(FilePath.Buffer, FilePath.MaximumLength);
762 
763  /* If it does not exist in the list already, free the allocated
764  * driver node, otherwise keep the original one in place. */
765  if (!AlreadyInserted)
766  {
767  if (DriverEntry->RegistryPath.Buffer)
768  {
769  CmpFree(DriverEntry->RegistryPath.Buffer,
770  DriverEntry->RegistryPath.MaximumLength);
771  }
772  if (DriverEntry->FilePath.Buffer)
773  {
774  CmpFree(DriverEntry->FilePath.Buffer,
775  DriverEntry->FilePath.MaximumLength);
776  }
777  if (DriverNode->Name.Buffer)
778  {
779  CmpFree(DriverNode->Name.Buffer,
780  DriverNode->Name.MaximumLength);
781  }
782  CmpFree(DriverNode, sizeof(BOOT_DRIVER_NODE));
783  }
784 
785  return FALSE;
786 }
BOOT_DRIVER_LIST_ENTRY ListEntry
Definition: cmboot.h:15
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define TRUE
Definition: types.h:120
FORCEINLINE VOID InsertHeadList(_Inout_ PLIST_ENTRY ListHead, _Inout_ __drv_aliasesMem PLIST_ENTRY Entry)
Definition: rtlfuncs.h:201
ULONG ErrorControl
Definition: cmboot.h:19
PVOID NTAPI CmpAllocate(_In_ SIZE_T Size, _In_ BOOLEAN Paged, _In_ ULONG Tag)
Definition: bootreg.c:90
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:213
#define InsertTailList(ListHead, Entry)
static USHORT PathLength
PCWSTR FilePath
uint32_t ULONG_PTR
Definition: typedefs.h:65
Definition: arc.h:198
#define L(x)
Definition: ntvdm.h:50
#define FALSE
Definition: types.h:117
unsigned char BOOLEAN
LOADER_PARAMETER_BLOCK LoaderBlock
Definition: winldr.h:48
NTSTATUS RtlAppendUnicodeToString(IN PUNICODE_STRING Str1, IN PWSTR Str2)
Definition: string_lib.cpp:62
#define TAG_WLDR_NAME
Definition: winldr.h:15
UNICODE_STRING Name
Definition: cmboot.h:17
#define ASSERT(a)
Definition: mode.c:44
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
VOID NTAPI CmpFree(_In_ PVOID Ptr, _In_ ULONG Quota)
Definition: bootreg.c:105
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
#define TAG_CM
Definition: cmlib.h:205
NTSYSAPI BOOLEAN NTAPI RtlCreateUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
_Must_inspect_result_ _In_ WDFDEVICE _In_ BOOLEAN _In_opt_ PVOID Tag
Definition: wdfdevice.h:4061
UNICODE_STRING Group
Definition: cmboot.h:16
DRIVER_INITIALIZE DriverEntry
Definition: condrv.c:21
unsigned short USHORT
Definition: pedump.c:61
NTSYSAPI NTSTATUS NTAPI RtlAppendUnicodeStringToString(PUNICODE_STRING Destination, PUNICODE_STRING Source)
#define NULL
Definition: types.h:112
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define ULONG_PTR
Definition: config.h:101
FORCEINLINE PVOID VaToPa(PVOID Va)
Definition: conversion.h:15
ULONG RegistryLength
Definition: arc.h:500
PLOADER_SYSTEM_BLOCK WinLdrSystemBlock
Definition: winldr.c:29

Referenced by SetupLdrScanBootDrivers().

◆ WinLdrInitializePhase1()

VOID WinLdrInitializePhase1 ( PLOADER_PARAMETER_BLOCK  LoaderBlock,
PCSTR  Options,
PCSTR  SystemPath,
PCSTR  BootPath,
USHORT  VersionToBoot 
)

Definition at line 117 of file winldr.c.

122 {
123  /*
124  * Examples of correct options and paths:
125  * CHAR Options[] = "/DEBUGPORT=COM1 /BAUDRATE=115200";
126  * CHAR Options[] = "/NODEBUG";
127  * CHAR SystemRoot[] = "\\WINNT\\";
128  * CHAR ArcBoot[] = "multi(0)disk(0)rdisk(0)partition(1)";
129  */
130 
131  PSTR LoadOptions, NewLoadOptions;
132  CHAR HalPath[] = "\\";
133  CHAR ArcBoot[MAX_PATH+1];
134  CHAR MiscFiles[MAX_PATH+1];
135  ULONG i;
136  ULONG_PTR PathSeparator;
138 
139  /* Construct SystemRoot and ArcBoot from SystemPath */
140  PathSeparator = strstr(BootPath, "\\") - BootPath;
141  RtlStringCbCopyNA(ArcBoot, sizeof(ArcBoot), BootPath, PathSeparator);
142 
143  TRACE("ArcBoot: '%s'\n", ArcBoot);
144  TRACE("SystemRoot: '%s'\n", SystemRoot);
145  TRACE("Options: '%s'\n", Options);
146 
147  /* Fill ARC BootDevice */
150  LoaderBlock->ArcBootDeviceName = PaToVa(LoaderBlock->ArcBootDeviceName);
151 
152 //
153 // IMPROVE!!
154 // SetupBlock->ArcSetupDeviceName must be the path to the setup **SOURCE**,
155 // and not the setup boot path. Indeed they may differ!!
156 //
157  if (LoaderBlock->SetupLdrBlock)
158  {
159  PSETUP_LOADER_BLOCK SetupBlock = LoaderBlock->SetupLdrBlock;
160 
161  /* Adjust the ARC path in the setup block - Matches ArcBoot path */
163  SetupBlock->ArcSetupDeviceName = PaToVa(SetupBlock->ArcSetupDeviceName);
164 
165  /* Convert the setup block pointer */
166  LoaderBlock->SetupLdrBlock = PaToVa(LoaderBlock->SetupLdrBlock);
167  }
168 
169  /* Fill ARC HalDevice, it matches ArcBoot path */
171  LoaderBlock->ArcHalDeviceName = PaToVa(LoaderBlock->ArcHalDeviceName);
172 
173  /* Fill SystemRoot */
176  LoaderBlock->NtBootPathName = PaToVa(LoaderBlock->NtBootPathName);
177 
178  /* Fill NtHalPathName */
180  RtlStringCbCopyA(LoaderBlock->NtHalPathName, sizeof(WinLdrSystemBlock->NtHalPathName), HalPath);
181  LoaderBlock->NtHalPathName = PaToVa(LoaderBlock->NtHalPathName);
182 
183  /* Fill LoadOptions and strip the '/' switch symbol in front of each option */
184  NewLoadOptions = LoadOptions = LoaderBlock->LoadOptions = WinLdrSystemBlock->LoadOptions;
186 
187  do
188  {
189  while (*LoadOptions == '/')
190  ++LoadOptions;
191 
192  *NewLoadOptions++ = *LoadOptions;
193  } while (*LoadOptions++);
194 
195  LoaderBlock->LoadOptions = PaToVa(LoaderBlock->LoadOptions);
196 
197  /* ARC devices */
200 
201  /* Convert ARC disk information from freeldr to a correct format */
202  for (i = 0; i < reactos_disk_count; i++)
203  {
204  PARC_DISK_SIGNATURE_EX ArcDiskSig;
205 
206  /* Allocate the ARC structure */
207  ArcDiskSig = FrLdrHeapAlloc(sizeof(ARC_DISK_SIGNATURE_EX), 'giSD');
208  if (!ArcDiskSig)
209  {
210  ERR("Failed to allocate ARC structure! Ignoring remaining ARC disks. (i = %lu, DiskCount = %lu)\n",
212  break;
213  }
214 
215  /* Copy the data over */
217 
218  /* Set the ARC Name pointer */
219  ArcDiskSig->DiskSignature.ArcName = PaToVa(ArcDiskSig->ArcName);
220 
221  /* Insert into the list */
223  &ArcDiskSig->DiskSignature.ListEntry);
224  }
225 
226  /* Convert all lists to Virtual address */
227 
228  /* Convert the ArcDisks list to virtual address */
230  LoaderBlock->ArcDiskInformation = PaToVa(LoaderBlock->ArcDiskInformation);
231 
232  /* Convert configuration entries to VA */
233  ConvertConfigToVA(LoaderBlock->ConfigurationRoot);
234  LoaderBlock->ConfigurationRoot = PaToVa(LoaderBlock->ConfigurationRoot);
235 
236  /* Convert all DTE into virtual addresses */
237  List_PaToVa(&LoaderBlock->LoadOrderListHead);
238 
239  /* This one will be converted right before switching to virtual paging mode */
240  //List_PaToVa(&LoaderBlock->MemoryDescriptorListHead);
241 
242  /* Convert list of boot drivers */
243  List_PaToVa(&LoaderBlock->BootDriverListHead);
244 
245  Extension = LoaderBlock->Extension;
246 
247  /* FIXME! HACK value for docking profile */
248  Extension->Profile.Status = 2;
249 
250  /* Check if FreeLdr detected a ACPI table */
251  if (AcpiPresent)
252  {
253  /* Set the pointer to something for compatibility */
254  Extension->AcpiTable = (PVOID)1;
255  // FIXME: Extension->AcpiTableSize;
256  }
257 
258 #ifdef _M_IX86
259  /* Set headless block pointer */
261  {
262  Extension->HeadlessLoaderBlock = &WinLdrSystemBlock->HeadlessLoaderBlock;
263  RtlCopyMemory(Extension->HeadlessLoaderBlock,
265  sizeof(HEADLESS_LOADER_BLOCK));
266  Extension->HeadlessLoaderBlock = PaToVa(Extension->HeadlessLoaderBlock);
267  }
268 #endif
269  /* Load drivers database */
270  RtlStringCbCopyA(MiscFiles, sizeof(MiscFiles), BootPath);
271  RtlStringCbCatA(MiscFiles, sizeof(MiscFiles), "AppPatch\\drvmain.sdb");
272  Extension->DrvDBImage = PaToVa(WinLdrLoadModule(MiscFiles,
273  &Extension->DrvDBSize,
275 
276  /* Convert the extension block pointer */
277  LoaderBlock->Extension = PaToVa(LoaderBlock->Extension);
278 
279  TRACE("WinLdrInitializePhase1() completed\n");
280 }
NTSTRSAFEAPI RtlStringCbCopyNA(_Out_writes_bytes_(cbDest) NTSTRSAFE_PSTR pszDest, _In_ size_t cbDest, _In_reads_bytes_(cbToCopy) STRSAFE_LPCSTR pszSrc, _In_ size_t cbToCopy)
Definition: ntstrsafe.h:395
PSTR ArcBootDeviceName
Definition: arc.h:503
ARC_DISK_INFORMATION ArcDiskInformation
Definition: winldr.h:60
ARC_DISK_SIGNATURE_EX reactos_arc_disk_info[]
Definition: archwsup.c:21
PCHAR ArcName
Definition: arc.h:210
VOID List_PaToVa(_In_ LIST_ENTRY *ListEntry)
char * strstr(char *String1, char *String2)
Definition: utclib.c:653
PLOADER_PARAMETER_EXTENSION Extension
Definition: arc.h:512
PCONFIGURATION_COMPONENT_DATA ConfigurationRoot
Definition: arc.h:502
char CHAR
Definition: xmlstorage.h:175
BOOLEAN WinLdrTerminalConnected
Definition: headless.c:31
HEADLESS_LOADER_BLOCK LoaderRedirectionInformation
Definition: headless.c:30
#define InsertTailList(ListHead, Entry)
CHAR ArcBootDeviceName[MAX_PATH+1]
Definition: winldr.h:56
uint32_t ULONG_PTR
Definition: typedefs.h:65
NTSTRSAFEAPI RtlStringCbCopyA(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PSTR pszDest, _In_ size_t cbDest, _In_ NTSTRSAFE_PCSTR pszSrc)
Definition: ntstrsafe.h:156
struct _SETUP_LOADER_BLOCK * SetupLdrBlock
Definition: arc.h:511
void * PVOID
Definition: retypes.h:9
FORCEINLINE PVOID FrLdrHeapAlloc(SIZE_T MemorySize, ULONG Tag)
Definition: mm.h:174
#define TRACE(s)
Definition: solgame.cpp:4
_In_ PWDFDEVICE_INIT _In_ PWDF_REMOVE_LOCK_OPTIONS Options
Definition: wdfdevice.h:3531
LIST_ENTRY ListEntry
Definition: arc.h:208
static const WCHAR SystemRoot[]
Definition: reg.c:38
CHAR ArcName[MAX_PATH]
Definition: winldr.h:37
#define MAX_PATH
Definition: compat.h:34
PARC_DISK_INFORMATION ArcDiskInformation
Definition: arc.h:509
LIST_ENTRY BootDriverListHead
Definition: arc.h:495
ULONG reactos_disk_count
Definition: archwsup.c:20
ARC_DISK_SIGNATURE DiskSignature
Definition: winldr.h:36
BOOLEAN AcpiPresent
Definition: macharm.c:21
CHAR LoadOptions[MAX_OPTIONS_LENGTH+1]
Definition: winldr.h:55
CHAR NtHalPathName[MAX_PATH+1]
Definition: winldr.h:59
LIST_ENTRY LoadOrderListHead
Definition: arc.h:493
#define ERR(fmt,...)
Definition: debug.h:110
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
PVOID WinLdrLoadModule(PCSTR ModuleName, PULONG Size, TYPE_OF_MEMORY MemoryType)
Definition: winldr.c:425
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
signed char * PSTR
Definition: retypes.h:7
VOID ConvertConfigToVA(PCONFIGURATION_COMPONENT_DATA Start)
Definition: conversion.c:51
FORCEINLINE PVOID PaToVa(PVOID Pa)
Definition: conversion.h:22
LIST_ENTRY DiskSignatureListHead
Definition: arc.h:221
PCHAR ArcSetupDeviceName
Definition: setupblk.h:112
unsigned int ULONG
Definition: retypes.h:1
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
CHAR NtBootPathName[MAX_PATH+1]
Definition: winldr.h:58
_Inout_opt_ PUNICODE_STRING Extension
Definition: fltkernel.h:1092
PLOADER_SYSTEM_BLOCK WinLdrSystemBlock
Definition: winldr.c:29
NTSTRSAFEAPI RtlStringCbCatA(_Inout_updates_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PSTR pszDest, _In_ size_t cbDest, _In_ NTSTRSAFE_PCSTR pszSrc)
Definition: ntstrsafe.h:625

Referenced by LoadAndBootWindowsCommon().

◆ WinLdrInitSystemHive()

BOOLEAN WinLdrInitSystemHive ( IN OUT PLOADER_PARAMETER_BLOCK  LoaderBlock,
IN PCSTR  SystemRoot,
IN BOOLEAN  Setup 
)

Definition at line 110 of file wlregistry.c.

114 {
115  CHAR SearchPath[1024];
116  PCSTR HiveName;
118 
119  if (Setup)
120  {
122  HiveName = "SETUPREG.HIV";
123  }
124  else
125  {
126  // There is a simple logic here: try to load usual hive (system), if it
127  // fails, then give system.alt a try, and finally try a system.sav
128 
129  // FIXME: For now we only try system
131  RtlStringCbCatA(SearchPath, sizeof(SearchPath), "system32\\config\\");
132  HiveName = "SYSTEM";
133  }
134 
135  TRACE("WinLdrInitSystemHive: loading hive %s%s\n", SearchPath, HiveName);
136  Success = WinLdrLoadSystemHive(LoaderBlock, SearchPath, HiveName);
137  if (!Success)
138  {
139  UiMessageBox("Could not load %s hive!", HiveName);
140  return FALSE;
141  }
142 
143  /* Import what was loaded */
144  Success = RegImportBinaryHive(VaToPa(LoaderBlock->RegistryBase), LoaderBlock->RegistryLength);
145  if (!Success)
146  {
147  UiMessageBox("Importing binary hive failed!");
148  return FALSE;
149  }
150 
151  /* Initialize the 'CurrentControlSet' link */
153  {
154  UiMessageBox("Initializing CurrentControlSet link failed!");
155  return FALSE;
156  }
157 
158  return TRUE;
159 }
ACPI_PHYSICAL_ADDRESS ACPI_SIZE BOOLEAN Warn BOOLEAN Physical UINT32 ACPI_TABLE_HEADER *OutTableHeader ACPI_TABLE_HEADER **OutTable ACPI_HANDLE UINT32 ACPI_WALK_CALLBACK ACPI_WALK_CALLBACK void void **ReturnValue UINT32 ACPI_BUFFER *RetPathPtr ACPI_OBJECT_HANDLER void *Data ACPI_OBJECT_HANDLER void **Data ACPI_STRING ACPI_OBJECT_LIST ACPI_BUFFER *ReturnObjectBuffer ACPI_DEVICE_INFO **ReturnBuffer ACPI_HANDLE ACPI_HANDLE ACPI_HANDLE *OutHandle ACPI_HANDLE *OutHandle void *Context void *Context ACPI_EVENT_HANDLER Handler UINT32 UINT32 ACPI_GPE_HANDLER void *Context UINT32 ACPI_NOTIFY_HANDLER void *Context ACPI_ADR_SPACE_TYPE ACPI_ADR_SPACE_HANDLER ACPI_ADR_SPACE_SETUP Setup
Definition: acpixf.h:828
#define TRUE
Definition: types.h:120
BOOLEAN RegImportBinaryHive(_In_ PVOID ChunkBase, _In_ ULONG ChunkSize)
Definition: registry.c:66
char CHAR
Definition: xmlstorage.h:175
BOOLEAN RegInitCurrentControlSet(_In_ BOOLEAN LastKnownGood)
Definition: registry.c:112
#define SearchPath
Definition: winbase.h:3761
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 FALSE
Definition: types.h:117
VOID UiMessageBox(PCSTR Format,...)
Definition: ui.c:363
unsigned char BOOLEAN
#define TRACE(s)
Definition: solgame.cpp:4
static const WCHAR SystemRoot[]
Definition: reg.c:38
static BOOLEAN WinLdrLoadSystemHive(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock, IN PCSTR DirectoryPath, IN PCSTR HiveName)
Definition: wlregistry.c:38
FORCEINLINE PVOID VaToPa(PVOID Va)
Definition: conversion.h:15
const char * PCSTR
Definition: typedefs.h:52
NTSTRSAFEAPI RtlStringCbCatA(_Inout_updates_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PSTR pszDest, _In_ size_t cbDest, _In_ NTSTRSAFE_PCSTR pszSrc)
Definition: ntstrsafe.h:625

Referenced by LoadAndBootWindows(), and LoadReactOSSetup().

◆ WinLdrLoadModule()

PVOID WinLdrLoadModule ( PCSTR  ModuleName,
PULONG  Size,
TYPE_OF_MEMORY  MemoryType 
)

Definition at line 425 of file winldr.c.

428 {
429  ULONG FileId;
430  PVOID PhysicalBase;
432  ULONG FileSize;
435 
436  *Size = 0;
437 
438  /* Open the image file */
440  Status = ArcOpen((PSTR)ModuleName, OpenReadOnly, &FileId);
441  if (Status != ESUCCESS)
442  {
443  /* In case of errors, we just return, without complaining to the user */
444  WARN("Error while opening '%s', Status: %u\n", ModuleName, Status);
445  return NULL;
446  }
447 
448  /* Retrieve its size */
450  if (Status != ESUCCESS)
451  {
452  ArcClose(FileId);
453  return NULL;
454  }
455  FileSize = FileInfo.EndingAddress.LowPart;
456  *Size = FileSize;
457 
458  /* Allocate memory */
459  PhysicalBase = MmAllocateMemoryWithType(FileSize, MemoryType);
460  if (PhysicalBase == NULL)
461  {
462  ERR("Could not allocate memory for '%s'\n", ModuleName);
463  ArcClose(FileId);
464  return NULL;
465  }
466 
467  /* Load the whole file */
468  Status = ArcRead(FileId, PhysicalBase, FileSize, &BytesRead);
469  ArcClose(FileId);
470  if (Status != ESUCCESS)
471  {
472  WARN("Error while reading '%s', Status: %u\n", ModuleName, Status);
473  return NULL;
474  }
475 
476  TRACE("Loaded %s at 0x%x with size 0x%x\n", ModuleName, PhysicalBase, FileSize);
477 
478  return PhysicalBase;
479 }
Definition: arc.h:32
#define WARN(fmt,...)
Definition: debug.h:112
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
ULONG ARC_STATUS
Definition: arc.h:4
ACPI_BUFFER *RetBuffer ACPI_BUFFER *RetBuffer char ACPI_WALK_RESOURCE_CALLBACK void *Context ACPI_BUFFER *RetBuffer UINT16 ACPI_RESOURCE **ResourcePtr ACPI_GENERIC_ADDRESS *Reg UINT32 *ReturnValue UINT8 UINT8 *Slp_TypB ACPI_PHYSICAL_ADDRESS PhysicalAddress64 UINT32 UINT32 *TimeElapsed UINT32 ACPI_STATUS const char UINT32 ACPI_STATUS const char UINT32 const char const char * ModuleName
Definition: acpixf.h:1274
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PLONGLONG _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_opt_ PULONG_PTR BytesRead
Definition: wdfiotarget.h:859
Status
Definition: gdiplustypes.h:24
#define TRACE(s)
Definition: solgame.cpp:4
VOID NtLdrOutputLoadMsg(_In_ PCSTR FileName, _In_opt_ PCSTR Description)
Definition: winldr.c:54
ARC_STATUS ArcRead(ULONG FileId, VOID *Buffer, ULONG N, ULONG *Count)
Definition: fs.c:236
PVOID MmAllocateMemoryWithType(SIZE_T MemorySize, TYPE_OF_MEMORY MemoryType)
Definition: mm.c:31
_Must_inspect_result_ _Out_ PLARGE_INTEGER FileSize
Definition: fsrtlfuncs.h:108
#define ERR(fmt,...)
Definition: debug.h:110
signed char * PSTR
Definition: retypes.h:7
#define NULL
Definition: types.h:112
ARC_STATUS ArcClose(ULONG FileId)
Definition: fs.c:218
ARC_STATUS ArcGetFileInformation(ULONG FileId, FILEINFORMATION *Information)
Definition: fs.c:250
struct FileInfo FileInfo
ARC_STATUS ArcOpen(CHAR *Path, OPENMODE OpenMode, ULONG *FileId)
Definition: fs.c:56
unsigned int ULONG
Definition: retypes.h:1

Referenced by SetupLdrInitErrataInf(), WinLdrInitErrataInf(), and WinLdrInitializePhase1().

◆ WinLdrLoadNLSData()

BOOLEAN WinLdrLoadNLSData ( _Inout_ PLOADER_PARAMETER_BLOCK  LoaderBlock,
_In_ PCSTR  DirectoryPath,
_In_ PCUNICODE_STRING  AnsiFileName,
_In_ PCUNICODE_STRING  OemFileName,
_In_ PCUNICODE_STRING  LangFileName,
_In_ PCUNICODE_STRING  OemHalFileName 
)

Definition at line 336 of file wlregistry.c.

343 {
346  ULONG AnsiFileId = -1, OemFileId = -1, LangFileId = -1;
347  ULONG AnsiFileSize, OemFileSize, LangFileSize;
348  ULONG TotalSize;
350  PVOID NlsDataBase, NlsVirtual;
351  BOOLEAN AnsiEqualsOem = FALSE;
353 
354  /* There may be a case, where OEM and ANSI pages coincide */
355  if (RtlCompareUnicodeString(AnsiFileName, OemFileName, TRUE) == 0)
356  AnsiEqualsOem = TRUE;
357 
358  /* Open file with ANSI and store its size */
359  RtlStringCbPrintfA(FileName, sizeof(FileName), "%s%wZ",
360  DirectoryPath, AnsiFileName);
361  Status = ArcOpen(FileName, OpenReadOnly, &AnsiFileId);
362  if (Status != ESUCCESS)
363  {
364  WARN("Error while opening '%s', Status: %u\n", FileName, Status);
365  goto Quit;
366  }
367 
368  Status = ArcGetFileInformation(AnsiFileId, &FileInfo);
369  if (Status != ESUCCESS)
370  goto Quit;
371  AnsiFileSize = FileInfo.EndingAddress.LowPart;
372  TRACE("AnsiFileSize: %d\n", AnsiFileSize);
373 
374  /* Open OEM file and store its length */
375  if (AnsiEqualsOem)
376  {
377  OemFileSize = 0;
378  }
379  else
380  {
381  RtlStringCbPrintfA(FileName, sizeof(FileName), "%s%wZ",
382  DirectoryPath, OemFileName);
383  Status = ArcOpen(FileName, OpenReadOnly, &OemFileId);
384  if (Status != ESUCCESS)
385  {
386  WARN("Error while opening '%s', Status: %u\n", FileName, Status);
387  goto Quit;
388  }
389 
390  Status = ArcGetFileInformation(OemFileId, &FileInfo);
391  if (Status != ESUCCESS)
392  goto Quit;
393  OemFileSize = FileInfo.EndingAddress.LowPart;
394  }
395  TRACE("OemFileSize: %d\n", OemFileSize);
396 
397  /* Finally open the language codepage file and store its length */
398  RtlStringCbPrintfA(FileName, sizeof(FileName), "%s%wZ",
399  DirectoryPath, LangFileName);
400  Status = ArcOpen(FileName, OpenReadOnly, &LangFileId);
401  if (Status != ESUCCESS)
402  {
403  WARN("Error while opening '%s', Status: %u\n", FileName, Status);
404  goto Quit;
405  }
406 
407  Status = ArcGetFileInformation(LangFileId, &FileInfo);
408  if (Status != ESUCCESS)
409  goto Quit;
410  LangFileSize = FileInfo.EndingAddress.LowPart;
411  TRACE("LangFileSize: %d\n", LangFileSize);
412 
413  //
414  // TODO: The OEMHAL file.
415  //
416 
417  /* Sum up all three length, having in mind that every one of them
418  must start at a page boundary => thus round up each file to a page */
419  TotalSize = MM_SIZE_TO_PAGES(AnsiFileSize) +
420  MM_SIZE_TO_PAGES(OemFileSize) +
421  MM_SIZE_TO_PAGES(LangFileSize);
422 
423  /* Store it for later marking the pages as NlsData type */
424  TotalNLSSize = TotalSize;
425 
426  NlsDataBase = MmAllocateMemoryWithType(TotalSize*MM_PAGE_SIZE, LoaderNlsData);
427  if (NlsDataBase == NULL)
428  goto Quit;
429 
430  NlsVirtual = PaToVa(NlsDataBase);
431  LoaderBlock->NlsData->AnsiCodePageData = NlsVirtual;
432 
433  LoaderBlock->NlsData->OemCodePageData =
434  (PVOID)((ULONG_PTR)NlsVirtual +
435  (MM_SIZE_TO_PAGES(AnsiFileSize) << MM_PAGE_SHIFT));
436 
437  LoaderBlock->NlsData->UnicodeCodePageData =
438  (PVOID)((ULONG_PTR)NlsVirtual +
439  (MM_SIZE_TO_PAGES(AnsiFileSize) << MM_PAGE_SHIFT) +
440  (MM_SIZE_TO_PAGES(OemFileSize) << MM_PAGE_SHIFT));
441 
442  /* ANSI and OEM data are the same - just set pointers to the same area */
443  if (AnsiEqualsOem)
444  LoaderBlock->NlsData->OemCodePageData = LoaderBlock->NlsData->AnsiCodePageData;
445 
446  /* Now actually read the data into memory, starting with the ANSI file */
447  RtlStringCbPrintfA(FileName, sizeof(FileName), "%s%wZ",
448  DirectoryPath, AnsiFileName);
450  Status = ArcRead(AnsiFileId,
451  VaToPa(LoaderBlock->NlsData->AnsiCodePageData),
452  AnsiFileSize, &BytesRead);
453  if (Status != ESUCCESS)
454  {
455  WARN("Error while reading '%s', Status: %u\n", FileName, Status);
456  goto Quit;
457  }
458 
459  /* OEM now, if it isn't the same as the ANSI one */
460  if (!AnsiEqualsOem)
461  {
462  RtlStringCbPrintfA(FileName, sizeof(FileName), "%s%wZ",
463  DirectoryPath, OemFileName);
465  Status = ArcRead(OemFileId,
466  VaToPa(LoaderBlock->NlsData->OemCodePageData),
467  OemFileSize, &BytesRead);
468  if (Status != ESUCCESS)
469  {
470  WARN("Error while reading '%s', Status: %u\n", FileName, Status);
471  goto Quit;
472  }
473  }
474 
475  /* Finally the language file */
476  RtlStringCbPrintfA(FileName, sizeof(FileName), "%s%wZ",
477  DirectoryPath, LangFileName);
479  Status = ArcRead(LangFileId,
480  VaToPa(LoaderBlock->NlsData->UnicodeCodePageData),
481  LangFileSize, &BytesRead);
482  if (Status != ESUCCESS)
483  {
484  WARN("Error while reading '%s', Status: %u\n", FileName, Status);
485  goto Quit;
486  }
487 
488  //
489  // THIS IS a HACK and should be replaced by actually loading the OEMHAL file!
490  //
491  LoaderBlock->OemFontFile = VaToPa(LoaderBlock->NlsData->UnicodeCodePageData);
492 
493  /* Convert NlsTables address to VA */
494  LoaderBlock->NlsData = PaToVa(LoaderBlock->NlsData);
495 
496 Quit:
497  if (LangFileId != -1)
498  ArcClose(LangFileId);
499  if (OemFileId != -1)
500  ArcClose(OemFileId);
501  if (AnsiFileId != -1)
502  ArcClose(AnsiFileId);
503 
504  if (Status != ESUCCESS)
505  UiMessageBox("Error reading NLS file %s", FileName);
506 
507  return (Status == ESUCCESS);
508 }
Definition: arc.h:32
#define TRUE
Definition: types.h:120
char CHAR
Definition: xmlstorage.h:175
#define WARN(fmt,...)
Definition: debug.h:112
ULONG ARC_STATUS
Definition: arc.h:4
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PLONGLONG _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_opt_ PULONG_PTR BytesRead
Definition: wdfiotarget.h:859
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define FALSE
Definition: types.h:117
VOID UiMessageBox(PCSTR Format,...)
Definition: ui.c:363
unsigned char BOOLEAN
void * PVOID
Definition: retypes.h:9
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
Status
Definition: gdiplustypes.h:24
#define TRACE(s)
Definition: solgame.cpp:4
VOID NtLdrOutputLoadMsg(_In_ PCSTR FileName, _In_opt_ PCSTR Description)
Definition: winldr.c:54
#define MAX_PATH
Definition: compat.h:34
ARC_STATUS ArcRead(ULONG FileId, VOID *Buffer, ULONG N, ULONG *Count)
Definition: fs.c:236
ULONG RtlCompareUnicodeString(PUNICODE_STRING s1, PUNICODE_STRING s2, BOOLEAN UpCase)
Definition: string_lib.cpp:31
PVOID MmAllocateMemoryWithType(SIZE_T MemorySize, TYPE_OF_MEMORY MemoryType)
Definition: mm.c:31
ULONG TotalNLSSize
Definition: wlregistry.c:20
#define NULL
Definition: types.h:112
ARC_STATUS ArcClose(ULONG FileId)
Definition: fs.c:218
ARC_STATUS ArcGetFileInformation(ULONG FileId, FILEINFORMATION *Information)
Definition: fs.c:250
struct FileInfo FileInfo
FORCEINLINE PVOID PaToVa(PVOID Pa)
Definition: conversion.h:22
ARC_STATUS ArcOpen(CHAR *Path, OPENMODE OpenMode, ULONG *FileId)
Definition: fs.c:56
unsigned int ULONG
Definition: retypes.h:1
FORCEINLINE PVOID VaToPa(PVOID Va)
Definition: conversion.h:15

Referenced by SetupLdrLoadNlsData(), and WinLdrScanSystemHive().

◆ WinLdrpDumpArcDisks()

VOID WinLdrpDumpArcDisks ( PLOADER_PARAMETER_BLOCK  LoaderBlock)

Definition at line 1304 of file winldr.c.

1305 {
1306  PLIST_ENTRY NextBd;
1307  PARC_DISK_SIGNATURE ArcDisk;
1308 
1309  NextBd = LoaderBlock->ArcDiskInformation->DiskSignatureListHead.Flink;
1310 
1311  while (NextBd != &LoaderBlock->ArcDiskInformation->DiskSignatureListHead)
1312  {
1313  ArcDisk = CONTAINING_RECORD(NextBd, ARC_DISK_SIGNATURE, ListEntry);
1314 
1315  TRACE("ArcDisk %s checksum: 0x%X, signature: 0x%X\n",
1316  ArcDisk->ArcName, ArcDisk->CheckSum, ArcDisk->Signature);
1317 
1318  NextBd = ArcDisk->ListEntry.Flink;
1319  }
1320 }
PCHAR ArcName
Definition: arc.h:210
ULONG Signature
Definition: arc.h:209
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define TRACE(s)
Definition: solgame.cpp:4
LIST_ENTRY ListEntry
Definition: arc.h:208
PARC_DISK_INFORMATION ArcDiskInformation
Definition: arc.h:509
Definition: typedefs.h:119
LIST_ENTRY DiskSignatureListHead
Definition: arc.h:221
ULONG CheckSum
Definition: arc.h:211

Referenced by LoadAndBootWindowsCommon().

◆ WinLdrpDumpBootDriver()

VOID WinLdrpDumpBootDriver ( PLOADER_PARAMETER_BLOCK  LoaderBlock)

Definition at line 1285 of file winldr.c.

1286 {
1287  PLIST_ENTRY NextBd;
1288  PBOOT_DRIVER_LIST_ENTRY BootDriver;
1289 
1290  NextBd = LoaderBlock->BootDriverListHead.Flink;
1291 
1292  while (NextBd != &LoaderBlock->BootDriverListHead)
1293  {
1294  BootDriver = CONTAINING_RECORD(NextBd, BOOT_DRIVER_LIST_ENTRY, Link);
1295 
1296  TRACE("BootDriver %wZ DTE %08X RegPath: %wZ\n", &BootDriver->FilePath,
1297  BootDriver->LdrEntry, &BootDriver->RegistryPath);
1298 
1299  NextBd = BootDriver->Link.Flink;
1300  }
1301 }
UNICODE_STRING FilePath
Definition: arc.h:201
static int Link(const char **args)
Definition: vfdcmd.c:2414
Definition: arc.h:198
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define TRACE(s)
Definition: solgame.cpp:4
LIST_ENTRY BootDriverListHead
Definition: arc.h:495
Definition: typedefs.h:119
UNICODE_STRING RegistryPath
Definition: arc.h:202
struct _LDR_DATA_TABLE_ENTRY * LdrEntry
Definition: arc.h:203
LIST_ENTRY Link
Definition: arc.h:200

Referenced by LoadAndBootWindowsCommon().

◆ WinLdrpDumpMemoryDescriptors()

VOID WinLdrpDumpMemoryDescriptors ( PLOADER_PARAMETER_BLOCK  LoaderBlock)

Definition at line 1266 of file winldr.c.

1267 {
1268  PLIST_ENTRY NextMd;
1270 
1271  NextMd = LoaderBlock->MemoryDescriptorListHead.Flink;
1272 
1273  while (NextMd != &LoaderBlock->MemoryDescriptorListHead)
1274  {
1276 
1277  TRACE("BP %08X PC %04X MT %d\n", MemoryDescriptor->BasePage,
1278  MemoryDescriptor->PageCount, MemoryDescriptor->MemoryType);
1279 
1280  NextMd = MemoryDescriptor->ListEntry.Flink;
1281  }
1282 }
_Must_inspect_result_ _In_ WDFUSBDEVICE _In_opt_ WDFREQUEST _In_opt_ PWDF_REQUEST_SEND_OPTIONS _In_ PWDF_USB_CONTROL_SETUP_PACKET _In_opt_ PWDF_MEMORY_DESCRIPTOR MemoryDescriptor
Definition: wdfusb.h:1331
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define TRACE(s)
Definition: solgame.cpp:4
Definition: typedefs.h:119
LIST_ENTRY MemoryDescriptorListHead
Definition: arc.h:494

Referenced by LoadAndBootWindowsCommon(), and WinLdrSetupMemoryLayout().

◆ WinLdrScanSystemHive()

BOOLEAN WinLdrScanSystemHive ( IN OUT PLOADER_PARAMETER_BLOCK  LoaderBlock,
IN PCSTR  SystemRoot 
)

Definition at line 161 of file wlregistry.c.

163 {
165  DECLARE_UNICODE_STRING_SIZE(AnsiFileName, MAX_PATH);
167  DECLARE_UNICODE_STRING_SIZE(LangFileName, MAX_PATH); // CaseTable
168  DECLARE_UNICODE_STRING_SIZE(OemHalFileName, MAX_PATH);
169  CHAR SearchPath[1024];
170 
171  /* Scan registry and prepare boot drivers list */
172  Success = WinLdrScanRegistry(&LoaderBlock->BootDriverListHead);
173  if (!Success)
174  {
175  UiMessageBox("Failed to load boot drivers!");
176  return FALSE;
177  }
178 
179  /* Get names of NLS files */
181  &AnsiFileName,
182  &OemFileName,
183  &LangFileName,
184  &OemHalFileName);
185  if (!Success)
186  {
187  UiMessageBox("Getting NLS names from registry failed!");
188  return FALSE;
189  }
190 
191  TRACE("NLS data: '%wZ' '%wZ' '%wZ' '%wZ'\n",
192  &AnsiFileName, &OemFileName, &LangFileName, &OemHalFileName);
193 
194  /* Load NLS data */
196  RtlStringCbCatA(SearchPath, sizeof(SearchPath), "system32\\");
197  Success = WinLdrLoadNLSData(LoaderBlock,
198  SearchPath,
199  &AnsiFileName,
200  &OemFileName,
201  &LangFileName,
202  &OemHalFileName);
203  TRACE("NLS data loading %s\n", Success ? "successful" : "failed");
204 
205  return TRUE;
206 }
#define TRUE
Definition: types.h:120
char CHAR
Definition: xmlstorage.h:175
#define SearchPath
Definition: winbase.h:3761
NTSTRSAFEAPI RtlStringCbCopyA(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PSTR pszDest, _In_ size_t cbDest, _In_ NTSTRSAFE_PCSTR pszSrc)
Definition: ntstrsafe.h:156
HKEY CurrentControlSetKey
Definition: registry.c:33
#define FALSE
Definition: types.h:117
VOID UiMessageBox(PCSTR Format,...)
Definition: ui.c:363
unsigned char BOOLEAN
BOOLEAN WinLdrLoadNLSData(_Inout_ PLOADER_PARAMETER_BLOCK LoaderBlock, _In_ PCSTR DirectoryPath, _In_ PCUNICODE_STRING AnsiFileName, _In_ PCUNICODE_STRING OemFileName, _In_ PCUNICODE_STRING LangFileName, _In_ PCUNICODE_STRING OemHalFileName)
Definition: wlregistry.c:336
#define TRACE(s)
Definition: solgame.cpp:4
static const WCHAR SystemRoot[]
Definition: reg.c:38
#define MAX_PATH
Definition: compat.h:34
#define DECLARE_UNICODE_STRING_SIZE(_var, _size)
Definition: wdfcore.h:155
static BOOLEAN WinLdrScanRegistry(IN OUT PLIST_ENTRY BootDriverListHead)
Definition: wlregistry.c:511
static BOOLEAN WinLdrGetNLSNames(_In_ HKEY ControlSet, _Inout_ PUNICODE_STRING AnsiFileName, _Inout_ PUNICODE_STRING OemFileName, _Inout_ PUNICODE_STRING LangFileName, _Inout_ PUNICODE_STRING OemHalFileName)
Definition: wlregistry.c:213
NTSTRSAFEAPI RtlStringCbCatA(_Inout_updates_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PSTR pszDest, _In_ size_t cbDest, _In_ NTSTRSAFE_PCSTR pszSrc)
Definition: ntstrsafe.h:625

Referenced by LoadAndBootWindows().

◆ WinLdrSetProcessorContext()

VOID WinLdrSetProcessorContext ( VOID  )

Definition at line 348 of file winldr.c.

349 {
350  TRACE("WinLdrSetProcessorContext\n");
351 
352  /* Disable Interrupts */
353  _disable();
354 
355  /* Re-initialize EFLAGS */
356  __writeeflags(0);
357 
358  /* Set the new PML4 */
360 
361  /* Get kernel mode address of gdt / idt */
363 
364  /* Create gdt entries and load gdtr */
365  Amd64SetupGdt(GdtIdt, KSEG0_BASE | (TssBasePage << MM_PAGE_SHIFT));
366 
367  /* Copy old Idt and set idtr */
369 
370  /* LDT is unused */
371 // __lldt(0);
372 
373  /* Load TSR */
374  __ltr(KGDT64_SYS_TSS);
375 
376  TRACE("leave WinLdrSetProcessorContext\n");
377 }
static VOID Amd64SetupIdt(PVOID IdtBase)
Definition: winldr.c:325
static VOID Amd64SetupGdt(PVOID GdtBase, ULONG64 TssBase)
Definition: winldr.c:276
PHARDWARE_PTE PxeBase
Definition: winldr.c:22
__INTRIN_INLINE void __writecr3(unsigned int Data)
Definition: intrin_x86.h:1795
#define KSEG0_BASE
Definition: ketypes.h:278
ULONG_PTR TssBasePage
Definition: winldr.c:27
void * PVOID
Definition: retypes.h:9
#define TRACE(s)
Definition: solgame.cpp:4
unsigned __int64 ULONG64
Definition: imports.h:198
#define KGDT64_SYS_TSS
Definition: ketypes.h:77
__INTRIN_INLINE void __writeeflags(uintptr_t Value)
Definition: intrin_x86.h:1670
#define NUM_GDT
Definition: winldr.h:16
void __cdecl _disable(void)
Definition: intrin_arm.h:365
PVOID GdtIdt
Definition: winldr.c:25

Referenced by LoadAndBootWindowsCommon().

◆ WinLdrSetupMachineDependent()

VOID WinLdrSetupMachineDependent ( PLOADER_PARAMETER_BLOCK  LoaderBlock)

Definition at line 379 of file winldr.c.

380 {
381  ULONG_PTR Pcr = 0;
382  ULONG_PTR Tss = 0;
383  ULONG BlockSize, NumPages;
384 
385  LoaderBlock->u.I386.CommonDataArea = (PVOID)DbgPrint; // HACK
386  LoaderBlock->u.I386.MachineType = MACHINE_TYPE_ISA;
387 
388  /* Allocate 2 pages for PCR */
389  Pcr = (ULONG_PTR)MmAllocateMemoryWithType(2 * MM_PAGE_SIZE, LoaderStartupPcrPage);
390  PcrBasePage = Pcr >> MM_PAGE_SHIFT;
391  if (Pcr == 0)
392  {
393  UiMessageBox("Can't allocate PCR.");
394  return;
395  }
396  RtlZeroMemory((PVOID)Pcr, 2 * MM_PAGE_SIZE);
397 
398  /* Allocate TSS */
399  BlockSize = (sizeof(KTSS) + MM_PAGE_SIZE) & ~(MM_PAGE_SIZE - 1);
401  TssBasePage = Tss >> MM_PAGE_SHIFT;
402 
403  /* Allocate space for new GDT + IDT */
404  BlockSize = NUM_GDT * sizeof(KGDTENTRY) + NUM_IDT * sizeof(KIDTENTRY);
405  NumPages = (BlockSize + MM_PAGE_SIZE - 1) >> MM_PAGE_SHIFT;
406  GdtIdt = (PKGDTENTRY)MmAllocateMemoryWithType(NumPages * MM_PAGE_SIZE, LoaderMemoryData);
407  if (GdtIdt == NULL)
408  {
409  UiMessageBox("Can't allocate pages for GDT+IDT!");
410  return;
411  }
412 
413  /* Zero newly prepared GDT+IDT */
414  RtlZeroMemory(GdtIdt, NumPages << MM_PAGE_SHIFT);
415 
416  // Before we start mapping pages, create a block of memory, which will contain
417  // PDE and PTEs
418  if (MempAllocatePageTables() == FALSE)
419  {
420  // FIXME: bugcheck
421  }
422 
423  /* Map stuff like PCR, KI_USER_SHARED_DATA and Apic */
425 }
#define PKGDTENTRY
Definition: ketypes.h:443
#define KTSS
Definition: ketypes.h:925
#define DbgPrint
Definition: hal.h:12
ULONG_PTR PcrBasePage
Definition: winldr.c:26
#define KGDTENTRY
Definition: ketypes.h:442
static BOOLEAN WinLdrMapSpecialPages(VOID)
Definition: winldr.c:244
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define FALSE
Definition: types.h:117
VOID UiMessageBox(PCSTR Format,...)
Definition: ui.c:363
I386_LOADER_BLOCK I386
Definition: arc.h:515
ULONG_PTR TssBasePage
Definition: winldr.c:27
void * PVOID
Definition: retypes.h:9
ULONG MachineType
Definition: arc.h:407
#define MACHINE_TYPE_ISA
Definition: ketypes.h:52
#define NUM_IDT
Definition: winldr.h:17
PVOID MmAllocateMemoryWithType(SIZE_T MemorySize, TYPE_OF_MEMORY MemoryType)
Definition: mm.c:31
PVOID CommonDataArea
Definition: arc.h:406
#define NUM_GDT
Definition: winldr.h:16
#define NULL
Definition: types.h:112
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define ULONG_PTR
Definition: config.h:101
PVOID GdtIdt
Definition: winldr.c:25
static BOOLEAN MempAllocatePageTables(VOID)
Definition: winldr.c:33
union _LOADER_PARAMETER_BLOCK::@3299 u

Referenced by LoadAndBootWindowsCommon().

◆ WinLdrSetupMemoryLayout()

BOOLEAN WinLdrSetupMemoryLayout ( IN OUT PLOADER_PARAMETER_BLOCK  LoaderBlock)

Definition at line 181 of file wlmemory.c.

182 {
183  PFN_NUMBER i, PagesCount, MemoryMapSizeInPages, NoEntries;
184  PFN_NUMBER LastPageIndex, MemoryMapStartPage;
186  ULONG LastPageType;
187  //PKTSS Tss;
188  //BOOLEAN Status;
189 
190  /* Cleanup heap */
192 
193  //
194  // Creating a suitable memory map for Windows can be tricky, so let's
195  // give a few advices:
196  // 1) One must not map the whole available memory pages to PDE!
197  // Map only what's needed - 16Mb, 24Mb, 32Mb max I think,
198  // thus occupying 4, 6 or 8 PDE entries for identical mapping,
199  // the same quantity for KSEG0_BASE mapping, one more entry for
200  // hyperspace and one more entry for HAL physical pages mapping.
201  // 2) Memory descriptors must map *the whole* physical memory
202  // showing any memory above 16/24/32 as FirmwareTemporary
203  //
204  // 3) Overall memory blocks count must not exceed 30 (?? why?)
205  //
206 
207  //
208  // During MmInitMachineDependent, the kernel zeroes PDE at the following address
209  // 0xC0300000 - 0xC03007FC
210  //
211  // Then it finds the best place for non-paged pool:
212  // StartPde C0300F70, EndPde C0300FF8, NumberOfPages C13, NextPhysPage 3AD
213  //
214 
215  // Allocate memory for memory allocation descriptors
218 
219  // Setup an entry for each descriptor
220  MemoryMap = MmGetMemoryMap(&NoEntries);
221  if (MemoryMap == NULL)
222  {
223  UiMessageBox("Can not retrieve the current memory map.");
224  return FALSE;
225  }
226 
227  // Calculate parameters of the memory map
228  MemoryMapStartPage = (ULONG_PTR)MemoryMap >> MM_PAGE_SHIFT;
229  MemoryMapSizeInPages = (NoEntries * sizeof(PAGE_LOOKUP_TABLE_ITEM) + MM_PAGE_SIZE - 1) / MM_PAGE_SIZE;
230 
231  TRACE("Got memory map with %d entries\n", NoEntries);
232 #if 0
233  // Always contiguously map low 1Mb of memory
234  Status = MempSetupPaging(0, 0x100, FALSE);
235  if (!Status)
236  {
237  ERR("Error during MempSetupPaging of low 1Mb\n");
238  return FALSE;
239  }
240 #endif
241 
242  /* Before creating the map, we need to map pages to kernel mode */
243  LastPageIndex = 1;
244  LastPageType = MemoryMap[1].PageAllocated;
245  for (i = 2; i < NoEntries; i++)
246  {
247  if ((MemoryMap[i].PageAllocated != LastPageType) ||
248  (i == NoEntries - 1))
249  {
250  MempSetupPagingForRegion(LastPageIndex, i - LastPageIndex, LastPageType);
251  LastPageIndex = i;
252  LastPageType = MemoryMap[i].PageAllocated;
253  }
254  }
255 
256  // Construct a good memory map from what we've got,
257  // but mark entries which the memory allocation bitmap takes
258  // as free entries (this is done in order to have the ability
259  // to place mem alloc bitmap outside lower 16Mb zone)
260  PagesCount = 1;
261  LastPageIndex = 0;
262  LastPageType = MemoryMap[0].PageAllocated;
263  for (i = 1; i < NoEntries; i++)
264  {
265  // Check if its memory map itself
266  if (i >= MemoryMapStartPage &&
267  i < (MemoryMapStartPage+MemoryMapSizeInPages))
268  {
269  // Exclude it if current page belongs to the memory map
270  MemoryMap[i].PageAllocated = LoaderFree;
271  }
272 
273  // Process entry
274  if (MemoryMap[i].PageAllocated == LastPageType &&
275  (i != NoEntries-1) )
276  {
277  PagesCount++;
278  }
279  else
280  {
281  // Add the resulting region
282  MempAddMemoryBlock(LoaderBlock, LastPageIndex, PagesCount, LastPageType);
283 
284  // Reset our counter vars
285  LastPageIndex = i;
286  LastPageType = MemoryMap[i].PageAllocated;
287  PagesCount = 1;
288  }
289  }
290 
291  // TEMP, DEBUG!
292  // adding special reserved memory zones for vmware workstation
293 #if 0
294  {
295  Mad[MadCount].BasePage = 0xfec00;
296  Mad[MadCount].PageCount = 0x10;
298  WinLdrInsertDescriptor(LoaderBlock, &Mad[MadCount]);
299  MadCount++;
300 
301  Mad[MadCount].BasePage = 0xfee00;
302  Mad[MadCount].PageCount = 0x1;
304  WinLdrInsertDescriptor(LoaderBlock, &Mad[MadCount]);
305  MadCount++;
306 
307  Mad[MadCount].BasePage = 0xfffe0;
308  Mad[MadCount].PageCount = 0x20;
310  WinLdrInsertDescriptor(LoaderBlock, &Mad[MadCount]);
311  MadCount++;
312  }
313 #endif
314 
315  /* Now we need to add high descriptors from the bios memory map */
316  for (i = 0; i < BiosMemoryMapEntryCount; i++)
317  {
318  /* Check if its higher than the lookup table */
320  {
321  /* Copy this descriptor */
322  MempAddMemoryBlock(LoaderBlock,
326  }
327  }
328 
329  TRACE("MadCount: %d\n", MadCount);
330 
331  WinLdrpDumpMemoryDescriptors(LoaderBlock); //FIXME: Delete!
332 
333  // Map our loader image, so we can continue running
334  /*Status = MempSetupPaging(OsLoaderBase >> MM_PAGE_SHIFT, OsLoaderSize >> MM_PAGE_SHIFT);
335  if (!Status)
336  {
337  UiMessageBox("Error during MempSetupPaging.");
338  return;
339  }*/
340 
341  // Fill the memory descriptor list and
342  //PrepareMemoryDescriptorList();
343  TRACE("Memory Descriptor List prepared, printing PDE\n");
344  List_PaToVa(&LoaderBlock->MemoryDescriptorListHead);
345 
346 #if DBG
347  MempDump();
348 #endif
349 
350  return TRUE;
351 }
VOID MempDump(VOID)
Definition: winldr.c:429
PFN_NUMBER MmHighestPhysicalPage
Definition: meminit.c:31
ULONG MadCount
Definition: wlmemory.c:58
#define TRUE
Definition: types.h:120
VOID List_PaToVa(_In_ LIST_ENTRY *ListEntry)
BIOS_MEMORY_MAP MemoryMap[32]
Definition: loader.c:11
TYPE_OF_MEMORY MemoryType
Definition: mm.h:43
VOID MempSetupPagingForRegion(PFN_NUMBER BasePage, PFN_NUMBER PageCount, ULONG Type)
Definition: wlmemory.c:106
BOOLEAN MempSetupPaging(IN PFN_NUMBER StartPage, IN PFN_NUMBER NumberOfPages, IN BOOLEAN KernelMapping)
Definition: winldr.c:170
MEMORY_ALLOCATION_DESCRIPTOR * Mad
Definition: wlmemory.c:57
TYPE_OF_MEMORY MemoryType
Definition: arc.h:193
ULONG PFN_NUMBER
Definition: ke.h:9
#define FALSE
Definition: types.h:117
#define MAX_MAD_COUNT
Definition: wlmemory.c:60
VOID UiMessageBox(PCSTR Format,...)
Definition: ui.c:363
PFN_NUMBER BasePage
Definition: mm.h:44
ULONG BiosMemoryMapEntryCount
Definition: meminit.c:34
Status
Definition: gdiplustypes.h:24
#define TRACE(s)
Definition: solgame.cpp:4
PPAGE_LOOKUP_TABLE_ITEM MmGetMemoryMap(PFN_NUMBER *NoEntries)
Definition: mm.c:297
VOID FrLdrHeapCleanupAll(VOID)
Definition: heap.c:248
PFREELDR_MEMORY_DESCRIPTOR BiosMemoryMap
Definition: meminit.c:33
PVOID MmAllocateMemoryWithType(SIZE_T MemorySize, TYPE_OF_MEMORY MemoryType)
Definition: mm.c:31
VOID WinLdrpDumpMemoryDescriptors(PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: winldr.c:1266
VOID MempAddMemoryBlock(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock, PFN_NUMBER BasePage, PFN_NUMBER PageCount, ULONG Type)
Definition: wlmemory.c:65
#define ERR(fmt,...)
Definition: debug.h:110
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
#define NULL
Definition: types.h:112
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
static VOID WinLdrInsertDescriptor(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock, IN PMEMORY_ALLOCATION_DESCRIPTOR NewDescriptor)
Definition: wlmemory.c:356
PFN_NUMBER PageCount
Definition: mm.h:45

Referenced by LoadAndBootWindowsCommon().

Variable Documentation

◆ BootFileSystem

PCWSTR BootFileSystem

◆ SosEnabled

◆ WinLdrSystemBlock