Kagome
Polkadot Runtime Engine in C++17
binaryen_memory_provider.cpp
Go to the documentation of this file.
1 
7 
9 
12  e) {
14  switch (e) {
15  case E::OUTDATED_EXTERNAL_INTERFACE:
16  return "Reference to the runtime external interface is outdated "
17  "(nullptr)";
18  }
19  return "Unknown error in BinaryenMemoryProvider";
20 }
21 
22 namespace kagome::runtime::binaryen {
23 
25  std::shared_ptr<const BinaryenMemoryFactory> memory_factory)
26  : memory_factory_{std::move(memory_factory)} {
27  BOOST_ASSERT(memory_factory_);
28  }
29 
30  std::optional<std::reference_wrapper<runtime::Memory>>
32  return memory_ == nullptr
33  ? std::nullopt
34  : std::optional<std::reference_wrapper<Memory>>{*memory_};
35  }
36 
37  outcome::result<void> BinaryenMemoryProvider::resetMemory(
38  WasmSize heap_base) {
39  auto rei = external_interface_.lock();
40  BOOST_ASSERT(rei != nullptr);
41  if (rei) {
42  memory_ = memory_factory_->make(rei->getMemory(), heap_base);
43  return outcome::success();
44  }
46  }
47 
49  std::weak_ptr<RuntimeExternalInterface> rei) {
50  BOOST_ASSERT(rei.lock() != nullptr);
51  external_interface_ = std::move(rei);
52  }
53 
54 } // namespace kagome::runtime::binaryen
uint32_t WasmSize
Size type is uint32_t because we are working in 32 bit address space.
Definition: types.hpp:35
OUTCOME_CPP_DEFINE_CATEGORY(kagome::runtime::binaryen, BinaryenMemoryProvider::Error, e)
outcome::result< void > resetMemory(WasmSize heap_base) override
BinaryenMemoryProvider(std::shared_ptr< const BinaryenMemoryFactory > memory_factory)
void setExternalInterface(std::weak_ptr< RuntimeExternalInterface > rei)
std::shared_ptr< const BinaryenMemoryFactory > memory_factory_
std::optional< std::reference_wrapper< runtime::Memory > > getCurrentMemory() const override
std::weak_ptr< RuntimeExternalInterface > external_interface_