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");
20 int ret = ftruncate(fd, wasm_memory_size+memory_prologue_size);
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");
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;
36 zeropage_base = mapbase + memory_prologue_size;
37 fullpage_base = last + memory_prologue_size;
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};
52 std::swap(zeropage_base, new_memory.zeropage_base);
53 std::swap(fullpage_base, new_memory.fullpage_base);