42} FREELDR_MEMORY_TYPE, *PFREELDR_MEMORY_TYPE;
44FREELDR_MEMORY_TYPE MemoryTypeArray[] =
63ULONG MemoryTypeCount =
sizeof(MemoryTypeArray) /
sizeof(MemoryTypeArray[0]);
66MmGetSystemMemoryMapTypeString(
75 return MemoryTypeArray[
Index].TypeString;
79 return MemoryTypeArray[0].TypeString;
89 for (
i = 0;
List[
i].PageCount != 0;
i++)
95 MmGetSystemMemoryMapTypeString(
List[
i].MemoryType));
111 TRACE(
"AddMemoryDescriptor(0x%Ix, 0x%Ix, %u)\n",
112 BasePage, PageCount, MemoryType);
114 EndPage = BasePage + PageCount;
125 DescriptCount =
Index;
126 while (
List[DescriptCount].PageCount != 0)
135 TRACE(
"AddMemoryDescriptor conflict @%lu: new=[%lx:%lx], existing=[%lx,%lx]\n",
156 (DescriptCount -
Index) *
sizeof(
List[0]));
180 (DescriptCount -
Index) *
sizeof(
List[0]));
194 if (DescriptCount >= MaxCount)
200 "Ran out of static memory descriptors!");
204 if (
Index < DescriptCount)
208 (DescriptCount -
Index) *
sizeof(
List[0]));
217 DbgDumpMemoryMap(
List);
219 return DescriptCount;
249 ERR(
"Could not get NtHeaders!\n");
254 "Could not get NtHeaders!\n");
259 if ((FileHeader->
Machine != IMAGE_FILE_MACHINE_NATIVE) ||
265 ERR(
"FreeLdr FileHeader is invalid.\n");
270 "FreeLdr FileHeader is invalid.\n"
271 "Machine == 0x%lx, expected 0x%lx\n"
272 "NumberOfSections == 0x%lx, expected 0x%lx\n"
273 "PointerToSymbolTable == 0x%lx, expected 0\n"
274 "NumberOfSymbols == 0x%lx, expected 0\n"
275 "SizeOfOptionalHeader == 0x%lx, expected 0x%lx\n",
276 FileHeader->
Machine, IMAGE_FILE_MACHINE_NATIVE,
291 ERR(
"FreeLdr OptionalHeader is invalid.\n");
296 "FreeLdr OptionalHeader is invalid.\n"
297 "Magic == 0x%lx, expected 0x%lx\n"
298 "Subsystem == 0x%lx, expected 1 (native)\n"
299 "ImageBase == 0x%lx, expected 0x%lx\n"
300 "SizeOfImage == 0x%lx, maximum 0x%lx\n"
301 "SectionAlignment 0x%lx doesn't match FileAlignment 0x%lx\n",
319 TRACE(
"Initializing Memory Manager.\n");
328 TRACE(
"System Memory Map (Base Address, Length, Type):\n");
331 TRACE(
"%x\t %x\t %s\n",
348 printf(
"Error initializing memory manager!\n");
410 TRACE(
"MmGetAddressablePageCountIncludingHoles() returning 0x%x\n", PageCount);
417 SIZE_T PageLookupTableSize;
426 RequiredPages = PageLookupTableSize / MM_PAGE_SIZE;
441 if (
MemoryDescriptor->BasePage + RequiredPages >= MM_MAX_PAGE_LOADER)
continue;
449 PageLookupTableEndPage =
min(CandidateBasePage + CandidatePageCount,
453 PageLookupTableMemAddress = (
PVOID)((PageLookupTableEndPage *
PAGE_SIZE)
454 - PageLookupTableSize);
456 TRACE(
"MmFindLocationForPageLookupTable() returning 0x%x\n", PageLookupTableMemAddress);
458 return PageLookupTableMemAddress;
467 TRACE(
"MmInitPageLookupTable()\n");
481 TRACE(
"Marking pages 0x%lx-0x%lx as type %s\n",
491 TRACE(
"Ignoring pages 0x%lx-0x%lx (%s)\n",
500 TRACE(
"Marking the page lookup table pages as reserved StartPage: 0x%x PageCount: 0x%x\n", PageLookupTableStartPage, PageLookupTablePageCount);
508 TRACE(
"MmMarkPagesInLookupTable()\n");
514 ERR(
"Memory (0x%lx:0x%lx) outside of lookup table! Valid range: 0x%lx-0x%lx.\n",
531 TRACE(
"MmMarkPagesInLookupTable() Done\n");
562 return FreePageCount;
576 AvailablePagesSoFar = 0;
584 AvailablePagesSoFar = 0;
589 AvailablePagesSoFar++;
592 if (AvailablePagesSoFar >= PagesNeeded)
606 AvailablePagesSoFar = 0;
611 AvailablePagesSoFar++;
614 if (AvailablePagesSoFar >= PagesNeeded)
630 if (LastPage > TotalPageCount)
635 AvailablePagesSoFar = 0;
640 AvailablePagesSoFar = 0;
645 AvailablePagesSoFar++;
648 if (AvailablePagesSoFar >= PagesNeeded)
686 if ((
StartPage + PageCount) > TotalPageCount)
VOID FrLdrBugCheckWithMessage(ULONG BugCode, PCHAR File, ULONG Line, PSTR Format,...)
#define MAX_FREELDR_PE_SIZE
@ FREELDR_IMAGE_CORRUPTION
#define DBG_DEFAULT_CHANNEL(ch)
struct PAGE_LOOKUP_TABLE_ITEM * PPAGE_LOOKUP_TABLE_ITEM
VOID MmInitializeHeap(PVOID PageLookupTable)
#define FREELDR_SECTION_COUNT
#define ROUND_UP(n, align)
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
PVOID PageLookupTableAddress
PFN_NUMBER MmGetAddressablePageCountIncludingHoles(VOID)
PFREELDR_MEMORY_DESCRIPTOR BiosMemoryMap
static VOID MmCheckFreeldrImageFile(VOID)
PFN_NUMBER TotalPagesInLookupTable
PFN_NUMBER MmGetPageNumberFromAddress(PVOID Address)
VOID MmMarkPagesInLookupTable(PVOID PageLookupTable, PFN_NUMBER StartPage, PFN_NUMBER PageCount, TYPE_OF_MEMORY PageAllocated)
PFN_NUMBER MmFindAvailablePages(PVOID PageLookupTable, PFN_NUMBER TotalPageCount, PFN_NUMBER PagesNeeded, BOOLEAN FromEnd)
const FREELDR_MEMORY_DESCRIPTOR * ArcGetMemoryDescriptor(const FREELDR_MEMORY_DESCRIPTOR *Current)
BOOLEAN MmInitializeMemoryManager(VOID)
VOID MmInitPageLookupTable(PVOID PageLookupTable, PFN_NUMBER TotalPageCount)
PFN_NUMBER MmCountFreePagesInLookupTable(PVOID PageLookupTable, PFN_NUMBER TotalPageCount)
PFN_NUMBER MmLowestPhysicalPage
PFN_NUMBER FreePagesInLookupTable
PFN_NUMBER MmFindAvailablePagesBeforePage(PVOID PageLookupTable, PFN_NUMBER TotalPageCount, PFN_NUMBER PagesNeeded, PFN_NUMBER LastPage)
VOID MmUpdateLastFreePageHint(PVOID PageLookupTable, PFN_NUMBER TotalPageCount)
PFN_NUMBER MmHighestPhysicalPage
PVOID MmFindLocationForPageLookupTable(PFN_NUMBER TotalPageCount)
PFN_NUMBER LastFreePageHint
ULONG AddMemoryDescriptor(IN OUT PFREELDR_MEMORY_DESCRIPTOR List, IN ULONG MaxCount, IN PFN_NUMBER BasePage, IN PFN_NUMBER PageCount, IN TYPE_OF_MEMORY MemoryType)
VOID MmAllocatePagesInLookupTable(PVOID PageLookupTable, PFN_NUMBER StartPage, PFN_NUMBER PageCount, TYPE_OF_MEMORY MemoryType)
BOOLEAN MmAreMemoryPagesAvailable(PVOID PageLookupTable, PFN_NUMBER TotalPageCount, PVOID PageAddress, PFN_NUMBER PageCount)
ULONG BiosMemoryMapEntryCount
#define IMAGE_SUBSYSTEM_NATIVE
#define IMAGE_NT_OPTIONAL_HDR_MAGIC
@ LoaderFirmwareTemporary
@ LoaderFirmwarePermanent
enum _TYPE_OF_MEMORY TYPE_OF_MEMORY
PFN_NUMBER PageAllocationLength
TYPE_OF_MEMORY PageAllocated
PFREELDR_MEMORY_DESCRIPTOR(* GetMemoryMap)(PULONG MaxMemoryMapSize)
#define RtlMoveMemory(Destination, Source, Length)
_In_ WDFCOLLECTION _In_ ULONG Index
_Must_inspect_result_ _In_ WDFCMRESLIST List
_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
int WINAPI EndPage(_In_ HDC)
int WINAPI StartPage(_In_ HDC)
_Must_inspect_result_ _In_ SIZE_T _In_ PVOID PageAddress