ReactOS  0.4.13-dev-455-g28ed234
winldr.h File Reference
#include <arc/setupblk.h>
#include <pshpack1.h>
#include <poppack.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  RSDP_DESCRIPTOR
 
struct  _ARC_DISK_SIGNATURE_EX
 

Macros

#define TAG_WLDR_DTE   'eDlW'
 
#define TAG_WLDR_BDE   'dBlW'
 
#define TAG_WLDR_NAME   'mNlW'
 
#define SECTOR_SIZE   512
 
#define NUM_GDT   128
 
#define NUM_IDT   0x100
 

Typedefs

typedef struct RSDP_DESCRIPTORPRSDP_DESCRIPTOR
 
typedef struct _ARC_DISK_SIGNATURE_EX ARC_DISK_SIGNATURE_EX
 
typedef struct _ARC_DISK_SIGNATURE_EXPARC_DISK_SIGNATURE_EX
 

Functions

VOID LoadAndBootWindows (IN OperatingSystemItem *OperatingSystem, IN USHORT OperatingSystemVersion)
 
VOID LoadReactOSSetup (IN OperatingSystemItem *OperatingSystem, IN USHORT OperatingSystemVersion)
 
PVOID VaToPa (PVOID Va)
 
PVOID PaToVa (PVOID Pa)
 
VOID List_PaToVa (_In_ LIST_ENTRY *ListEntry)
 
BOOLEAN WinLdrLoadImage (IN PCHAR FileName, TYPE_OF_MEMORY MemoryType, OUT PVOID *ImageBasePA)
 
BOOLEAN WinLdrAllocateDataTableEntry (IN OUT PLIST_ENTRY ModuleListHead, IN PCCH BaseDllName, IN PCCH FullDllName, IN PVOID BasePA, OUT PLDR_DATA_TABLE_ENTRY *NewEntry)
 
BOOLEAN WinLdrScanImportDescriptorTable (IN OUT PLIST_ENTRY ModuleListHead, IN PCCH DirectoryPath, IN PLDR_DATA_TABLE_ENTRY ScanDTE)
 
BOOLEAN WinLdrCheckForLoadedDll (IN OUT PLIST_ENTRY ModuleListHead, IN PCH DllName, OUT PLDR_DATA_TABLE_ENTRY *LoadedEntry)
 
BOOLEAN MempSetupPaging (IN PFN_NUMBER StartPage, IN PFN_NUMBER NumberOfPages, IN BOOLEAN KernelMapping)
 
VOID MempUnmapPage (PFN_NUMBER Page)
 
VOID MempDump (VOID)
 
VOID WinLdrSetupMachineDependent (PLOADER_PARAMETER_BLOCK LoaderBlock)
 
VOID WinLdrSetProcessorContext (VOID)
 

Macro Definition Documentation

◆ NUM_GDT

#define NUM_GDT   128

Definition at line 37 of file winldr.h.

◆ NUM_IDT

#define NUM_IDT   0x100

Definition at line 38 of file winldr.h.

◆ SECTOR_SIZE

#define SECTOR_SIZE   512

Definition at line 34 of file winldr.h.

◆ TAG_WLDR_BDE

#define TAG_WLDR_BDE   'dBlW'

Definition at line 27 of file winldr.h.

◆ TAG_WLDR_DTE

#define TAG_WLDR_DTE   'eDlW'

Definition at line 26 of file winldr.h.

◆ TAG_WLDR_NAME

#define TAG_WLDR_NAME   'mNlW'

Definition at line 28 of file winldr.h.

Typedef Documentation

◆ ARC_DISK_SIGNATURE_EX

◆ PARC_DISK_SIGNATURE_EX

◆ PRSDP_DESCRIPTOR

Function Documentation

◆ List_PaToVa()

VOID List_PaToVa ( _In_ LIST_ENTRY ListEntry)

◆ LoadAndBootWindows()

VOID LoadAndBootWindows ( IN OperatingSystemItem OperatingSystem,
IN USHORT  OperatingSystemVersion 
)

Definition at line 650 of file winldr.c.

