Kagome
Polkadot Runtime Engine in C++17
memory_extension.cpp
Go to the documentation of this file.
1 
6 #include <exception>
7 
8 #include <boost/assert.hpp>
9 
12 
13 namespace kagome::host_api {
15  std::shared_ptr<const runtime::MemoryProvider> memory_provider)
16  : memory_provider_(std::move(memory_provider)),
17  logger_{log::createLogger("MemoryExtension", "memory_extension")} {
18  BOOST_ASSERT_MSG(memory_provider_ != nullptr, "memory provider is nullptr");
19  }
20 
22  runtime::WasmSize size) {
23  return memory_provider_->getCurrentMemory()->get().allocate(size);
24  }
25 
27  auto opt_size = memory_provider_->getCurrentMemory()->get().deallocate(ptr);
28  if (not opt_size) {
29  logger_->warn(
30  "Ptr {} does not point to any memory chunk in wasm memory. Nothing "
31  "deallocated",
32  ptr);
33  return;
34  }
35  }
36 } // namespace kagome::host_api
uint32_t WasmSize
Size type is uint32_t because we are working in 32 bit address space.
Definition: types.hpp:35
void ext_allocator_free_version_1(runtime::WasmPointer ptr)
STL namespace.
runtime::WasmPointer ext_allocator_malloc_version_1(runtime::WasmSize size)
uint32_t WasmPointer
type of wasm memory is 32 bit integer
Definition: types.hpp:26
std::shared_ptr< const runtime::MemoryProvider > memory_provider_
Logger createLogger(const std::string &tag)
Definition: logger.cpp:112
MemoryExtension(std::shared_ptr< const runtime::MemoryProvider > memory_provider)