Kagome
Polkadot Runtime Engine in C++17
module_instance_impl.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_CORE_RUNTIME_BINARYEN_MODULE_WASM_MODULE_INSTANCE_IMPL
7 #define KAGOME_CORE_RUNTIME_BINARYEN_MODULE_WASM_MODULE_INSTANCE_IMPL
8 
10 
11 #include "log/logger.hpp"
12 
13 namespace wasm {
14  using namespace ::wasm; // NOLINT(google-build-using-namespace)
15  class Module;
16  class ModuleInstance;
17 } // namespace wasm
18 
19 namespace kagome::runtime::binaryen {
20 
21  class RuntimeExternalInterface;
22 
23  class ModuleInstanceImpl final : public ModuleInstance {
24  public:
25  enum class Error {
26  UNEXPECTED_EXIT = 1,
27  EXECUTION_ERROR,
28  CAN_NOT_OBTAIN_GLOBAL
29  };
30 
32  std::shared_ptr<wasm::Module> parent,
33  std::shared_ptr<RuntimeExternalInterface> rei,
34  const common::Hash256 &code_hash);
35 
36  const common::Hash256 &getCodeHash() const override {
37  return code_hash_;
38  }
39 
40  outcome::result<PtrSize> callExportFunction(
41  std::string_view name, common::BufferView args) const override;
42 
43  outcome::result<std::optional<WasmValue>> getGlobal(
44  std::string_view name) const override;
45 
46  InstanceEnvironment const &getEnvironment() const override;
47 
48  outcome::result<void> resetEnvironment() override;
49 
50  void forDataSegment(DataSegmentProcessor const &callback) const override;
51 
52  private:
54  std::shared_ptr<RuntimeExternalInterface> rei_;
55  std::shared_ptr<wasm::Module>
56  parent_; // must be kept alive because binaryen's module instance keeps
57  // a reference to it
59 
60  std::unique_ptr<wasm::ModuleInstance> module_instance_;
62  };
63 
64 } // namespace kagome::runtime::binaryen
65 
67 
68 #endif // KAGOME_CORE_RUNTIME_BINARYEN_MODULE_WASM_MODULE_INSTANCE_IMPL
std::function< void(SegmentOffset, SegmentData)> DataSegmentProcessor
std::unique_ptr< wasm::ModuleInstance > module_instance_
std::shared_ptr< soralog::Logger > Logger
Definition: logger.hpp:23
std::shared_ptr< RuntimeExternalInterface > rei_
const common::Hash256 & getCodeHash() const override
OUTCOME_HPP_DECLARE_ERROR(kagome::runtime::binaryen, ModuleInstanceImpl::Error)