Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
sysio::chain::wasm_interface_impl Struct Reference

#include <wasm_interface_private.hpp>

Collaboration diagram for sysio::chain::wasm_interface_impl:

Classes

struct  wasm_cache_entry
 

Public Types

typedef boost::multi_index_container< wasm_cache_entry, indexed_by< ordered_unique< tag< by_hash >, composite_key< wasm_cache_entry, member< wasm_cache_entry, digest_type, &wasm_cache_entry::code_hash >, member< wasm_cache_entry, uint8_t, &wasm_cache_entry::vm_type >, member< wasm_cache_entry, uint8_t, &wasm_cache_entry::vm_version > > >, ordered_non_unique< tag< by_first_block_num >, member< wasm_cache_entry, uint32_t, &wasm_cache_entry::first_block_num_used > >, ordered_non_unique< tag< by_last_block_num >, member< wasm_cache_entry, uint32_t, &wasm_cache_entry::last_block_num_used > > > > wasm_cache_index
 

Public Member Functions

 wasm_interface_impl (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)
 
 ~wasm_interface_impl ()
 
std::vector< uint8_tparse_initial_memory (const Module &module)
 
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 (uint32_t lib)
 
const std::unique_ptr< wasm_instantiated_module_interface > & get_instantiated_module (const digest_type &code_hash, const uint8_t &vm_type, const uint8_t &vm_version, transaction_context &trx_context)
 

Public Attributes

bool is_shutting_down = false
 
std::unique_ptr< wasm_runtime_interfaceruntime_interface
 
wasm_cache_index wasm_instantiation_cache
 
const chainbase::databasedb
 
const wasm_interface::vm_type wasm_runtime_time
 

Detailed Description

Definition at line 37 of file wasm_interface_private.hpp.

Member Typedef Documentation

◆ wasm_cache_index

boost::multi_index_container< wasm_cache_entry, indexed_by< ordered_unique<tag<by_hash>, composite_key< wasm_cache_entry, member<wasm_cache_entry, digest_type, &wasm_cache_entry::code_hash>, member<wasm_cache_entry, uint8_t, &wasm_cache_entry::vm_type>, member<wasm_cache_entry, uint8_t, &wasm_cache_entry::vm_version> > >, ordered_non_unique<tag<by_first_block_num>, member<wasm_cache_entry, uint32_t, &wasm_cache_entry::first_block_num_used> >, ordered_non_unique<tag<by_last_block_num>, member<wasm_cache_entry, uint32_t, &wasm_cache_entry::last_block_num_used> > > > sysio::chain::wasm_interface_impl::wasm_cache_index

Definition at line 200 of file wasm_interface_private.hpp.

Constructor & Destructor Documentation

◆ wasm_interface_impl()

sysio::chain::wasm_interface_impl::wasm_interface_impl ( 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 )
inline

Definition at line 61 of file wasm_interface_private.hpp.

