23#define WRAPPED_GUESTPTR(x) \
30#define WRAPPED_GUESTPTR_RETURN(x) \
32 return this->ptr64_.x; \
34 return this->ptr32_.x; \
37#define WRAPPED_GUESTPTR_OPERATOR(x) \
45template <
bool _Physical,
bool _Array,
bool _Const>
49template <
bool _Physical>
58template <
bool _Physical>
67template <
bool _Physical>
76template <
bool _Physical>
84#define GUEST_SIZET_TYPE \
85 basic_guest_ptr<_Tp, _PtrType, _Physical, std::enable_if_t<is_guest_size_v<_Tp>>>
92template <
typename _Tp,
typename _PtrType,
bool _Physical>
96 using basic_type =
typename std::remove_pointer_t<std::remove_extent_t<_Tp>>;
97 using array_element_type = std::remove_extent_t<_Tp>;
99 static constexpr bool _is_array_v = std::is_array_v<_Tp>;
100 static constexpr bool _is_pointer_v = std::is_pointer_v<array_element_type>;
101 static constexpr bool _is_ppointer_v =
102 std::is_pointer_v<std::remove_pointer_t<array_element_type>>;
103 static constexpr bool _is_guest_ptr_t_v =
false;
105 template <
typename Tp,
typename Tp2 = std::remove_all_extents_t<std::remove_const_t<Tp>>>
106 static constexpr bool _is_supported_type() {
107 return std::is_same_v<Tp2, uint32_t> || std::is_same_v<Tp2, uint64_t>;
121 inline bool x64()
const {
return this->x64_; }
140 template <
typename I>
145 template <
typename I>
162 template <
typename I>
167 template <
typename I>
174 template <
typename PtrType>
178 template <
typename PtrType>
182 template <
typename PtrType>
186 template <
typename PtrType>
190 template <
typename PtrType>
194 template <
typename PtrType>
200 inline uint64_t _get_value(
size_t index)
const {
201 if constexpr (_is_array_v) {
204 result = this->ptr64_[index];
206 result = this->ptr32_[index];
212 result = *this->ptr64_;
214 result = *this->ptr32_;
220 inline auto _get_ptr(
size_t index)
const {
223 result.x64_ = this->x64_;
224 result._domain(&(this->
domain()));
225 result._mapping(this->_mapping());
226 if constexpr (!_Physical) {
229 result.reset(this->x64_, this->_get_value(index));
233 inline auto _get(
size_t index)
const {
234 if constexpr (_is_pointer_v) {
235 return _get_ptr(index);
237 return _get_value(index);
243 inline auto at(
size_t index)
const {
244 static_assert(_is_array_v,
"at(index) is only available for arrays");
248 static_assert(_is_array_v,
"operator[] is only available for arrays");
249 return this->
at(index);
251 inline auto get()
const {
return this->_get(0); }
256 template <
typename Tp = _Tp,
typename std::enable_if_t<!std::is_po
inter_v<Tp>>* dummy =
nullptr>
257 inline void set(uint64_t value)
const {
258 static_assert(!_is_array_v,
"set(value) is not available for arrays");
260 *this->ptr64_ = value;
262 *this->ptr32_ = value;
265 template <
typename Tp = _Tp,
typename std::enable_if_t<!std::is_po
inter_v<Tp>>* dummy =
nullptr>
266 inline void set(
size_t index, uint64_t value)
const {
267 static_assert(_is_array_v,
"set(index, value) is only available for arrays");
269 this->ptr64_[index] = value;
271 this->ptr32_[index] = value;
277 typename Tp = _Tp,
typename InTp,
typename InPtrType,
278 typename std::enable_if_t<std::is_pointer_v<std::remove_extent_t<Tp>>>* dummy =
nullptr>
280 static_assert(!_is_array_v,
"set(ptr) is not available for arrays");
284 typename Tp = _Tp,
typename InTp,
typename InPtrType,
285 typename std::enable_if_t<std::is_pointer_v<std::remove_extent_t<Tp>>>* dummy =
nullptr>
287 static_assert(_is_array_v,
"set(index, ptr) is only available for arrays");
292 template <
typename Tp = _Tp,
typename InTp,
typename InPtrType>
296 template <
typename Tp = _Tp,
typename InTp,
typename InPtrType>
298 if constexpr (_is_supported_type<InTp>()) {
300 using InBasicType = std::remove_const_t<std::remove_extent_t<InTp>>;
301 if constexpr (std::is_same_v<uint64_t, InBasicType>) {
304 }
else if constexpr (std::is_same_v<uint32_t, InBasicType>) {
308 static_assert(std::is_same_v<uint32_t, InBasicType> ||
309 std::is_same_v<uint64_t, InBasicType>,
313 static_assert(std::is_same_v<std::remove_const_t<Tp>, std::remove_const_t<InTp>> ||
314 std::is_void_v<Tp> || std::is_void_v<InTp>,
315 "Assignment from incompatible type");
316 static_assert(std::is_const_v<Tp> || !std::is_const_v<InTp>,
317 "Cannot convert const to non-const");
318 this->x64_ = in.x64_;
320 this->ptr64_ = in.ptr64_;
322 this->ptr32_ = in.ptr32_;
329 template <
typename InTp,
typename InPtrType>
331 *
this = std::move(in);
333 template <
typename Tp = _Tp,
typename InTp,
typename InPtrType>
335 if constexpr (_is_supported_type<InTp>()) {
337 using InBasicType = std::remove_const_t<std::remove_extent_t<InTp>>;
338 if constexpr (std::is_same_v<uint64_t, InBasicType>) {
340 this->ptr64_ = std::move(in);
341 }
else if constexpr (std::is_same_v<uint32_t, InBasicType>) {
343 this->ptr32_ = std::move(in);
345 static_assert(std::is_same_v<uint32_t, InBasicType> ||
346 std::is_same_v<uint64_t, InBasicType>,
350 static_assert(std::is_same_v<std::remove_const_t<Tp>, std::remove_const_t<InTp>> ||
351 std::is_void_v<Tp> || std::is_void_v<InTp>,
352 "Assignment from incompatible type");
353 static_assert(std::is_const_v<Tp> || !std::is_const_v<InTp>,
354 "Cannot convert const to non-const");
355 this->x64_ = in.x64_;
357 this->ptr64_ = std::move(in.ptr64_);
359 this->ptr32_ = std::move(in.ptr32_);
367 template <
typename... Arguments>
372 template <
typename... Arguments>
384 result = this->ptr64_;
386 result = this->ptr32_;
395 template <
typename... Arguments>
400 template <
typename... Arguments>
408 template <
typename U = _Tp,
typename Tp,
typename PtrType,
409 typename std::enable_if_t<is_guest_size_v<Tp>>* dummy =
nullptr>
413 template <
typename U = _Tp,
typename Tp,
typename PtrType,
414 typename std::enable_if_t<is_guest_size_v<Tp>>* dummy =
nullptr>
416 *
this = std::move(in);
429 inline void _mapping(
const std::shared_ptr<GuestMemoryMapping>& in) {
432 inline void _mapping(std::shared_ptr<GuestMemoryMapping>&& in) {
435 inline auto _buffer()
const {
437 return reinterpret_cast<std::remove_all_extents_t<_Tp>*
>(this->ptr64_._buffer());
439 return reinterpret_cast<std::remove_all_extents_t<_Tp>*
>(this->ptr32_._buffer());
444 this->ptr64_._buffer(
reinterpret_cast<uint64_t*
>(in));
446 this->ptr32_._buffer(
reinterpret_cast<uint32_t*
>(in));
451 this->ptr64_._buffer(
reinterpret_cast<const uint64_t*
>(in));
453 this->ptr32_._buffer(
reinterpret_cast<const uint32_t*
>(in));
459 inline void _page_directory(uint64_t in) {
WRAPPED_GUESTPTR(_page_directory(in)); }
463 template <
typename U,
typename PtrType,
bool Physical,
typename Enabled>
467 template <
typename OutTp,
typename OutPtrType,
typename InTp,
typename InPtrType,
bool Physical>
470 template <
typename OutTp,
typename OutPtrType,
typename InTp,
typename InPtrType,
bool Physical>
473 template <
typename OutTp,
typename OutPtrType,
typename InTp,
typename InPtrType,
bool Physical>
476 template <
typename OutTp,
typename OutPtrType,
typename InTp,
typename InPtrType,
bool Physical>
479 template <
typename OutTp,
typename OutPtrType,
typename InTp,
typename InPtrType,
bool Physical>
482 template <
typename OutTp,
typename OutPtrType,
typename InTp,
typename InPtrType,
bool Physical>
485 template <
typename OutTp,
typename OutPtrType,
typename InTp,
typename InPtrType,
bool Physical>
490#undef GUEST_SIZET_TYPE
491#undef WRAPPED_GUESTPTR_OPERATOR
492#undef WRAPPED_GUESTPTR_RETURN
493#undef WRAPPED_GUESTPTR
503 template <
typename I,
typename std::enable_if_t<std::is_
integral_v<I>>* dummy =
nullptr>
509 operator uint64_t()
const {
return value_; }
A class representing a single Domain.
Definition Domain.hh:44
Specialization of basic_guest_ptr<_Tp, guest_ptr_t, _Physical> to handle both uint32_t and uint64_t.
Definition guest_size_t_ptr.hh:94
friend basic_guest_ptr< OutTp, OutPtrType, Physical > const_ptr_cast(const basic_guest_ptr< InTp, InPtrType, Physical > &)
uint64_t page_offset() const
Definition guest_size_t_ptr.hh:117
GUEST_SIZET_TYPE(const Vcpu &vcpu, Arguments &&... args)
Definition guest_size_t_ptr.hh:373
basic_guest_ptr< _Tp, _PtrType, _Physical > operator-(I offset)
Definition guest_size_t_ptr.hh:168
basic_guest_ptr< _Tp, _PtrType, _Physical > operator++(int)
Definition guest_size_t_ptr.hh:134
friend basic_guest_ptr< OutTp, OutPtrType, Physical > reinterpret_ptr_cast(const basic_guest_ptr< InTp, InPtrType, Physical > &)
GUEST_SIZET_TYPE(basic_guest_ptr< InTp, InPtrType, _Physical > &&in) noexcept
Definition guest_size_t_ptr.hh:330
auto at(size_t index) const
Getter methods.
Definition guest_size_t_ptr.hh:243
bool operator<=(const basic_guest_ptr< void, PtrType, _Physical > &in) const
Definition guest_size_t_ptr.hh:179
void reset(const basic_guest_ptr< Tp, PtrType, _Physical > &in)
Definition guest_size_t_ptr.hh:410
friend void _ptr_cast_impl(const basic_guest_ptr< InTp, InPtrType, Physical > &, basic_guest_ptr< OutTp, OutPtrType, Physical > &)
Friend the casting functions.
GUEST_SIZET_TYPE & operator=(const basic_guest_ptr< InTp, InPtrType, _Physical > &in)
Definition guest_size_t_ptr.hh:297
void reset(basic_guest_ptr< Tp, PtrType, _Physical > &&in)
Definition guest_size_t_ptr.hh:415
friend basic_guest_ptr< OutTp, OutPtrType, Physical > static_ptr_cast(const basic_guest_ptr< InTp, InPtrType, Physical > &)
bool operator<(const basic_guest_ptr< void, PtrType, _Physical > &in) const
Definition guest_size_t_ptr.hh:175
basic_guest_ptr< _Tp, _PtrType, _Physical > & operator--()
Definition guest_size_t_ptr.hh:152
friend basic_guest_ptr< OutTp, OutPtrType, Physical > const_ptr_cast(basic_guest_ptr< InTp, InPtrType, Physical > &&)
GUEST_SIZET_TYPE(bool x64, Arguments &&... args)
Definition guest_size_t_ptr.hh:368
GUEST_SIZET_TYPE(GUEST_SIZET_TYPE &&) noexcept=default
bool operator>=(const basic_guest_ptr< void, PtrType, _Physical > &in) const
Definition guest_size_t_ptr.hh:187
void set(size_t index, const basic_guest_ptr< InTp, InPtrType, _Physical > &in)
Definition guest_size_t_ptr.hh:286
basic_guest_ptr< _Tp, _PtrType, _Physical > & operator+=(I offset)
Definition guest_size_t_ptr.hh:141
void reset(const Vcpu &vcpu, Arguments &&... args)
Reset operations.
Definition guest_size_t_ptr.hh:396
void reset()
Definition guest_size_t_ptr.hh:405
void set(uint64_t value) const
Setter methods.
Definition guest_size_t_ptr.hh:257
friend basic_guest_ptr< OutTp, OutPtrType, Physical > reinterpret_ptr_cast(basic_guest_ptr< InTp, InPtrType, Physical > &&)
GUEST_SIZET_TYPE & operator=(basic_guest_ptr< InTp, InPtrType, _Physical > &&in) noexcept
Definition guest_size_t_ptr.hh:334
void reset(bool x64, Arguments &&... args)
Definition guest_size_t_ptr.hh:401
const Domain & domain() const
Definition guest_size_t_ptr.hh:119
basic_guest_ptr< _Tp, _PtrType, _Physical > operator+(I offset)
Definition guest_size_t_ptr.hh:146
GUEST_SIZET_TYPE & operator=(const GUEST_SIZET_TYPE &) noexcept=default
basic_guest_ptr< _Tp, _PtrType, _Physical > & operator++()
Definition guest_size_t_ptr.hh:130
uint64_t page_directory() const
Definition guest_size_t_ptr.hh:118
std::ostream & write_stream(std::ostream &os) const
Definition guest_size_t_ptr.hh:125
basic_guest_ptr< void, void, _Physical, void > clone(uint64_t address) const
Helper to create a new instance of this pointer.
Definition guest_size_t_ptr.hh:380
size_t length() const
Definition guest_size_t_ptr.hh:124
auto get() const
Definition guest_size_t_ptr.hh:251
bool x64() const
Definition guest_size_t_ptr.hh:121
GUEST_SIZET_TYPE(const GUEST_SIZET_TYPE &) noexcept=default
Default constructors.
GUEST_SIZET_TYPE()
Common constructors.
Definition guest_size_t_ptr.hh:366
auto operator[](size_t index) const
Definition guest_size_t_ptr.hh:247
basic_guest_ptr< _Tp, _PtrType, _Physical > operator--(int)
Definition guest_size_t_ptr.hh:156
uint64_t page_number() const
Definition guest_size_t_ptr.hh:116
void set(size_t index, uint64_t value) const
Definition guest_size_t_ptr.hh:266
bool operator!=(const basic_guest_ptr< void, PtrType, _Physical > &in) const
Definition guest_size_t_ptr.hh:195
void set(const basic_guest_ptr< InTp, InPtrType, _Physical > &in)
Definition guest_size_t_ptr.hh:279
std::string str() const
Definition guest_size_t_ptr.hh:120
bool operator>(const basic_guest_ptr< void, PtrType, _Physical > &in) const
Definition guest_size_t_ptr.hh:183
auto operator*() const
Definition guest_size_t_ptr.hh:123
friend basic_guest_ptr< OutTp, OutPtrType, Physical > static_ptr_cast(basic_guest_ptr< InTp, InPtrType, Physical > &&)
uint64_t address() const
Basic information.
Definition guest_size_t_ptr.hh:115
basic_guest_ptr< _Tp, _PtrType, _Physical > & operator-=(I offset)
Definition guest_size_t_ptr.hh:163
bool operator==(const basic_guest_ptr< void, PtrType, _Physical > &in) const
Definition guest_size_t_ptr.hh:191
GUEST_SIZET_TYPE(const basic_guest_ptr< InTp, InPtrType, _Physical > &in)
Definition guest_size_t_ptr.hh:293
A class representing a single virtual processor.
Definition Vcpu.hh:33
virtual bool long_mode() const =0
Check if the processor is in long mode.
virtual bool long_compatibility_mode() const =0
Check if the processor is currently in long compatibility mode.
Definition guest_ptr.hh:88
uint64_t address() const
Functions for getting the underlying address.
Definition guest_ptr.hh:124
void reset()
Definition guest_ptr.hh:345
Helper class to transparently convert between guest size and a value.
Definition guest_size_t_ptr.hh:498
guest_size_t()
Definition guest_size_t_ptr.hh:500
guest_size_t(uint64_t value)
Definition guest_size_t_ptr.hh:501
guest_size_t & operator=(I value)
Definition guest_size_t_ptr.hh:504
#define WRAPPED_GUESTPTR_OPERATOR(x)
Definition guest_size_t_ptr.hh:37
#define WRAPPED_GUESTPTR_RETURN(x)
Definition guest_size_t_ptr.hh:30
#define WRAPPED_GUESTPTR(x)
Definition guest_size_t_ptr.hh:23
Core IntroVirt classes.
Definition Cr0.hh:20
guest_size_t guest_ptr_t
Definition fwd.hh:80
basic_guest_ptr< uint32_t, void, _Physical > ptr32_
Definition guest_size_t_ptr.hh:53
bool x64_
Definition guest_size_t_ptr.hh:52
basic_guest_ptr< uint64_t, void, _Physical > ptr64_
Definition guest_size_t_ptr.hh:54
bool x64_
Definition guest_size_t_ptr.hh:61
basic_guest_ptr< const uint32_t, void, _Physical > ptr32_
Definition guest_size_t_ptr.hh:62
basic_guest_ptr< const uint64_t, void, _Physical > ptr64_
Definition guest_size_t_ptr.hh:63
basic_guest_ptr< uint32_t[], void, _Physical > ptr32_
Definition guest_size_t_ptr.hh:71
bool x64_
Definition guest_size_t_ptr.hh:70
basic_guest_ptr< uint64_t[], void, _Physical > ptr64_
Definition guest_size_t_ptr.hh:72
basic_guest_ptr< const uint64_t[], void, _Physical > ptr64_
Definition guest_size_t_ptr.hh:81
bool x64_
Definition guest_size_t_ptr.hh:79
basic_guest_ptr< const uint32_t[], void, _Physical > ptr32_
Definition guest_size_t_ptr.hh:80
Definition guest_size_t_ptr.hh:46