652 {
653  ULONG_PTR SectionId;
654  PCSTR SectionName = OperatingSystem->SystemPartition;
655  CHAR SettingsValue[80];
656  BOOLEAN HasSection;
659  CHAR BootOptions[256];
660  PCHAR File;
662  PLOADER_PARAMETER_BLOCK LoaderBlock;
663 
664  /* Get OS setting value */
665  SettingsValue[0] = ANSI_NULL;
666  IniOpenSection("Operating Systems", &SectionId);
667  IniReadSettingByName(SectionId, SectionName, SettingsValue, sizeof(SettingsValue));
668 
669  /* Open the operating system section specified in the .ini file */
670  HasSection = IniOpenSection(SectionName, &SectionId);
671 
672  UiDrawBackdrop();
673  UiDrawProgressBarCenter(1, 100, "Loading NT...");
674 
675  /* Read the system path is set in the .ini file */
676  if (!HasSection ||
677  !IniReadSettingByName(SectionId, "SystemPath", BootPath, sizeof(BootPath)))
678  {
679  strcpy(BootPath, SectionName);
680  }
681 
682  /*
683  * Check whether BootPath is a full path
684  * and if not, create a full boot path.
685  *
686  * See FsOpenFile for the technique used.
687  */
688  if (strrchr(BootPath, ')') == NULL)
689  {
690  /* Temporarily save the boot path */
692 
693  /* This is not a full path. Use the current (i.e. boot) device. */
695 
696  /* Append a path separator if needed */
697  if (FileName[0] != '\\' && FileName[0] != '/')
698  strcat(BootPath, "\\");
699 
700  /* Append the remaining path */
702  }
703 
704  /* Append a backslash if needed */
705  if ((BootPath[0] == 0) || BootPath[strlen(BootPath) - 1] != '\\')
706  strcat(BootPath, "\\");
707 
708  /* Read booting options */
709  if (!HasSection || !IniReadSettingByName(SectionId, "Options", BootOptions, sizeof(BootOptions)))
710  {
711  /* Get options after the title */
712  PCSTR p = SettingsValue;
713  while (*p == ' ' || *p == '"')
714  p++;
715  while (*p != '\0' && *p != '"')
716  p++;
717  strcpy(BootOptions, p);
718  TRACE("BootOptions: '%s'\n", BootOptions);
719  }
720 
721  /* Append boot-time options */
723 
724  /* Check if a ramdisk file was given */
725  File = strstr(BootOptions, "/RDPATH=");
726  if (File)
727  {
728  /* Copy the file name and everything else after it */
729  strcpy(FileName, File + 8);
730 
731  /* Null-terminate */
732  *strstr(FileName, " ") = ANSI_NULL;
733 
734  /* Load the ramdisk */
736  {
737  UiMessageBox("Failed to load RAM disk file %s", FileName);
738  return;
739  }
740  }
741 
742  /* Let user know we started loading */
743  //UiDrawStatusText("Loading...");
744 
745  TRACE("BootPath: '%s'\n", BootPath);
746 
747  /* Allocate and minimalist-initialize LPB */
748  AllocateAndInitLPB(&LoaderBlock);
749 
750  /* Load the system hive */
751  UiDrawBackdrop();
752  UiDrawProgressBarCenter(15, 100, "Loading system hive...");
753  Success = WinLdrInitSystemHive(LoaderBlock, BootPath, FALSE);
754  TRACE("SYSTEM hive %s\n", (Success ? "loaded" : "not loaded"));
755  /* Bail out if failure */
756  if (!Success)
757  return;
758 
759  /* Load NLS data, OEM font, and prepare boot drivers list */
760  Success = WinLdrScanSystemHive(LoaderBlock, BootPath);
761  TRACE("SYSTEM hive %s\n", (Success ? "scanned" : "not scanned"));
762  /* Bail out if failure */
763  if (!Success)
764  return;
765 
766  /* Finish loading */
768  LoaderBlock,
769  BootOptions,
770  BootPath,
771  FALSE);
772 }
VOID AllocateAndInitLPB(PLOADER_PARAMETER_BLOCK *OutLoaderBlock)
Definition: winldr.c:49
VOID AppendBootTimeOptions(PCHAR BootOptions)
Definition: options.c:244
signed char * PCHAR
Definition: retypes.h:7
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
BOOLEAN NTAPI RamDiskLoadVirtualFile(IN PCHAR FileName)
Definition: ramdisk.c:121
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char * strstr(char *String1, char *String2)
Definition: utclib.c:653
char CHAR
Definition: xmlstorage.h:175
_Check_return_ _CRTIMP _CONST_RETURN char *__cdecl strrchr(_In_z_ const char *_Str, _In_ int _Ch)
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define ANSI_NULL
_In_opt_ PVOID _In_ PCSTR File
Definition: iofuncs.h:615
VOID UiMessageBox(PCSTR Format,...)
Definition: ui.c:347
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
USHORT OperatingSystemVersion
Definition: bootmgr.c:35
BOOLEAN IniReadSettingByName(ULONG_PTR SectionId, PCSTR SettingName, PCHAR Buffer, ULONG BufferSize)
Definition: inifile.c:147
#define TRACE(s)
Definition: solgame.cpp:4
BOOLEAN IniOpenSection(PCSTR SectionName, ULONG_PTR *SectionId)
Definition: inifile.c:25
#define MAX_PATH
Definition: compat.h:26
VOID UiDrawBackdrop(VOID)
Definition: ui.c:241
#define MachDiskGetBootPath(Path, Size)
Definition: machine.h:118
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
VOID LoadAndBootWindowsCommon(USHORT OperatingSystemVersion, PLOADER_PARAMETER_BLOCK LoaderBlock, LPCSTR BootOptions, LPCSTR BootPath, BOOLEAN Setup)
Definition: winldr.c:775
const char * PCSTR
Definition: typedefs.h:51
Definition: File.h:15
GLfloat GLfloat p
Definition: glext.h:8902
BOOLEAN WinLdrInitSystemHive(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock, IN PCSTR SystemRoot, IN BOOLEAN Setup)
Definition: wlregistry.c:121
BOOLEAN WinLdrScanSystemHive(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock, IN LPCSTR DirectoryPath)
Definition: wlregistry.c:171
char BootPath[0x100]
Definition: mach.c:35
VOID UiDrawProgressBarCenter(ULONG Position, ULONG Range, PCHAR ProgressText)
Definition: ui.c:373

◆ LoadReactOSSetup()

VOID LoadReactOSSetup ( IN OperatingSystemItem OperatingSystem,
IN USHORT  OperatingSystemVersion 
)

Definition at line 140 of file setupldr.c.

