Kagome
Polkadot Runtime Engine in C++17
module_instance.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_CORE_RUNTIME_WAVM_IMPL_MODULE_INSTANCE_HPP
7 #define KAGOME_CORE_RUNTIME_WAVM_IMPL_MODULE_INSTANCE_HPP
8 
10 
11 #include <string_view>
12 
13 #include <WAVM/Runtime/Runtime.h>
14 #include <optional>
15 
16 #include "log/logger.hpp"
17 #include "runtime/ptr_size.hpp"
18 
19 namespace WAVM {
20  namespace Runtime {
21  struct Instance;
22  } // namespace Runtime
23 } // namespace WAVM
24 
25 namespace kagome::runtime::wavm {
26 
27  class CompartmentWrapper;
28 
30  : public ModuleInstance,
31  public std::enable_shared_from_this<ModuleInstanceImpl> {
32  public:
33  enum class Error {
34  FUNC_NOT_FOUND = 1,
35  WRONG_ARG_COUNT,
36  EXECUTION_ERROR,
37  WRONG_RETURN_TYPE
38  };
39 
42  WAVM::Runtime::GCPointer<WAVM::Runtime::Instance> instance,
43  WAVM::Runtime::ModuleRef module,
44  std::shared_ptr<const CompartmentWrapper> compartment,
45  const common::Hash256 &code_hash);
46 
47  const common::Hash256 &getCodeHash() const override {
48  return code_hash_;
49  }
50 
51  outcome::result<PtrSize> callExportFunction(
52  std::string_view name, common::BufferView encoded_args) const override;
53 
54  outcome::result<std::optional<WasmValue>> getGlobal(
55  std::string_view name) const override;
56 
57  void forDataSegment(DataSegmentProcessor const &callback) const override;
58 
59  InstanceEnvironment const &getEnvironment() const override;
60  outcome::result<void> resetEnvironment() override;
61 
62  private:
64  WAVM::Runtime::GCPointer<WAVM::Runtime::Instance> instance_;
65  WAVM::Runtime::ModuleRef module_;
66  std::shared_ptr<const CompartmentWrapper> compartment_;
69  };
70 
71 } // namespace kagome::runtime::wavm
72 
74 
75 #endif // KAGOME_CORE_RUNTIME_WAVM_IMPL_MODULE_INSTANCE_HPP
std::function< void(SegmentOffset, SegmentData)> DataSegmentProcessor
OUTCOME_HPP_DECLARE_ERROR(kagome::api, JRpcServerImpl::Error)
const common::Hash256 & getCodeHash() const override
std::shared_ptr< soralog::Logger > Logger
Definition: logger.hpp:23
std::shared_ptr< const CompartmentWrapper > compartment_
WAVM::Runtime::GCPointer< WAVM::Runtime::Instance > instance_