Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
memory.hpp
Go to the documentation of this file.
1#pragma once
2
7
8#include <stdint.h>
9#include <stddef.h>
10
11namespace sysio { namespace chain { namespace eosvmoc {
12
13class memory {
14 static constexpr uint64_t intrinsic_count = intrinsic_table_size();
15 //warning: changing the following 3 params will invalidate existing PIC
16 static constexpr uint64_t mutable_global_size = 8u * sysio::chain::wasm_constraints::maximum_mutable_globals/4u;
17 static constexpr uint64_t table_size = 16u * sysio::chain::wasm_constraints::maximum_table_elements;
18 static constexpr size_t wcb_allowance = 512u;
19 static_assert(sizeof(control_block) <= wcb_allowance, "SYS VM OC memory doesn't set aside enough memory for control block");
20
21 //round up the prologue to multiple of 4K page
22 static constexpr uint64_t memory_prologue_size = ((memory::wcb_allowance + mutable_global_size + table_size + intrinsic_count*UINT64_C(8))+UINT64_C(4095))/UINT64_C(4096)*UINT64_C(4096);
23 //prologue + 8GB fault buffer + 4096 addtional buffer for safety
24 static constexpr uint64_t total_memory_per_slice = memory_prologue_size + UINT64_C(0x200000000) + UINT64_C(4096);
25
26 public:
27 explicit memory(uint64_t max_pages);
28 ~memory();
29 memory(const memory&) = delete;
30 memory& operator=(const memory&) = delete;
31 void reset(uint64_t max_pages);
32
33 uint8_t* const zero_page_memory_base() const { return zeropage_base; }
34 uint8_t* const full_page_memory_base() const { return fullpage_base; }
35
36 control_block* const get_control_block() const { return reinterpret_cast<control_block* const>(zeropage_base - cb_offset);}
37
38 //these two are really only inteded for SEGV handling
39 uint8_t* const start_of_memory_slices() const { return mapbase; }
40 size_t size_of_memory_slice_mapping() const { return mapsize; }
41
42 //to obtain memory protected for n wasm-pages, use the pointer computed from:
43 // zero_page_memory_base()+stride*n
44 static constexpr size_t stride = total_memory_per_slice;
45
46 //offsets to various interesting things in the memory
47 static constexpr uintptr_t linear_memory = 0;
48 static constexpr uintptr_t cb_offset = wcb_allowance + mutable_global_size + table_size;
50 // The maximum amount of data that PIC code can include in the prologue
51 static constexpr uintptr_t max_prologue_size = mutable_global_size + table_size;
52
53 static_assert(-cb_offset == EOS_VM_OC_CONTROL_BLOCK_OFFSET, "SYS VM OC control block offset has slid out of place somehow");
54 static_assert(stride == EOS_VM_OC_MEMORY_STRIDE, "SYS VM OC memory stride has slid out of place somehow");
55
56 private:
57 uint8_t* mapbase;
58 uint64_t mapsize;
59
60 uint8_t* zeropage_base;
61 uint8_t* fullpage_base;
62};
63
64}}}
65
66#define OFFSET_OF_CONTROL_BLOCK_MEMBER(M) (-(int)sysio::chain::eosvmoc::memory::cb_offset + (int)offsetof(sysio::chain::eosvmoc::control_block, M))
67#define OFFSET_OF_FIRST_INTRINSIC ((int)-sysio::chain::eosvmoc::memory::first_intrinsic_offset)
static constexpr size_t stride
Definition memory.hpp:44
uint8_t *const full_page_memory_base() const
Definition memory.hpp:34
memory(uint64_t max_pages)
Definition memory.cpp:14
memory(const memory &)=delete
static constexpr uintptr_t first_intrinsic_offset
Definition memory.hpp:49
memory & operator=(const memory &)=delete
uint8_t *const zero_page_memory_base() const
Definition memory.hpp:33
uint8_t *const start_of_memory_slices() const
Definition memory.hpp:39
static constexpr uintptr_t cb_offset
Definition memory.hpp:48
control_block *const get_control_block() const
Definition memory.hpp:36
void reset(uint64_t max_pages)
Definition memory.cpp:46
static constexpr uintptr_t linear_memory
Definition memory.hpp:47
size_t size_of_memory_slice_mapping() const
Definition memory.hpp:40
static constexpr uintptr_t max_prologue_size
Definition memory.hpp:51
#define EOS_VM_OC_CONTROL_BLOCK_OFFSET
#define EOS_VM_OC_MEMORY_STRIDE
eos_vm_oc_control_block control_block
Definition sys-vm-oc.hpp:21
constexpr std::size_t intrinsic_table_size()
_W64 unsigned int uintptr_t
Definition stdint.h:165
#define UINT64_C(val)
Definition stdint.h:284
unsigned char uint8_t
Definition stdint.h:124
unsigned __int64 uint64_t
Definition stdint.h:136