142 {
143  ULONG_PTR SectionId;
144  PCSTR SectionName = OperatingSystem->SystemPartition;
145  CHAR SettingsValue[80];
146  BOOLEAN HasSection;
147  CHAR BootOptions2[256];
148  PCHAR File;
149  CHAR FileName[512];
150  CHAR BootPath[512];
151  LPCSTR LoadOptions;
153  BOOLEAN BootFromFloppy;
155  ULONG i, ErrorLine;
156  HINF InfHandle;
157  INFCONTEXT InfContext;
158  PLOADER_PARAMETER_BLOCK LoaderBlock;
159  PSETUP_LOADER_BLOCK SetupBlock;
160  LPCSTR SystemPath;
161  LPCSTR SourcePaths[] =
162  {
163  "", /* Only for floppy boot */
164 #if defined(_M_IX86)
165  "I386\\",
166 #elif defined(_M_MPPC)
167  "PPC\\",
168 #elif defined(_M_MRX000)
169  "MIPS\\",
170 #endif
171  "reactos\\",
172  NULL
173  };
174 
175  UiDrawStatusText("Setup is loading...");
176 
177  /* Get OS setting value */
178  SettingsValue[0] = ANSI_NULL;
179  IniOpenSection("Operating Systems", &SectionId);
180  IniReadSettingByName(SectionId, SectionName, SettingsValue, sizeof(SettingsValue));
181 
182  /* Open the operating system section specified in the .ini file */
183  HasSection = IniOpenSection(SectionName, &SectionId);
184 
185  UiDrawBackdrop();
186  UiDrawProgressBarCenter(1, 100, "Loading ReactOS Setup...");
187 
188  /* Read the system path is set in the .ini file */
189  if (!HasSection ||
190  !IniReadSettingByName(SectionId, "SystemPath", BootPath, sizeof(BootPath)))
191  {
192  /*
193  * IMPROVE: I don't want to call MachDiskGetBootPath here as a
194  * default choice because I can call it after (see few lines below).
195  * Also doing the strcpy call as it is done in winldr.c is not
196  * really what we want. Instead I reset BootPath here so that
197  * we can build the full path using the general code from below.
198  */
199  // MachDiskGetBootPath(BootPath, sizeof(BootPath));
200  // strcpy(BootPath, SectionName);
201  BootPath[0] = '\0';
202  }
203 
204  /*
205  * Check whether BootPath is a full path
206  * and if not, create a full boot path.
207  *
208  * See FsOpenFile for the technique used.
209  */
210  if (strrchr(BootPath, ')') == NULL)
211  {
212  /* Temporarily save the boot path */
214 
215  /* This is not a full path. Use the current (i.e. boot) device. */
217 
218  /* Append a path separator if needed */
219  if (FileName[0] != '\\' && FileName[0] != '/')
220  strcat(BootPath, "\\");
221 
222  /* Append the remaining path */
224  }
225 
226  /* Append a backslash if needed */
227  if ((strlen(BootPath) == 0) || BootPath[strlen(BootPath) - 1] != '\\')
228  strcat(BootPath, "\\");
229 
230  /* Read booting options */
231  if (!HasSection || !IniReadSettingByName(SectionId, "Options", BootOptions2, sizeof(BootOptions2)))
232  {
233  /* Get options after the title */
234  PCSTR p = SettingsValue;
235  while (*p == ' ' || *p == '"')
236  p++;
237  while (*p != '\0' && *p != '"')
238  p++;
239  strcpy(BootOptions2, p);
240  TRACE("BootOptions: '%s'\n", BootOptions2);
241  }
242 
243  /* Check if a ramdisk file was given */
244  File = strstr(BootOptions2, "/RDPATH=");
245  if (File)
246  {
247  /* Copy the file name and everything else after it */
248  strcpy(FileName, File + 8);
249 
250  /* Null-terminate */
251  *strstr(FileName, " ") = ANSI_NULL;
252 
253  /* Load the ramdisk */
255  {
256  UiMessageBox("Failed to load RAM disk file %s", FileName);
257  return;
258  }
259  }
260 
261  TRACE("BootPath: '%s'\n", BootPath);
262 
263  /* And check if we booted from floppy */
264  BootFromFloppy = strstr(BootPath, "fdisk") != NULL;
265 
266  /* Open 'txtsetup.sif' from any of source paths */
268  for (i = BootFromFloppy ? 0 : 1; ; i++)
269  {
270  SystemPath = SourcePaths[i];
271  if (!SystemPath)
272  {
273  UiMessageBox("Failed to open txtsetup.sif");
274  return;
275  }
276  strcpy(File, SystemPath);
278  strcat(FileName, "txtsetup.sif");
279  if (InfOpenFile(&InfHandle, FileName, &ErrorLine))
280  {
281  break;
282  }
283  }
284 
285  TRACE("BootPath: '%s', SystemPath: '%s'\n", BootPath, SystemPath);
286 
287  /* Get Load options - debug and non-debug */
288  if (!InfFindFirstLine(InfHandle, "SetupData", "OsLoadOptions", &InfContext))
289  {
290  ERR("Failed to find 'SetupData/OsLoadOptions'\n");
291  return;
292  }
293 
294  if (!InfGetDataField(&InfContext, 1, &LoadOptions))
295  {
296  ERR("Failed to get load options\n");
297  return;
298  }
299 
300 #if DBG
301  /* Get debug load options and use them */
302  if (InfFindFirstLine(InfHandle, "SetupData", "DbgOsLoadOptions", &InfContext))
303  {
304  LPCSTR DbgLoadOptions;
305 
306  if (InfGetDataField(&InfContext, 1, &DbgLoadOptions))
307  LoadOptions = DbgLoadOptions;
308  }
309 #endif
310 
311  /* Copy loadoptions (original string will be freed) */
312  BootOptions = FrLdrTempAlloc(strlen(LoadOptions) + 1, TAG_BOOT_OPTIONS);
313  strcpy(BootOptions, LoadOptions);
314 
315  TRACE("BootOptions: '%s'\n", BootOptions);
316 
317  /* Allocate and minimalist-initialize LPB */
318  AllocateAndInitLPB(&LoaderBlock);
319 
320  /* Allocate and initialize setup loader block */
321  SetupBlock = &WinLdrSystemBlock->SetupBlock;
322  LoaderBlock->SetupLdrBlock = SetupBlock;
323 
324  /* Set textmode setup flag */
325  SetupBlock->Flags = SETUPLDR_TEXT_MODE;
326 
327  /* Load the system hive "setupreg.hiv" for setup */
328  UiDrawBackdrop();
329  UiDrawProgressBarCenter(15, 100, "Loading setup system hive...");
330  Success = WinLdrInitSystemHive(LoaderBlock, BootPath, TRUE);
331  TRACE("Setup SYSTEM hive %s\n", (Success ? "loaded" : "not loaded"));
332  /* Bail out if failure */
333  if (!Success)
334  return;
335 
336  /* Load NLS data, they are in the System32 directory of the installation medium */
338  strcat(FileName, "system32\\");
339  SetupLdrLoadNlsData(LoaderBlock, InfHandle, FileName);
340 
341  // UiDrawStatusText("Press F6 if you need to install a 3rd-party SCSI or RAID driver...");
342 
343  /* Get a list of boot drivers */
344  SetupLdrScanBootDrivers(&LoaderBlock->BootDriverListHead, InfHandle, BootPath);
345 
346  /* Close the inf file */
347  InfCloseFile(InfHandle);
348 
349  UiDrawStatusText("The Setup program is starting...");
350 
351  /* Load ReactOS Setup */
353  LoaderBlock,
354  BootOptions,
355  BootPath,
356  TRUE);
357 }
signed char * PCHAR
Definition: retypes.h:7
#define TRUE
Definition: types.h:120
#define _WIN32_WINNT_WS03
Definition: sdkddkver.h:23
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
BOOLEAN NTAPI RamDiskLoadVirtualFile(IN PCHAR FileName)
Definition: ramdisk.c:121
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char * strstr(char *String1, char *String2)
Definition: utclib.c:653
char CHAR
Definition: xmlstorage.h:175
_Check_return_ _CRTIMP _CONST_RETURN char *__cdecl strrchr(_In_z_ const char *_Str, _In_ int _Ch)
char * LPSTR
Definition: xmlstorage.h:182
BOOLEAN InfGetDataField(PINFCONTEXT Context, ULONG FieldIndex, PWCHAR *Data)
Definition: infrosget.c:127
static VOID SetupLdrLoadNlsData(PLOADER_PARAMETER_BLOCK LoaderBlock, HINF InfHandle, LPCSTR SearchPath)
Definition: setupldr.c:36
uint32_t ULONG_PTR
Definition: typedefs.h:63
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static VOID SetupLdrScanBootDrivers(PLIST_ENTRY BootDriverListHead, HINF InfHandle, LPCSTR SearchPath)
Definition: setupldr.c:87
struct _SETUP_LOADER_BLOCK * SetupLdrBlock
Definition: arc.h:511
#define ANSI_NULL
_In_opt_ PVOID _In_ PCSTR File
Definition: iofuncs.h:615
VOID UiMessageBox(PCSTR Format,...)
Definition: ui.c:347
FORCEINLINE PVOID FrLdrTempAlloc(_In_ SIZE_T Size, _In_ ULONG Tag)
Definition: mm.h:177
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
const char * LPCSTR
Definition: xmlstorage.h:183
BOOLEAN IniReadSettingByName(ULONG_PTR SectionId, PCSTR SettingName, PCHAR Buffer, ULONG BufferSize)
Definition: inifile.c:147
#define TRACE(s)
Definition: solgame.cpp:4
BOOLEAN IniOpenSection(PCSTR SectionName, ULONG_PTR *SectionId)
Definition: inifile.c:25
LIST_ENTRY BootDriverListHead
Definition: arc.h:495
VOID UiDrawStatusText(PCSTR StatusText)
Definition: ui.c:276
VOID InfCloseFile(HINF InfHandle)
Definition: inffile.c:1046
VOID UiDrawBackdrop(VOID)
Definition: ui.c:241
SETUP_LOADER_BLOCK SetupBlock
Definition: winldr.h:74
#define ERR(fmt,...)
Definition: debug.h:109
#define TAG_BOOT_OPTIONS
Definition: setupldr.c:30
#define SETUPLDR_TEXT_MODE
Definition: setupblk.h:7
BOOLEAN InfFindFirstLine(HINF InfHandle, PCSTR Section, PCSTR Key, PINFCONTEXT Context)
Definition: inffile.c:1068
BOOLEAN InfOpenFile(PHINF InfHandle, PCSTR FileName, PULONG ErrorLine)
Definition: inffile.c:936
#define MachDiskGetBootPath(Path, Size)
Definition: machine.h:118
VOID AllocateAndInitLPB(PLOADER_PARAMETER_BLOCK *OutLoaderBlock)
Definition: winldr.c:49
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
unsigned int ULONG
Definition: retypes.h:1
VOID LoadAndBootWindowsCommon(USHORT OperatingSystemVersion, PLOADER_PARAMETER_BLOCK LoaderBlock, LPCSTR BootOptions, LPCSTR BootPath, BOOLEAN Setup)
Definition: winldr.c:775
const char * PCSTR
Definition: typedefs.h:51
Definition: File.h:15
GLfloat GLfloat p
Definition: glext.h:8902
BOOLEAN WinLdrInitSystemHive(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock, IN PCSTR SystemRoot, IN BOOLEAN Setup)
Definition: wlregistry.c:121
char BootPath[0x100]
Definition: mach.c:35
VOID UiDrawProgressBarCenter(ULONG Position, ULONG Range, PCHAR ProgressText)
Definition: ui.c:373
PLOADER_SYSTEM_BLOCK WinLdrSystemBlock
Definition: winldr.c:42

