Kagome
Polkadot Runtime Engine in C++17
kagome::runtime::binaryen::MemoryImpl Class Referencefinal

#include <memory_impl.hpp>

Inheritance diagram for kagome::runtime::binaryen::MemoryImpl:
Collaboration diagram for kagome::runtime::binaryen::MemoryImpl:

Public Member Functions

 MemoryImpl (wasm::ShellExternalInterface::Memory *memory, std::unique_ptr< MemoryAllocator > &&allocator)
 
 MemoryImpl (wasm::ShellExternalInterface::Memory *memory, WasmSize heap_base)
 
 MemoryImpl (const MemoryImpl &copy)=delete
 
MemoryImploperator= (const MemoryImpl &copy)=delete
 
 MemoryImpl (MemoryImpl &&move)=delete
 
MemoryImploperator= (MemoryImpl &&move)=delete
 
 ~MemoryImpl () override=default
 
WasmPointer allocate (WasmSize size) override
 
std::optional< WasmSizedeallocate (WasmPointer ptr) override
 
int8_t load8s (WasmPointer addr) const override
 
uint8_t load8u (WasmPointer addr) const override
 
int16_t load16s (WasmPointer addr) const override
 
uint16_t load16u (WasmPointer addr) const override
 
int32_t load32s (WasmPointer addr) const override
 
uint32_t load32u (WasmPointer addr) const override
 
int64_t load64s (WasmPointer addr) const override
 
uint64_t load64u (WasmPointer addr) const override
 
std::array< uint8_t, 16 > load128 (WasmPointer addr) const override
 
common::Buffer loadN (kagome::runtime::WasmPointer addr, kagome::runtime::WasmSize n) const override
 
std::string loadStr (kagome::runtime::WasmPointer addr, kagome::runtime::WasmSize length) const override
 
void store8 (WasmPointer addr, int8_t value) override
 
void store16 (WasmPointer addr, int16_t value) override
 
void store32 (WasmPointer addr, int32_t value) override
 
void store64 (WasmPointer addr, int64_t value) override
 
void store128 (WasmPointer addr, const std::array< uint8_t, 16 > &value) override
 
void storeBuffer (kagome::runtime::WasmPointer addr, gsl::span< const uint8_t > value) override
 
WasmSpan storeBuffer (gsl::span< const uint8_t > value) override
 allocates buffer in memory and copies value into memory More...
 
void resize (WasmSize new_size) override
 
WasmSize size () const override
 Return the size of the memory. More...
 
- Public Member Functions inherited from kagome::runtime::Memory
virtual ~Memory ()=default
 

Private Attributes

wasm::ShellExternalInterface::Memory * memory_
 
WasmSize size_
 
std::unique_ptr< MemoryAllocatorallocator_
 
log::Logger logger_
 

Additional Inherited Members

- Static Public Attributes inherited from kagome::runtime::Memory
static constexpr uint32_t kMaxMemorySize
 

Detailed Description

Memory implementation for wasm environment Most code is taken from Binaryen's implementation here: https://github.com/WebAssembly/binaryen/blob/master/src/shell-interface.h#L37

Note
Memory size of this implementation is at least a page size (4096 bytes)

Definition at line 37 of file memory_impl.hpp.

Constructor & Destructor Documentation

kagome::runtime::binaryen::MemoryImpl::MemoryImpl ( wasm::ShellExternalInterface::Memory *  memory,
std::unique_ptr< MemoryAllocator > &&  allocator 
)

Definition at line 13 of file memory_impl.cpp.

kagome::runtime::binaryen::MemoryImpl::MemoryImpl ( wasm::ShellExternalInterface::Memory *  memory,
WasmSize  heap_base 
)

Definition at line 22 of file memory_impl.cpp.

kagome::runtime::binaryen::MemoryImpl::MemoryImpl ( const MemoryImpl copy)
delete
kagome::runtime::binaryen::MemoryImpl::MemoryImpl ( MemoryImpl &&  move)
delete
kagome::runtime::binaryen::MemoryImpl::~MemoryImpl ( )
overridedefault

Member Function Documentation

WasmPointer kagome::runtime::binaryen::MemoryImpl::allocate ( WasmSize  size)
overridevirtual

Allocates memory of given size and returns address in the memory

Parameters
sizeallocated memory size
Returns
address to allocated memory. If there is no available slot for such allocation, then -1 is returned

Implements kagome::runtime::Memory.

Definition at line 32 of file memory_impl.cpp.

std::optional< WasmSize > kagome::runtime::binaryen::MemoryImpl::deallocate ( WasmPointer  ptr)
overridevirtual

Deallocates memory in provided region

Parameters
ptraddress of deallocated memory
Returns
size of deallocated memory or none if given address does not point to any allocated pieces of memory

Implements kagome::runtime::Memory.

Definition at line 36 of file memory_impl.cpp.

std::array< uint8_t, 16 > kagome::runtime::binaryen::MemoryImpl::load128 ( WasmPointer  addr) const
overridevirtual

Implements kagome::runtime::Memory.

Definition at line 72 of file memory_impl.cpp.

int16_t kagome::runtime::binaryen::MemoryImpl::load16s ( WasmPointer  addr) const
overridevirtual

Implements kagome::runtime::Memory.

Definition at line 48 of file memory_impl.cpp.

uint16_t kagome::runtime::binaryen::MemoryImpl::load16u ( WasmPointer  addr) const
overridevirtual

Implements kagome::runtime::Memory.

Definition at line 52 of file memory_impl.cpp.

