3#include <sysio/vm/types.hpp>
4#include <sysio/vm/span.hpp>
7namespace sysio {
namespace vm {
15 template <
typename T, std::
size_t LegacyAlign=0>
16 struct argument_proxy;
20 template <
typename T, std::
size_t LegacyAlign>
21 struct argument_proxy<
T*, LegacyAlign> {
22 static_assert(LegacyAlign %
alignof(
T) == 0,
"Specified alignment must be at least alignment of T");
23 static_assert(std::is_trivially_copyable_v<T>,
"argument_proxy requires a trivially copyable type");
25 if (!LegacyAlign ||
reinterpret_cast<std::uintptr_t
>(original_ptr) % LegacyAlign != 0) {
27 memcpy( std::addressof(*
copy), original_ptr,
sizeof(
T) );
33 other.original_ptr =
nullptr;
36#pragma GCC diagnostic push
37#pragma GCC diagnostic ignored "-Wnonnull"
38 if constexpr (!std::is_const_v<T>)
40 memcpy(original_ptr, std::addressof(*
copy),
sizeof(
T));
41#pragma GCC diagnostic pop
43 constexpr operator T*() {
return get(); }
44 constexpr operator const T*()
const {
return get(); }
47 constexpr const T*
get()
const {
49 return std::addressof(*
copy);
51 return static_cast<const T*
>(original_ptr);
56 static constexpr bool is_legacy() {
return LegacyAlign != 0; }
63 std::optional<std::remove_cv_t<T>>
copy;
66 template <
typename T, std::
size_t LegacyAlign>
67 struct argument_proxy<
span<
T>, LegacyAlign> :
span<T> {
68 static_assert(LegacyAlign %
alignof(
T) == 0,
"Specified alignment must be at least alignment of T");
69 static_assert(std::is_trivially_copyable_v<T>,
"argument_proxy requires a trivially copyable type");
74 copy( is_aligned(ptr) ? nullptr : new
std::remove_cv_t<
T>[size] ) {
77 memcpy(
copy.get(), original_ptr, this->size_bytes() );
82#pragma GCC diagnostic push
83#pragma GCC diagnostic ignored "-Wnonnull"
84 if constexpr (!std::is_const_v<T>)
86 memcpy(original_ptr,
copy.get(), this->size_bytes());
87#pragma GCC diagnostic pop
89 static constexpr bool is_legacy() {
return LegacyAlign != 0; }
93 inline static constexpr bool is_aligned(
void* ptr) {
return reinterpret_cast<std::uintptr_t
>(ptr) % LegacyAlign == 0; }
95 std::unique_ptr<std::remove_cv_t<T>[]>
copy =
nullptr;
101 template <
typename T, std::
size_t LA>
103 template <
typename T>
107 template <
typename T>
108 constexpr inline static bool is_argument_proxy_type_v = std::is_same_v<decltype(detail::is_argument_proxy_type(std::declval<T>())), std::true_type>;
void copy(const path &from, const path &to)
sysio::vm::span< T, Extent > span
constexpr std::true_type is_argument_proxy_type(argument_proxy< T >)
#define T(meth, val, expected)
static constexpr bool is_legacy()
constexpr const void * get_original_pointer() const
constexpr argument_proxy(void *ptr)
constexpr argument_proxy(argument_proxy &&other)
constexpr const T * operator->() const
constexpr const T * get() const
constexpr argument_proxy(const argument_proxy &)=delete
constexpr T * operator->()
constexpr const void * get_original_pointer() const
static constexpr bool is_legacy()
constexpr argument_proxy(argument_proxy &&)=default
constexpr argument_proxy(const argument_proxy &)=delete
constexpr argument_proxy(void *ptr, uint32_t size)
memcpy((char *) pInfo->slotDescription, s, l)