◆ 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 KSEG0_BASE
Definition: ketypes.h:273
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:109

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 }

◆ PaToVa()

◆ VaToPa()

◆ WinLdrAllocateDataTableEntry()

BOOLEAN WinLdrAllocateDataTableEntry ( IN OUT PLIST_ENTRY  ModuleListHead,
IN PCCH  BaseDllName,
IN PCCH  FullDllName,
IN PVOID  BasePA,
OUT PLDR_DATA_TABLE_ENTRY NewEntry 
)

Definition at line 172 of file peloader.c.

177 {
178  PVOID BaseVA = PaToVa(BasePA);
179  PWSTR Buffer;
180  PLDR_DATA_TABLE_ENTRY DataTableEntry;
181  PIMAGE_NT_HEADERS NtHeaders;
182  USHORT Length;
183  TRACE("WinLdrAllocateDataTableEntry(, '%s', '%s', %p)\n",
184  BaseDllName, FullDllName, BasePA);
185 
186  /* Allocate memory for a data table entry, zero-initialize it */
188  TAG_WLDR_DTE);
189  if (DataTableEntry == NULL)
190  return FALSE;
191  RtlZeroMemory(DataTableEntry, sizeof(LDR_DATA_TABLE_ENTRY));
192 
193  /* Get NT headers from the image */
194  NtHeaders = RtlImageNtHeader(BasePA);
195 
196  /* Initialize corresponding fields of DTE based on NT headers value */
197  DataTableEntry->DllBase = BaseVA;
198  DataTableEntry->SizeOfImage = NtHeaders->OptionalHeader.SizeOfImage;
199  DataTableEntry->EntryPoint = RVA(BaseVA, NtHeaders->OptionalHeader.AddressOfEntryPoint);
200  DataTableEntry->SectionPointer = 0;
201  DataTableEntry->CheckSum = NtHeaders->OptionalHeader.CheckSum;
202 
203  /* Initialize BaseDllName field (UNICODE_STRING) from the Ansi BaseDllName
204  by simple conversion - copying each character */
205  Length = (USHORT)(strlen(BaseDllName) * sizeof(WCHAR));
207  if (Buffer == NULL)
208  {
209  FrLdrHeapFree(DataTableEntry, TAG_WLDR_DTE);
210  return FALSE;
211  }
213 
214  DataTableEntry->BaseDllName.Length = Length;
215  DataTableEntry->BaseDllName.MaximumLength = Length;
216  DataTableEntry->BaseDllName.Buffer = PaToVa(Buffer);
217  while (*BaseDllName != 0)
218  {
219  *Buffer++ = *BaseDllName++;
220  }
221 
222  /* Initialize FullDllName field (UNICODE_STRING) from the Ansi FullDllName
223  using the same method */
224  Length = (USHORT)(strlen(FullDllName) * sizeof(WCHAR));
226  if (Buffer == NULL)
227  {
228  FrLdrHeapFree(DataTableEntry, TAG_WLDR_DTE);
229  return FALSE;
230  }
232 
233  DataTableEntry->FullDllName.Length = Length;
234  DataTableEntry->FullDllName.MaximumLength = Length;
235  DataTableEntry->FullDllName.Buffer = PaToVa(Buffer);
236  while (*FullDllName != 0)
237  {
238  *Buffer++ = *FullDllName++;
239  }
240 
241  /* Initialize what's left - LoadCount which is 1, and set Flags so that
242  we know this entry is processed */
243  DataTableEntry->Flags = LDRP_ENTRY_PROCESSED;
244  DataTableEntry->LoadCount = 1;
245 
246  /* Insert this DTE to a list in the LPB */
248  TRACE("Inserting DTE %p, name='%.*S' DllBase=%p \n", DataTableEntry,
249  DataTableEntry->BaseDllName.Length / 2,
250  VaToPa(DataTableEntry->BaseDllName.Buffer),
251  DataTableEntry->DllBase);
252 
253  /* Save pointer to a newly allocated and initialized entry */
254  *NewEntry = DataTableEntry;
255 
256  /* Return success */
257  return TRUE;
258 }
#define LDRP_ENTRY_PROCESSED
Definition: ldrtypes.h:43
#define TRUE
Definition: types.h:120
FORCEINLINE VOID FrLdrHeapFree(PVOID MemoryPointer, ULONG Tag)
Definition: mm.h:170
USHORT MaximumLength
Definition: env_spec_w32.h:370
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
uint16_t * PWSTR
Definition: typedefs.h:54
ULONG SizeOfImage
Definition: ldrtypes.h:142
#define InsertTailList(ListHead, Entry)
IMAGE_OPTIONAL_HEADER32 OptionalHeader
Definition: ntddk_ex.h:184
PVOID DllBase
Definition: btrfs_drv.h:1835
PVOID EntryPoint
Definition: ntddk_ex.h:203
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
_In_ PCWSTR FullDllName
Definition: ldrtypes.h:246
FORCEINLINE PVOID FrLdrHeapAlloc(SIZE_T MemorySize, ULONG Tag)
Definition: mm.h:163
#define TRACE(s)
Definition: solgame.cpp:4
__wchar_t WCHAR
Definition: xmlstorage.h:180
ULONG CheckSum
Definition: btrfs_drv.h:1841
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
struct _LDR_DATA_TABLE_ENTRY * PLDR_DATA_TABLE_ENTRY
Definition: btrfs_drv.h:1831
#define TAG_WLDR_NAME
Definition: winldr.h:28
LIST_ENTRY InLoadOrderLinks
Definition: ldrtypes.h:137
#define RVA(m, b)
Definition: freeldr.h:24
PVOID SectionPointer
Definition: ntddk_ex.h:213
unsigned short USHORT
Definition: pedump.c:61
UNICODE_STRING FullDllName
Definition: btrfs_drv.h:1837
UNICODE_STRING BaseDllName
Definition: ldrtypes.h:144
#define TAG_WLDR_DTE
Definition: winldr.h:26
#define RtlImageNtHeader
Definition: compat.h:457
FORCEINLINE PVOID PaToVa(PVOID Pa)
Definition: conversion.h:22
ULONG Flags
Definition: ntddk_ex.h:207
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
FORCEINLINE PVOID VaToPa(PVOID Va)
Definition: conversion.h:15
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
LIST_ENTRY * ModuleListHead
Definition: kdpacket.c:23
USHORT LoadCount
Definition: ntddk_ex.h:208

