14 std::unique_ptr<MemoryAllocator> &&allocator)
25 std::make_unique<MemoryAllocator>(
27 [
this](
auto new_size) {
return resize(new_size); },
28 [
this]() {
return size_; }},
41 BOOST_ASSERT(
allocator_->checkAddress<int8_t>(addr));
42 return memory_->get<int8_t>(addr);
45 BOOST_ASSERT(
allocator_->checkAddress<uint8_t>(addr));
46 return memory_->get<uint8_t>(addr);
49 BOOST_ASSERT(
allocator_->checkAddress<int16_t>(addr));
50 return memory_->get<int16_t>(addr);
53 BOOST_ASSERT(
allocator_->checkAddress<uint16_t>(addr));
54 return memory_->get<uint16_t>(addr);
57 BOOST_ASSERT(
allocator_->checkAddress<int32_t>(addr));
58 return memory_->get<int32_t>(addr);
61 BOOST_ASSERT(
allocator_->checkAddress<uint32_t>(addr));
62 return memory_->get<uint32_t>(addr);
65 BOOST_ASSERT(
allocator_->checkAddress<int64_t>(addr));
66 return memory_->get<int64_t>(addr);
69 BOOST_ASSERT(
allocator_->checkAddress<uint64_t>(addr));
70 return memory_->get<uint64_t>(addr);
73 BOOST_ASSERT((
allocator_->checkAddress<std::array<uint8_t, 16>>(addr)));
74 return memory_->get<std::array<uint8_t, 16>>(addr);
79 BOOST_ASSERT(
size_ > addr and
size_ - addr >= n);
82 for (
auto i = addr; i < addr + n; i++) {
90 BOOST_ASSERT(
size_ > addr and
size_ - addr >= length);
93 for (
auto i = addr; i < addr + length; i++) {
94 res.push_back(static_cast<char>(
memory_->get<uint8_t>(i)));
100 BOOST_ASSERT((
allocator_->checkAddress<int8_t>(addr)));
101 memory_->set<int8_t>(addr, value);
105 BOOST_ASSERT((
allocator_->checkAddress<int16_t>(addr)));
106 memory_->set<int16_t>(addr, value);
110 BOOST_ASSERT((
allocator_->checkAddress<int32_t>(addr)));
111 memory_->set<int32_t>(addr, value);
115 BOOST_ASSERT((
allocator_->checkAddress<int64_t>(addr)));
116 memory_->set<int64_t>(addr, value);
120 const std::array<uint8_t, 16> &value) {
121 BOOST_ASSERT((
allocator_->checkAddress<std::array<uint8_t, 16>>(addr)));
122 memory_->set<std::array<uint8_t, 16>>(addr, value);
126 gsl::span<const uint8_t> value) {
127 const auto size =
static_cast<size_t>(value.size());
129 for (
size_t i = addr, j = 0; i < addr +
size; i++, j++) {
135 const auto size =
static_cast<size_t>(value.size());
136 BOOST_ASSERT(std::numeric_limits<WasmSize>::max() >
size);
138 if (wasm_pointer == 0) {
142 return PtrSize(wasm_pointer, value.size()).combine();
Class represents arbitrary (including empty) byte buffer.
uint32_t load32u(WasmPointer addr) const override
uint32_t WasmSize
Size type is uint32_t because we are working in 32 bit address space.
void store64(WasmPointer addr, int64_t value) override
uint8_t load8u(WasmPointer addr) const override
void storeBuffer(kagome::runtime::WasmPointer addr, gsl::span< const uint8_t > value) override
int8_t load8s(WasmPointer addr) const override
std::string loadStr(kagome::runtime::WasmPointer addr, kagome::runtime::WasmSize length) const override
void store128(WasmPointer addr, const std::array< uint8_t, 16 > &value) override
uint64_t load64u(WasmPointer addr) const override
void store8(WasmPointer addr, int8_t value) override
int64_t load64s(WasmPointer addr) const override
constexpr size_t kInitialMemorySize
wasm::ShellExternalInterface::Memory * memory_
void resize(WasmSize new_size) override
SLBuffer & reserve(size_t size)
uint64_t WasmSpan
combination of pointer and size, where less significant part represents wasm pointer, and most significant represents size
std::optional< WasmSize > deallocate(WasmPointer ptr) override
std::unique_ptr< MemoryAllocator > allocator_
uint32_t WasmPointer
type of wasm memory is 32 bit integer
WasmPointer allocate(WasmSize size) override
int16_t load16s(WasmPointer addr) const override
SLBuffer & putUint8(uint8_t n)
Put a 8-bit {.
uint16_t load16u(WasmPointer addr) const override
Logger createLogger(const std::string &tag)
MemoryImpl(wasm::ShellExternalInterface::Memory *memory, std::unique_ptr< MemoryAllocator > &&allocator)
common::Buffer loadN(kagome::runtime::WasmPointer addr, kagome::runtime::WasmSize n) const override
void store32(WasmPointer addr, int32_t value) override
void store16(WasmPointer addr, int16_t value) override
std::array< uint8_t, 16 > load128(WasmPointer addr) const override
WasmSize size() const override
Return the size of the memory.
int32_t load32s(WasmPointer addr) const override