libtransistor
A userland library for the Nintendo Switch
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
Functions
alloc_pages.h File Reference

Page allocation functions. More...

#include <libtransistor/types.h>
#include <stdint.h>
Include dependency graph for alloc_pages.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void * alloc_pages (size_t min, size_t max, size_t *actual)
 Allocates memory pages. More...
 
bool free_pages (void *pages)
 Frees memory pages returned from alloc_pages. More...
 

Detailed Description

Page allocation functions.

Function Documentation

void* alloc_pages ( size_t  min,
size_t  max,
size_t *  actual 
)

Allocates memory pages.

This will allocate a page-aligned region of memory that is at least min bytes long and no more than max bytes long. The actual length of the memory region is written to actual.

If min == max, you are guaranteed to either get that much memory or no memory at all, and can pass NULL in actual.

The pointer returned by this function should be passed to free_pages before the program terminates.

If alloc_pages has been set in loader_config, that allocator will be used instead of the application's self-hosted one.

Parameters
minLower bound on how much memory to allocate (in bytes)
maxUpper bound on how much memory to allocate (in bytes)
actualOutput for how much memory was actually allocated. Can be NULL.
Returns
Pointer to the allocated region, or NULL if it was not able to be allocated.
bool free_pages ( void *  pages)

Frees memory pages returned from alloc_pages.

Frees a region of memory returned from alloc_pages. The memory should be RW-, type 5 (HEAP), and have no attributes set.

If alloc_pages has been set in loader_config, that allocator will be used instead of the application's self-hosted one.

Parameters
pagesPointer returned by alloc_pages
Returns
True if there was an error freeing the memory region