Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
sysio::chain::eosvmoc::memory Class Reference

#include <memory.hpp>

Collaboration diagram for sysio::chain::eosvmoc::memory:

Public Member Functions

 memory (uint64_t max_pages)
 
 ~memory ()
 
 memory (const memory &)=delete
 
memoryoperator= (const memory &)=delete
 
void reset (uint64_t max_pages)
 
uint8_t *const zero_page_memory_base () const
 
uint8_t *const full_page_memory_base () const
 
control_block *const get_control_block () const
 
uint8_t *const start_of_memory_slices () const
 
size_t size_of_memory_slice_mapping () const
 

Static Public Attributes

static constexpr size_t stride = total_memory_per_slice
 
static constexpr uintptr_t linear_memory = 0
 
static constexpr uintptr_t cb_offset = wcb_allowance + mutable_global_size + table_size
 
static constexpr uintptr_t first_intrinsic_offset = cb_offset + 8u
 
static constexpr uintptr_t max_prologue_size = mutable_global_size + table_size
 

Detailed Description

Definition at line 13 of file memory.hpp.

Constructor & Destructor Documentation

◆ memory() [1/2]

sysio::chain::eosvmoc::memory::memory ( uint64_t max_pages)
explicit

Definition at line 14 of file memory.cpp.

14 {
15 uint64_t number_slices = max_pages + 1;
16 uint64_t wasm_memory_size = max_pages * wasm_constraints::wasm_page_size;
17 int fd = syscall(SYS_memfd_create, "eosvmoc_mem", MFD_CLOEXEC);
18 FC_ASSERT(fd >= 0, "Failed to create memory memfd");
19 auto cleanup_fd = fc::make_scoped_exit([&fd](){close(fd);});
20 int ret = ftruncate(fd, wasm_memory_size+memory_prologue_size);
21 FC_ASSERT(!ret, "Failed to grow memory memfd");
22
23 mapsize = total_memory_per_slice*number_slices;
24 mapbase = (uint8_t*)mmap(nullptr, mapsize, PROT_NONE, MAP_PRIVATE|MAP_ANON, 0, 0);
25 FC_ASSERT(mapbase != MAP_FAILED, "Failed to mmap memory");
26
27 uint8_t* next_slice = mapbase;
28 uint8_t* last;
29
30 for(unsigned int p = 0; p < number_slices; ++p) {
31 last = (uint8_t*)mmap(next_slice, memory_prologue_size+64u*1024u*p, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED, fd, 0);
32 FC_ASSERT(last != MAP_FAILED, "Failed to mmap memory");
33 next_slice += total_memory_per_slice;
34 }
35
36 zeropage_base = mapbase + memory_prologue_size;
37 fullpage_base = last + memory_prologue_size;
38
39 //layout the intrinsic jump table
40 uintptr_t* const intrinsic_jump_table = reinterpret_cast<uintptr_t* const>(zeropage_base - first_intrinsic_offset);
41 const intrinsic_map_t& intrinsics = get_intrinsic_map();
42 for(const auto& intrinsic : intrinsics)
43 intrinsic_jump_table[-intrinsic.second.ordinal] = (uintptr_t)intrinsic.second.function_ptr;
44}
const mie::Vuint & p
Definition bn.cpp:27
static constexpr uintptr_t first_intrinsic_offset
Definition memory.hpp:49
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
void close(T *e, websocketpp::connection_hdl hdl)
scoped_exit< Callback > make_scoped_exit(Callback &&c)
const intrinsic_map_t & get_intrinsic_map()
Definition intrinsic.cpp:10
std::map< std::string, intrinsic_entry > intrinsic_map_t
Definition intrinsic.hpp:24
_W64 unsigned int uintptr_t
Definition stdint.h:165
unsigned char uint8_t
Definition stdint.h:124
unsigned __int64 uint64_t
Definition stdint.h:136
CK_RV ret
Here is the call graph for this function:

◆ ~memory()

sysio::chain::eosvmoc::memory::~memory ( )

Definition at line 56 of file memory.cpp.

56 {
57 munmap(mapbase, mapsize);
58}

◆ memory() [2/2]

sysio::chain::eosvmoc::memory::memory ( const memory & )
delete

Member Function Documentation

◆ full_page_memory_base()

uint8_t *const sysio::chain::eosvmoc::memory::full_page_memory_base ( ) const
inline

Definition at line 34 of file memory.hpp.

34{ return fullpage_base; }
Here is the caller graph for this function:

◆ get_control_block()

control_block *const sysio::chain::eosvmoc::memory::get_control_block ( ) const
inline

Definition at line 36 of file memory.hpp.

36{ return reinterpret_cast<control_block* const>(zeropage_base - cb_offset);}
static constexpr uintptr_t cb_offset
Definition memory.hpp:48
eos_vm_oc_control_block control_block
Definition sys-vm-oc.hpp:21
Here is the caller graph for this function:

◆ operator=()

memory & sysio::chain::eosvmoc::memory::operator= ( const memory & )
delete

◆ reset()

void sysio::chain::eosvmoc::memory::reset ( uint64_t max_pages)

Definition at line 46 of file memory.cpp.

46 {
47 uint64_t old_max_pages = mapsize / memory::total_memory_per_slice - 1;
48 if(max_pages == old_max_pages) return;
49 memory new_memory{max_pages};
50 std::swap(mapbase, new_memory.mapbase);
51 std::swap(mapsize, new_memory.mapsize);
52 std::swap(zeropage_base, new_memory.zeropage_base);
53 std::swap(fullpage_base, new_memory.fullpage_base);
54}
memory(uint64_t max_pages)
Definition memory.cpp:14
void swap(picojson::value &x, picojson::value &y)
Here is the call graph for this function:

◆ size_of_memory_slice_mapping()

size_t sysio::chain::eosvmoc::memory::size_of_memory_slice_mapping ( ) const
inline

Definition at line 40 of file memory.hpp.

40{ return mapsize; }
Here is the caller graph for this function:

◆ start_of_memory_slices()

uint8_t *const sysio::chain::eosvmoc::memory::start_of_memory_slices ( ) const
inline

Definition at line 39 of file memory.hpp.

39{ return mapbase; }
Here is the caller graph for this function:

◆ zero_page_memory_base()

uint8_t *const sysio::chain::eosvmoc::memory::zero_page_memory_base ( ) const
inline

Definition at line 33 of file memory.hpp.

33{ return zeropage_base; }
Here is the caller graph for this function:

Member Data Documentation

◆ cb_offset

uintptr_t sysio::chain::eosvmoc::memory::cb_offset = wcb_allowance + mutable_global_size + table_size
staticconstexpr

Definition at line 48 of file memory.hpp.

◆ first_intrinsic_offset

uintptr_t sysio::chain::eosvmoc::memory::first_intrinsic_offset = cb_offset + 8u
staticconstexpr

Definition at line 49 of file memory.hpp.

◆ linear_memory

uintptr_t sysio::chain::eosvmoc::memory::linear_memory = 0
staticconstexpr

Definition at line 47 of file memory.hpp.

◆ max_prologue_size

uintptr_t sysio::chain::eosvmoc::memory::max_prologue_size = mutable_global_size + table_size
staticconstexpr

Definition at line 51 of file memory.hpp.

◆ stride

size_t sysio::chain::eosvmoc::memory::stride = total_memory_per_slice
staticconstexpr

Definition at line 44 of file memory.hpp.


The documentation for this class was generated from the following files: