Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
wasm_interface.hpp
Go to the documentation of this file.
1#pragma once
6#include <functional>
7#include "Runtime/Linker.h"
8#include "Runtime/Runtime.h"
9
10namespace sysio { namespace chain {
11
12 class apply_context;
13 class wasm_runtime_interface;
14 class controller;
15 namespace eosvmoc { struct config; }
16
17 struct wasm_exit {
18 int32_t code = 0;
19 };
20
26 public:
27 enum class vm_type {
28 eos_vm,
31 };
32
33 //return string description of vm_type
34 static std::string vm_type_string(vm_type vmtype) {
35 switch (vmtype) {
36 case vm_type::eos_vm:
37 return "sys-vm";
38 case vm_type::eos_vm_oc:
39 return "sys-vm-oc";
40 default:
41 return "sys-vm-jit";
42 }
43 }
44
45 wasm_interface(vm_type vm, bool eosvmoc_tierup, const chainbase::database& d, const boost::filesystem::path data_dir, const eosvmoc::config& eosvmoc_config, bool profile);
47
48 //call before dtor to skip what can be minutes of dtor overhead with some runtimes; can cause leaks
50
51 //validates code -- does a WASM validation pass and checks the wasm against SYSIO specific constraints
52 static void validate(const controller& control, const bytes& code);
53
54 //indicate that a particular code probably won't be used after given block_num
55 void code_block_num_last_used(const digest_type& code_hash, const uint8_t& vm_type, const uint8_t& vm_version, const uint32_t& block_num);
56
57 //indicate the current LIB. evicts old cache entries
58 void current_lib(const uint32_t lib);
59
60 //Calls apply or error on a given code
61 void apply(const digest_type& code_hash, const uint8_t& vm_type, const uint8_t& vm_version, apply_context& context);
62
63 //Immediately exits currently running wasm. UB is called when no wasm running
64 void exit();
65
66 // If substitute_apply is set, then apply calls it before doing anything else. If substitute_apply returns true,
67 // then apply returns immediately.
68 std::function<bool(
70 private:
72 };
73
74} } // sysio::chain
75
76namespace sysio{ namespace chain {
77 std::istream& operator>>(std::istream& in, wasm_interface::vm_type& runtime);
78}}
79
80FC_REFLECT_ENUM( sysio::chain::wasm_interface::vm_type, (eos_vm)(eos_vm_jit)(eos_vm_oc) )
wasm_interface(vm_type vm, bool eosvmoc_tierup, const chainbase::database &d, const boost::filesystem::path data_dir, const eosvmoc::config &eosvmoc_config, bool profile)
static void validate(const controller &control, const bytes &code)
static std::string vm_type_string(vm_type vmtype)
void code_block_num_last_used(const digest_type &code_hash, const uint8_t &vm_type, const uint8_t &vm_version, const uint32_t &block_num)
void current_lib(const uint32_t lib)
std::function< bool(const digest_type &code_hash, uint8_t vm_type, uint8_t vm_version, apply_context &context)> substitute_apply
void apply(const digest_type &code_hash, const uint8_t &vm_type, const uint8_t &vm_version, apply_context &context)
datastream< ST > & operator>>(datastream< ST > &s, sysio::chain::may_not_exist< T > &v)
Definition abi_def.hpp:152
#define FC_REFLECT_ENUM(ENUM, FIELDS)
Definition reflect.hpp:194
unsigned int uint32_t
Definition stdint.h:126
signed int int32_t
Definition stdint.h:123
unsigned char uint8_t
Definition stdint.h:124