Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
execution_interface.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <sysio/vm/wasm_stack.hpp>
4#include <sysio/vm/utils.hpp>
5#include <sysio/vm/exceptions.hpp>
6#include <cstring>
7#include <limits>
8
9namespace sysio { namespace vm {
10
11 // interface used for the host function system to use
12 // clients can create their own interface to overlay their own implementations
13 struct execution_interface {
15 inline void* get_memory() const { return memory; }
16 inline void trim_operands(std::size_t amt) { os->trim(amt); }
17
18 template <typename T>
19 inline void push_operand(T&& op) { os->push(std::forward<T>(op)); }
20 inline auto pop_operand() { return os->pop(); }
21 inline const auto& operand_from_back(std::size_t index) const { return os->get_back(index); }
22
23 template <typename T>
24 inline void* validate_pointer(wasm_ptr_t ptr, wasm_size_t len) const {
25 auto result = memory + ptr;
26 validate_pointer<T>(result, len);
27 return result;
28 }
29
30 template <typename T>
31 inline void validate_pointer(const void* ptr, wasm_size_t len) const {
32 SYS_VM_ASSERT( len <= std::numeric_limits<wasm_size_t>::max() / (wasm_size_t)sizeof(T), wasm_interpreter_exception, "length will overflow" );
33 volatile auto check_addr = *(reinterpret_cast<const char*>(ptr) + (len * sizeof(T)) - 1);
35 }
36
38 auto result = memory + ptr;
40 return result;
41 }
42
43 inline void validate_null_terminated_pointer(const void* ptr) const {
44 volatile auto check_addr = std::strlen(static_cast<const char*>(ptr));
46 }
47 char* memory;
49 };
50}} // ns sysio::vm
ElemT & get_back(size_t i)
void push(ElemT &&e)
void trim(size_t amt)
void ignore_unused_variable_warning(T &...)
Definition utils.hpp:101
std::uint32_t wasm_ptr_t
Definition types.hpp:149
std::uint32_t wasm_size_t
Definition types.hpp:150
#define T(meth, val, expected)
void * validate_null_terminated_pointer(wasm_ptr_t ptr) const
execution_interface(char *memory, operand_stack *os)
void * validate_pointer(wasm_ptr_t ptr, wasm_size_t len) const
void validate_pointer(const void *ptr, wasm_size_t len) const
const auto & operand_from_back(std::size_t index) const
void validate_null_terminated_pointer(const void *ptr) const
#define SYS_VM_ASSERT(expr, exc_type, msg)
Definition exceptions.hpp:8
size_t len