61 : db(d), wasm_runtime_time(vm) {
62#ifdef SYSIO_SYS_VM_RUNTIME_ENABLED
63 if(vm == wasm_interface::vm_type::eos_vm)
64 runtime_interface = std::make_unique<webassembly::eos_vm_runtime::eos_vm_runtime<sysio::vm::interpreter>>();
65#endif
66#ifdef SYSIO_SYS_VM_JIT_RUNTIME_ENABLED
67 if(vm == wasm_interface::vm_type::eos_vm_jit && profile) {
69 runtime_interface = std::make_unique<webassembly::eos_vm_runtime::eos_vm_profile_runtime>();
70 }
71 if(vm == wasm_interface::vm_type::eos_vm_jit && !profile)
72 runtime_interface = std::make_unique<webassembly::eos_vm_runtime::eos_vm_runtime<sysio::vm::jit>>();
73#endif
74#ifdef SYSIO_SYS_VM_OC_RUNTIME_ENABLED
75 if(vm == wasm_interface::vm_type::eos_vm_oc)
76 runtime_interface = std::make_unique<webassembly::eosvmoc::eosvmoc_runtime>(data_dir, eosvmoc_config, d);
77#endif
79 SYS_THROW(wasm_exception, "${r} wasm runtime not supported on this platform and/or configuration", ("r", vm));
80
81#ifdef SYSIO_SYS_VM_OC_RUNTIME_ENABLED
82 if(eosvmoc_tierup) {
83 SYS_ASSERT(vm != wasm_interface::vm_type::eos_vm_oc, wasm_exception, "You can't use SYS VM OC as the base runtime when tier up is activated");
84 eosvmoc.emplace(data_dir, eosvmoc_config, d);
85 }
86#endif
87 }
#define SYS_THROW(exc_type, FORMAT,...)
#define SYS_ASSERT(expr, exc_type, FORMAT,...)
Definition exceptions.hpp:7
key Invalid authority Invalid transaction Invalid block ID Invalid packed transaction Invalid chain ID Invalid symbol Signature type is not a currently activated type Block can not be found Unlinkable block Block does not guarantee concurrent execution without conflicts Block exhausted allowed resources Block is from the future Block is not signed by expected producer Block includes an ill formed protocol feature activation extension Block includes an ill formed additional block signature extension Error decompressing transaction Transaction should have at least one required authority Expired Transaction Invalid Reference Block Duplicate deferred transaction The transaction can not be found Transaction is too big Invalid transaction extension Transaction includes disallowed Transaction exceeded transient resource limit Account name already exists sysio_assert_message assertion failure Action can not be found Attempt to use unaccessible API Inline Action exceeds maximum size limit sysio_assert_code assertion failure uses restricted error code value action return value size too big Permission Query Exception Contract Table Query Exception Database is an unknown or unsupported version Database usage is at unsafe levels wasm_exception
void set_profile_interval_us(uint32_t value)
Definition profile.hpp:271
const wasm_interface::vm_type wasm_runtime_time
std::unique_ptr< wasm_runtime_interface > runtime_interface
Here is the call graph for this function:

◆ ~wasm_interface_impl()

sysio::chain::wasm_interface_impl::~wasm_interface_impl ( )
inline

Definition at line 89 of file wasm_interface_private.hpp.

89 {
91 for(wasm_cache_index::iterator it = wasm_instantiation_cache.begin(); it != wasm_instantiation_cache.end(); ++it)
92 wasm_instantiation_cache.modify(it, [](wasm_cache_entry& e) {
93 e.module.release()->fast_shutdown();
94 });
95 }

Member Function Documentation

◆ code_block_num_last_used()

void sysio::chain::wasm_interface_impl::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 )
inline

Definition at line 115 of file wasm_interface_private.hpp.

115 {
116 wasm_cache_index::iterator it = wasm_instantiation_cache.find(boost::make_tuple(code_hash, vm_type, vm_version));
117 if(it != wasm_instantiation_cache.end())
118 wasm_instantiation_cache.modify(it, [block_num](wasm_cache_entry& e) {
119 e.last_block_num_used = block_num;
120 });
121 }
wasm_interface::vm_type vm_type

◆ current_lib()

void sysio::chain::wasm_interface_impl::current_lib ( uint32_t lib)
inline

Definition at line 123 of file wasm_interface_private.hpp.

123 {
124 //anything last used before or on the LIB can be evicted
125 const auto first_it = wasm_instantiation_cache.get<by_last_block_num>().begin();
126 const auto last_it = wasm_instantiation_cache.get<by_last_block_num>().upper_bound(lib);
127#ifdef SYSIO_SYS_VM_OC_RUNTIME_ENABLED
128 if(eosvmoc) for(auto it = first_it; it != last_it; it++)
129 eosvmoc->cc.free_code(it->code_hash, it->vm_version);
130#endif
131 wasm_instantiation_cache.get<by_last_block_num>().erase(first_it, last_it);
132 }

◆ get_instantiated_module()

const std::unique_ptr< wasm_instantiated_module_interface > & sysio::chain::wasm_interface_impl::get_instantiated_module ( const digest_type & code_hash,
const uint8_t & vm_type,
const uint8_t & vm_version,
transaction_context & trx_context )
inline

Definition at line 134 of file wasm_interface_private.hpp.

