Add virtmemFindAliasMemory to virtmem APIs

This commit is contained in:
Nickie S 2020-11-01 13:45:14 +03:00
parent 091f88915d
commit e0b8852257
2 changed files with 14 additions and 0 deletions

View File

@ -59,6 +59,15 @@ void* virtmemFindStack(size_t size, size_t guard_size);
*/ */
void* virtmemFindCodeMemory(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. * @brief Reserves a range of memory address space.
* @param mem Pointer to the address space slice. * @param mem Pointer to the address space slice.

View File

@ -273,6 +273,11 @@ void* virtmemFindCodeMemory(size_t size, size_t guard_size) {
return _memregionFindRandom(g_IsLegacyKernel ? &g_StackRegion : &g_AslrRegion, size, 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) { VirtmemReservation* virtmemAddReservation(void* mem, size_t size) {
if (!mutexIsLockedByCurrentThread(&g_VirtmemMutex)) return NULL; if (!mutexIsLockedByCurrentThread(&g_VirtmemMutex)) return NULL;
VirtmemReservation* rv = (VirtmemReservation*)malloc(sizeof(VirtmemReservation)); VirtmemReservation* rv = (VirtmemReservation*)malloc(sizeof(VirtmemReservation));