Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
sysio::vm::wasm_allocator Class Reference

#include <allocator.hpp>

Public Member Functions

template<typename T >
void alloc (size_t size=1)
 
template<typename T >
void free (std::size_t size)
 
void free ()
 
 wasm_allocator ()
 
void reset (uint32_t new_pages)
 
void reset ()
 
template<typename T >
Tget_base_ptr () const
 
template<typename T >
Tcreate_pointer (uint32_t offset)
 
int32_t get_current_page () const
 
bool is_in_region (char *p)
 
template<typename T >
void alloc (size_t size=1)
 
template<typename T >
void free (std::size_t size)
 
void free ()
 
 wasm_allocator ()
 
void reset (uint32_t new_pages)
 
void reset ()
 
template<typename T >
Tget_base_ptr () const
 
template<typename T >
Tcreate_pointer (uint32_t offset)
 
int32_t get_current_page () const
 
bool is_in_region (char *p)
 

Detailed Description

Definition at line 409 of file allocator.hpp.

Constructor & Destructor Documentation

◆ wasm_allocator() [1/2]

sysio::vm::wasm_allocator::wasm_allocator ( )
inline

Definition at line 439 of file allocator.hpp.

439 {
440 std::size_t syspagesize = static_cast<std::size_t>(::sysconf(_SC_PAGESIZE));
441 raw = (char*)mmap(NULL, max_memory + 2*syspagesize, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
442 SYS_VM_ASSERT( raw != MAP_FAILED, wasm_bad_alloc, "mmap failed to alloca pages" );
443 int err = mprotect(raw, syspagesize, PROT_READ);
444 SYS_VM_ASSERT(err == 0, wasm_bad_alloc, "mprotect failed");
445 raw += syspagesize;
446 page = 0;
447 }
#define SYS_VM_ASSERT(expr, exc_type, msg)
Definition exceptions.hpp:8

◆ wasm_allocator() [2/2]

sysio::vm::wasm_allocator::wasm_allocator ( )
inline

Definition at line 439 of file allocator.hpp.

439 {
440 std::size_t syspagesize = static_cast<std::size_t>(::sysconf(_SC_PAGESIZE));
441 raw = (char*)mmap(NULL, max_memory + 2*syspagesize, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
442 SYS_VM_ASSERT( raw != MAP_FAILED, wasm_bad_alloc, "mmap failed to alloca pages" );
443 int err = mprotect(raw, syspagesize, PROT_READ);
444 SYS_VM_ASSERT(err == 0, wasm_bad_alloc, "mprotect failed");
445 raw += syspagesize;
446 page = 0;
447 }

Member Function Documentation

◆ alloc() [1/2]

template<typename T >
void sysio::vm::wasm_allocator::alloc ( size_t size = 1)
inline

Definition at line 416 of file allocator.hpp.

416 {
417 if (size == 0) return;
418 SYS_VM_ASSERT(page >= 0, wasm_bad_alloc, "require memory to allocate");
419 SYS_VM_ASSERT(size + page <= max_pages, wasm_bad_alloc, "exceeded max number of pages");
420 int err = mprotect(raw + (page_size * page), (page_size * size), PROT_READ | PROT_WRITE);
421 SYS_VM_ASSERT(err == 0, wasm_bad_alloc, "mprotect failed");
422 T* ptr = (T*)(raw + (page_size * page));
423 memset(ptr, 0, page_size * size);
424 page += size;
425 }
#define T(meth, val, expected)
memset(pInfo->slotDescription, ' ', 64)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ alloc() [2/2]

template<typename T >
void sysio::vm::wasm_allocator::alloc ( size_t size = 1)
inline

Definition at line 416 of file allocator.hpp.

416 {
417 if (size == 0) return;
418 SYS_VM_ASSERT(page >= 0, wasm_bad_alloc, "require memory to allocate");
419 SYS_VM_ASSERT(size + page <= max_pages, wasm_bad_alloc, "exceeded max number of pages");
420 int err = mprotect(raw + (page_size * page), (page_size * size), PROT_READ | PROT_WRITE);
421 SYS_VM_ASSERT(err == 0, wasm_bad_alloc, "mprotect failed");
422 T* ptr = (T*)(raw + (page_size * page));
423 memset(ptr, 0, page_size * size);
424 page += size;
425 }
Here is the call graph for this function:

◆ create_pointer() [1/2]

template<typename T >
T * sysio::vm::wasm_allocator::create_pointer ( uint32_t offset)
inline

Definition at line 484 of file allocator.hpp.

484{ return reinterpret_cast<T*>(raw + offset); }

◆ create_pointer() [2/2]

template<typename T >
T * sysio::vm::wasm_allocator::create_pointer ( uint32_t offset)
inline

Definition at line 484 of file allocator.hpp.

484{ return reinterpret_cast<T*>(raw + offset); }

◆ free() [1/4]

void sysio::vm::wasm_allocator::free ( )
inline

Definition at line 435 of file allocator.hpp.

435 {
436 std::size_t syspagesize = static_cast<std::size_t>(::sysconf(_SC_PAGESIZE));
437 munmap(raw - syspagesize, max_memory + 2*syspagesize);
438 }
Here is the caller graph for this function:

◆ free() [2/4]

void sysio::vm::wasm_allocator::free ( )
inline

Definition at line 435 of file allocator.hpp.

435 {
436 std::size_t syspagesize = static_cast<std::size_t>(::sysconf(_SC_PAGESIZE));
437 munmap(raw - syspagesize, max_memory + 2*syspagesize);
438 }

◆ free() [3/4]

template<typename T >
void sysio::vm::wasm_allocator::free ( std::size_t size)
inline

Definition at line 427 of file allocator.hpp.

427 {
428 if (size == 0) return;
429 SYS_VM_ASSERT(page >= 0, wasm_bad_alloc, "require memory to deallocate");
430 SYS_VM_ASSERT(size <= static_cast<uint32_t>(page), wasm_bad_alloc, "freed too many pages");
431 page -= size;
432 int err = mprotect(raw + (page_size * page), (page_size * size), PROT_NONE);
433 SYS_VM_ASSERT(err == 0, wasm_bad_alloc, "mprotect failed");
434 }
unsigned int uint32_t
Definition stdint.h:126
Here is the caller graph for this function:

◆ free() [4/4]

template<typename T >
void sysio::vm::wasm_allocator::free ( std::size_t size)
inline

Definition at line 427 of file allocator.hpp.

427 {
428 if (size == 0) return;
429 SYS_VM_ASSERT(page >= 0, wasm_bad_alloc, "require memory to deallocate");
430 SYS_VM_ASSERT(size <= static_cast<uint32_t>(page), wasm_bad_alloc, "freed too many pages");
431 page -= size;
432 int err = mprotect(raw + (page_size * page), (page_size * size), PROT_NONE);
433 SYS_VM_ASSERT(err == 0, wasm_bad_alloc, "mprotect failed");
434 }

◆ get_base_ptr() [1/2]

template<typename T >
T * sysio::vm::wasm_allocator::get_base_ptr ( ) const
inline

Definition at line 480 of file allocator.hpp.

480 {
481 return reinterpret_cast<T*>(raw);
482 }

◆ get_base_ptr() [2/2]

template<typename T >
T * sysio::vm::wasm_allocator::get_base_ptr ( ) const
inline

Definition at line 480 of file allocator.hpp.

480 {
481 return reinterpret_cast<T*>(raw);
482 }

◆ get_current_page() [1/2]

int32_t sysio::vm::wasm_allocator::get_current_page ( ) const
inline

Definition at line 485 of file allocator.hpp.

485{ return page; }
Here is the caller graph for this function:

◆ get_current_page() [2/2]

int32_t sysio::vm::wasm_allocator::get_current_page ( ) const
inline

Definition at line 485 of file allocator.hpp.

485{ return page; }

◆ is_in_region() [1/2]

bool sysio::vm::wasm_allocator::is_in_region ( char * p)
inline

Definition at line 486 of file allocator.hpp.

486{ return p >= raw && p < raw + max_memory; }
const mie::Vuint & p
Definition bn.cpp:27

◆ is_in_region() [2/2]

bool sysio::vm::wasm_allocator::is_in_region ( char * p)
inline

Definition at line 486 of file allocator.hpp.

486{ return p >= raw && p < raw + max_memory; }

◆ reset() [1/4]

void sysio::vm::wasm_allocator::reset ( )
inline

Definition at line 469 of file allocator.hpp.

469 {
470 if (page >= 0) {
471 std::size_t syspagesize = static_cast<std::size_t>(::sysconf(_SC_PAGESIZE));
472 memset(raw, '\0', page_size * page); // zero the memory
473 int err = mprotect(raw - syspagesize, page_size * page + syspagesize, PROT_NONE);
474 SYS_VM_ASSERT(err == 0, wasm_bad_alloc, "mprotect failed");
475 }
476 page = -1;
477 }
Here is the call graph for this function:

◆ reset() [2/4]

void sysio::vm::wasm_allocator::reset ( )
inline

Definition at line 469 of file allocator.hpp.

469 {
470 if (page >= 0) {
471 std::size_t syspagesize = static_cast<std::size_t>(::sysconf(_SC_PAGESIZE));
472 memset(raw, '\0', page_size * page); // zero the memory
473 int err = mprotect(raw - syspagesize, page_size * page + syspagesize, PROT_NONE);
474 SYS_VM_ASSERT(err == 0, wasm_bad_alloc, "mprotect failed");
475 }
476 page = -1;
477 }
Here is the call graph for this function:

◆ reset() [3/4]

void sysio::vm::wasm_allocator::reset ( uint32_t new_pages)
inline

Definition at line 452 of file allocator.hpp.

452 {
453 if (page >= 0) {
454 memset(raw, '\0', page_size * page); // zero the memory
455 } else {
456 std::size_t syspagesize = static_cast<std::size_t>(::sysconf(_SC_PAGESIZE));
457 int err = mprotect(raw - syspagesize, syspagesize, PROT_READ);
458 SYS_VM_ASSERT(err == 0, wasm_bad_alloc, "mprotect failed");
459 page = 0;
460 }
461 if(new_pages > static_cast<uint32_t>(page)) {
462 alloc<char>(new_pages - page);
463 } else if(new_pages < static_cast<uint32_t>(page)) {
464 free<char>(page - new_pages);
465 }
466 }
void alloc(size_t size=1)
Here is the call graph for this function:

◆ reset() [4/4]

void sysio::vm::wasm_allocator::reset ( uint32_t new_pages)
inline

Definition at line 452 of file allocator.hpp.

452 {
453 if (page >= 0) {
454 memset(raw, '\0', page_size * page); // zero the memory
455 } else {
456 std::size_t syspagesize = static_cast<std::size_t>(::sysconf(_SC_PAGESIZE));
457 int err = mprotect(raw - syspagesize, syspagesize, PROT_READ);
458 SYS_VM_ASSERT(err == 0, wasm_bad_alloc, "mprotect failed");
459 page = 0;
460 }
461 if(new_pages > static_cast<uint32_t>(page)) {
462 alloc<char>(new_pages - page);
463 } else if(new_pages < static_cast<uint32_t>(page)) {
464 free<char>(page - new_pages);
465 }
466 }
Here is the call graph for this function:

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