UEFIStarter
a simple UEFI framework
|
Memory allocation tracker: use this to prevent memory leaks. More...
Go to the source code of this file.
Data Structures | |
struct | memory_page_list_entry_t |
type for a single tracked allocation of memory pages More... | |
struct | memory_page_list_t |
type for a list node of tracked memory page allocations More... | |
struct | pool_memory_list_t |
type for a list node of tracked pool memory More... | |
Macros | |
#define | MEMORY_PAGE_LIST_MAX_ENTRY_COUNT 510 |
maximum number of entries per memory page list node More... | |
#define | POOL_MEMORY_LIST_MAX_ENTRY_COUNT 1022 |
like MEMORY_PAGE_LIST_MAX_ENTRY_COUNT, but for pool_memory_list_t | |
Functions | |
void | reset_memory_tracking () |
Resets the internal memory tracking. More... | |
void * | allocate_pages (UINTN pages) |
Allocate tracked memory pages. More... | |
BOOLEAN | free_pages (void *address, UINTN pages) |
Frees tracked memory pages. More... | |
void * | allocate_pages_ex (UINTN pages, BOOLEAN track, EFI_ALLOCATE_TYPE type, void *target_address) |
internal: allocates memory pages. More... | |
BOOLEAN | free_pages_ex (void *address, UINTN pages, BOOLEAN track) |
internal: frees memory pages. More... | |
void | track_pool_memory (void *address) |
Starts tracking a pool memory address. More... | |
UINTN | free_pool_memory_entries () |
Frees all currently tracked pool memory entries. More... | |
void | print_memory_page_list () |
Debugging function: prints a human-readable list of tracked memory pages. | |
void | print_pool_memory_list () |
Debugging function: prints a human-readable list of tracked pool memory entries. | |
void | init_tracking_memory () |
Initialize the memory tracker. | |
UINTN | stop_tracking_memory () |
Stops tracking all memory. More... | |
Memory allocation tracker: use this to prevent memory leaks.
#define MEMORY_PAGE_LIST_MAX_ENTRY_COUNT 510 |
maximum number of entries per memory page list node
Keep this as high as possible without breaking page size: sizeof(memory_page_list_t) should be as close to n*4096 as possible without going over it.
As of right now 510 will result in 2 pages for 64 bit systems and 1 page for 32 bit systems.
void reset_memory_tracking | ( | ) |
Resets the internal memory tracking.
This will forget all currently tracked memory, resulting in untracked memory leaks if you're not freeing those pages later.
void* allocate_pages | ( | UINTN | pages | ) |
Allocate tracked memory pages.
pages | the number of pages to allocate |
BOOLEAN free_pages | ( | void * | address, |
UINTN | pages | ||
) |
Frees tracked memory pages.
address | the first page's address |
pages | the number of pages allocated |
void * allocate_pages_ex | ( | UINTN | pages, |
BOOLEAN | track, | ||
EFI_ALLOCATE_TYPE | type, | ||
void * | target_address | ||
) |
internal: allocates memory pages.
This function isn't static - if you declare it with "extern" in a header you can access it directly.
pages | the amount of pages to allocate |
track | whether to track the pages |
type | see UEFI's boot services AllocatePages() MemoryType parameter, usually AllocateAnyPages |
target_address | see UEFI's boot services AllocatePages() Memory parameter, usually ignored |
BOOLEAN free_pages_ex | ( | void * | address, |
UINTN | pages, | ||
BOOLEAN | track | ||
) |
internal: frees memory pages.
This function isn't static - if you declare it with "extern" in a header you can access it directly.
address | the first page's address |
pages | the number of pages allocated |
track | whether the pages were tracked |
void track_pool_memory | ( | void * | address | ) |
Starts tracking a pool memory address.
Once pool memory is tracked the next call to free_pool_memory_entries() will free all currently tracked pool memory entries. Consider this function call to mean "I don't need this piece of memory anymore, free it whenever".
address | the start of the pool memory |
UINTN free_pool_memory_entries | ( | ) |
Frees all currently tracked pool memory entries.
UINTN stop_tracking_memory | ( | ) |
Stops tracking all memory.
This will log errors if there are unfreed memory pages.