2014-07-31 18:08:02 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
2015-09-26 22:46:04 +02:00
|
|
|
#include "vm_ref.h"
|
|
|
|
|
|
2016-07-27 23:43:22 +02:00
|
|
|
class ppu_thread;
|
2014-09-12 15:08:24 +02:00
|
|
|
|
2014-07-31 18:08:02 +02:00
|
|
|
namespace vm
|
|
|
|
|
{
|
2016-02-01 22:52:49 +01:00
|
|
|
// SFINAE helper type for vm::_ptr_base comparison operators (enables comparison between equal types and between any type and void*)
|
|
|
|
|
template<typename T1, typename T2, typename RT = void>
|
|
|
|
|
using if_comparable_t = std::enable_if_t<std::is_void<T1>::value || std::is_void<T2>::value || std::is_same<std::remove_cv_t<T1>, std::remove_cv_t<T2>>::value, RT>;
|
|
|
|
|
|
|
|
|
|
template<typename T, typename AT = u32>
|
|
|
|
|
class _ptr_base
|
2014-08-01 18:27:48 +02:00
|
|
|
{
|
2015-09-26 22:46:04 +02:00
|
|
|
AT m_addr;
|
2015-06-13 03:31:45 +02:00
|
|
|
|
|
|
|
|
static_assert(!std::is_pointer<T>::value, "vm::_ptr_base<> error: invalid type (pointer)");
|
|
|
|
|
static_assert(!std::is_reference<T>::value, "vm::_ptr_base<> error: invalid type (reference)");
|
|
|
|
|
|
2015-09-26 22:46:04 +02:00
|
|
|
public:
|
|
|
|
|
using type = T;
|
|
|
|
|
using addr_type = std::remove_cv_t<AT>;
|
|
|
|
|
|
|
|
|
|
_ptr_base() = default;
|
|
|
|
|
|
2016-05-13 16:01:48 +02:00
|
|
|
_ptr_base(vm::addr_t addr)
|
2015-09-26 22:46:04 +02:00
|
|
|
: m_addr(addr)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-13 16:01:48 +02:00
|
|
|
addr_type addr() const
|
2014-08-01 18:27:48 +02:00
|
|
|
{
|
|
|
|
|
return m_addr;
|
|
|
|
|
}
|
2015-06-22 22:01:06 +02:00
|
|
|
|
2016-02-01 22:52:49 +01:00
|
|
|
void set(addr_type addr)
|
2015-08-18 14:31:48 +02:00
|
|
|
{
|
2016-02-01 22:52:49 +01:00
|
|
|
this->m_addr = addr;
|
2015-08-18 14:31:48 +02:00
|
|
|
}
|
|
|
|
|
|
2016-05-13 16:01:48 +02:00
|
|
|
static _ptr_base make(addr_type addr)
|
2015-08-18 14:31:48 +02:00
|
|
|
{
|
2016-05-13 16:01:48 +02:00
|
|
|
_ptr_base result;
|
|
|
|
|
result.m_addr = addr;
|
|
|
|
|
return result;
|
2015-08-18 14:31:48 +02:00
|
|
|
}
|
|
|
|
|
|
2016-02-01 22:52:49 +01:00
|
|
|
// Enable only the conversions which are originally possible between pointer types
|
|
|
|
|
template<typename T2, typename AT2, typename = std::enable_if_t<std::is_convertible<T*, T2*>::value>>
|
|
|
|
|
operator _ptr_base<T2, AT2>() const
|
2015-06-22 22:01:06 +02:00
|
|
|
{
|
2016-05-13 16:01:48 +02:00
|
|
|
return vm::cast(m_addr, HERE);
|
2015-06-22 22:01:06 +02:00
|
|
|
}
|
|
|
|
|
|
2016-05-13 16:01:48 +02:00
|
|
|
explicit operator bool() const
|
2015-06-22 22:01:06 +02:00
|
|
|
{
|
2016-02-01 22:52:49 +01:00
|
|
|
return m_addr != 0;
|
2015-06-22 22:01:06 +02:00
|
|
|
}
|
2015-08-18 14:31:48 +02:00
|
|
|
|
2016-02-01 22:52:49 +01:00
|
|
|
// Get vm pointer to a struct member
|
2017-04-19 13:31:56 +02:00
|
|
|
template <typename MT, typename T2, typename = if_comparable_t<T, T2>>
|
2016-02-01 22:52:49 +01:00
|
|
|
_ptr_base<MT> ptr(MT T2::*const mptr) const
|
2015-08-18 14:31:48 +02:00
|
|
|
{
|
2017-04-19 13:31:56 +02:00
|
|
|
return vm::cast(vm::cast(m_addr, HERE) + offset32(mptr));
|
2015-08-18 14:31:48 +02:00
|
|
|
}
|
2016-02-01 22:52:49 +01:00
|
|
|
|
|
|
|
|
// Get vm pointer to a struct member with array subscription
|
2017-04-19 13:31:56 +02:00
|
|
|
template <typename MT, typename T2, typename ET = std::remove_extent_t<MT>, typename = if_comparable_t<T, T2>>
|
2016-02-01 22:52:49 +01:00
|
|
|
_ptr_base<ET> ptr(MT T2::*const mptr, u32 index) const
|
2014-09-11 21:18:19 +02:00
|
|
|
{
|
2018-09-03 17:46:14 +02:00
|
|
|
return vm::cast(vm::cast(m_addr, HERE) + offset32(mptr) + u32{sizeof(ET)} * index);
|
2014-09-11 21:18:19 +02:00
|
|
|
}
|
|
|
|
|
|
2016-02-01 22:52:49 +01:00
|
|
|
// Get vm reference to a struct member
|
2017-04-19 13:31:56 +02:00
|
|
|
template <typename MT, typename T2, typename = if_comparable_t<T, T2>>
|
2016-02-01 22:52:49 +01:00
|
|
|
_ref_base<MT> ref(MT T2::*const mptr) const
|
2014-08-01 18:27:48 +02:00
|
|
|
{
|
2017-04-19 13:31:56 +02:00
|
|
|
return vm::cast(vm::cast(m_addr, HERE) + offset32(mptr));
|
2016-02-01 22:52:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get vm reference to a struct member with array subscription
|
2017-04-19 13:31:56 +02:00
|
|
|
template <typename MT, typename T2, typename ET = std::remove_extent_t<MT>, typename = if_comparable_t<T, T2>>
|
2016-02-01 22:52:49 +01:00
|
|
|
_ref_base<ET> ref(MT T2::*const mptr, u32 index) const
|
|
|
|
|
{
|
2018-09-03 17:46:14 +02:00
|
|
|
return vm::cast(vm::cast(m_addr, HERE) + offset32(mptr) + u32{sizeof(ET)} * index);
|
2016-02-01 22:52:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get vm reference
|
|
|
|
|
_ref_base<T, u32> ref() const
|
|
|
|
|
{
|
2016-05-13 16:01:48 +02:00
|
|
|
return vm::cast(m_addr, HERE);
|
2014-08-01 18:27:48 +02:00
|
|
|
}
|
2014-09-04 19:32:20 +02:00
|
|
|
|
2014-11-19 15:16:30 +01:00
|
|
|
T* get_ptr() const
|
2014-08-01 18:27:48 +02:00
|
|
|
{
|
2016-02-01 22:52:49 +01:00
|
|
|
return static_cast<T*>(vm::base(vm::cast(m_addr, HERE)));
|
2014-08-01 18:27:48 +02:00
|
|
|
}
|
2015-02-07 14:46:42 +01:00
|
|
|
|
2015-06-14 23:52:22 +02:00
|
|
|
T* operator ->() const
|
2014-08-01 18:27:48 +02:00
|
|
|
{
|
2015-06-14 23:52:22 +02:00
|
|
|
return get_ptr();
|
2014-08-01 18:27:48 +02:00
|
|
|
}
|
|
|
|
|
|
2016-02-01 22:52:49 +01:00
|
|
|
std::add_lvalue_reference_t<T> operator *() const
|
2014-09-11 21:18:19 +02:00
|
|
|
{
|
2016-02-01 22:52:49 +01:00
|
|
|
return *static_cast<T*>(vm::base(vm::cast(m_addr, HERE)));
|
2014-08-01 18:27:48 +02:00
|
|
|
}
|
|
|
|
|
|
2016-02-01 22:52:49 +01:00
|
|
|
std::add_lvalue_reference_t<T> operator [](u32 index) const
|
2015-02-07 14:46:42 +01:00
|
|
|
{
|
2018-09-03 17:46:14 +02:00
|
|
|
return *static_cast<T*>(vm::base(vm::cast(m_addr, HERE) + u32{sizeof(T)} * index));
|
2014-09-04 19:32:20 +02:00
|
|
|
}
|
2015-06-15 03:22:01 +02:00
|
|
|
|
2015-10-16 02:25:39 +02:00
|
|
|
// Test address for arbitrary alignment: (addr & (align - 1)) == 0
|
2018-09-05 15:24:11 +02:00
|
|
|
bool aligned(u32 align = alignof(T)) const
|
2015-09-26 22:46:04 +02:00
|
|
|
{
|
|
|
|
|
return (m_addr & (align - 1)) == 0;
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-26 17:06:06 +02:00
|
|
|
// Get type size
|
|
|
|
|
static constexpr u32 size()
|
|
|
|
|
{
|
2018-09-03 17:46:14 +02:00
|
|
|
return sizeof(T);
|
2016-05-26 17:06:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get type alignment
|
|
|
|
|
static constexpr u32 align()
|
|
|
|
|
{
|
2018-08-31 15:47:30 +02:00
|
|
|
return alignof(T);
|
2016-05-26 17:06:06 +02:00
|
|
|
}
|
|
|
|
|
|
2016-02-01 22:52:49 +01:00
|
|
|
_ptr_base<T, u32> operator +() const
|
2015-09-26 22:46:04 +02:00
|
|
|
{
|
2016-05-13 16:01:48 +02:00
|
|
|
return vm::cast(m_addr, HERE);
|
2016-02-01 22:52:49 +01:00
|
|
|
}
|
2015-09-26 22:46:04 +02:00
|
|
|
|
2016-02-01 22:52:49 +01:00
|
|
|
_ptr_base<T, u32> operator +(u32 count) const
|
|
|
|
|
{
|
2018-09-03 17:46:14 +02:00
|
|
|
return vm::cast(vm::cast(m_addr, HERE) + count * size());
|
2016-02-01 22:52:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_ptr_base<T, u32> operator -(u32 count) const
|
|
|
|
|
{
|
2018-09-03 17:46:14 +02:00
|
|
|
return vm::cast(vm::cast(m_addr, HERE) - count * size());
|
2016-02-01 22:52:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
friend _ptr_base<T, u32> operator +(u32 count, const _ptr_base& ptr)
|
|
|
|
|
{
|
2018-09-03 17:46:14 +02:00
|
|
|
return vm::cast(vm::cast(ptr.m_addr, HERE) + count * size());
|
2016-02-01 22:52:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Pointer difference operator
|
|
|
|
|
template<typename T2, typename AT2>
|
2016-08-12 18:24:29 +02:00
|
|
|
std::enable_if_t<std::is_object<T2>::value && std::is_same<std::decay_t<T>, std::decay_t<T2>>::value, s32> operator -(const _ptr_base<T2, AT2>& right) const
|
2016-02-01 22:52:49 +01:00
|
|
|
{
|
2018-09-03 17:46:14 +02:00
|
|
|
return static_cast<s32>(vm::cast(m_addr, HERE) - vm::cast(right.m_addr, HERE)) / size();
|
2016-02-01 22:52:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_ptr_base operator ++(int)
|
|
|
|
|
{
|
2016-05-13 16:01:48 +02:00
|
|
|
_ptr_base result = *this;
|
2018-09-03 17:46:14 +02:00
|
|
|
m_addr = vm::cast(m_addr, HERE) + size();
|
2016-05-13 16:01:48 +02:00
|
|
|
return result;
|
2015-06-21 16:48:21 +02:00
|
|
|
}
|
|
|
|
|
|
2015-09-26 22:46:04 +02:00
|
|
|
_ptr_base& operator ++()
|
2015-06-21 16:48:21 +02:00
|
|
|
{
|
2018-09-03 17:46:14 +02:00
|
|
|
m_addr = vm::cast(m_addr, HERE) + size();
|
2015-09-26 22:46:04 +02:00
|
|
|
return *this;
|
2015-06-21 16:48:21 +02:00
|
|
|
}
|
|
|
|
|
|
2015-09-26 22:46:04 +02:00
|
|
|
_ptr_base operator --(int)
|
|
|
|
|
{
|
2016-06-07 22:24:20 +02:00
|
|
|
_ptr_base result = *this;
|
2018-09-03 17:46:14 +02:00
|
|
|
m_addr = vm::cast(m_addr, HERE) - size();
|
2016-05-13 16:01:48 +02:00
|
|
|
return result;
|
2015-09-26 22:46:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_ptr_base& operator --()
|
|
|
|
|
{
|
2018-09-03 17:46:14 +02:00
|
|
|
m_addr = vm::cast(m_addr, HERE) - size();
|
2015-09-26 22:46:04 +02:00
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_ptr_base& operator +=(s32 count)
|
|
|
|
|
{
|
2018-09-03 17:46:14 +02:00
|
|
|
m_addr = vm::cast(m_addr, HERE) + count * size();
|
2015-09-26 22:46:04 +02:00
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_ptr_base& operator -=(s32 count)
|
|
|
|
|
{
|
2018-09-03 17:46:14 +02:00
|
|
|
m_addr = vm::cast(m_addr, HERE) - count * size();
|
2015-09-26 22:46:04 +02:00
|
|
|
return *this;
|
|
|
|
|
}
|
2014-08-31 17:01:48 +02:00
|
|
|
};
|
|
|
|
|
|
2016-02-01 22:52:49 +01:00
|
|
|
template<typename AT, typename RT, typename... T>
|
|
|
|
|
class _ptr_base<RT(T...), AT>
|
2014-08-31 17:01:48 +02:00
|
|
|
{
|
|
|
|
|
AT m_addr;
|
|
|
|
|
|
2015-09-26 22:46:04 +02:00
|
|
|
public:
|
|
|
|
|
using addr_type = std::remove_cv_t<AT>;
|
|
|
|
|
|
|
|
|
|
_ptr_base() = default;
|
|
|
|
|
|
2016-05-13 16:01:48 +02:00
|
|
|
_ptr_base(vm::addr_t addr)
|
2015-09-26 22:46:04 +02:00
|
|
|
: m_addr(addr)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-13 16:01:48 +02:00
|
|
|
addr_type addr() const
|
2014-08-31 17:01:48 +02:00
|
|
|
{
|
|
|
|
|
return m_addr;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-01 22:52:49 +01:00
|
|
|
void set(addr_type addr)
|
2014-08-31 17:01:48 +02:00
|
|
|
{
|
2016-02-01 22:52:49 +01:00
|
|
|
m_addr = addr;
|
2014-09-04 19:32:20 +02:00
|
|
|
}
|
|
|
|
|
|
2016-05-13 16:01:48 +02:00
|
|
|
static _ptr_base make(addr_type addr)
|
2014-08-01 18:27:48 +02:00
|
|
|
{
|
2016-05-13 16:01:48 +02:00
|
|
|
_ptr_base result;
|
|
|
|
|
result.m_addr = addr;
|
|
|
|
|
return result;
|
2014-08-01 18:27:48 +02:00
|
|
|
}
|
2014-09-04 19:32:20 +02:00
|
|
|
|
2016-02-01 22:52:49 +01:00
|
|
|
// Conversion to another function pointer
|
|
|
|
|
template<typename AT2>
|
|
|
|
|
operator _ptr_base<RT(T...), AT2>() const
|
2014-08-01 18:27:48 +02:00
|
|
|
{
|
2016-05-13 16:01:48 +02:00
|
|
|
return vm::cast(m_addr, HERE);
|
2014-08-01 18:27:48 +02:00
|
|
|
}
|
2014-09-01 14:47:26 +02:00
|
|
|
|
2016-05-13 16:01:48 +02:00
|
|
|
explicit operator bool() const
|
2014-09-01 14:47:26 +02:00
|
|
|
{
|
2015-06-14 23:52:22 +02:00
|
|
|
return m_addr != 0;
|
2014-09-01 14:47:26 +02:00
|
|
|
}
|
2016-02-01 22:52:49 +01:00
|
|
|
|
|
|
|
|
_ptr_base<RT(T...), u32> operator +() const
|
|
|
|
|
{
|
2016-05-13 16:01:48 +02:00
|
|
|
return vm::cast(m_addr, HERE);
|
2016-02-01 22:52:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Callback; defined in PPUCallback.h, passing context is mandatory
|
2016-07-27 23:43:22 +02:00
|
|
|
RT operator()(ppu_thread& ppu, T... args) const;
|
2014-08-01 18:27:48 +02:00
|
|
|
};
|
|
|
|
|
|
2016-02-01 22:52:49 +01:00
|
|
|
template<typename AT, typename RT, typename... T>
|
|
|
|
|
class _ptr_base<RT(*)(T...), AT>
|
2015-01-28 13:59:16 +01:00
|
|
|
{
|
|
|
|
|
static_assert(!sizeof(AT), "vm::_ptr_base<> error: use RT(T...) format for functions instead of RT(*)(T...)");
|
|
|
|
|
};
|
|
|
|
|
|
2015-05-27 05:11:59 +02:00
|
|
|
// Native endianness pointer to LE data
|
2015-06-14 23:52:22 +02:00
|
|
|
template<typename T, typename AT = u32> using ptrl = _ptr_base<to_le_t<T>, AT>;
|
2016-05-26 17:06:06 +02:00
|
|
|
template<typename T, typename AT = u32> using cptrl = ptrl<const T, AT>;
|
2015-05-27 05:11:59 +02:00
|
|
|
|
|
|
|
|
// Native endianness pointer to BE data
|
2015-06-14 23:52:22 +02:00
|
|
|
template<typename T, typename AT = u32> using ptrb = _ptr_base<to_be_t<T>, AT>;
|
2016-05-26 17:06:06 +02:00
|
|
|
template<typename T, typename AT = u32> using cptrb = ptrb<const T, AT>;
|
2015-05-27 05:11:59 +02:00
|
|
|
|
2015-04-15 16:27:37 +02:00
|
|
|
// BE pointer to LE data
|
2015-06-14 23:52:22 +02:00
|
|
|
template<typename T, typename AT = u32> using bptrl = _ptr_base<to_le_t<T>, to_be_t<AT>>;
|
2014-09-02 00:22:13 +02:00
|
|
|
|
2015-04-15 16:27:37 +02:00
|
|
|
// BE pointer to BE data
|
2015-06-14 23:52:22 +02:00
|
|
|
template<typename T, typename AT = u32> using bptrb = _ptr_base<to_be_t<T>, to_be_t<AT>>;
|
2014-09-02 00:22:13 +02:00
|
|
|
|
2015-04-15 16:27:37 +02:00
|
|
|
// LE pointer to LE data
|
2015-06-14 23:52:22 +02:00
|
|
|
template<typename T, typename AT = u32> using lptrl = _ptr_base<to_le_t<T>, to_le_t<AT>>;
|
2015-05-27 05:11:59 +02:00
|
|
|
|
|
|
|
|
// LE pointer to BE data
|
2015-06-14 23:52:22 +02:00
|
|
|
template<typename T, typename AT = u32> using lptrb = _ptr_base<to_be_t<T>, to_le_t<AT>>;
|
2014-09-02 00:22:13 +02:00
|
|
|
|
2018-02-09 15:49:37 +01:00
|
|
|
inline namespace ps3_
|
2014-09-01 18:16:44 +02:00
|
|
|
{
|
2016-02-01 22:52:49 +01:00
|
|
|
// Default pointer type for PS3 HLE functions (Native endianness pointer to BE data)
|
2015-06-14 23:52:22 +02:00
|
|
|
template<typename T, typename AT = u32> using ptr = ptrb<T, AT>;
|
2016-05-26 17:06:06 +02:00
|
|
|
template<typename T, typename AT = u32> using cptr = ptr<const T, AT>;
|
2015-06-14 23:52:22 +02:00
|
|
|
|
2016-02-01 22:52:49 +01:00
|
|
|
// Default pointer to pointer type for PS3 HLE functions (Native endianness pointer to BE pointer to BE data)
|
2015-06-14 23:52:22 +02:00
|
|
|
template<typename T, typename AT = u32, typename AT2 = u32> using pptr = ptr<ptr<T, AT2>, AT>;
|
2016-05-26 17:06:06 +02:00
|
|
|
template<typename T, typename AT = u32, typename AT2 = u32> using cpptr = pptr<const T, AT, AT2>;
|
2014-09-02 00:22:13 +02:00
|
|
|
|
2016-02-01 22:52:49 +01:00
|
|
|
// Default pointer type for PS3 HLE structures (BE pointer to BE data)
|
2015-06-14 23:52:22 +02:00
|
|
|
template<typename T, typename AT = u32> using bptr = bptrb<T, AT>;
|
2016-05-26 17:06:06 +02:00
|
|
|
template<typename T, typename AT = u32> using bcptr = bptr<const T, AT>;
|
2015-06-14 23:52:22 +02:00
|
|
|
|
2016-02-01 22:52:49 +01:00
|
|
|
// Default pointer to pointer type for PS3 HLE structures (BE pointer to BE pointer to BE data)
|
2015-06-14 23:52:22 +02:00
|
|
|
template<typename T, typename AT = u32, typename AT2 = u32> using bpptr = bptr<ptr<T, AT2>, AT>;
|
2016-05-26 17:06:06 +02:00
|
|
|
template<typename T, typename AT = u32, typename AT2 = u32> using bcpptr = bpptr<const T, AT, AT2>;
|
2015-09-26 22:46:04 +02:00
|
|
|
|
2016-02-01 22:52:49 +01:00
|
|
|
// Perform static_cast (for example, vm::ptr<void> to vm::ptr<char>)
|
|
|
|
|
template<typename CT, typename T, typename AT, typename = decltype(static_cast<to_be_t<CT>*>(std::declval<T*>()))>
|
|
|
|
|
inline _ptr_base<to_be_t<CT>> static_ptr_cast(const _ptr_base<T, AT>& other)
|
2015-09-26 22:46:04 +02:00
|
|
|
{
|
2016-05-13 16:01:48 +02:00
|
|
|
return vm::cast(other.addr(), HERE);
|
2015-09-26 22:46:04 +02:00
|
|
|
}
|
|
|
|
|
|
2016-02-01 22:52:49 +01:00
|
|
|
// Perform const_cast (for example, vm::cptr<char> to vm::ptr<char>)
|
|
|
|
|
template<typename CT, typename T, typename AT, typename = decltype(const_cast<to_be_t<CT>*>(std::declval<T*>()))>
|
|
|
|
|
inline _ptr_base<to_be_t<CT>> const_ptr_cast(const _ptr_base<T, AT>& other)
|
2015-09-26 22:46:04 +02:00
|
|
|
{
|
2016-05-13 16:01:48 +02:00
|
|
|
return vm::cast(other.addr(), HERE);
|
2015-09-26 22:46:04 +02:00
|
|
|
}
|
2014-09-01 18:16:44 +02:00
|
|
|
}
|
2014-09-02 00:22:13 +02:00
|
|
|
|
2015-04-15 16:27:37 +02:00
|
|
|
struct null_t
|
|
|
|
|
{
|
2016-02-01 22:52:49 +01:00
|
|
|
template<typename T, typename AT>
|
2016-05-13 16:01:48 +02:00
|
|
|
operator _ptr_base<T, AT>() const
|
2016-02-01 22:52:49 +01:00
|
|
|
{
|
2016-05-13 16:01:48 +02:00
|
|
|
return _ptr_base<T, AT>{};
|
2016-02-01 22:52:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename T, typename AT>
|
2016-05-13 16:01:48 +02:00
|
|
|
friend bool operator ==(const null_t&, const _ptr_base<T, AT>& ptr)
|
2016-02-01 22:52:49 +01:00
|
|
|
{
|
|
|
|
|
return !ptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename T, typename AT>
|
2016-05-13 16:01:48 +02:00
|
|
|
friend bool operator ==(const _ptr_base<T, AT>& ptr, const null_t&)
|
2016-02-01 22:52:49 +01:00
|
|
|
{
|
|
|
|
|
return !ptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename T, typename AT>
|
2016-05-13 16:01:48 +02:00
|
|
|
friend bool operator !=(const null_t&, const _ptr_base<T, AT>& ptr)
|
2016-02-01 22:52:49 +01:00
|
|
|
{
|
|
|
|
|
return ptr.operator bool();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename T, typename AT>
|
2016-05-13 16:01:48 +02:00
|
|
|
friend bool operator !=(const _ptr_base<T, AT>& ptr, const null_t&)
|
2016-02-01 22:52:49 +01:00
|
|
|
{
|
|
|
|
|
return ptr.operator bool();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename T, typename AT>
|
2016-05-13 16:01:48 +02:00
|
|
|
friend bool operator <(const null_t&, const _ptr_base<T, AT>& ptr)
|
2016-02-01 22:52:49 +01:00
|
|
|
{
|
|
|
|
|
return ptr.operator bool();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename T, typename AT>
|
2016-05-13 16:01:48 +02:00
|
|
|
friend bool operator <(const _ptr_base<T, AT>&, const null_t&)
|
2016-02-01 22:52:49 +01:00
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2018-02-09 13:24:46 +01:00
|
|
|
|
2016-02-01 22:52:49 +01:00
|
|
|
template<typename T, typename AT>
|
2016-05-13 16:01:48 +02:00
|
|
|
friend bool operator <=(const null_t&, const _ptr_base<T, AT>&)
|
2016-02-01 22:52:49 +01:00
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename T, typename AT>
|
2016-05-13 16:01:48 +02:00
|
|
|
friend bool operator <=(const _ptr_base<T, AT>& ptr, const null_t&)
|
2016-02-01 22:52:49 +01:00
|
|
|
{
|
|
|
|
|
return !ptr.operator bool();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename T, typename AT>
|
2016-05-13 16:01:48 +02:00
|
|
|
friend bool operator >(const null_t&, const _ptr_base<T, AT>&)
|
2016-02-01 22:52:49 +01:00
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename T, typename AT>
|
2016-05-13 16:01:48 +02:00
|
|
|
friend bool operator >(const _ptr_base<T, AT>& ptr, const null_t&)
|
2016-02-01 22:52:49 +01:00
|
|
|
{
|
|
|
|
|
return ptr.operator bool();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename T, typename AT>
|
2016-05-13 16:01:48 +02:00
|
|
|
friend bool operator >=(const null_t&, const _ptr_base<T, AT>& ptr)
|
2016-02-01 22:52:49 +01:00
|
|
|
{
|
|
|
|
|
return !ptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename T, typename AT>
|
2016-05-13 16:01:48 +02:00
|
|
|
friend bool operator >=(const _ptr_base<T, AT>&, const null_t&)
|
2015-04-15 16:27:37 +02:00
|
|
|
{
|
2016-02-01 22:52:49 +01:00
|
|
|
return true;
|
2015-04-15 16:27:37 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2016-02-01 22:52:49 +01:00
|
|
|
// Null pointer convertible to any vm::ptr* type
|
2015-04-15 20:33:44 +02:00
|
|
|
static null_t null;
|
2015-06-14 23:52:22 +02:00
|
|
|
}
|
|
|
|
|
|
2016-02-01 22:52:49 +01:00
|
|
|
template<typename T1, typename AT1, typename T2, typename AT2>
|
|
|
|
|
inline vm::if_comparable_t<T1, T2, bool> operator ==(const vm::_ptr_base<T1, AT1>& left, const vm::_ptr_base<T2, AT2>& right)
|
2015-06-14 23:52:22 +02:00
|
|
|
{
|
2015-09-26 22:46:04 +02:00
|
|
|
return left.addr() == right.addr();
|
2015-06-14 23:52:22 +02:00
|
|
|
}
|
|
|
|
|
|
2016-02-01 22:52:49 +01:00
|
|
|
template<typename T1, typename AT1, typename T2, typename AT2>
|
|
|
|
|
inline vm::if_comparable_t<T1, T2, bool> operator !=(const vm::_ptr_base<T1, AT1>& left, const vm::_ptr_base<T2, AT2>& right)
|
2015-06-14 23:52:22 +02:00
|
|
|
{
|
2015-09-26 22:46:04 +02:00
|
|
|
return left.addr() != right.addr();
|
2015-06-14 23:52:22 +02:00
|
|
|
}
|
|
|
|
|
|
2016-02-01 22:52:49 +01:00
|
|
|
template<typename T1, typename AT1, typename T2, typename AT2>
|
|
|
|
|
inline vm::if_comparable_t<T1, T2, bool> operator <(const vm::_ptr_base<T1, AT1>& left, const vm::_ptr_base<T2, AT2>& right)
|
2015-06-14 23:52:22 +02:00
|
|
|
{
|
2015-09-26 22:46:04 +02:00
|
|
|
return left.addr() < right.addr();
|
2015-06-14 23:52:22 +02:00
|
|
|
}
|
|
|
|
|
|
2016-02-01 22:52:49 +01:00
|
|
|
template<typename T1, typename AT1, typename T2, typename AT2>
|
|
|
|
|
inline vm::if_comparable_t<T1, T2, bool> operator <=(const vm::_ptr_base<T1, AT1>& left, const vm::_ptr_base<T2, AT2>& right)
|
2015-06-14 23:52:22 +02:00
|
|
|
{
|
2015-09-26 22:46:04 +02:00
|
|
|
return left.addr() <= right.addr();
|
2015-06-14 23:52:22 +02:00
|
|
|
}
|
|
|
|
|
|
2016-02-01 22:52:49 +01:00
|
|
|
template<typename T1, typename AT1, typename T2, typename AT2>
|
|
|
|
|
inline vm::if_comparable_t<T1, T2, bool> operator >(const vm::_ptr_base<T1, AT1>& left, const vm::_ptr_base<T2, AT2>& right)
|
2015-06-14 23:52:22 +02:00
|
|
|
{
|
2015-09-26 22:46:04 +02:00
|
|
|
return left.addr() > right.addr();
|
2015-06-14 23:52:22 +02:00
|
|
|
}
|
|
|
|
|
|
2016-02-01 22:52:49 +01:00
|
|
|
template<typename T1, typename AT1, typename T2, typename AT2>
|
|
|
|
|
inline vm::if_comparable_t<T1, T2, bool> operator >=(const vm::_ptr_base<T1, AT1>& left, const vm::_ptr_base<T2, AT2>& right)
|
2015-06-14 23:52:22 +02:00
|
|
|
{
|
2015-09-26 22:46:04 +02:00
|
|
|
return left.addr() >= right.addr();
|
2015-06-14 23:52:22 +02:00
|
|
|
}
|
|
|
|
|
|
2016-02-01 22:52:49 +01:00
|
|
|
// Change AT endianness to BE/LE
|
|
|
|
|
template<typename T, typename AT, bool Se>
|
|
|
|
|
struct to_se<vm::_ptr_base<T, AT>, Se>
|
2015-06-13 03:31:45 +02:00
|
|
|
{
|
2015-09-26 22:46:04 +02:00
|
|
|
using type = vm::_ptr_base<T, typename to_se<AT, Se>::type>;
|
2015-06-13 03:31:45 +02:00
|
|
|
};
|
|
|
|
|
|
2016-04-25 12:49:12 +02:00
|
|
|
// Format pointer
|
|
|
|
|
template<typename T, typename AT>
|
2016-08-03 22:51:05 +02:00
|
|
|
struct fmt_unveil<vm::_ptr_base<T, AT>, void>
|
2015-01-13 18:14:07 +01:00
|
|
|
{
|
2016-08-11 01:29:59 +02:00
|
|
|
using type = vm::_ptr_base<T>; // Use only T, ignoring AT
|
2016-08-03 22:51:05 +02:00
|
|
|
|
2016-08-07 15:59:46 +02:00
|
|
|
static inline auto get(const vm::_ptr_base<T, AT>& arg)
|
2015-01-18 23:54:56 +01:00
|
|
|
{
|
2016-08-03 22:51:05 +02:00
|
|
|
return fmt_unveil<AT>::get(arg.addr());
|
2016-04-25 12:49:12 +02:00
|
|
|
}
|
|
|
|
|
};
|
2016-08-11 01:29:59 +02:00
|
|
|
|
|
|
|
|
template<>
|
|
|
|
|
struct fmt_class_string<vm::_ptr_base<const void>, void>
|
|
|
|
|
{
|
|
|
|
|
static void format(std::string& out, u64 arg);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
|
struct fmt_class_string<vm::_ptr_base<T>, void> : fmt_class_string<vm::_ptr_base<const void>, void>
|
|
|
|
|
{
|
|
|
|
|
// Classify all pointers as const void*
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<>
|
|
|
|
|
struct fmt_class_string<vm::_ptr_base<const char>, void>
|
|
|
|
|
{
|
|
|
|
|
static void format(std::string& out, u64 arg);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<>
|
|
|
|
|
struct fmt_class_string<vm::_ptr_base<char>, void> : fmt_class_string<vm::_ptr_base<const char>>
|
|
|
|
|
{
|
|
|
|
|
// Classify char* as const char*
|
|
|
|
|
};
|