Referenced by LoadBootDeviceDriver(), LoadModule(), WinLdrLoadDeviceDriver(), and WinLdrpLoadAndScanReferencedDll().

◆ WinLdrCheckForLoadedDll()

BOOLEAN WinLdrCheckForLoadedDll ( IN OUT PLIST_ENTRY  ModuleListHead,
IN PCH  DllName,
OUT PLDR_DATA_TABLE_ENTRY LoadedEntry 
)

Definition at line 58 of file peloader.c.

61 {
62  PLDR_DATA_TABLE_ENTRY DataTableEntry;
63  LIST_ENTRY *ModuleEntry;
64 
65  TRACE("WinLdrCheckForLoadedDll: DllName %s\n", DllName);
66 
67  /* Just go through each entry in the LoadOrderList and compare loaded module's
68  name with a given name */
69  ModuleEntry = ModuleListHead->Flink;
70  while (ModuleEntry != ModuleListHead)
71  {
72  /* Get pointer to the current DTE */
73  DataTableEntry = CONTAINING_RECORD(ModuleEntry,
75  InLoadOrderLinks);
76 
77  TRACE("WinLdrCheckForLoadedDll: DTE %p, EP %p, base %p name '%.*ws'\n",
78  DataTableEntry, DataTableEntry->EntryPoint, DataTableEntry->DllBase,
79  DataTableEntry->BaseDllName.Length / 2, VaToPa(DataTableEntry->BaseDllName.Buffer));
80 
81  /* Compare names */
82  if (WinLdrpCompareDllName(DllName, &DataTableEntry->BaseDllName))
83  {
84  /* Yes, found it, report pointer to the loaded module's DTE
85  to the caller and increase load count for it */
86  *LoadedEntry = DataTableEntry;
87  DataTableEntry->LoadCount++;
88  TRACE("WinLdrCheckForLoadedDll: LoadedEntry %X\n", DataTableEntry);
89  return TRUE;
90  }
91 
92  /* Go to the next entry */
93  ModuleEntry = ModuleEntry->Flink;
94  }
95 
96  /* Nothing found */
97  return FALSE;
98 }
#define TRUE
Definition: types.h:120
static BOOLEAN WinLdrpCompareDllName(IN PCH DllName, IN PUNICODE_STRING UnicodeName)
Definition: peloader.c:455
PVOID DllBase
Definition: btrfs_drv.h:1835
PVOID EntryPoint
Definition: ntddk_ex.h:203
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:119
#define TRACE(s)
Definition: solgame.cpp:4
Definition: btrfs_drv.h:1831
Definition: typedefs.h:117
UNICODE_STRING BaseDllName
Definition: ldrtypes.h:144
FORCEINLINE PVOID VaToPa(PVOID Va)
Definition: conversion.h:15
LIST_ENTRY * ModuleListHead
Definition: kdpacket.c:23
USHORT LoadCount
Definition: ntddk_ex.h:208

