30 #include <type_traits> 124 g_mm->free_map(vmap);
173 for (
const auto &p : list)
176 auto &&vmap =
g_mm->alloc_map(size);
185 g_mm->free_map(vmap);
227 auto &&vmap =
g_mm->alloc_map(size +
lower(virt));
229 #ifdef MAP_PTR_TESTING 242 virt, cr3, size, pat);
246 g_mm->free_map(vmap);
339 class unique_map_ptr_x64
368 { (void) donotcare; }
380 m_unaligned_size(size)
479 for (
const auto &p : list)
486 m_unaligned_size += p.second;
489 m_virt |=
lower(list.front().first);
490 m_virt |=
upper(vmap);
495 for (
const auto &p : list)
497 auto &&phys =
upper(p.first);
498 auto &&
size = p.second;
501 g_pt->map_4k(vmap + voff, phys + poff, attr);
545 m_unaligned_size(size)
549 m_virt |=
lower(virt);
550 m_virt |=
upper(vmap);
552 m_unaligned_size +=
lower(virt);
583 {
reset(other.release()); }
597 { cleanup(m_virt, m_unaligned_size); });
601 m_unaligned_size = 0;
627 reset(other.release());
668 {
return *
reinterpret_cast<pointer>(m_virt); }
681 {
return reinterpret_cast<pointer>(m_virt); }
694 {
return reinterpret_cast<pointer>(m_virt); }
704 {
return m_virt != 0 && m_size != 0 && m_unaligned_size != 0; }
735 auto old_virt = m_virt;
736 auto old_size = m_size;
737 auto old_unaligned_size = m_unaligned_size;
741 m_unaligned_size = 0;
743 return std::make_tuple(reinterpret_cast<pointer>(old_virt), old_size, old_unaligned_size);
770 auto old_virt = m_virt;
771 auto old_unaligned_size = m_unaligned_size;
775 m_unaligned_size = unaligned_size;
777 cleanup(old_virt, old_unaligned_size);
798 {
reset(std::get<0>(p), std::get<1>(p), std::get<2>(p)); }
813 std::swap(m_unaligned_size, other.m_unaligned_size);
828 auto &&vmap =
upper(m_virt);
829 for (
auto vadr = vmap; vadr < vmap + m_unaligned_size; vadr +=
x64::page_size)
844 auto &&vmap =
upper(m_virt);
859 g_mm->free_map(reinterpret_cast<pointer>(vmap));
879 template <
class T1,
class T2>
881 {
return x.get() == y.get(); }
883 template <
class T1,
class T2>
885 {
return x.get() != y.get(); }
887 template <
class T1,
class T2>
889 {
return x.
get() < y.get(); }
891 template <
class T1,
class T2>
893 {
return x.
get() <= y.get(); }
895 template <
class T1,
class T2>
897 {
return x.get() > y.get(); }
899 template <
class T1,
class T2>
901 {
return x.get() >= y.get(); }
905 { (void) dontcare;
return !x; }
909 { (void) dontcare;
return !y; }
913 { (void) dontcare;
return x; }
917 { (void) dontcare;
return y; }
929 auto &&pml4_map = bfn::make_unique_map_x64<uintptr_t>(
cr3);
933 expects(pml4_pte.phys_addr() != 0);
937 auto &&pdpt_map = bfn::make_unique_map_x64<uintptr_t>(pml4_pte.phys_addr());
941 expects(pdpt_pte.phys_addr() != 0);
948 auto &&pd_map = bfn::make_unique_map_x64<uintptr_t>(pdpt_pte.phys_addr());
952 expects(pd_pte.phys_addr() != 0);
959 auto &&pt_map = bfn::make_unique_map_x64<uintptr_t>(pd_pte.phys_addr());
963 expects(pt_pte.phys_addr() != 0);
void reset(const std::tuple< pointer, size_type, size_type > &p) noexcept
void uintptr_t uintptr_t cr3
auto make_unique_map_x64(typename unique_map_ptr_x64< T >::pointer phys, x64::memory_attr::attr_type attr=x64::memory_attr::rw_wb)
bool operator==(const unique_map_ptr_x64< T1 > &x, const unique_map_ptr_x64< T2 > &y)
virtual size_type size() const noexcept
constexpr const auto cache_line_size
virtual ~unique_map_ptr_x64() noexcept
unique_map_ptr_x64(integer_pointer virt, size_type size)
constexpr const auto from
void invlpg(T val) noexcept
auto upper(T ptr) noexcept
void clflush(integer_pointer addr) noexcept
bool operator!=(const unique_map_ptr_x64< T1 > &x, const unique_map_ptr_x64< T2 > &y)
std::add_lvalue_reference< T >::type operator*() const
void uintptr_t uintptr_t size_t x64::msrs::value_type pat
unique_map_ptr_x64(integer_pointer vmap, const std::vector< std::pair< integer_pointer, size_type >> &list, x64::memory_attr::attr_type attr)
void uint64_t uint64_t uint64_t *rdx noexcept
constexpr const auto from
constexpr const auto from
auto index(const T virt, const F from)
void uintptr_t uintptr_t size_t size
unique_map_ptr_x64(std::nullptr_t donotcare)
constexpr const auto rw_wb
void swap(unique_map_ptr_x64 &other) noexcept
unique_map_ptr_x64 & operator=(std::nullptr_t dontcare) noexcept
unique_map_ptr_x64 & operator=(unique_map_ptr_x64 &&other) noexcept
unique_map_ptr_x64(integer_pointer vmap, integer_pointer phys, x64::memory_attr::attr_type attr)
uintptr_t integer_pointer
constexpr const auto page_size
unique_map_ptr_x64(integer_pointer vmap, integer_pointer virt, integer_pointer cr3, size_type size, x64::msrs::value_type pat)
bool operator>(const unique_map_ptr_x64< T1 > &x, const unique_map_ptr_x64< T2 > &y)
uintptr_t virt_to_phys_with_cr3(uintptr_t virt, uintptr_t cr3)
virtual pointer get() const noexcept
void reset(pointer ptr=pointer(), size_type size=size_type(), size_type unaligned_size=size_type()) noexcept
E guard_exceptions(E error_code, T func)
auto operator->() const noexcept
bool operator>=(const unique_map_ptr_x64< T1 > &x, const unique_map_ptr_x64< T2 > &y)
void cache_flush() noexcept
auto lower(T ptr) noexcept
constexpr const auto from
void swap(unique_map_ptr_x64< T > &x, unique_map_ptr_x64< T > &y) noexcept
constexpr const auto from
unique_map_ptr_x64(unique_map_ptr_x64 &&other) noexcept
void map_with_cr3(uintptr_t vmap, uintptr_t virt, uintptr_t cr3, size_t size, x64::msrs::value_type pat)