Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
stack.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4
5namespace sysio { namespace chain { namespace eosvmoc {
6
7extern "C" void eosvmoc_switch_stack(void* stack, void(*fn)(void*), void* data);
8
9// Allows wasm code to run with a stack whose size can be adjusted based
10// on the configurable max_call_depth. It is assumed that max_call_depth
11// is rarely changed.
13 // Must match the limit enforced by codegen.
14 static constexpr std::size_t max_bytes_per_frame = 16*1024;
15
16 void * stack_top = nullptr;
17 std::size_t stack_size = 0;
18 // Assume that the default stack is large enough if we can't consume more than 4 MB
19 std::size_t call_depth_limit = 4*1024*1024 / max_bytes_per_frame;
20
21 execution_stack() = default;
24
25 void reset(std::size_t max_call_depth);
26 void reset();
27
28 template<typename F>
29 void run(F&& f) {
30 if (stack_top) {
31 eosvmoc_switch_stack(stack_top, [](void* data) { (*static_cast<F*>(data))(); }, &f);
32 } else {
33 f();
34 }
35 }
36
38 reset();
39 }
40};
41
42}}}
void eosvmoc_switch_stack(void *stack, void(*fn)(void *), void *data)
execution_stack(const execution_stack &)=delete
execution_stack & operator=(const execution_stack &)=delete
static constexpr std::size_t max_bytes_per_frame
Definition stack.hpp:14