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

#include <memory_impl.hpp>

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

Public Member Functions

 MemoryImpl (WAVM::Runtime::Memory *memory, std::unique_ptr< MemoryAllocator > &&allocator)
 
 MemoryImpl (WAVM::Runtime::Memory *memory, WasmSize heap_base)
 
 MemoryImpl (const MemoryImpl &copy)=delete
 
MemoryImploperator= (const MemoryImpl &copy)=delete
 
 MemoryImpl (MemoryImpl &&move)=delete
 
MemoryImploperator= (MemoryImpl &&move)=delete
 
WasmPointer allocate (WasmSize size) override
 
std::optional< WasmSizedeallocate (WasmPointer ptr) override
 
template<typename T , typename = std::enable_if_t<std::is_integral_v<T>>>
load (WasmPointer addr) const
 
template<typename T , typename = std::enable_if_t<std::is_integral_v<T>>>
T * loadArray (WasmPointer addr, size_t num) const
 
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 (WasmPointer addr, WasmSize n) const override
 
std::string loadStr (WasmPointer addr, WasmSize n) const override
 
template<typename T , typename = std::enable_if_t<std::is_integral_v<T>>>
void store (WasmPointer addr, T value)
 
template<typename T , typename = std::enable_if_t<std::is_integral_v<T>>>
void storeArray (WasmPointer addr, gsl::span< T > array)
 
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 (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...
 
WasmSize size () const override
 Return the size of the memory. More...
 
void resize (WasmSize new_size) override
 
- Public Member Functions inherited from kagome::runtime::Memory
virtual ~Memory ()=default
 

Private Member Functions

void fill (PtrSize span, uint8_t value)
 

Private Attributes

std::unique_ptr< MemoryAllocatorallocator_
 
WAVM::Runtime::Memory * memory_
 
log::Logger logger_
 

Static Private Attributes

static constexpr uint32_t kPageSize = 4096
 

Additional Inherited Members

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

Detailed Description

Definition at line 27 of file memory_impl.hpp.

Constructor & Destructor Documentation

kagome::runtime::wavm::MemoryImpl::MemoryImpl ( WAVM::Runtime::Memory *  memory,
std::unique_ptr< MemoryAllocator > &&  allocator 
)

Definition at line 12 of file memory_impl.cpp.

kagome::runtime::wavm::MemoryImpl::MemoryImpl ( WAVM::Runtime::Memory *  memory,
WasmSize  heap_base 
)

Definition at line 22 of file memory_impl.cpp.

kagome::runtime::wavm::MemoryImpl::MemoryImpl ( const MemoryImpl copy)
delete
kagome::runtime::wavm::MemoryImpl::MemoryImpl ( MemoryImpl &&  move)
delete

Member Function Documentation

WasmPointer kagome::runtime::wavm::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 31 of file memory_impl.cpp.

std::optional< WasmSize > kagome::runtime::wavm::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 35 of file memory_impl.cpp.

void kagome::runtime::wavm::MemoryImpl::fill ( PtrSize  span,
uint8_t  value 
)
inlineprivate

Definition at line 113 of file memory_impl.hpp.

template<typename T , typename = std::enable_if_t<std::is_integral_v<T>>>
T kagome::runtime::wavm::MemoryImpl::load ( WasmPointer  addr) const
inline

Definition at line 41 of file memory_impl.hpp.

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

Implements kagome::runtime::Memory.

Definition at line 63 of file memory_impl.cpp.

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

Implements kagome::runtime::Memory.

Definition at line 45 of file memory_impl.cpp.

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

Implements kagome::runtime::Memory.

Definition at line 48 of file memory_impl.cpp.

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

Implements kagome::runtime::Memory.

Definition at line 51 of file memory_impl.cpp.

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

Implements kagome::runtime::Memory.

Definition at line 54 of file memory_impl.cpp.

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

Implements kagome::runtime::Memory.

Definition at line 57 of file memory_impl.cpp.

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

Implements kagome::runtime::Memory.

Definition at line 60 of file memory_impl.cpp.

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

Load integers from provided address

Implements kagome::runtime::Memory.

Definition at line 39 of file memory_impl.cpp.

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

Implements kagome::runtime::Memory.

Definition at line 42 of file memory_impl.cpp.

template<typename T , typename = std::enable_if_t<std::is_integral_v<T>>>
T* kagome::runtime::wavm::MemoryImpl::loadArray ( WasmPointer  addr,
size_t  num 
) const
inline

Definition at line 48 of file memory_impl.hpp.

common::Buffer kagome::runtime::wavm::MemoryImpl::loadN ( WasmPointer  addr,
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 70 of file memory_impl.cpp.

std::string kagome::runtime::wavm::MemoryImpl::loadStr ( WasmPointer  addr,
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 77 of file memory_impl.cpp.

MemoryImpl& kagome::runtime::wavm::MemoryImpl::operator= ( const MemoryImpl copy)
delete
MemoryImpl& kagome::runtime::wavm::MemoryImpl::operator= ( MemoryImpl &&  move)
delete
void kagome::runtime::wavm::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 100 of file memory_impl.hpp.

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

Return the size of the memory.

Implements kagome::runtime::Memory.

Definition at line 96 of file memory_impl.hpp.

template<typename T , typename = std::enable_if_t<std::is_integral_v<T>>>
void kagome::runtime::wavm::MemoryImpl::store ( WasmPointer  addr,
value 
)
inline

Definition at line 69 of file memory_impl.hpp.

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

Implements kagome::runtime::Memory.

Definition at line 100 of file memory_impl.cpp.

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

Implements kagome::runtime::Memory.

Definition at line 91 of file memory_impl.cpp.

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

Implements kagome::runtime::Memory.

Definition at line 94 of file memory_impl.cpp.

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

Implements kagome::runtime::Memory.

Definition at line 97 of file memory_impl.cpp.

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

Store integers at given address of the wasm memory

Implements kagome::runtime::Memory.

Definition at line 88 of file memory_impl.cpp.

template<typename T , typename = std::enable_if_t<std::is_integral_v<T>>>
void kagome::runtime::wavm::MemoryImpl::storeArray ( WasmPointer  addr,
gsl::span< T >  array 
)
inline

Definition at line 78 of file memory_impl.hpp.

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

Implements kagome::runtime::Memory.

Definition at line 104 of file memory_impl.cpp.

WasmSpan kagome::runtime::wavm::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 109 of file memory_impl.cpp.

Member Data Documentation

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

Definition at line 120 of file memory_impl.hpp.

constexpr uint32_t kagome::runtime::wavm::MemoryImpl::kPageSize = 4096
staticprivate

Definition at line 119 of file memory_impl.hpp.

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

Definition at line 122 of file memory_impl.hpp.

WAVM::Runtime::Memory* kagome::runtime::wavm::MemoryImpl::memory_
private

Definition at line 121 of file memory_impl.hpp.


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