Memory tracker, will find memory leaks.
More...
#include <Library/UefiLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/MemoryAllocationLib.h>
#include <UEFIStarter/core/memory.h>
#include <UEFIStarter/core/logger.h>
Memory tracker, will find memory leaks.
- Author
- Richard Nusser
- Copyright
- 2017-2018 Richard Nusser
- License
- GPLv3 (see http://www.gnu.org/licenses/)
- See also
- https://github.com/rinusser/UEFIStarter
◆ allocate_pages_ex()
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.
- Parameters
-
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 |
- Returns
- the first page's address, or NULL on error
◆ reset_memory_tracking()
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.
◆ _get_next_free_entry()
internal: finds next memory page allocation list entry
- Parameters
-
page_list | the page list node to look in |
index | the index variable to write any matches to |
- Returns
- whether the lookup succeeded
- Todo:
- if there's a next page_list, check that. if not, allocate new page_list and link to it
◆ _find_page_list_entry()
internal: finds a page list entry with the given start address
- Parameters
-
address | the first page's address to look for |
- Returns
- a pointer to the list entry, or NULL if address isn't tracked
◆ allocate_pages()
void* allocate_pages |
( |
UINTN |
pages | ) |
|
Allocate tracked memory pages.
- Parameters
-
pages | the number of pages to allocate |
- Returns
- the first page's address, or NULL on error
◆ free_pages_ex()
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.
- Parameters
-
address | the first page's address |
pages | the number of pages allocated |
track | whether the pages were tracked |
- Returns
- whether the pages were freed successfully
◆ free_pages()
BOOLEAN free_pages |
( |
void * |
address, |
|
|
UINTN |
pages |
|
) |
| |
Frees tracked memory pages.
- Parameters
-
address | the first page's address |
pages | the number of pages allocated |
- Returns
- whether the pages were freed successfully
◆ track_pool_memory()
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".
- Parameters
-
address | the start of the pool memory |
- Todo:
- implement linked list for pool memory tracking
◆ free_pool_memory_entries()
UINTN free_pool_memory_entries |
( |
| ) |
|
Frees all currently tracked pool memory entries.
- Returns
- the number of entries freed.
◆ stop_tracking_memory()
UINTN stop_tracking_memory |
( |
| ) |
|
Stops tracking all memory.
This will log errors if there are unfreed memory pages.
- Returns
- the number of errors, 0 if there were no tracked memory pages remaining
- Todo:
- the free_pool_memory_entries() call was at the end of this function - make sure there aren't any side-effects from calling this before the NULL check below