29 lines
947 B
C++
29 lines
947 B
C++
#pragma once
|
|
#include "memory/MemoryManager.h"
|
|
#include "memory/VMM.h"
|
|
#include "misc/utils.h"
|
|
|
|
char* strdup_from_user(const char* user_string);
|
|
|
|
template <typename T, unsigned long S = sizeof(T), typename V> T* user_address_to_typed_pointer(V address)
|
|
{
|
|
uint64_t phys = VMM::get_physical((uint64_t)address);
|
|
if (phys == (uint64_t)-1) return nullptr;
|
|
return (T*)MemoryManager::get_unaligned_mappings((void*)phys, Utilities::get_blocks_from_size(PAGE_SIZE, S),
|
|
MAP_READ_WRITE);
|
|
}
|
|
|
|
template <typename T, unsigned long S = sizeof(T)> void free_user_typed_pointer(T* ptr)
|
|
{
|
|
MemoryManager::release_unaligned_mappings(ptr, Utilities::get_blocks_from_size(PAGE_SIZE, S));
|
|
}
|
|
|
|
template <typename T> T* obtain_user_ref(T* user_ptr)
|
|
{
|
|
return user_address_to_typed_pointer<T>(user_ptr);
|
|
}
|
|
|
|
template <typename T> void release_user_ref(T* ptr)
|
|
{
|
|
return free_user_typed_pointer(ptr);
|
|
} |