if (MemorySize == 0)
{
- DbgPrint((DPRINT_MEMORY, "MmAllocateMemory() called for 0 bytes. Returning NULL.\n"));
+ DPRINTM(DPRINT_MEMORY, "MmAllocateMemory() called for 0 bytes. Returning NULL.\n");
UiMessageBoxCritical("Memory allocation failed: MmAllocateMemory() called for 0 bytes.");
return NULL;
}
// then return NULL
if (FreePagesInLookupTable < PagesNeeded)
{
- DbgPrint((DPRINT_MEMORY, "Memory allocation failed in MmAllocateMemory(). Not enough free memory to allocate %d bytes.\n", MemorySize));
+ DPRINTM(DPRINT_MEMORY, "Memory allocation failed in MmAllocateMemory(). Not enough free memory to allocate %d bytes.\n", MemorySize);
UiMessageBoxCritical("Memory allocation failed: out of memory.");
return NULL;
}
if (FirstFreePageFromEnd == 0)
{
- DbgPrint((DPRINT_MEMORY, "Memory allocation failed in MmAllocateMemory(). Not enough free memory to allocate %d bytes.\n", MemorySize));
+ DPRINTM(DPRINT_MEMORY, "Memory allocation failed in MmAllocateMemory(). Not enough free memory to allocate %d bytes.\n", MemorySize);
UiMessageBoxCritical("Memory allocation failed: out of memory.");
return NULL;
}
MemPointer = (PVOID)((ULONG_PTR)FirstFreePageFromEnd * MM_PAGE_SIZE);
#ifdef DBG
- DbgPrint((DPRINT_MEMORY, "Allocated %d bytes (%d pages) of memory starting at page %d.\n", MemorySize, PagesNeeded, FirstFreePageFromEnd));
- DbgPrint((DPRINT_MEMORY, "Memory allocation pointer: 0x%x\n", MemPointer));
+ DPRINTM(DPRINT_MEMORY, "Allocated %d bytes (%d pages) of memory starting at page %d.\n", MemorySize, PagesNeeded, FirstFreePageFromEnd);
+ DPRINTM(DPRINT_MEMORY, "Memory allocation pointer: 0x%x\n", MemPointer);
#endif // DBG
// Update LoaderPagesSpanned count
if (MemorySize > MM_PAGE_SIZE)
{
- DbgPrint((DPRINT_MEMORY, "Consider using other functions to allocate %d bytes of memory!\n", MemorySize));
+ DPRINTM(DPRINT_MEMORY, "Consider using other functions to allocate %d bytes of memory!\n", MemorySize);
}
// Get the buffer from BGET pool
if (Result == NULL)
{
- DbgPrint((DPRINT_MEMORY, "Heap allocation for %d bytes failed\n", MemorySize));
+ DPRINTM(DPRINT_MEMORY, "Heap allocation for %d bytes failed\n", MemorySize);
}
// Gather some stats
bstats(&CurAlloc, &TotalFree, &MaxFree, &NumberOfGets, &NumberOfRels);
- DbgPrint((DPRINT_MEMORY, "Current alloced %d bytes, free %d bytes, allocs %d, frees %d\n",
- CurAlloc, TotalFree, NumberOfGets, NumberOfRels));
+ DPRINTM(DPRINT_MEMORY, "Current alloced %d bytes, free %d bytes, allocs %d, frees %d\n",
+ CurAlloc, TotalFree, NumberOfGets, NumberOfRels);
return Result;
}
if (MemorySize == 0)
{
- DbgPrint((DPRINT_MEMORY, "MmAllocateMemoryAtAddress() called for 0 bytes. Returning NULL.\n"));
+ DPRINTM(DPRINT_MEMORY, "MmAllocateMemoryAtAddress() called for 0 bytes. Returning NULL.\n");
UiMessageBoxCritical("Memory allocation failed: MmAllocateMemoryAtAddress() called for 0 bytes.");
return NULL;
}
// then return NULL
if (FreePagesInLookupTable < PagesNeeded)
{
- DbgPrint((DPRINT_MEMORY, "Memory allocation failed in MmAllocateMemoryAtAddress(). "
+ DPRINTM(DPRINT_MEMORY, "Memory allocation failed in MmAllocateMemoryAtAddress(). "
"Not enough free memory to allocate %d bytes (requesting %d pages but have only %d). "
- "\n", MemorySize, PagesNeeded, FreePagesInLookupTable));
+ "\n", MemorySize, PagesNeeded, FreePagesInLookupTable);
UiMessageBoxCritical("Memory allocation failed: out of memory.");
return NULL;
}
if (MmAreMemoryPagesAvailable(PageLookupTableAddress, TotalPagesInLookupTable, DesiredAddress, PagesNeeded) == FALSE)
{
- DbgPrint((DPRINT_MEMORY, "Memory allocation failed in MmAllocateMemoryAtAddress(). "
+ DPRINTM(DPRINT_MEMORY, "Memory allocation failed in MmAllocateMemoryAtAddress(). "
"Not enough free memory to allocate %d bytes at address %p.\n",
- MemorySize, DesiredAddress));
+ MemorySize, DesiredAddress);
// Don't tell this to user since caller should try to alloc this memory
// at a different address
MemPointer = (PVOID)((ULONG_PTR)StartPageNumber * MM_PAGE_SIZE);
#ifdef DBG
- DbgPrint((DPRINT_MEMORY, "Allocated %d bytes (%d pages) of memory starting at page %d.\n", MemorySize, PagesNeeded, StartPageNumber));
- DbgPrint((DPRINT_MEMORY, "Memory allocation pointer: 0x%x\n", MemPointer));
+ DPRINTM(DPRINT_MEMORY, "Allocated %d bytes (%d pages) of memory starting at page %d.\n", MemorySize, PagesNeeded, StartPageNumber);
+ DPRINTM(DPRINT_MEMORY, "Memory allocation pointer: 0x%x\n", MemPointer);
#endif // DBG
// Update LoaderPagesSpanned count
return MemPointer;
}
+VOID MmSetMemoryType(PVOID MemoryAddress, ULONG MemorySize, TYPE_OF_MEMORY NewType)
+{
+ ULONG PagesNeeded;
+ ULONG StartPageNumber;
+
+ // Find out how many blocks it will take to
+ // satisfy this allocation
+ PagesNeeded = ROUND_UP(MemorySize, MM_PAGE_SIZE) / MM_PAGE_SIZE;
+
+ // Get the starting page number
+ StartPageNumber = MmGetPageNumberFromAddress(MemoryAddress);
+
+ // Set new type for these pages
+ MmAllocatePagesInLookupTable(PageLookupTableAddress, StartPageNumber, PagesNeeded, NewType);
+}
+
PVOID MmAllocateHighestMemoryBelowAddress(ULONG MemorySize, PVOID DesiredAddress, TYPE_OF_MEMORY MemoryType)
{
ULONG PagesNeeded;
if (MemorySize == 0)
{
- DbgPrint((DPRINT_MEMORY, "MmAllocateHighestMemoryBelowAddress() called for 0 bytes. Returning NULL.\n"));
+ DPRINTM(DPRINT_MEMORY, "MmAllocateHighestMemoryBelowAddress() called for 0 bytes. Returning NULL.\n");
UiMessageBoxCritical("Memory allocation failed: MmAllocateHighestMemoryBelowAddress() called for 0 bytes.");
return NULL;
}
// then return NULL
if (FreePagesInLookupTable < PagesNeeded)
{
- DbgPrint((DPRINT_MEMORY, "Memory allocation failed in MmAllocateHighestMemoryBelowAddress(). Not enough free memory to allocate %d bytes.\n", MemorySize));
+ DPRINTM(DPRINT_MEMORY, "Memory allocation failed in MmAllocateHighestMemoryBelowAddress(). Not enough free memory to allocate %d bytes.\n", MemorySize);
UiMessageBoxCritical("Memory allocation failed: out of memory.");
return NULL;
}
if (FirstFreePageFromEnd == 0)
{
- DbgPrint((DPRINT_MEMORY, "Memory allocation failed in MmAllocateHighestMemoryBelowAddress(). Not enough free memory to allocate %d bytes.\n", MemorySize));
+ DPRINTM(DPRINT_MEMORY, "Memory allocation failed in MmAllocateHighestMemoryBelowAddress(). Not enough free memory to allocate %d bytes.\n", MemorySize);
UiMessageBoxCritical("Memory allocation failed: out of memory.");
return NULL;
}
MemPointer = (PVOID)((ULONG_PTR)FirstFreePageFromEnd * MM_PAGE_SIZE);
#ifdef DBG
- DbgPrint((DPRINT_MEMORY, "Allocated %d bytes (%d pages) of memory starting at page %d.\n", MemorySize, PagesNeeded, FirstFreePageFromEnd));
- DbgPrint((DPRINT_MEMORY, "Memory allocation pointer: 0x%x\n", MemPointer));
+ DPRINTM(DPRINT_MEMORY, "Allocated %d bytes (%d pages) of memory starting at page %d.\n", MemorySize, PagesNeeded, FirstFreePageFromEnd);
+ DPRINTM(DPRINT_MEMORY, "Memory allocation pointer: 0x%x\n", MemPointer);
#endif // DBG
// Update LoaderPagesSpanned count
ULONG Idx;
PPAGE_LOOKUP_TABLE_ITEM RealPageLookupTable = (PPAGE_LOOKUP_TABLE_ITEM)PageLookupTableAddress;
- DbgPrint((DPRINT_MEMORY, "----------- Memory Allocation Bitmap -----------\n"));
+ DPRINTM(DPRINT_MEMORY, "----------- Memory Allocation Bitmap -----------\n");
for (Idx=0; Idx<TotalPagesInLookupTable; Idx++)
{
if ((Idx % 32) == 0)
{
- DbgPrint((DPRINT_MEMORY, "\n"));
- DbgPrint((DPRINT_MEMORY, "%08x:\t", (Idx * MM_PAGE_SIZE)));
+ DPRINTM(DPRINT_MEMORY, "\n");
+ DPRINTM(DPRINT_MEMORY, "%08x:\t", (Idx * MM_PAGE_SIZE));
}
else if ((Idx % 4) == 0)
{
- DbgPrint((DPRINT_MEMORY, " "));
+ DPRINTM(DPRINT_MEMORY, " ");
}
switch (RealPageLookupTable[Idx].PageAllocated)
{
case LoaderFree:
- DbgPrint((DPRINT_MEMORY, "*"));
+ DPRINTM(DPRINT_MEMORY, "*");
break;
case LoaderBad:
- DbgPrint((DPRINT_MEMORY, "-"));
+ DPRINTM(DPRINT_MEMORY, "-");
break;
case LoaderLoadedProgram:
- DbgPrint((DPRINT_MEMORY, "O"));
+ DPRINTM(DPRINT_MEMORY, "O");
break;
case LoaderFirmwareTemporary:
- DbgPrint((DPRINT_MEMORY, "T"));
+ DPRINTM(DPRINT_MEMORY, "T");
break;
case LoaderFirmwarePermanent:
- DbgPrint((DPRINT_MEMORY, "P"));
+ DPRINTM(DPRINT_MEMORY, "P");
break;
case LoaderOsloaderHeap:
- DbgPrint((DPRINT_MEMORY, "H"));
+ DPRINTM(DPRINT_MEMORY, "H");
break;
case LoaderOsloaderStack:
- DbgPrint((DPRINT_MEMORY, "S"));
+ DPRINTM(DPRINT_MEMORY, "S");
break;
case LoaderSystemCode:
- DbgPrint((DPRINT_MEMORY, "K"));
+ DPRINTM(DPRINT_MEMORY, "K");
break;
case LoaderHalCode:
- DbgPrint((DPRINT_MEMORY, "L"));
+ DPRINTM(DPRINT_MEMORY, "L");
break;
case LoaderBootDriver:
- DbgPrint((DPRINT_MEMORY, "B"));
+ DPRINTM(DPRINT_MEMORY, "B");
break;
case LoaderStartupPcrPage:
- DbgPrint((DPRINT_MEMORY, "G"));
+ DPRINTM(DPRINT_MEMORY, "G");
break;
case LoaderRegistryData:
- DbgPrint((DPRINT_MEMORY, "R"));
+ DPRINTM(DPRINT_MEMORY, "R");
break;
case LoaderMemoryData:
- DbgPrint((DPRINT_MEMORY, "M"));
+ DPRINTM(DPRINT_MEMORY, "M");
break;
case LoaderNlsData:
- DbgPrint((DPRINT_MEMORY, "N"));
+ DPRINTM(DPRINT_MEMORY, "N");
break;
case LoaderSpecialMemory:
- DbgPrint((DPRINT_MEMORY, "C"));
+ DPRINTM(DPRINT_MEMORY, "C");
break;
default:
- DbgPrint((DPRINT_MEMORY, "?"));
+ DPRINTM(DPRINT_MEMORY, "?");
break;
}
}
- DbgPrint((DPRINT_MEMORY, "\n"));
+ DPRINTM(DPRINT_MEMORY, "\n");
}
#endif // DBG