Referenced by WinLdrLoadDeviceDriver(), WinLdrpBindImportName(), and WinLdrScanImportDescriptorTable().

◆ WinLdrLoadImage()

BOOLEAN WinLdrLoadImage ( IN PCHAR  FileName,
TYPE_OF_MEMORY  MemoryType,
OUT PVOID ImageBasePA 
)

Definition at line 268 of file peloader.c.

271 {
272  ULONG FileId;
273  PVOID PhysicalBase;
274  PVOID VirtualBase = NULL;
275  UCHAR HeadersBuffer[SECTOR_SIZE * 2];
276  PIMAGE_NT_HEADERS NtHeaders;
277  PIMAGE_SECTION_HEADER SectionHeader;
278  ULONG VirtualSize, SizeOfRawData, NumberOfSections;
281  ULONG i, BytesRead;
282  TRACE("WinLdrLoadImage(%s, %ld, *)\n", FileName, MemoryType);
283 
284  /* Open the image file */
285  Status = ArcOpen(FileName, OpenReadOnly, &FileId);
286  if (Status != ESUCCESS)
287  {
288  // UiMessageBox("Can not open the file.");
289  return FALSE;
290  }
291 
292  /* Load the first 2 sectors of the image so we can read the PE header */
293  Status = ArcRead(FileId, HeadersBuffer, SECTOR_SIZE * 2, &BytesRead);
294  if (Status != ESUCCESS)
295  {
296  UiMessageBox("Error reading from file.");
297  ArcClose(FileId);
298  return FALSE;
299  }
300 
301  /* Now read the MZ header to get the offset to the PE Header */
302  NtHeaders = RtlImageNtHeader(HeadersBuffer);
303  if (!NtHeaders)
304  {
305  // Print(L"Error - no NT header found in %s\n", FileName);
306  UiMessageBox("Error - no NT header found.");
307  ArcClose(FileId);
308  return FALSE;
309  }
310 
311  /* Ensure this is executable image */
312  if (((NtHeaders->FileHeader.Characteristics & IMAGE_FILE_EXECUTABLE_IMAGE) == 0))
313  {
314  // Print(L"Not an executable image %s\n", FileName);
315  UiMessageBox("Not an executable image.");
316  ArcClose(FileId);
317  return FALSE;
318  }
319 
320  /* Store number of sections to read and a pointer to the first section */
321  NumberOfSections = NtHeaders->FileHeader.NumberOfSections;
322  SectionHeader = IMAGE_FIRST_SECTION(NtHeaders);
323 
324  /* Try to allocate this memory, if fails - allocate somewhere else */
325  PhysicalBase = MmAllocateMemoryAtAddress(NtHeaders->OptionalHeader.SizeOfImage,
326  (PVOID)((ULONG)NtHeaders->OptionalHeader.ImageBase & (KSEG0_BASE - 1)),
327  MemoryType);
328 
329  if (PhysicalBase == NULL)
330  {
331  /* It's ok, we don't panic - let's allocate again at any other "low" place */
332  PhysicalBase = MmAllocateMemoryWithType(NtHeaders->OptionalHeader.SizeOfImage, MemoryType);
333 
334  if (PhysicalBase == NULL)
335  {
336  // Print(L"Failed to alloc pages for image %s\n", FileName);
337  UiMessageBox("Failed to alloc pages for image.");
338  ArcClose(FileId);
339  return FALSE;
340  }
341  }
342 
343  /* This is the real image base - in form of a virtual address */
344  VirtualBase = PaToVa(PhysicalBase);
345 
346  TRACE("Base PA: 0x%X, VA: 0x%X\n", PhysicalBase, VirtualBase);
347 
348  /* Set to 0 position and fully load the file image */
349  Position.HighPart = Position.LowPart = 0;
350  Status = ArcSeek(FileId, &Position, SeekAbsolute);
351  if (Status != ESUCCESS)
352  {
353  UiMessageBox("Error seeking to start of file.");
354  ArcClose(FileId);
355  return FALSE;
356  }
357 
358  Status = ArcRead(FileId, PhysicalBase, NtHeaders->OptionalHeader.SizeOfHeaders, &BytesRead);
359  if (Status != ESUCCESS)
360  {
361  // Print(L"Error reading headers %s\n", FileName);
362  UiMessageBox("Error reading headers.");
363  ArcClose(FileId);
364  return FALSE;
365  }
366 
367  /* Reload the NT Header */
368  NtHeaders = RtlImageNtHeader(PhysicalBase);
369 
370  /* Load the first section */
371  SectionHeader = IMAGE_FIRST_SECTION(NtHeaders);
372 
373  /* Fill output parameters */
374  *ImageBasePA = PhysicalBase;
375 
376  /* Walk through each section and read it (check/fix any possible
377  bad situations, if they arise) */
378  for (i = 0; i < NumberOfSections; i++)
379  {
380  VirtualSize = SectionHeader->Misc.VirtualSize;
381  SizeOfRawData = SectionHeader->SizeOfRawData;
382 
383  /* Handle a case when VirtualSize equals 0 */
384  if (VirtualSize == 0)
385  VirtualSize = SizeOfRawData;
386 
387  /* If PointerToRawData is 0, then force its size to be also 0 */
388  if (SectionHeader->PointerToRawData == 0)
389  {
390  SizeOfRawData = 0;
391  }
392  else
393  {
394  /* Cut the loaded size to the VirtualSize extents */
395  if (SizeOfRawData > VirtualSize)
396  SizeOfRawData = VirtualSize;
397  }
398 
399  /* Actually read the section (if its size is not 0) */
400  if (SizeOfRawData != 0)
401  {
402  /* Seek to the correct position */
403  Position.LowPart = SectionHeader->PointerToRawData;
404  Status = ArcSeek(FileId, &Position, SeekAbsolute);
405 
406  TRACE("SH->VA: 0x%X\n", SectionHeader->VirtualAddress);
407 
408  /* Read this section from the file, size = SizeOfRawData */
409  Status = ArcRead(FileId, (PUCHAR)PhysicalBase + SectionHeader->VirtualAddress, SizeOfRawData, &BytesRead);
410  if (Status != ESUCCESS)
411  {
412  ERR("WinLdrLoadImage(): Error reading section from file!\n");
413  break;
414  }
415  }
416 
417  /* Size of data is less than the virtual size - fill up the remainder with zeroes */
418  if (SizeOfRawData < VirtualSize)
419  {
420  TRACE("WinLdrLoadImage(): SORD %d < VS %d\n", SizeOfRawData, VirtualSize);
421  RtlZeroMemory((PVOID)(SectionHeader->VirtualAddress + (ULONG_PTR)PhysicalBase + SizeOfRawData), VirtualSize - SizeOfRawData);
422  }
423 
424  SectionHeader++;
425  }
426 
427  /* We are done with the file - close it */
428  ArcClose(FileId);
429 
430  /* If loading failed - return right now */
431  if (Status != ESUCCESS)
432  return FALSE;
433 
434  /* Relocate the image, if it needs it */
435  if (NtHeaders->OptionalHeader.ImageBase != (ULONG_PTR)VirtualBase)
436  {
437  WARN("Relocating %p -> %p\n", NtHeaders->OptionalHeader.ImageBase,
438  VirtualBase);
439  return (BOOLEAN)LdrRelocateImageWithBias(PhysicalBase,
440  (ULONG_PTR)VirtualBase - (ULONG_PTR)PhysicalBase,
441  "FreeLdr",
442  TRUE,
443  TRUE, /* in case of conflict still return success */
444  FALSE);
445  }
446 
447  TRACE("WinLdrLoadImage() done, PA = %p\n", *ImageBasePA);
448  return TRUE;
449 }
#define TRUE
Definition: types.h:120
Definition: arc.h:32
static COORD Position
Definition: mouse.c:34
unsigned char * PUCHAR
Definition: retypes.h:3
#define WARN(fmt,...)
Definition: debug.h:111
ULONG ARC_STATUS
Definition: arc.h:4
DWORD PointerToRawData
Definition: pedump.c:290
IMAGE_OPTIONAL_HEADER32 OptionalHeader
Definition: ntddk_ex.h:184
union _IMAGE_SECTION_HEADER::@1523 Misc
uint32_t ULONG_PTR
Definition: typedefs.h:63
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 IMAGE_FIRST_SECTION(NtHeader)
Definition: ntimage.h:427
#define SECTOR_SIZE
Definition: winldr.h:34
#define KSEG0_BASE
Definition: ketypes.h:273
VOID UiMessageBox(PCSTR Format,...)
Definition: ui.c:347
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
IMAGE_FILE_HEADER FileHeader
Definition: ntddk_ex.h:183
#define TRACE(s)
Definition: solgame.cpp:4
#define IMAGE_FILE_EXECUTABLE_IMAGE
Definition: pedump.c:160
ARC_STATUS ArcRead(ULONG FileId, VOID *Buffer, ULONG N, ULONG *Count)
Definition: fs.c:237
unsigned char UCHAR
Definition: xmlstorage.h:181
PVOID MmAllocateMemoryWithType(SIZE_T MemorySize, TYPE_OF_MEMORY MemoryType)
Definition: mm.c:31
ARC_STATUS ArcSeek(ULONG FileId, LARGE_INTEGER *Position, SEEKMODE SeekMode)
Definition: fs.c:244
PVOID MmAllocateMemoryAtAddress(SIZE_T MemorySize, PVOID DesiredAddress, TYPE_OF_MEMORY MemoryType)
Definition: mm.c:85
Status
Definition: gdiplustypes.h:24
#define ERR(fmt,...)
Definition: debug.h:109
NTSYSAPI ULONG NTAPI LdrRelocateImageWithBias(_In_ PVOID NewAddress, _In_ LONGLONG AdditionalBias, _In_ PCCH LoaderName, _In_ ULONG Success, _In_ ULONG Conflict, _In_ ULONG Invalid)
ARC_STATUS ArcClose(ULONG FileId)
Definition: fs.c:219
#define RtlImageNtHeader
Definition: compat.h:457
FORCEINLINE PVOID PaToVa(PVOID Pa)
Definition: conversion.h:22
ARC_STATUS ArcOpen(CHAR *Path, OPENMODE OpenMode, ULONG *FileId)
Definition: fs.c:57
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
_Must_inspect_result_ _In_ PFILE_OBJECT _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ FLT_IO_OPERATION_FLAGS _Out_opt_ PULONG BytesRead
Definition: fltkernel.h:1255