int32_t kagome::runtime::binaryen::MemoryImpl::load32s ( WasmPointer  addr) const
overridevirtual

Implements kagome::runtime::Memory.

Definition at line 56 of file memory_impl.cpp.

uint32_t kagome::runtime::binaryen::MemoryImpl::load32u ( WasmPointer  addr) const
overridevirtual

Implements kagome::runtime::Memory.

Definition at line 60 of file memory_impl.cpp.

int64_t kagome::runtime::binaryen::MemoryImpl::load64s ( WasmPointer  addr) const
overridevirtual

Implements kagome::runtime::Memory.

Definition at line 64 of file memory_impl.cpp.

uint64_t kagome::runtime::binaryen::MemoryImpl::load64u ( WasmPointer  addr) const
overridevirtual

Implements kagome::runtime::Memory.

Definition at line 68 of file memory_impl.cpp.

int8_t kagome::runtime::binaryen::MemoryImpl::load8s ( WasmPointer  addr) const
overridevirtual

Load integers from provided address

Implements kagome::runtime::Memory.

Definition at line 40 of file memory_impl.cpp.

uint8_t kagome::runtime::binaryen::MemoryImpl::load8u ( WasmPointer  addr) const
overridevirtual

Implements kagome::runtime::Memory.

Definition at line 44 of file memory_impl.cpp.

common::Buffer kagome::runtime::binaryen::MemoryImpl::loadN ( kagome::runtime::WasmPointer  addr,
kagome::runtime::WasmSize  n 
) const
overridevirtual

Load bytes from provided address into the buffer of size n

Parameters
addraddress in memory to load bytes
nnumber of bytes to be loaded
Returns
Buffer of length N

Implements kagome::runtime::Memory.

Definition at line 77 of file memory_impl.cpp.

std::string kagome::runtime::binaryen::MemoryImpl::loadStr ( kagome::runtime::WasmPointer  addr,
kagome::runtime::WasmSize  n 
) const
overridevirtual

Load string from address into buffer of size n

Parameters
addraddress in memory to load bytes
nnumber of bytes
Returns
string with data

Implements kagome::runtime::Memory.

Definition at line 88 of file memory_impl.cpp.

MemoryImpl& kagome::runtime::binaryen::MemoryImpl::operator= ( const MemoryImpl copy)
delete
MemoryImpl& kagome::runtime::binaryen::MemoryImpl::operator= ( MemoryImpl &&  move)
delete
void kagome::runtime::binaryen::MemoryImpl::resize ( WasmSize  new_size)
inlineoverridevirtual

Resizes memory to the given size

Parameters
new_size

We use this condition to avoid deallocated_ pointers fixup

Implements kagome::runtime::Memory.

Definition at line 77 of file memory_impl.hpp.

WasmSize kagome::runtime::binaryen::MemoryImpl::size ( ) const
inlineoverridevirtual

Return the size of the memory.

Implements kagome::runtime::Memory.

Definition at line 88 of file memory_impl.hpp.

void kagome::runtime::binaryen::MemoryImpl::store128 ( WasmPointer  addr,
const std::array< uint8_t, 16 > &  value 
)
overridevirtual

Implements kagome::runtime::Memory.

Definition at line 119 of file memory_impl.cpp.

void kagome::runtime::binaryen::MemoryImpl::store16 ( WasmPointer  addr,
int16_t  value 
)
overridevirtual

Implements kagome::runtime::Memory.

Definition at line 104 of file memory_impl.cpp.

void kagome::runtime::binaryen::MemoryImpl::store32 ( WasmPointer  addr,
int32_t  value 
)
overridevirtual

Implements kagome::runtime::Memory.

Definition at line 109 of file memory_impl.cpp.

void kagome::runtime::binaryen::MemoryImpl::store64 ( WasmPointer  addr,
int64_t  value 
)
overridevirtual

Implements kagome::runtime::Memory.

Definition at line 114 of file memory_impl.cpp.

void kagome::runtime::binaryen::MemoryImpl::store8 ( WasmPointer  addr,
int8_t  value 
)
overridevirtual

Store integers at given address of the wasm memory

Implements kagome::runtime::Memory.

Definition at line 99 of file memory_impl.cpp.

void kagome::runtime::binaryen::MemoryImpl::storeBuffer ( kagome::runtime::WasmPointer  addr,
gsl::span< const uint8_t >  value 
)
overridevirtual

Implements kagome::runtime::Memory.

Definition at line 125 of file memory_impl.cpp.

WasmSpan kagome::runtime::binaryen::MemoryImpl::storeBuffer ( gsl::span< const uint8_t >  value)
overridevirtual

allocates buffer in memory and copies value into memory

Parameters
valuebuffer to store
Returns
full wasm pointer to allocated buffer

Implements kagome::runtime::Memory.

Definition at line 134 of file memory_impl.cpp.

Member Data Documentation

std::unique_ptr<MemoryAllocator> kagome::runtime::binaryen::MemoryImpl::allocator_
private

Definition at line 95 of file memory_impl.hpp.

log::Logger kagome::runtime::binaryen::MemoryImpl::logger_
private

Definition at line 97 of file memory_impl.hpp.

wasm::ShellExternalInterface::Memory* kagome::runtime::binaryen::MemoryImpl::memory_
private

Definition at line 93 of file memory_impl.hpp.

WasmSize kagome::runtime::binaryen::MemoryImpl::size_
private

Definition at line 94 of file memory_impl.hpp.


The documentation for this class was generated from the following files: