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;
250 ERR(
"Could not get NtHeaders!\n");
255 "Could not get NtHeaders!\n");
260 if ((FileHeader->
Machine != IMAGE_FILE_MACHINE_NATIVE) ||
266 ERR(
"FreeLdr FileHeader is invalid.\n");
271 "FreeLdr FileHeader is invalid.\n"
272 "Machine == 0x%lx, expected 0x%lx\n"
273 "NumberOfSections == 0x%lx, expected 0x%lx\n"
274 "PointerToSymbolTable == 0x%lx, expected 0\n"
275 "NumberOfSymbols == 0x%lx, expected 0\n"
276 "SizeOfOptionalHeader == 0x%lx, expected 0x%lx\n",
277 FileHeader->
Machine, IMAGE_FILE_MACHINE_NATIVE,
292 ERR(
"FreeLdr OptionalHeader is invalid.\n");
297 "FreeLdr OptionalHeader is invalid.\n"
298 "Magic == 0x%lx, expected 0x%lx\n"
299 "Subsystem == 0x%lx, expected 1 (native)\n"
300 "ImageBase == 0x%lx, expected 0x%lx\n"
301 "SizeOfImage == 0x%lx, maximum 0x%lx\n"
302 "SectionAlignment 0x%lx doesn't match FileAlignment 0x%lx\n",
321 TRACE(
"Initializing Memory Manager.\n");
330 TRACE(
"System Memory Map (Base Address, Length, Type):\n");
333 TRACE(
"%x\t %x\t %s\n",
350 printf(
"Error initializing memory manager!\n");
412 TRACE(
"MmGetAddressablePageCountIncludingHoles() returning 0x%x\n", PageCount);
419 SIZE_T PageLookupTableSize;
424 PVOID PageLookupTableMemAddress;
428 RequiredPages = PageLookupTableSize / MM_PAGE_SIZE;
443 if (
MemoryDescriptor->BasePage + RequiredPages >= MM_MAX_PAGE_LOADER)
continue;
451 PageLookupTableEndPage =
min(CandidateBasePage + CandidatePageCount,
455 PageLookupTableMemAddress = (
PVOID)((PageLookupTableEndPage *
PAGE_SIZE)
456 - PageLookupTableSize);
458 TRACE(
"MmFindLocationForPageLookupTable() returning 0x%x\n", PageLookupTableMemAddress);
460 return PageLookupTableMemAddress;
469 TRACE(
"MmInitPageLookupTable()\n");
483 TRACE(
"Marking pages 0x%lx-0x%lx as type %s\n",
493 TRACE(
"Ignoring pages 0x%lx-0x%lx (%s)\n",
502 TRACE(
"Marking the page lookup table pages as reserved StartPage: 0x%x PageCount: 0x%x\n", PageLookupTableStartPage, PageLookupTablePageCount);
510 TRACE(
"MmMarkPagesInLookupTable()\n");
516 ERR(
"Memory (0x%lx:0x%lx) outside of lookup table! Valid range: 0x%lx-0x%lx.\n",
533 TRACE(
"MmMarkPagesInLookupTable() Done\n");
564 return FreePageCount;
578 AvailablePagesSoFar = 0;
586 AvailablePagesSoFar = 0;
591 AvailablePagesSoFar++;
594 if (AvailablePagesSoFar >= PagesNeeded)
608 AvailablePagesSoFar = 0;
613 AvailablePagesSoFar++;
616 if (AvailablePagesSoFar >= PagesNeeded)
632 if (LastPage > TotalPageCount)
637 AvailablePagesSoFar = 0;
642 AvailablePagesSoFar = 0;
647 AvailablePagesSoFar++;
650 if (AvailablePagesSoFar >= PagesNeeded)
688 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