Kagome
Polkadot Runtime Engine in C++17
kagome::runtime::Memory Class Referenceabstract

#include <memory.hpp>

Inheritance diagram for kagome::runtime::Memory:
Collaboration diagram for kagome::runtime::Memory:

Public Member Functions

virtual ~Memory ()=default
 
virtual WasmSize size () const =0
 Return the size of the memory. More...
 
virtual void resize (WasmSize new_size)=0
 
virtual WasmPointer allocate (WasmSize size)=0
 
virtual std::optional< WasmSizedeallocate (WasmPointer ptr)=0
 
virtual int8_t load8s (WasmPointer addr) const =0
 
virtual uint8_t load8u (WasmPointer addr) const =0
 
virtual int16_t load16s (WasmPointer addr) const =0
 
virtual uint16_t load16u (WasmPointer addr) const =0
 
virtual int32_t load32s (WasmPointer addr) const =0
 
virtual uint32_t load32u (WasmPointer addr) const =0
 
virtual int64_t load64s (WasmPointer addr) const =0
 
virtual uint64_t load64u (WasmPointer addr) const =0
 
virtual std::array< uint8_t, 16 > load128 (WasmPointer addr) const =0
 
virtual common::Buffer loadN (WasmPointer addr, WasmSize n) const =0
 
virtual std::string loadStr (WasmPointer addr, WasmSize n) const =0
 
virtual void store8 (WasmPointer addr, int8_t value)=0
 
virtual void store16 (WasmPointer addr, int16_t value)=0
 
virtual void store32 (WasmPointer addr, int32_t value)=0
 
virtual void store64 (WasmPointer addr, int64_t value)=0
 
virtual void store128 (WasmPointer addr, const std::array< uint8_t, 16 > &value)=0
 
virtual void storeBuffer (WasmPointer addr, gsl::span< const uint8_t > value)=0
 
virtual WasmSpan storeBuffer (gsl::span< const uint8_t > value)=0
 allocates buffer in memory and copies value into memory More...
 

Static Public Attributes

static constexpr uint32_t kMaxMemorySize
 

Detailed Description

The underlying memory can be accessed through unaligned pointers which isn't well-behaved in C++. WebAssembly nonetheless expects it to behave properly. Avoid emitting unaligned load/store by checking for alignment explicitly, and performing memcpy if unaligned.

The allocated memory tries to have the same alignment as the memory being simulated.

Definition at line 39 of file memory.hpp.

Constructor & Destructor Documentation

virtual kagome::runtime::Memory::~Memory ( )
virtualdefault

Member Function Documentation

virtual WasmPointer kagome::runtime::Memory::allocate ( WasmSize  size)
pure virtual

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

Implemented in kagome::runtime::binaryen::MemoryImpl, and kagome::runtime::wavm::MemoryImpl.

virtual std::optional<WasmSize> kagome::runtime::Memory::deallocate ( WasmPointer  ptr)
pure virtual

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

Implemented in kagome::runtime::binaryen::MemoryImpl, and kagome::runtime::wavm::MemoryImpl.

virtual std::array<uint8_t, 16> kagome::runtime::Memory::load128 ( WasmPointer  addr) const
pure virtual
virtual int16_t kagome::runtime::Memory::load16s ( WasmPointer  addr) const
pure virtual
virtual uint16_t kagome::runtime::Memory::load16u ( WasmPointer  addr) const
pure virtual
virtual int32_t kagome::runtime::Memory::load32s ( WasmPointer  addr) const
pure virtual
virtual uint32_t kagome::runtime::Memory::load32u ( WasmPointer  addr) const
pure virtual
virtual int64_t kagome::runtime::Memory::load64s ( WasmPointer  addr) const
pure virtual
virtual uint64_t kagome::runtime::Memory::load64u ( WasmPointer  addr) const
pure virtual
virtual int8_t kagome::runtime::Memory::load8s ( WasmPointer  addr) const
pure virtual

Load integers from provided address

Implemented in kagome::runtime::wavm::MemoryImpl, and kagome::runtime::binaryen::MemoryImpl.

virtual uint8_t kagome::runtime::Memory::load8u ( WasmPointer  addr) const
pure virtual
virtual common::Buffer kagome::runtime::Memory::loadN ( WasmPointer  addr,
WasmSize  n 
) const
pure virtual

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

Implemented in kagome::runtime::wavm::MemoryImpl, and kagome::runtime::binaryen::MemoryImpl.

virtual std::string kagome::runtime::Memory::loadStr ( WasmPointer  addr,
WasmSize  n 
) const
pure virtual

Load string from address into buffer of size n

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

Implemented in kagome::runtime::wavm::MemoryImpl, and kagome::runtime::binaryen::MemoryImpl.

virtual void kagome::runtime::Memory::resize ( WasmSize  new_size)
pure virtual

Resizes memory to the given size

Parameters
new_size

Implemented in kagome::runtime::wavm::MemoryImpl, and kagome::runtime::binaryen::MemoryImpl.

virtual WasmSize kagome::runtime::Memory::size ( ) const
pure virtual

Return the size of the memory.

Implemented in kagome::runtime::wavm::MemoryImpl, and kagome::runtime::binaryen::MemoryImpl.

virtual void kagome::runtime::Memory::store128 ( WasmPointer  addr,
const std::array< uint8_t, 16 > &  value 
)
pure virtual
virtual void kagome::runtime::Memory::store16 ( WasmPointer  addr,
int16_t  value 
)
pure virtual
virtual void kagome::runtime::Memory::store32 ( WasmPointer  addr,
int32_t  value 
)
pure virtual
virtual void kagome::runtime::Memory::store64 ( WasmPointer  addr,
int64_t  value 
)
pure virtual
virtual void kagome::runtime::Memory::store8 ( WasmPointer  addr,
int8_t  value 
)
pure virtual

Store integers at given address of the wasm memory

Implemented in kagome::runtime::wavm::MemoryImpl, and kagome::runtime::binaryen::MemoryImpl.

virtual void kagome::runtime::Memory::storeBuffer ( WasmPointer  addr,
gsl::span< const uint8_t >  value 
)
pure virtual
virtual WasmSpan kagome::runtime::Memory::storeBuffer ( gsl::span< const uint8_t >  value)
pure virtual

allocates buffer in memory and copies value into memory

Parameters
valuebuffer to store
Returns
full wasm pointer to allocated buffer

Implemented in kagome::runtime::wavm::MemoryImpl, and kagome::runtime::binaryen::MemoryImpl.

Member Data Documentation

constexpr uint32_t kagome::runtime::Memory::kMaxMemorySize
static
Initial value:
=
std::numeric_limits<uint32_t>::max()

Definition at line 43 of file memory.hpp.


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