Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
sysio::chain::webassembly::eos_vm_runtime Namespace Reference

Classes

struct  apply_options
 
class  eos_vm_instantiated_module
 
class  eos_vm_profile_runtime
 
class  eos_vm_runtime
 
struct  profile_config
 
struct  setcode_options
 

Functions

void validate (const bytes &code, const whitelisted_intrinsics_type &intrinsics)
 
void validate (const bytes &code, const wasm_config &cfg, const whitelisted_intrinsics_type &intrinsics)
 

Function Documentation

◆ validate() [1/2]

void sysio::chain::webassembly::eos_vm_runtime::validate ( const bytes & code,
const wasm_config & cfg,
const whitelisted_intrinsics_type & intrinsics )

Definition at line 84 of file sys-vm.cpp.

84 {
85 SYS_ASSERT(code.size() <= cfg.max_module_bytes, wasm_serialization_error, "Code too large");
86 wasm_code_ptr code_ptr((uint8_t*)code.data(), code.size());
87 try {
88 eos_vm_null_backend_t<wasm_config> bkend(code_ptr, code.size(), nullptr, cfg);
89 // check import signatures
90 eos_vm_host_functions_t::resolve(bkend.get_module());
91 // check that the imports are all currently enabled
92 const auto& imports = bkend.get_module().imports;
93 for(std::uint32_t i = 0; i < imports.size(); ++i) {
94 SYS_ASSERT(std::string_view((char*)imports[i].module_str.raw(), imports[i].module_str.size()) == "env" &&
95 is_intrinsic_whitelisted(intrinsics, std::string_view((char*)imports[i].field_str.raw(), imports[i].field_str.size())),
96 wasm_serialization_error, "${module}.${fn} unresolveable",
97 ("module", std::string((char*)imports[i].module_str.raw(), imports[i].module_str.size()))
98 ("fn", std::string((char*)imports[i].field_str.raw(), imports[i].field_str.size())));
99 }
100 // check apply
101 uint32_t apply_idx = bkend.get_module().get_exported_function("apply");
102 SYS_ASSERT(apply_idx < std::numeric_limits<uint32_t>::max(), wasm_serialization_error, "apply not exported");
103 const vm::func_type& apply_type = bkend.get_module().get_function_type(apply_idx);
104 SYS_ASSERT((apply_type == vm::host_function{{vm::i64, vm::i64, vm::i64}, {}}), wasm_serialization_error, "apply has wrong type");
105 } catch(vm::exception& e) {
106 SYS_THROW(wasm_serialization_error, e.detail());
107 }
108}
#define SYS_THROW(exc_type, FORMAT,...)
#define SYS_ASSERT(expr, exc_type, FORMAT,...)
Definition exceptions.hpp:7
module & get_module()
Definition backend.hpp:248
backend_t bkend(hello_wasm, ehm, &wa)
bool is_intrinsic_whitelisted(const whitelisted_intrinsics_type &whitelisted_intrinsics, std::string_view name)
unsigned int uint32_t
Definition stdint.h:126
unsigned char uint8_t
Definition stdint.h:124
std::uint32_t max_module_bytes
uint32_t get_exported_function(const std::string_view str)
Definition types.hpp:227
guarded_vector< import_entry > imports
Definition types.hpp:170
auto & get_function_type(uint32_t index) const
Definition types.hpp:221
Here is the call graph for this function:

◆ validate() [2/2]

void sysio::chain::webassembly::eos_vm_runtime::validate ( const bytes & code,
const whitelisted_intrinsics_type & intrinsics )

Definition at line 64 of file sys-vm.cpp.

64 {
65 wasm_code_ptr code_ptr((uint8_t*)code.data(), code.size());
66 try {
67 eos_vm_null_backend_t<setcode_options> bkend(code_ptr, code.size(), nullptr);
68 // check import signatures
69 eos_vm_host_functions_t::resolve(bkend.get_module());
70 // check that the imports are all currently enabled
71 const auto& imports = bkend.get_module().imports;
72 for(std::uint32_t i = 0; i < imports.size(); ++i) {
73 SYS_ASSERT(std::string_view((char*)imports[i].module_str.raw(), imports[i].module_str.size()) == "env" &&
74 is_intrinsic_whitelisted(intrinsics, std::string_view((char*)imports[i].field_str.raw(), imports[i].field_str.size())),
75 wasm_serialization_error, "${module}.${fn} unresolveable",
76 ("module", std::string((char*)imports[i].module_str.raw(), imports[i].module_str.size()))
77 ("fn", std::string((char*)imports[i].field_str.raw(), imports[i].field_str.size())));
78 }
79 } catch(vm::exception& e) {
80 SYS_THROW(wasm_serialization_error, e.detail());
81 }
82}
virtual const char * detail() const =0
Here is the call graph for this function:
Here is the caller graph for this function: