memory_manager_x64.h
Go to the documentation of this file.
1 //
2 // Bareflank Hypervisor
3 //
4 // Copyright (C) 2015 Assured Information Security, Inc.
5 // Author: Rian Quinn <quinnr@ainfosec.com>
6 // Author: Brendan Kerrigan <kerriganb@ainfosec.com>
7 //
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Lesser General Public
10 // License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 
22 #ifndef MEMORY_MANAGER_X64_H
23 #define MEMORY_MANAGER_X64_H
24 
25 #include <map>
26 #include <vector>
27 
28 #include <memory.h>
29 #include <constants.h>
30 
31 #include <intrinsics/x64.h>
33 
73 {
74 public:
75 
76  using pointer = void *;
77  using integer_pointer = uintptr_t;
78  using size_type = std::size_t;
80  using memory_descriptor_list = std::vector<memory_descriptor>;
81 
87  virtual ~memory_manager_x64() = default;
88 
97 
114 
128  virtual pointer alloc_map(size_type size) noexcept;
129 
142  virtual void free(pointer ptr) noexcept;
143 
156  virtual void free_map(pointer ptr) noexcept;
157 
169  virtual size_type size(pointer ptr) const noexcept;
170 
182  virtual size_type size_map(pointer ptr) const noexcept;
183 
195 
207 
219 
230  virtual pointer virtptr_to_physptr(pointer virt) const;
231 
243 
254  virtual integer_pointer physptr_to_virtint(pointer phys) const;
255 
266  virtual pointer physint_to_virtptr(integer_pointer phys) const;
267 
278  virtual pointer physptr_to_virtptr(pointer phys) const;
279 
291 
302  virtual attr_type virtptr_to_attrint(pointer virt) const;
303 
319  virtual void add_md(integer_pointer virt, integer_pointer phys, attr_type attr);
320 
330  virtual void remove_md(integer_pointer virt) noexcept;
331 
344  virtual memory_descriptor_list descriptors() const;
345 
346 private:
347 
348  memory_manager_x64() noexcept;
349 
350  integer_pointer lower(integer_pointer ptr) const noexcept;
351  integer_pointer upper(integer_pointer ptr) const noexcept;
352 
353 private:
354 
355  std::map<integer_pointer, integer_pointer> m_virt_to_phys_map;
356  std::map<integer_pointer, integer_pointer> m_phys_to_virt_map;
357  std::map<integer_pointer, attr_type> m_virt_to_attr_map;
358 
360  mem_pool<MAX_PAGE_POOL, x64::page_shift> g_page_pool;
361  mem_pool<MAX_MEM_MAP_POOL, x64::page_shift> g_mem_map_pool;
362 
363 public:
364 
365  memory_manager_x64(const memory_manager_x64 &) = delete;
366  memory_manager_x64 &operator=(const memory_manager_x64 &) = delete;
367 };
368 
377 #define g_mm memory_manager_x64::instance()
378 
379 #endif
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)
uint64_t type
Definition: memory.h:63
virtual integer_pointer virtint_to_physint(integer_pointer virt) const
virtual void free(pointer ptr) noexcept
#define MAX_PAGE_POOL
Definition: constants.h:142
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
virtual ~memory_manager_x64()=default
void uint64_t uint64_t uint64_t *rdx noexcept
#define MAX_MEM_MAP_POOL
Definition: constants.h:154
virtual integer_pointer physptr_to_virtint(pointer phys) const
#define MAX_HEAP_POOL
Definition: constants.h:130
constexpr const auto page_shift
Definition: x64.h:36
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
virtual pointer virtint_to_physptr(integer_pointer virt) const
virtual integer_pointer physint_to_virtint(integer_pointer phys) const
virtual memory_descriptor_list descriptors() const
virtual pointer physptr_to_virtptr(pointer phys) const
constexpr const auto cache_line_shift
Definition: x64.h:38
virtual void remove_md(integer_pointer virt) noexcept
virtual void free_map(pointer ptr) noexcept
virtual attr_type virtint_to_attrint(integer_pointer virt) const
Definition: cache_x64.h:31
virtual pointer virtptr_to_physptr(pointer virt) const