54#define BYTE_LENGTH_SHIFT 3
56#define GUARDED_HEAP_MAP_TABLE_ENTRY_SHIFT \
57 (EFI_PAGE_SHIFT - BYTE_LENGTH_SHIFT)
59#define GUARDED_HEAP_MAP_TABLE_DEPTH 5
62#define GUARDED_HEAP_MAP_ENTRY_BIT_SHIFT 6
64#define GUARDED_HEAP_MAP_ENTRY_BITS \
65 (1 << GUARDED_HEAP_MAP_ENTRY_BIT_SHIFT)
67#define GUARDED_HEAP_MAP_ENTRY_BYTES \
68 (GUARDED_HEAP_MAP_ENTRY_BITS / 8)
71#define GUARDED_HEAP_MAP_ENTRY_SHIFT \
72 (GUARDED_HEAP_MAP_ENTRY_BITS \
73 - GUARDED_HEAP_MAP_TABLE_ENTRY_SHIFT * 4 \
74 - GUARDED_HEAP_MAP_ENTRY_BIT_SHIFT \
78#define GUARDED_HEAP_MAP_ENTRY_MASK \
79 ((1 << GUARDED_HEAP_MAP_ENTRY_SHIFT) - 1)
82#define GUARDED_HEAP_MAP_SIZE \
83 ((1 << GUARDED_HEAP_MAP_ENTRY_SHIFT) * GUARDED_HEAP_MAP_ENTRY_BYTES)
86#define GUARDED_HEAP_MAP_UNIT_SIZE \
87 (GUARDED_HEAP_MAP_SIZE * 8 * EFI_PAGE_SIZE)
90#define GUARDED_HEAP_MAP_ENTRIES_PER_UNIT \
91 (GUARDED_HEAP_MAP_SIZE / GUARDED_HEAP_MAP_ENTRY_BYTES)
94#define GUARDED_HEAP_MAP_ENTRY_INDEX(Address) \
95 (RShiftU64 (Address, EFI_PAGE_SHIFT \
96 + GUARDED_HEAP_MAP_ENTRY_BIT_SHIFT) \
97 & GUARDED_HEAP_MAP_ENTRY_MASK)
100#define GUARDED_HEAP_MAP_ENTRY_BIT_INDEX(Address) \
101 (RShiftU64 (Address, EFI_PAGE_SHIFT) \
102 & ((1 << GUARDED_HEAP_MAP_ENTRY_BIT_SHIFT) - 1))
107#define GUARDED_HEAP_MAP_BITS \
108 (1 << (GUARDED_HEAP_MAP_ENTRY_SHIFT \
109 + GUARDED_HEAP_MAP_ENTRY_BIT_SHIFT))
114#define GUARDED_HEAP_MAP_BIT_INDEX(Address) \
115 (RShiftU64 (Address, EFI_PAGE_SHIFT) \
116 & ((1 << (GUARDED_HEAP_MAP_ENTRY_SHIFT \
117 + GUARDED_HEAP_MAP_ENTRY_BIT_SHIFT)) - 1))
122#define GUARDED_HEAP_MAP_TABLE_SHIFT \
123 (GUARDED_HEAP_MAP_ENTRY_SHIFT + GUARDED_HEAP_MAP_ENTRY_BIT_SHIFT \
130#define GUARDED_HEAP_MAP_TABLE_DEPTH_SHIFTS \
132 GUARDED_HEAP_MAP_TABLE_SHIFT + GUARDED_HEAP_MAP_TABLE_ENTRY_SHIFT * 3, \
133 GUARDED_HEAP_MAP_TABLE_SHIFT + GUARDED_HEAP_MAP_TABLE_ENTRY_SHIFT * 2, \
134 GUARDED_HEAP_MAP_TABLE_SHIFT + GUARDED_HEAP_MAP_TABLE_ENTRY_SHIFT, \
135 GUARDED_HEAP_MAP_TABLE_SHIFT, \
136 EFI_PAGE_SHIFT + GUARDED_HEAP_MAP_ENTRY_BIT_SHIFT \
143#define GUARDED_HEAP_MAP_TABLE_DEPTH_MASKS \
145 (1 << GUARDED_HEAP_MAP_TABLE_ENTRY_SHIFT) - 1, \
146 (1 << GUARDED_HEAP_MAP_TABLE_ENTRY_SHIFT) - 1, \
147 (1 << GUARDED_HEAP_MAP_TABLE_ENTRY_SHIFT) - 1, \
148 (1 << GUARDED_HEAP_MAP_TABLE_ENTRY_SHIFT) - 1, \
149 (1 << GUARDED_HEAP_MAP_ENTRY_SHIFT) - 1 \
155#define GUARD_HEAP_TYPE_PAGE BIT0
156#define GUARD_HEAP_TYPE_POOL BIT1
157#define GUARD_HEAP_TYPE_FREED BIT4
158#define GUARD_HEAP_TYPE_ALL \
159 (GUARD_HEAP_TYPE_PAGE|GUARD_HEAP_TYPE_POOL|GUARD_HEAP_TYPE_FREED)
164#define HEAP_GUARD_DEBUG_LEVEL (DEBUG_POOL|DEBUG_PAGE)
192 IN UINT64 NumberOfPages,
290 IN UINT64 SizeRequested
470extern BOOLEAN mOnGuarding;
480 RUNTIME_PAGE_ALLOCATION_GRANULARITY == EFI_PAGE_SIZE ||
483 "Unsupported Heap Guard configuration on system with greater than EFI_PAGE_SIZE RUNTIME_PAGE_ALLOCATION_GRANULARITY"
VOID SetGuardForMemory(IN EFI_PHYSICAL_ADDRESS Memory, IN UINTN NumberOfPages)
VOID AdjustMemoryF(IN OUT EFI_PHYSICAL_ADDRESS *Memory, IN OUT UINTN *NumberOfPages)
VOID EFIAPI GuardFreedPagesChecked(IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINTN Pages)
VOID * AdjustPoolHeadF(IN EFI_PHYSICAL_ADDRESS Memory, IN UINTN NoPages, IN UINTN Size)
VOID EFIAPI DumpGuardedMemoryBitmap(VOID)
BOOLEAN PromoteGuardedFreePages(OUT EFI_PHYSICAL_ADDRESS *StartAddress, OUT EFI_PHYSICAL_ADDRESS *EndAddress)
BOOLEAN EFIAPI IsGuardPage(IN EFI_PHYSICAL_ADDRESS Address)
VOID MergeGuardPages(IN EFI_MEMORY_DESCRIPTOR *MemoryMapEntry, IN EFI_PHYSICAL_ADDRESS MaxAddress)
BOOLEAN IsHeapGuardEnabled(UINT8 GuardType)
EFI_STATUS CoreConvertPages(IN UINT64 Start, IN UINT64 NumberOfPages, IN EFI_MEMORY_TYPE NewType)
VOID AdjustMemoryA(IN OUT EFI_PHYSICAL_ADDRESS *Memory, IN OUT UINTN *NumberOfPages)
VOID UnsetGuardForMemory(IN EFI_PHYSICAL_ADDRESS Memory, IN UINTN NumberOfPages)
UINT64 AdjustMemoryS(IN UINT64 Start, IN UINT64 Size, IN UINT64 SizeRequested)
BOOLEAN IsPoolTypeToGuard(IN EFI_MEMORY_TYPE MemoryType)
BOOLEAN EFIAPI IsMemoryGuarded(IN EFI_PHYSICAL_ADDRESS Address)
BOOLEAN IsPageTypeToGuard(IN EFI_MEMORY_TYPE MemoryType, IN EFI_ALLOCATE_TYPE AllocateType)
EFI_STATUS CoreConvertPagesWithGuard(IN UINT64 Start, IN UINTN NumberOfPages, IN EFI_MEMORY_TYPE NewType)
VOID HeapGuardCpuArchProtocolNotify(VOID)
VOID * AdjustPoolHeadA(IN EFI_PHYSICAL_ADDRESS Memory, IN UINTN NoPages, IN UINTN Size)
#define FixedPcdGet64(TokenName)
UINT64 EFI_PHYSICAL_ADDRESS