74 return reinterpret_cast<pointer>(g_page_pool.alloc(
size));
76 return reinterpret_cast<pointer>(g_heap_pool.alloc(
size));
92 return reinterpret_cast<pointer>(g_mem_map_pool.alloc(
size));
105 if (g_heap_pool.contains(uintptr))
106 return g_heap_pool.free(uintptr);
108 if (g_page_pool.contains(uintptr))
109 return g_page_pool.free(uintptr);
117 if (g_mem_map_pool.contains(uintptr))
118 return g_mem_map_pool.free(uintptr);
126 if (g_heap_pool.contains(uintptr))
127 return g_heap_pool.size(uintptr);
129 if (g_page_pool.contains(uintptr))
130 return g_page_pool.size(uintptr);
140 if (g_mem_map_pool.contains(uintptr))
141 return g_mem_map_pool.size(uintptr);
152 std::lock_guard<std::mutex> guard(g_add_md_mutex);
158 {
return this->virtint_to_physint(reinterpret_cast<integer_pointer>(virt)); }
162 {
return reinterpret_cast<pointer>(this->virtint_to_physint(virt)); }
174 std::lock_guard<std::mutex> guard(g_add_md_mutex);
180 {
return this->physint_to_virtint(reinterpret_cast<integer_pointer>(phys)); }
184 {
return reinterpret_cast<pointer>(this->physint_to_virtint(phys)); }
188 {
return reinterpret_cast<pointer>(this->physptr_to_virtint(phys)); }
195 std::lock_guard<std::mutex> guard(g_add_md_mutex);
196 return m_virt_to_attr_map.at(
upper(virt));
201 {
return this->virtint_to_attrint(reinterpret_cast<integer_pointer>(virt)); }
206 auto ___ = gsl::on_failure([&]
208 std::lock_guard<std::mutex> guard(g_add_md_mutex);
210 m_virt_to_phys_map.erase(virt);
211 m_phys_to_virt_map.erase(phys);
212 m_virt_to_attr_map.erase(virt);
220 std::lock_guard<std::mutex> guard(g_add_md_mutex);
222 m_virt_to_phys_map[
virt] = phys;
223 m_phys_to_virt_map[phys] =
virt;
224 m_virt_to_attr_map[
virt] = attr;
235 bferror <<
"remove_md: virt == 0" << bfendl;
241 bferror <<
"remove_md: lower(virt) != 0" << bfendl;
247 phys = virtint_to_physint(
virt);
248 std::lock_guard<std::mutex> guard(g_add_md_mutex);
250 m_virt_to_phys_map.erase(
virt);
251 m_phys_to_virt_map.erase(phys);
252 m_virt_to_attr_map.erase(
virt);
260 std::lock_guard<std::mutex> guard(g_add_md_mutex);
262 for (
const auto &p : m_virt_to_phys_map)
265 auto phys = p.second;
266 auto attr = m_virt_to_attr_map.at(
virt);
268 list.push_back({phys,
virt, attr});
274 memory_manager_x64::memory_manager_x64()
noexcept :
275 g_heap_pool(reinterpret_cast<uintptr_t>(g_heap_pool_owner)),
276 g_page_pool(reinterpret_cast<uintptr_t>(g_page_pool_owner)),
303 #ifdef CROSS_COMPILED 306 _malloc_r(
struct _reent *,
size_t size)
307 {
return g_mm->alloc(size); }
310 _free_r(
struct _reent *,
void *ptr)
314 _calloc_r(
struct _reent *,
size_t nmemb,
size_t size)
316 if (
auto ptr =
g_mm->alloc(nmemb * size))
317 return __builtin_memset(ptr, 0, nmemb * size);
323 _realloc_r(
struct _reent *,
void *ptr,
size_t size)
325 auto old_sze =
g_mm->size(ptr);
326 auto new_ptr =
g_mm->alloc(size);
328 if (!new_ptr || old_sze == 0)
333 __builtin_memcpy(new_ptr, ptr, size > old_sze ? old_sze : size);
virtual pointer alloc_map(size_type size) noexcept
virtual pointer alloc(size_type size) noexcept
virtual void add_md(integer_pointer virt, integer_pointer phys, attr_type attr)
virtual integer_pointer virtint_to_physint(integer_pointer virt) const
virtual void free(pointer ptr) noexcept
auto upper(T ptr) noexcept
#define MEMORY_MANAGER_FAILURE
virtual pointer physint_to_virtptr(integer_pointer phys) const
std::vector< memory_descriptor > memory_descriptor_list
virtual integer_pointer virtptr_to_physint(pointer virt) const
virtual size_type size_map(pointer ptr) const noexcept
virtual attr_type virtptr_to_attrint(pointer virt) const
constexpr const auto size
void uint64_t uint64_t uint64_t *rdx noexcept
virtual integer_pointer physptr_to_virtint(pointer phys) const
int64_t add_md(struct memory_descriptor *md) noexcept
static memory_manager_x64 * instance() noexcept
decltype(memory_descriptor::type) attr_type
constexpr page_table_x64::integer_pointer virt
virtual size_type size(pointer ptr) const noexcept
uintptr_t integer_pointer
virtual pointer virtint_to_physptr(integer_pointer virt) const
virtual integer_pointer physint_to_virtint(integer_pointer phys) const
constexpr const auto page_size
virtual memory_descriptor_list descriptors() const
virtual pointer physptr_to_virtptr(pointer phys) const
E guard_exceptions(E error_code, T func)
__attribute__((constructor)) static void ctor_func()
std::mutex g_add_md_mutex
virtual void remove_md(integer_pointer virt) noexcept
auto lower(T ptr) noexcept
virtual void free_map(pointer ptr) noexcept
virtual attr_type virtint_to_attrint(integer_pointer virt) const
#define MEM_MAP_POOL_START
uintptr_t integer_pointer
virtual pointer virtptr_to_physptr(pointer virt) const
uintptr_t virtptr_to_physint(void *ptr)