Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
wasm_interface.cpp
Go to the documentation of this file.
9#include <boost/core/ignore_unused.hpp>
19#include <fc/crypto/sha256.hpp>
20#include <fc/crypto/sha1.hpp>
21#include <fc/io/raw.hpp>
22
23#include <softfloat.hpp>
24#include <compiler_builtins.hpp>
25#include <boost/asio.hpp>
26#include <boost/bind.hpp>
27#include <fstream>
28#include <string.h>
29
30#if defined(SYSIO_SYS_VM_RUNTIME_ENABLED) || defined(SYSIO_SYS_VM_JIT_RUNTIME_ENABLED)
31#include <sysio/vm/allocator.hpp>
32#endif
33
34namespace sysio { namespace chain {
35
36 wasm_interface::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)
37 : my( new wasm_interface_impl(vm, eosvmoc_tierup, d, data_dir, eosvmoc_config, profile) ) {}
38
40
41 void wasm_interface::validate(const controller& control, const bytes& code) {
42 const auto& pso = control.db().get<protocol_state_object>();
43
45 const auto& gpo = control.get_global_properties();
46 webassembly::eos_vm_runtime::validate( code, gpo.wasm_configuration, pso.whitelisted_intrinsics );
47 return;
48 }
50 try {
51 Serialization::MemoryInputStream stream((U8*)code.data(), code.size());
52 WASM::serialize(stream, module);
54 SYS_ASSERT(false, wasm_serialization_error, e.message.c_str());
55 } catch(const IR::ValidationException& e) {
56 SYS_ASSERT(false, wasm_serialization_error, e.message.c_str());
57 }
58
60 validator.validate();
61
62 webassembly::eos_vm_runtime::validate( code, pso.whitelisted_intrinsics );
63
64 //there are a couple opportunties for improvement here--
65 //Easy: Cache the Module created here so it can be reused for instantiaion
66 //Hard: Kick off instantiation in a separate thread at this location
67 }
68
70 my->is_shutting_down = true;
71 }
72
73 void wasm_interface::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) {
74 my->code_block_num_last_used(code_hash, vm_type, vm_version, block_num);
75 }
76
78 my->current_lib(lib);
79 }
80
81 void wasm_interface::apply( const digest_type& code_hash, const uint8_t& vm_type, const uint8_t& vm_version, apply_context& context ) {
82 if(substitute_apply && substitute_apply(code_hash, vm_type, vm_version, context))
83 return;
84#ifdef SYSIO_SYS_VM_OC_RUNTIME_ENABLED
85 if(my->eosvmoc) {
86 const chain::eosvmoc::code_descriptor* cd = nullptr;
87 try {
88 cd = my->eosvmoc->cc.get_descriptor_for_code(code_hash, vm_version);
89 }
90 catch(...) {
91 //swallow errors here, if SYS VM OC has gone in to the weeds we shouldn't bail: continue to try and run baseline
92 //In the future, consider moving bits of SYS VM that can fire exceptions and such out of this call path
93 static bool once_is_enough;
94 if(!once_is_enough)
95 elog("SYS VM OC has encountered an unexpected failure");
96 once_is_enough = true;
97 }
98 if(cd) {
99 my->eosvmoc->exec.execute(*cd, my->eosvmoc->mem, context);
100 return;
101 }
102 }
103#endif
104 my->get_instantiated_module(code_hash, vm_type, vm_version, context.trx_context)->apply(context);
105 }
106
108 my->runtime_interface->immediately_exit_currently_running_module();
109 }
110
113
114std::istream& operator>>(std::istream& in, wasm_interface::vm_type& runtime) {
115 std::string s;
116 in >> s;
117 if (s == "sys-vm")
118 runtime = sysio::chain::wasm_interface::vm_type::eos_vm;
119 else if (s == "sys-vm-jit")
120 runtime = sysio::chain::wasm_interface::vm_type::eos_vm_jit;
121 else if (s == "sys-vm-oc")
122 runtime = sysio::chain::wasm_interface::vm_type::eos_vm_oc;
123 else
124 in.setstate(std::ios_base::failbit);
125 return in;
126}
127
128} }
uint8_t U8
Definition BasicTypes.h:5
#define SYS_ASSERT(expr, exc_type, FORMAT,...)
Definition exceptions.hpp:7
const ObjectType & get(CompatibleKey &&key) const
const global_property_object & get_global_properties() const
const chainbase::database & db() const
bool is_builtin_activated(builtin_protocol_feature_t f) const
Maintains global state information about consensus protocol rules.
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)
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)
Defines exception's used by fc.
#define elog(FORMAT,...)
Definition logger.hpp:130
void serialize(Stream &stream, U8 &i)
datastream< ST > & operator>>(datastream< ST > &s, sysio::chain::may_not_exist< T > &v)
Definition abi_def.hpp:152
void validate(const bytes &code, const whitelisted_intrinsics_type &intrinsics)
Definition sys-vm.cpp:64
unsigned int uint32_t
Definition stdint.h:126
unsigned char uint8_t
Definition stdint.h:124
CK_ULONG d
char * s