Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add virtmemFindAliasMemory to virtmem APIs #501

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions nx/include/switch/kernel/virtmem.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ void* virtmemFindStack(size_t size, size_t guard_size);
*/
void* virtmemFindCodeMemory(size_t size, size_t guard_size);

/**
* @brief Finds a random slice of free alias address space.
* @param size Desired size of the slice (rounded up to page alignment).
* @param guard_size Desired size of the unmapped guard areas surrounding the slice (rounded up to page alignment).
* @return 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 \ref virtmemLock and \ref virtmemUnlock).
*/
void* virtmemFindAlias(size_t size, size_t guard_size);

/**
* @brief Reserves a range of memory address space.
* @param mem Pointer to the address space slice.
Expand Down
5 changes: 5 additions & 0 deletions nx/source/kernel/virtmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,11 @@ void* virtmemFindCodeMemory(size_t size, size_t guard_size) {
return _memregionFindRandom(g_IsLegacyKernel ? &g_StackRegion : &g_AslrRegion, size, guard_size);
}

void* virtmemFindAlias(size_t size, size_t guard_size) {
if (!mutexIsLockedByCurrentThread(&g_VirtmemMutex)) return NULL;
return _memregionFindRandom(&g_AliasRegion, size, guard_size);
}

VirtmemReservation* virtmemAddReservation(void* mem, size_t size) {
if (!mutexIsLockedByCurrentThread(&g_VirtmemMutex)) return NULL;
VirtmemReservation* rv = (VirtmemReservation*)malloc(sizeof(VirtmemReservation));
Expand Down