mirror of
https://github.com/reactos/reactos.git
synced 2025-02-24 17:34:57 +00:00
[FREELDR]
Implement MmCheckFreeldrImageFile() to check that freeldr was properly compiled and loaded. svn path=/trunk/; revision=58066
This commit is contained in:
parent
803933e000
commit
2755e37848
6 changed files with 80 additions and 8 deletions
|
@ -171,14 +171,6 @@ i386PrintExceptionText(ULONG TrapIndex, PKTRAP_FRAME TrapFrame, PKSPECIAL_REGIST
|
|||
InstructionPointer[6], InstructionPointer[7]);
|
||||
}
|
||||
|
||||
char *BugCodeStrings[] =
|
||||
{
|
||||
"TEST_BUGCHECK",
|
||||
"MISSING_HARDWARE_REQUIREMENTS",
|
||||
};
|
||||
|
||||
ULONG_PTR BugCheckInfo[5];
|
||||
|
||||
void
|
||||
NTAPI
|
||||
FrLdrBugCheckEx(
|
||||
|
|
|
@ -427,3 +427,13 @@ RtlAssert(IN PVOID FailedAssertion,
|
|||
|
||||
DbgBreakPoint();
|
||||
}
|
||||
|
||||
char *BugCodeStrings[] =
|
||||
{
|
||||
"TEST_BUGCHECK",
|
||||
"MISSING_HARDWARE_REQUIREMENTS",
|
||||
"FREELDR_IMAGE_CORRUPTION",
|
||||
};
|
||||
|
||||
ULONG_PTR BugCheckInfo[5];
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#define BIOSCALLBUFSEGMENT (BIOSCALLBUFFER/16) /* Buffer to store temporary data for any Int386() call */
|
||||
#define BIOSCALLBUFOFFSET HEX(0000) /* Buffer to store temporary data for any Int386() call */
|
||||
#define BIOSCALLBUFSIZE PAGE_SIZE /* max is sizeof(VESA_SVGA_INFO) = 512 */
|
||||
#define MAX_FREELDR_PE_SIZE (DISKREADBUFFER - FREELDR_PE_BASE)
|
||||
|
||||
/* These addresses specify the realmode "BSS section" layout */
|
||||
#define BSS_RealModeEntry (BSS_START + 0)
|
||||
|
|
|
@ -120,4 +120,19 @@ void MEMORY_WRITE_BREAKPOINT4(unsigned long addr);
|
|||
|
||||
#endif // DBG
|
||||
|
||||
void
|
||||
NTAPI
|
||||
FrLdrBugCheck(ULONG BugCode);
|
||||
|
||||
/* Bugcheck codes */
|
||||
enum _FRLDR_BUGCHECK_CODES
|
||||
{
|
||||
TEST_BUGCHECK,
|
||||
MISSING_HARDWARE_REQUIREMENTS,
|
||||
FREELDR_IMAGE_CORRUPTION,
|
||||
};
|
||||
|
||||
extern char *BugCodeStrings[];
|
||||
extern ULONG_PTR BugCheckInfo[5];
|
||||
|
||||
#endif // defined __DEBUG_H
|
||||
|
|
|
@ -19,6 +19,13 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
extern char __ImageBase;
|
||||
#ifdef __GNUC__
|
||||
#define FREELDR_SECTION_COUNT 3
|
||||
#else
|
||||
#define FREELDR_SECTION_COUNT 1
|
||||
#endif
|
||||
|
||||
typedef struct _FREELDR_MEMORY_DESCRIPTOR
|
||||
{
|
||||
TYPE_OF_MEMORY MemoryType;
|
||||
|
|
|
@ -163,6 +163,47 @@ ArcGetMemoryDescriptor(const FREELDR_MEMORY_DESCRIPTOR* Current)
|
|||
}
|
||||
|
||||
|
||||
BOOLEAN
|
||||
MmCheckFreeldrImageFile()
|
||||
{
|
||||
PIMAGE_NT_HEADERS NtHeaders;
|
||||
PIMAGE_FILE_HEADER FileHeader;
|
||||
PIMAGE_OPTIONAL_HEADER OptionalHeader;
|
||||
|
||||
/* Get the NT headers */
|
||||
NtHeaders = RtlImageNtHeader(&__ImageBase);
|
||||
if (!NtHeaders)
|
||||
{
|
||||
ERR("Coult not get NtHeaders!\n");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Check the file header */
|
||||
FileHeader = &NtHeaders->FileHeader;
|
||||
if ((FileHeader->Machine != IMAGE_FILE_MACHINE_NATIVE) ||
|
||||
(FileHeader->NumberOfSections != FREELDR_SECTION_COUNT) ||
|
||||
(FileHeader->PointerToSymbolTable != 0) ||
|
||||
(FileHeader->NumberOfSymbols != 0) ||
|
||||
(FileHeader->NumberOfSymbols != 0) ||
|
||||
(FileHeader->SizeOfOptionalHeader != 0xE0))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Check the optional header */
|
||||
OptionalHeader = &NtHeaders->OptionalHeader;
|
||||
if ((OptionalHeader->Magic != IMAGE_NT_OPTIONAL_HDR_MAGIC) ||
|
||||
(OptionalHeader->Subsystem != 1) || // native
|
||||
(OptionalHeader->ImageBase != FREELDR_PE_BASE) ||
|
||||
(OptionalHeader->SizeOfImage > MAX_FREELDR_PE_SIZE) ||
|
||||
(OptionalHeader->SectionAlignment != OptionalHeader->FileAlignment))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOLEAN MmInitializeMemoryManager(VOID)
|
||||
{
|
||||
#if DBG
|
||||
|
@ -171,6 +212,12 @@ BOOLEAN MmInitializeMemoryManager(VOID)
|
|||
|
||||
TRACE("Initializing Memory Manager.\n");
|
||||
|
||||
/* Check the freeldr binary */
|
||||
if (!MmCheckFreeldrImageFile())
|
||||
{
|
||||
FrLdrBugCheck(FREELDR_IMAGE_CORRUPTION);
|
||||
}
|
||||
|
||||
BiosMemoryMap = MachVtbl.GetMemoryMap(&BiosMemoryMapEntryCount);
|
||||
|
||||
#if DBG
|
||||
|
|
Loading…
Reference in a new issue