1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-12-23 02:42:09 +00:00

kern: fix KTypedAddress, strengthen assertions

This commit is contained in:
Michael Scire 2020-08-18 09:30:19 -07:00 committed by SciresM
parent 47f2e93a42
commit fac502aaa3

View file

@ -32,13 +32,10 @@ namespace ams::kern {
constexpr ALWAYS_INLINE explicit KTypedAddress(U *ptr) : address(reinterpret_cast<uintptr_t>(ptr)) { /* ... */ } constexpr ALWAYS_INLINE explicit KTypedAddress(U *ptr) : address(reinterpret_cast<uintptr_t>(ptr)) { /* ... */ }
/* Copy constructor. */ /* Copy constructor. */
constexpr ALWAYS_INLINE KTypedAddress(const KTypedAddress &rhs) : address(rhs.address) { /* ... */ } constexpr ALWAYS_INLINE KTypedAddress(const KTypedAddress &rhs) = default;
/* Assignment operator. */ /* Assignment operator. */
constexpr ALWAYS_INLINE KTypedAddress operator=(KTypedAddress rhs) { constexpr ALWAYS_INLINE KTypedAddress &operator=(const KTypedAddress &rhs) = default;
this->address = rhs.address;
return *this;
}
/* Arithmetic operators. */ /* Arithmetic operators. */
template<typename I> template<typename I>
@ -203,6 +200,26 @@ namespace ams::kern {
static_assert(sizeof(KVirtualAddress) == sizeof(uintptr_t)); static_assert(sizeof(KVirtualAddress) == sizeof(uintptr_t));
static_assert(sizeof(KProcessAddress) == sizeof(uintptr_t)); static_assert(sizeof(KProcessAddress) == sizeof(uintptr_t));
static_assert(std::is_trivially_copyable<KPhysicalAddress>::value);
static_assert(std::is_trivially_copyable<KVirtualAddress>::value);
static_assert(std::is_trivially_copyable<KProcessAddress>::value);
static_assert(std::is_trivially_copy_constructible<KPhysicalAddress>::value);
static_assert(std::is_trivially_copy_constructible<KVirtualAddress>::value);
static_assert(std::is_trivially_copy_constructible<KProcessAddress>::value);
static_assert(std::is_trivially_move_constructible<KPhysicalAddress>::value);
static_assert(std::is_trivially_move_constructible<KVirtualAddress>::value);
static_assert(std::is_trivially_move_constructible<KProcessAddress>::value);
static_assert(std::is_trivially_copy_assignable<KPhysicalAddress>::value);
static_assert(std::is_trivially_copy_assignable<KVirtualAddress>::value);
static_assert(std::is_trivially_copy_assignable<KProcessAddress>::value);
static_assert(std::is_trivially_move_assignable<KPhysicalAddress>::value);
static_assert(std::is_trivially_move_assignable<KVirtualAddress>::value);
static_assert(std::is_trivially_move_assignable<KProcessAddress>::value);
static_assert(std::is_trivially_destructible<KPhysicalAddress>::value); static_assert(std::is_trivially_destructible<KPhysicalAddress>::value);
static_assert(std::is_trivially_destructible<KVirtualAddress>::value); static_assert(std::is_trivially_destructible<KVirtualAddress>::value);
static_assert(std::is_trivially_destructible<KProcessAddress>::value); static_assert(std::is_trivially_destructible<KProcessAddress>::value);
@ -212,6 +229,10 @@ namespace ams::kern {
static_assert(Null<KVirtualAddress> == Null<uintptr_t>); static_assert(Null<KVirtualAddress> == Null<uintptr_t>);
static_assert(Null<KProcessAddress> == Null<uintptr_t>); static_assert(Null<KProcessAddress> == Null<uintptr_t>);
/* Constructor/assignment validations. */
static_assert([]{ const KPhysicalAddress a(5); KPhysicalAddress b(a); return b; }() == KPhysicalAddress(5));
static_assert([]{ const KPhysicalAddress a(5); KPhysicalAddress b(10); b = a; return b; }() == KPhysicalAddress(5));
/* Arithmetic validations. */ /* Arithmetic validations. */
static_assert(KPhysicalAddress(10) + 5 == KPhysicalAddress(15)); static_assert(KPhysicalAddress(10) + 5 == KPhysicalAddress(15));
static_assert(KPhysicalAddress(10) - 5 == KPhysicalAddress(5)); static_assert(KPhysicalAddress(10) - 5 == KPhysicalAddress(5));