libnx  v4.6.0
virtmem.h
Go to the documentation of this file.
1 /**
2  * @file virtmem.h
3  * @brief Virtual memory mapping utilities
4  * @author plutoo
5  * @copyright libnx Authors
6  */
7 #pragma once
8 #include "../types.h"
9 
10 /// Address space reservation type (see \ref virtmemAddReservation)
12 
13 /// Locks the virtual memory manager mutex.
14 void virtmemLock(void);
15 
16 /// Unlocks the virtual memory manager mutex.
17 void virtmemUnlock(void);
18 
19 /**
20  * @brief Finds a random slice of free general purpose address space.
21  * @param size Desired size of the slice (rounded up to page alignment).
22  * @param guard_size Desired size of the unmapped guard areas surrounding the slice (rounded up to page alignment).
23  * @return Pointer to the slice of address space, or NULL on failure.
24  * @note The virtual memory manager mutex must be held during the find-and-map process (see \ref virtmemLock and \ref virtmemUnlock).
25  */
26 void* virtmemFindAslr(size_t size, size_t guard_size);
27 
28 /**
29  * @brief Finds a random slice of free stack address space.
30  * @param size Desired size of the slice (rounded up to page alignment).
31  * @param guard_size Desired size of the unmapped guard areas surrounding the slice (rounded up to page alignment).
32  * @return Pointer to the slice of address space, or NULL on failure.
33  * @note The virtual memory manager mutex must be held during the find-and-map process (see \ref virtmemLock and \ref virtmemUnlock).
34  */
35 void* virtmemFindStack(size_t size, size_t guard_size);
36 
37 /**
38  * @brief Finds a random slice of free code memory address space.
39  * @param size Desired size of the slice (rounded up to page alignment).
40  * @param guard_size Desired size of the unmapped guard areas surrounding the slice (rounded up to page alignment).
41  * @return Pointer to the slice of address space, or NULL on failure.
42  * @note The virtual memory manager mutex must be held during the find-and-map process (see \ref virtmemLock and \ref virtmemUnlock).
43  */
44 void* virtmemFindCodeMemory(size_t size, size_t guard_size);
45 
46 /**
47  * @brief Reserves a range of memory address space.
48  * @param mem Pointer to the address space slice.
49  * @param size Size of the slice.
50  * @return Pointer to a reservation object, or NULL on failure.
51  * @remark This function is intended to be used in lieu of a memory map operation when the memory won't be mapped straight away.
52  * @note The virtual memory manager mutex must be held during the find-and-reserve process (see \ref virtmemLock and \ref virtmemUnlock).
53  */
54 VirtmemReservation* virtmemAddReservation(void* mem, size_t size);
55 
56 /**
57  * @brief Releases a memory address space reservation.
58  * @param rv Reservation to release.
59  * @note The virtual memory manager mutex must be held before calling this function (see \ref virtmemLock and \ref virtmemUnlock).
60  */
void virtmemUnlock(void)
Unlocks the virtual memory manager mutex.
void * virtmemFindCodeMemory(size_t size, size_t guard_size)
Finds a random slice of free code memory address space.
void virtmemRemoveReservation(VirtmemReservation *rv)
Releases a memory address space reservation.
VirtmemReservation * virtmemAddReservation(void *mem, size_t size)
Reserves a range of memory address space.
void * virtmemFindStack(size_t size, size_t guard_size)
Finds a random slice of free stack address space.
void * virtmemFindAslr(size_t size, size_t guard_size)
Finds a random slice of free general purpose address space.
void virtmemLock(void)
Locks the virtual memory manager mutex.
struct VirtmemReservation VirtmemReservation
Address space reservation type (see virtmemAddReservation)
Definition: virtmem.h:11