136 {
137 wasm_cache_index::iterator it = wasm_instantiation_cache.find(
138 boost::make_tuple(code_hash, vm_type, vm_version) );
139 const code_object* codeobject = nullptr;
140 if(it == wasm_instantiation_cache.end()) {
141 codeobject = &db.get<code_object,by_code_hash>(boost::make_tuple(code_hash, vm_type, vm_version));
142
143 it = wasm_instantiation_cache.emplace( wasm_interface_impl::wasm_cache_entry{
144 .code_hash = code_hash,
145 .first_block_num_used = codeobject->first_block_used,
146 .last_block_num_used = UINT32_MAX,
147 .module = nullptr,
148 .vm_type = vm_type,
149 .vm_version = vm_version
150 } ).first;
151 }
152
153 if(!it->module) {
154 if(!codeobject)
155 codeobject = &db.get<code_object,by_code_hash>(boost::make_tuple(code_hash, vm_type, vm_version));
156
157 auto timer_pause = fc::make_scoped_exit([&](){
158 trx_context.resume_billing_timer();
159 });
160 trx_context.pause_billing_timer();
162 std::vector<U8> bytes = {
163 (const U8*)codeobject->code.data(),
164 (const U8*)codeobject->code.data() + codeobject->code.size()};
165 try {
166 Serialization::MemoryInputStream stream((const U8*)bytes.data(),
167 bytes.size());
169 WASM::serialize(stream, module);
170 module.userSections.clear();
172 SYS_ASSERT(false, wasm_serialization_error, e.message.c_str());
173 } catch (const IR::ValidationException& e) {
174 SYS_ASSERT(false, wasm_serialization_error, e.message.c_str());
175 }
176
177 wasm_instantiation_cache.modify(it, [&](auto& c) {
178 c.module = runtime_interface->instantiate_module((const char*)bytes.data(), bytes.size(), parse_initial_memory(module), code_hash, vm_type, vm_version);
179 });
180 }
181 return it->module;
182 }
uint8_t U8
Definition BasicTypes.h:5
const ObjectType & get(CompatibleKey &&key) const
void serialize(Stream &stream, U8 &i)
scoped_exit< Callback > make_scoped_exit(Callback &&c)
std::vector< char > bytes
Definition alt_bn128.hpp:10
#define UINT32_MAX
Definition stdint.h:188
std::string message
Definition Validate.h:15
std::vector< uint8_t > parse_initial_memory(const Module &module)
Here is the call graph for this function:

◆ parse_initial_memory()

std::vector< uint8_t > sysio::chain::wasm_interface_impl::parse_initial_memory ( const Module & module)
inline

Definition at line 97 of file wasm_interface_private.hpp.

97 {
98 std::vector<uint8_t> mem_image;
99
100 for(const DataSegment& data_segment : module.dataSegments) {
101 SYS_ASSERT(data_segment.baseOffset.type == InitializerExpression::Type::i32_const, wasm_exception, "");
102 SYS_ASSERT(module.memories.defs.size(), wasm_exception, "");
103 const U32 base_offset = data_segment.baseOffset.i32;
104 const Uptr memory_size = (module.memories.defs[0].type.size.min << IR::numBytesPerPageLog2);
105 if(base_offset >= memory_size || base_offset + data_segment.data.size() > memory_size)
106 FC_THROW_EXCEPTION(wasm_execution_error, "WASM data segment outside of valid memory range");
107 if(base_offset + data_segment.data.size() > mem_image.size())
108 mem_image.resize(base_offset + data_segment.data.size(), 0x00);
109 memcpy(mem_image.data() + base_offset, data_segment.data.data(), data_segment.data.size());
110 }
111
112 return mem_image;
113 }
uint32_t U32
Definition BasicTypes.h:9
PointerIntHelper< sizeof(size_t)>::UnsignedIntType Uptr
Definition BasicTypes.h:22
#define FC_THROW_EXCEPTION(EXCEPTION, FORMAT,...)
size_t memory_size(const T &obj)
std::vector< U8 > data
Definition Module.h:95
InitializerExpression baseOffset
Definition Module.h:94
memcpy((char *) pInfo->slotDescription, s, l)
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ db

const chainbase::database& sysio::chain::wasm_interface_impl::db

Definition at line 203 of file wasm_interface_private.hpp.

◆ is_shutting_down

bool sysio::chain::wasm_interface_impl::is_shutting_down = false

Definition at line 184 of file wasm_interface_private.hpp.

◆ runtime_interface

std::unique_ptr<wasm_runtime_interface> sysio::chain::wasm_interface_impl::runtime_interface

Definition at line 185 of file wasm_interface_private.hpp.

◆ wasm_instantiation_cache

wasm_cache_index sysio::chain::wasm_interface_impl::wasm_instantiation_cache

Definition at line 201 of file wasm_interface_private.hpp.

◆ wasm_runtime_time

const wasm_interface::vm_type sysio::chain::wasm_interface_impl::wasm_runtime_time

Definition at line 204 of file wasm_interface_private.hpp.


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