Referenced by LoadBootDeviceDriver(), LoadModule(), WinLdrLoadDeviceDriver(), and WinLdrpLoadAndScanReferencedDll().

◆ WinLdrScanImportDescriptorTable()

BOOLEAN WinLdrScanImportDescriptorTable ( IN OUT PLIST_ENTRY  ModuleListHead,
IN PCCH  DirectoryPath,
IN PLDR_DATA_TABLE_ENTRY  ScanDTE 
)

Definition at line 101 of file peloader.c.

104 {
105  PLDR_DATA_TABLE_ENTRY DataTableEntry;
106  PIMAGE_IMPORT_DESCRIPTOR ImportTable;
107  ULONG ImportTableSize;
108  PCH ImportName;
110 
111  /* Get a pointer to the import table of this image */
112  ImportTable = (PIMAGE_IMPORT_DESCRIPTOR)RtlImageDirectoryEntryToData(VaToPa(ScanDTE->DllBase),
113  TRUE, IMAGE_DIRECTORY_ENTRY_IMPORT, &ImportTableSize);
114 
115  {
116  UNICODE_STRING BaseName;
117  BaseName.Buffer = VaToPa(ScanDTE->BaseDllName.Buffer);
118  BaseName.MaximumLength = ScanDTE->BaseDllName.MaximumLength;
119  BaseName.Length = ScanDTE->BaseDllName.Length;
120  TRACE("WinLdrScanImportDescriptorTable(): %wZ ImportTable = 0x%X\n",
121  &BaseName, ImportTable);
122  }
123 
124  /* If image doesn't have any import directory - just return success */
125  if (ImportTable == NULL)
126  return TRUE;
127 
128  /* Loop through all entries */
129  for (;(ImportTable->Name != 0) && (ImportTable->FirstThunk != 0);ImportTable++)
130  {
131  /* Get pointer to the name */
132  ImportName = (PCH)VaToPa(RVA(ScanDTE->DllBase, ImportTable->Name));
133  TRACE("WinLdrScanImportDescriptorTable(): Looking at %s\n", ImportName);
134 
135  /* In case we get a reference to ourselves - just skip it */
136  if (WinLdrpCompareDllName(ImportName, &ScanDTE->BaseDllName))
137  continue;
138 
139  /* Load the DLL if it is not already loaded */
140  if (!WinLdrCheckForLoadedDll(ModuleListHead, ImportName, &DataTableEntry))
141  {
143  DirectoryPath,
144  ImportName,
145  &DataTableEntry);
146  if (!Success)
147  {
148  ERR("WinLdrpLoadAndScanReferencedDll() failed\n");
149  return Success;
150  }
151  }
152 
153  /* Scan its import address table */
155  DataTableEntry->DllBase,
156  ScanDTE->DllBase,
157  (PIMAGE_THUNK_DATA)RVA(ScanDTE->DllBase, ImportTable->FirstThunk),
158  DirectoryPath);
159 
160  if (!Success)
161  {
162  ERR("WinLdrpScanImportAddressTable() failed: ImportName = '%s', DirectoryPath = '%s'\n",
163  ImportName, DirectoryPath);
164  return Success;
165  }
166  }
167 
168  return TRUE;
169 }
#define TRUE
Definition: types.h:120
static BOOLEAN WinLdrpCompareDllName(IN PCH DllName, IN PUNICODE_STRING UnicodeName)
Definition: peloader.c:455
USHORT MaximumLength
Definition: env_spec_w32.h:370
static BOOLEAN WinLdrpScanImportAddressTable(IN OUT PLIST_ENTRY ModuleListHead, IN PVOID DllBase, IN PVOID ImageBase, IN PIMAGE_THUNK_DATA ThunkData, IN PCSTR DirectoryPath)
Definition: peloader.c:801
struct _IMAGE_IMPORT_DESCRIPTOR * PIMAGE_IMPORT_DESCRIPTOR
BOOLEAN WinLdrCheckForLoadedDll(IN OUT PLIST_ENTRY ModuleListHead, IN PCH DllName, OUT PLDR_DATA_TABLE_ENTRY *LoadedEntry)
Definition: peloader.c:58
PVOID DllBase
Definition: btrfs_drv.h:1835
CHAR * PCH
Definition: ntbasedef.h:398
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
#define TRACE(s)
Definition: solgame.cpp:4
#define RtlImageDirectoryEntryToData
Definition: compat.h:460
Definition: btrfs_drv.h:1831
#define ERR(fmt,...)
Definition: debug.h:109
#define RVA(m, b)
Definition: freeldr.h:24
static BOOLEAN WinLdrpLoadAndScanReferencedDll(PLIST_ENTRY ModuleListHead, PCCH DirectoryPath, PCH ImportName, PLDR_DATA_TABLE_ENTRY *DataTableEntry)
Definition: peloader.c:751
#define IMAGE_DIRECTORY_ENTRY_IMPORT
Definition: pedump.c:260
DWORD RVA
Definition: compat.h:903
unsigned int ULONG
Definition: retypes.h:1
FORCEINLINE PVOID VaToPa(PVOID Va)
Definition: conversion.h:15
LIST_ENTRY * ModuleListHead
Definition: kdpacket.c:23

