TianoCore EDK2 master
|
#include "HeapGuard.h"
Go to the source code of this file.
Variables | |
GLOBAL_REMOVE_IF_UNREFERENCED BOOLEAN | mOnGuarding = FALSE |
GLOBAL_REMOVE_IF_UNREFERENCED UINT64 | mGuardedMemoryMap = 0 |
GLOBAL_REMOVE_IF_UNREFERENCED UINTN | mMapLevel = 1 |
GLOBAL_REMOVE_IF_UNREFERENCED UINTN | mLevelShift [GUARDED_HEAP_MAP_TABLE_DEPTH] = GUARDED_HEAP_MAP_TABLE_DEPTH_SHIFTS |
GLOBAL_REMOVE_IF_UNREFERENCED UINTN | mLevelMask [GUARDED_HEAP_MAP_TABLE_DEPTH] = GUARDED_HEAP_MAP_TABLE_DEPTH_MASKS |
EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL * | mSmmMemoryAttribute = NULL |
UEFI Heap Guard functions.
Copyright (c) 2017-2018, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent
Definition in file HeapGuard.c.
Adjust the start address and number of pages to free according to Guard.
The purpose of this function is to keep the shared Guard page with adjacent memory block if it's still in guard, or free it if no more sharing. Another is to reserve pages as Guard pages in partial page free situation.
[in,out] | Memory | Base address of memory to free. |
[in,out] | NumberOfPages | Size of memory to free. |
Definition at line 825 of file HeapGuard.c.
Adjust the pool head position to make sure the Guard page is adjavent to pool tail or pool head.
[in] | Memory | Base address of memory allocated. |
[in] | NoPages | Number of pages actually allocated. |
[in] | Size | Size of memory requested. (plus pool head/tail overhead) |
Definition at line 948 of file HeapGuard.c.
VOID * AdjustPoolHeadF | ( | IN EFI_PHYSICAL_ADDRESS | Memory | ) |
Get the page base address according to pool head address.
[in] | Memory | Head address of pool to free. |
Definition at line 976 of file HeapGuard.c.
Set corresponding bits in bitmap table to 0 according to the address.
[in] | Address | Start address to set for. |
[in] | BitNumber | Number of bits to set. |
[in] | BitMap | Pointer to bitmap which covers the Address. |
Definition at line 111 of file HeapGuard.c.
VOID EFIAPI ClearGuardedMemoryBits | ( | IN EFI_PHYSICAL_ADDRESS | Address, |
IN UINTN | NumberOfPages | ||
) |
Clear corresponding bits in bitmap table according to given memory range.
[in] | Address | Memory address to unset from. |
[in] | NumberOfPages | Number of pages to unset guard. |
Definition at line 359 of file HeapGuard.c.
VOID EFIAPI DumpGuardedMemoryBitmap | ( | VOID | ) |
Dump the guarded memory bit map.
Definition at line 1269 of file HeapGuard.c.
UINTN FindGuardedMemoryMap | ( | IN EFI_PHYSICAL_ADDRESS | Address, |
IN BOOLEAN | AllocMapUnit, | ||
OUT UINT64 ** | BitMap | ||
) |
Locate the pointer of bitmap from the guarded memory bitmap tables, which covers the given Address.
[in] | Address | Start address to search the bitmap for. |
[in] | AllocMapUnit | Flag to indicate memory allocation for the table. |
[out] | BitMap | Pointer to bitmap which covers the Address. |
Definition at line 244 of file HeapGuard.c.
Get corresponding bits in bitmap table according to the address.
The value of bit 0 corresponds to the status of memory at given Address. No more than 64 bits can be retrieved in one call.
[in] | Address | Start address to retrieve bits for. |
[in] | BitNumber | Number of bits to get. |
[in] | BitMap | Pointer to bitmap which covers the Address. |
Definition at line 166 of file HeapGuard.c.
UINTN GetGuardedMemoryBits | ( | IN EFI_PHYSICAL_ADDRESS | Address, |
IN UINTN | NumberOfPages | ||
) |
Retrieve corresponding bits in bitmap table according to given memory range.
[in] | Address | Memory address to retrieve from. |
[in] | NumberOfPages | Number of pages to retrieve. |
Definition at line 395 of file HeapGuard.c.
UINTN EFIAPI GetGuardMapBit | ( | IN EFI_PHYSICAL_ADDRESS | Address | ) |
Get bit value in bitmap table for the given address.
[in] | Address | The address to retrieve for. |
Definition at line 441 of file HeapGuard.c.
UINTN InternalAllocMaxAddressWithGuard | ( | IN OUT LIST_ENTRY * | FreePageList, |
IN UINTN | NumberOfPages, | ||
IN UINTN | MaxAddress, | ||
IN EFI_MEMORY_TYPE | MemoryType | ||
) |
Helper function of memory allocation with Guard pages.
FreePageList | The free page node. |
NumberOfPages | Number of pages to be allocated. |
MaxAddress | Request to allocate memory below this address. |
MemoryType | Type of memory requested. |
Definition at line 1004 of file HeapGuard.c.
BOOLEAN EFIAPI IsGuardPage | ( | IN EFI_PHYSICAL_ADDRESS | Address | ) |
Check to see if the page at the given address is a Guard page or not.
[in] | Address | The address to check for. |
Definition at line 471 of file HeapGuard.c.
BOOLEAN IsHeapGuardEnabled | ( | VOID | ) |
Check to see if the heap guard is enabled for page and/or pool allocation.
Definition at line 672 of file HeapGuard.c.
BOOLEAN EFIAPI IsMemoryGuarded | ( | IN EFI_PHYSICAL_ADDRESS | Address | ) |
Check to see if the page at the given address is guarded or not.
[in] | Address | The address to check for. |
Definition at line 496 of file HeapGuard.c.
BOOLEAN IsMemoryTypeToGuard | ( | IN EFI_MEMORY_TYPE | MemoryType, |
IN EFI_ALLOCATE_TYPE | AllocateType, | ||
IN UINT8 | PageOrPool | ||
) |
Check to see if the memory at the given address should be guarded or not.
[in] | MemoryType | Memory type to check. |
[in] | AllocateType | Allocation type to check. |
[in] | PageOrPool | Indicate a page allocation or pool allocation. |
Definition at line 589 of file HeapGuard.c.
BOOLEAN IsPageTypeToGuard | ( | IN EFI_MEMORY_TYPE | MemoryType, |
IN EFI_ALLOCATE_TYPE | AllocateType | ||
) |
Check to see if the page at the given address should be guarded or not.
[in] | MemoryType | Page type to check. |
[in] | AllocateType | Allocation type to check. |
Definition at line 658 of file HeapGuard.c.
BOOLEAN IsPoolTypeToGuard | ( | IN EFI_MEMORY_TYPE | MemoryType | ) |
Check to see if the pool at the given address should be guarded or not.
[in] | MemoryType | Pool type to check. |
Definition at line 637 of file HeapGuard.c.
Helper function to allocate pages without Guard for internal uses.
[in] | Pages | Page number. |
Definition at line 212 of file HeapGuard.c.
VOID SetAllGuardPages | ( | VOID | ) |
Set all Guard pages which cannot be set during the non-SMM mode time.
Definition at line 1112 of file HeapGuard.c.
Set corresponding bits in bitmap table to 1 according to the address.
[in] | Address | Start address to set for. |
[in] | BitNumber | Number of bits to set. |
[in] | BitMap | Pointer to bitmap which covers the Address. |
Definition at line 55 of file HeapGuard.c.
VOID EFIAPI SetGuardedMemoryBits | ( | IN EFI_PHYSICAL_ADDRESS | Address, |
IN UINTN | NumberOfPages | ||
) |
Set corresponding bits in bitmap table to 1 according to given memory range.
[in] | Address | Memory address to guard from. |
[in] | NumberOfPages | Number of pages to guard. |
Definition at line 322 of file HeapGuard.c.
VOID SetGuardForMemory | ( | IN EFI_PHYSICAL_ADDRESS | Memory, |
IN UINTN | NumberOfPages | ||
) |
Set head Guard and tail Guard for the given memory range.
[in] | Memory | Base address of memory to set guard for. |
[in] | NumberOfPages | Memory size in pages. |
Definition at line 692 of file HeapGuard.c.
VOID EFIAPI SetGuardPage | ( | IN EFI_PHYSICAL_ADDRESS | BaseAddress | ) |
Set the page at the given address to be a Guard page.
This is done by changing the page table attribute to be NOT PRESENT.
[in] | BaseAddress | Page address to Guard at. |
Definition at line 514 of file HeapGuard.c.
VOID SmmEntryPointMemoryManagementHook | ( | VOID | ) |
Hook function used to set all Guard pages after entering SMM mode.
Definition at line 1218 of file HeapGuard.c.
EFI_STATUS SmmInternalFreePagesExWithGuard | ( | IN EFI_PHYSICAL_ADDRESS | Memory, |
IN UINTN | NumberOfPages, | ||
IN BOOLEAN | AddRegion | ||
) |
Helper function of memory free with Guard pages.
[in] | Memory | Base address of memory being freed. |
[in] | NumberOfPages | The number of pages to free. |
[in] | AddRegion | If this memory is new added region. |
EFI_NOT_FOUND | Could not find the entry that covers the range. |
EFI_INVALID_PARAMETER | Address not aligned, Address is zero or NumberOfPages is zero. |
Definition at line 1083 of file HeapGuard.c.
Helper function to convert a UINT64 value in binary to a string.
[in] | Value | Value of a UINT64 integer. |
[out] | BinString | String buffer to contain the conversion result. |
Definition at line 1245 of file HeapGuard.c.
VOID UnsetGuardForMemory | ( | IN EFI_PHYSICAL_ADDRESS | Memory, |
IN UINTN | NumberOfPages | ||
) |
Unset head Guard and tail Guard for the given memory range.
[in] | Memory | Base address of memory to unset guard for. |
[in] | NumberOfPages | Memory size in pages. |
Definition at line 728 of file HeapGuard.c.
VOID EFIAPI UnsetGuardPage | ( | IN EFI_PHYSICAL_ADDRESS | BaseAddress | ) |
Unset the Guard page at the given address to the normal memory.
This is done by changing the page table attribute to be PRESENT.
[in] | BaseAddress | Page address to Guard at. |
Definition at line 544 of file HeapGuard.c.
BOOLEAN VerifyMemoryGuard | ( | IN EFI_PHYSICAL_ADDRESS | BaseAddress, |
IN UINTN | NumberOfPages | ||
) |
Debug function used to verify if the Guard page is well set or not.
[in] | BaseAddress | Address of memory to check. |
[in] | NumberOfPages | Size of memory in pages. |
Definition at line 1378 of file HeapGuard.c.
GLOBAL_REMOVE_IF_UNREFERENCED UINT64 mGuardedMemoryMap = 0 |
Definition at line 22 of file HeapGuard.c.
GLOBAL_REMOVE_IF_UNREFERENCED UINTN mLevelMask[GUARDED_HEAP_MAP_TABLE_DEPTH] = GUARDED_HEAP_MAP_TABLE_DEPTH_MASKS |
Definition at line 36 of file HeapGuard.c.
GLOBAL_REMOVE_IF_UNREFERENCED UINTN mLevelShift[GUARDED_HEAP_MAP_TABLE_DEPTH] = GUARDED_HEAP_MAP_TABLE_DEPTH_SHIFTS |
Definition at line 34 of file HeapGuard.c.
GLOBAL_REMOVE_IF_UNREFERENCED UINTN mMapLevel = 1 |
Definition at line 29 of file HeapGuard.c.
GLOBAL_REMOVE_IF_UNREFERENCED BOOLEAN mOnGuarding = FALSE |
Definition at line 15 of file HeapGuard.c.
EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL* mSmmMemoryAttribute = NULL |
Definition at line 42 of file HeapGuard.c.