6 #ifndef KAGOME_CORE_RUNTIME_WAVM_IMPL_MEMORY_HPP 7 #define KAGOME_CORE_RUNTIME_WAVM_IMPL_MEMORY_HPP 22 class MemoryAllocator;
30 std::unique_ptr<MemoryAllocator> &&allocator);
40 template <
typename T,
typename = std::enable_if_t<std::is_
integral_v<T>>>
42 auto res = WAVM::Runtime::memoryRef<T>(
memory_, addr);
47 template <
typename T,
typename = std::enable_if_t<std::is_
integral_v<T>>>
49 auto res = WAVM::Runtime::memoryArrayPtr<T>(
memory_, addr, num);
68 template <
typename T,
typename = std::enable_if_t<std::is_
integral_v<T>>>
72 WAVM::Runtime::memoryArrayPtr<uint8_t>(
memory_, addr,
sizeof(value)),
77 template <
typename T,
typename = std::enable_if_t<std::is_
integral_v<T>>>
80 std::memcpy(WAVM::Runtime::memoryArrayPtr<uint8_t>(
81 memory_, addr,
sizeof(array.size_bytes())),
91 const std::array<uint8_t, 16> &value)
override;
104 if (new_size >=
size()) {
105 auto new_page_number = (new_size /
kPageSize) + 1;
106 WAVM::Runtime::growMemory(
108 new_page_number - WAVM::Runtime::getMemoryNumPages(
memory_));
115 WAVM::Runtime::memoryArrayPtr<uint8_t>(
memory_, span.
ptr, span.
size);
116 memset(native_ptr, value, span.
size);
127 #endif // KAGOME_CORE_RUNTIME_WAVM_IMPL_MEMORY_HPP
void store16(WasmPointer addr, int16_t value) override
Class represents arbitrary (including empty) byte buffer.
WasmSize size() const override
Return the size of the memory.
uint8_t load8u(WasmPointer addr) const override
static constexpr uint32_t kPageSize
int32_t load32s(WasmPointer addr) const override
uint32_t WasmSize
Size type is uint32_t because we are working in 32 bit address space.
WAVM::Runtime::Memory * memory_
WasmPointer ptr
address of buffer
void storeBuffer(WasmPointer addr, gsl::span< const uint8_t > value) override
int8_t load8s(WasmPointer addr) const override
uint16_t load16u(WasmPointer addr) const override
#define SL_TRACE_FUNC_CALL(logger, ret,...)
void store64(WasmPointer addr, int64_t value) override
WasmPointer allocate(WasmSize size) override
void store(WasmPointer addr, T value)
std::array< uint8_t, 16 > load128(WasmPointer addr) const override
void fill(PtrSize span, uint8_t value)
void store32(WasmPointer addr, int32_t value) override
common::Buffer loadN(WasmPointer addr, WasmSize n) const override
uint32_t load32u(WasmPointer addr) const override
T load(WasmPointer addr) const
int64_t load64s(WasmPointer addr) const override
void resize(WasmSize new_size) override
void store128(WasmPointer addr, const std::array< uint8_t, 16 > &value) override
MemoryImpl(WAVM::Runtime::Memory *memory, std::unique_ptr< MemoryAllocator > &&allocator)
std::shared_ptr< soralog::Logger > Logger
T * loadArray(WasmPointer addr, size_t num) const
uint64_t WasmSpan
combination of pointer and size, where less significant part represents wasm pointer, and most significant represents size
void storeArray(WasmPointer addr, gsl::span< T > array)
uint32_t WasmPointer
type of wasm memory is 32 bit integer
MemoryImpl & operator=(const MemoryImpl ©)=delete
int16_t load16s(WasmPointer addr) const override
#define SL_TRACE_VOID_FUNC_CALL(logger,...)
std::unique_ptr< MemoryAllocator > allocator_
std::optional< WasmSize > deallocate(WasmPointer ptr) override
WasmSize size
length of buffer
uint64_t load64u(WasmPointer addr) const override
std::string loadStr(WasmPointer addr, WasmSize n) const override
void store8(WasmPointer addr, int8_t value) override