Referenced by LoadBootDeviceDriver(), LoadWindowsCore(), WinLdrLoadDeviceDriver(), and WinLdrpLoadAndScanReferencedDll().

◆ 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:1675
#define KSEG0_BASE
Definition: ketypes.h:273
ULONG_PTR TssBasePage
Definition: winldr.c:27
void * PVOID
Definition: retypes.h:9
#define TRACE(s)
Definition: solgame.cpp:4
#define NUM_GDT
Definition: winldr.h:37
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:1550
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:438
#define KTSS
Definition: ketypes.h:920
#define DbgPrint
Definition: loader.c:25
#define NUM_IDT
Definition: winldr.h:38
ULONG_PTR PcrBasePage
Definition: winldr.c:26
#define KGDTENTRY
Definition: ketypes.h:437
static BOOLEAN WinLdrMapSpecialPages(VOID)
Definition: winldr.c:244
uint32_t ULONG_PTR
Definition: typedefs.h:63
VOID UiMessageBox(PCSTR Format,...)
Definition: ui.c:347
I386_LOADER_BLOCK I386
Definition: arc.h:515
smooth NULL
Definition: ftsmooth.c:416
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_GDT
Definition: winldr.h:37
PVOID MmAllocateMemoryWithType(SIZE_T MemorySize, TYPE_OF_MEMORY MemoryType)
Definition: mm.c:31
PVOID CommonDataArea
Definition: arc.h:406
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define ULONG_PTR
Definition: config.h:101
PVOID GdtIdt
Definition: winldr.c:25
union _LOADER_PARAMETER_BLOCK::@3247 u
static BOOLEAN MempAllocatePageTables(VOID)
Definition: winldr.c:33

Referenced by LoadAndBootWindowsCommon().