libnx  v4.2.2
Typedefs | Functions
virtmem.h File Reference

Virtual memory mapping utilities. More...

#include "../types.h"

Go to the source code of this file.

Typedefs

typedef struct VirtmemReservation VirtmemReservation
 Address space reservation type (see virtmemAddReservation)
 

Functions

void virtmemLock (void)
 Locks the virtual memory manager mutex.
 
void virtmemUnlock (void)
 Unlocks the virtual memory manager mutex.
 
void * virtmemFindAslr (size_t size, size_t guard_size)
 Finds a random slice of free general purpose address space. More...
 
void * virtmemFindStack (size_t size, size_t guard_size)
 Finds a random slice of free stack address space. More...
 
void * virtmemFindCodeMemory (size_t size, size_t guard_size)
 Finds a random slice of free code memory address space. More...
 
VirtmemReservationvirtmemAddReservation (void *mem, size_t size)
 Reserves a range of memory address space. More...
 
void virtmemRemoveReservation (VirtmemReservation *rv)
 Releases a memory address space reservation. More...
 

Detailed Description

Virtual memory mapping utilities.

Author
plutoo

Function Documentation

◆ virtmemAddReservation()

VirtmemReservation* virtmemAddReservation ( void *  mem,
size_t  size 
)

Reserves a range of memory address space.

Parameters
memPointer to the address space slice.
sizeSize of the slice.
Returns
Pointer to a reservation object, or NULL on failure.
Remarks
This function is intended to be used in lieu of a memory map operation when the memory won't be mapped straight away.
Note
The virtual memory manager mutex must be held during the find-and-reserve process (see virtmemLock and virtmemUnlock).

◆ virtmemFindAslr()

void* virtmemFindAslr ( size_t  size,
size_t  guard_size 
)

Finds a random slice of free general purpose address space.

Parameters
sizeDesired size of the slice (rounded up to page alignment).
guard_sizeDesired size of the unmapped guard areas surrounding the slice (rounded up to page alignment).
Returns
Pointer to the slice of address space, or NULL on failure.
Note
The virtual memory manager mutex must be held during the find-and-map process (see virtmemLock and virtmemUnlock).

◆ virtmemFindCodeMemory()

void* virtmemFindCodeMemory ( size_t  size,
size_t  guard_size 
)

Finds a random slice of free code memory address space.

Parameters
sizeDesired size of the slice (rounded up to page alignment).
guard_sizeDesired size of the unmapped guard areas surrounding the slice (rounded up to page alignment).
Returns
Pointer to the slice of address space, or NULL on failure.
Note
The virtual memory manager mutex must be held during the find-and-map process (see virtmemLock and virtmemUnlock).

◆ virtmemFindStack()

void* virtmemFindStack ( size_t  size,
size_t  guard_size 
)

Finds a random slice of free stack address space.

Parameters
sizeDesired size of the slice (rounded up to page alignment).
guard_sizeDesired size of the unmapped guard areas surrounding the slice (rounded up to page alignment).
Returns
Pointer to the slice of address space, or NULL on failure.
Note
The virtual memory manager mutex must be held during the find-and-map process (see virtmemLock and virtmemUnlock).

◆ virtmemRemoveReservation()

void virtmemRemoveReservation ( VirtmemReservation rv)

Releases a memory address space reservation.

Parameters
rvReservation to release.
Note
The virtual memory manager mutex must be held before calling this function (see virtmemLock and virtmemUnlock).