Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
common.hpp
Go to the documentation of this file.
1#pragma once
2
5#include <sysio/vm/host_function.hpp>
6#include <sysio/vm/argument_proxy.hpp>
7#include <sysio/vm/span.hpp>
8#include <sysio/vm/types.hpp>
9
10namespace sysio { namespace chain { namespace webassembly {
11 // forward declaration
12 class interface;
13}}} // ns sysio::chain::webassembly
14
15// TODO need to fix up wasm_tests to not use this macro
16#define SYSIO_INJECTED_MODULE_NAME "sysio_injection"
17
18namespace sysio { namespace chain {
19
20 class apply_context;
21 class transaction_context;
22
23 inline static constexpr auto sysio_injected_module_name = SYSIO_INJECTED_MODULE_NAME;
24
25 template <typename T, std::size_t Extent = sysio::vm::dynamic_extent>
27
28 template <typename T, std::size_t Align = alignof(T)>
30
31 template <typename T, std::size_t Align = alignof(T)>
33
35 null_terminated_ptr(const char* ptr) : ptr(ptr) {}
36 const char* data() const { return ptr; }
37 const char* ptr;
38 };
39
41 void* dst;
42 const void* src;
44 };
45
47 const void* lhs;
48 const void* rhs;
50 };
51
53 const void* dst;
54 const int32_t val;
56 };
57
58 // define the type converter for sysio
59 template<typename Interface>
60 struct basic_type_converter : public sysio::vm::type_converter<webassembly::interface, Interface> {
65
66 SYS_VM_FROM_WASM(bool, (uint32_t value)) { return value ? 1 : 0; }
67
69 auto d = this->template validate_pointer<char>(dst, size);
70 auto s = this->template validate_pointer<char>(src, size);
71 this->template validate_pointer<char>(dst, 1);
72 return { d, s, size };
73 }
74
76 auto l = this->template validate_pointer<char>(lhs, size);
77 auto r = this->template validate_pointer<char>(rhs, size);
78 return { l, r, size };
79 }
80
82 auto d = this->template validate_pointer<char>(dst, size);
83 this->template validate_pointer<char>(dst, 1);
84 return { d, val, size };
85 }
86
87 template <typename T>
88 auto from_wasm(vm::wasm_ptr_t ptr) const
89 -> std::enable_if_t< std::is_pointer_v<T>,
91 auto p = this->template validate_pointer<std::remove_pointer_t<T>>(ptr, 1);
92 return {p};
93 }
94
95 template <typename T>
96 auto from_wasm(vm::wasm_ptr_t ptr, vm::tag<T> = {}) const
97 -> std::enable_if_t< vm::is_argument_proxy_type_v<T> &&
98 std::is_pointer_v<typename T::proxy_type>, T> {
99 if constexpr(T::is_legacy()) {
100 SYS_ASSERT(ptr != 0, wasm_execution_error, "references cannot be created for null pointers");
101 }
102 auto p = this->template validate_pointer<typename T::pointee_type>(ptr, 1);
103 return {p};
104 }
105
107 auto p = this->validate_null_terminated_pointer(ptr);
108 return {static_cast<const char*>(p)};
109 }
110 SYS_VM_FROM_WASM(name, (uint64_t e)) { return name{e}; }
111 uint64_t to_wasm(name&& n) { return n.to_uint64_t(); }
112 SYS_VM_FROM_WASM(float32_t, (float f)) { return ::to_softfloat32(f); }
113 SYS_VM_FROM_WASM(float64_t, (double f)) { return ::to_softfloat64(f); }
114 };
115
117
122
123}} // sysio::chain
const mie::Vuint & p
Definition bn.cpp:27
const mie::Vuint & r
Definition bn.cpp:28
#define SYS_ASSERT(expr, exc_type, FORMAT,...)
Definition exceptions.hpp:7
#define SYSIO_INJECTED_MODULE_NAME
Definition common.hpp:16
basic_type_converter< sysio::vm::execution_interface > type_converter
Definition common.hpp:116
sysio::vm::wasm_size_t wasm_size_t
Definition common.hpp:121
std::uint32_t wasm_ptr_t
Definition types.hpp:149
std::uint32_t wasm_size_t
Definition types.hpp:150
#define value
Definition pkcs11.h:157
#define T(meth, val, expected)
unsigned int uint32_t
Definition stdint.h:126
signed int int32_t
Definition stdint.h:123
unsigned __int64 uint64_t
Definition stdint.h:136
SYS_VM_FROM_WASM(float32_t,(float f))
Definition common.hpp:112
SYS_VM_FROM_WASM(null_terminated_ptr,(vm::wasm_ptr_t ptr))
Definition common.hpp:106
SYS_VM_FROM_WASM(bool,(uint32_t value))
Definition common.hpp:66
auto from_wasm(vm::wasm_ptr_t ptr, vm::tag< T >={}) const -> std::enable_if_t< vm::is_argument_proxy_type_v< T > &&std::is_pointer_v< typename T::proxy_type >, T >
Definition common.hpp:96
SYS_VM_FROM_WASM(memset_params,(vm::wasm_ptr_t dst, int32_t val, vm::wasm_size_t size))
Definition common.hpp:81
auto from_wasm(vm::wasm_ptr_t ptr) const -> std::enable_if_t< std::is_pointer_v< T >, vm::argument_proxy< T > >
Definition common.hpp:88
SYS_VM_FROM_WASM(name,(uint64_t e))
Definition common.hpp:110
SYS_VM_FROM_WASM(memcmp_params,(vm::wasm_ptr_t lhs, vm::wasm_ptr_t rhs, vm::wasm_size_t size))
Definition common.hpp:75
SYS_VM_FROM_WASM(memcpy_params,(vm::wasm_ptr_t dst, vm::wasm_ptr_t src, vm::wasm_size_t size))
Definition common.hpp:68
SYS_VM_FROM_WASM(float64_t,(double f))
Definition common.hpp:113
vm::wasm_size_t size
Definition common.hpp:49
vm::wasm_size_t size
Definition common.hpp:43
vm::wasm_size_t size
Definition common.hpp:55
Immutable except for fc::from_variant.
Definition name.hpp:43
null_terminated_ptr(const char *ptr)
Definition common.hpp:35
const char * data() const
Definition common.hpp:36
auto from_wasm(wasm_ptr_t ptr, wasm_size_t len, tag< T >={}) const -> std::enable_if_t< is_span_type_v< T >, T >
CK_ULONG d
char * s
int l