1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-22 18:53:28 +01:00

vm_ptr.h: Improve try_read() (#10627)

This commit is contained in:
Eladash 2021-07-29 21:14:29 +03:00 committed by GitHub
parent 3a6399aaaa
commit d85bb3f4eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -206,16 +206,24 @@ namespace vm
return *this;
}
template <bool = false> requires (std::is_copy_constructible_v<T>)
std::pair<bool, std::conditional_t<std::is_void_v<T>, char, std::remove_const_t<T>>> try_read() const
{
alignas(sizeof(T) >= 16 ? 16 : 8) char buf[sizeof(T)]{};
const bool ok = vm::try_access(vm::cast(m_addr), buf, sizeof(T), false);
return { ok, std::bit_cast<decltype(try_read().second)>(buf) };
}
template <bool = false> requires (!std::is_void_v<T>)
bool try_read(std::conditional_t<std::is_void_v<T>, char, std::remove_const_t<T>>& out) const
{
return vm::try_access(vm::cast(m_addr), &out, sizeof(T), false);
return vm::try_access(vm::cast(m_addr), std::addressof(out), sizeof(T), false);
}
template <bool = false> requires (!std::is_void_v<T> && !std::is_const_v<T>)
bool try_write(const std::conditional_t<std::is_void_v<T>, char, T>& _in) const
{
return vm::try_access(vm::cast(m_addr), const_cast<T*>(&_in), sizeof(T), true);
return vm::try_access(vm::cast(m_addr), const_cast<T*>(std::addressof(_in)), sizeof(T), true);
}
// Don't use