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

#include <allocator.hpp>

Public Member Functions

 contiguous_allocator (size_t size)
 
 ~contiguous_allocator ()
 
template<typename T >
Talloc (size_t size=0)
 
template<typename T >
void reclaim (const T *ptr, size_t size=0)
 
void free ()
 
 contiguous_allocator (size_t size)
 
 ~contiguous_allocator ()
 
template<typename T >
Talloc (size_t size=0)
 
template<typename T >
void reclaim (const T *ptr, size_t size=0)
 
void free ()
 

Static Public Member Functions

template<std::size_t align_amt>
static constexpr size_t align_offset (size_t offset)
 
static std::size_t align_to_page (std::size_t offset)
 
template<std::size_t align_amt>
static constexpr size_t align_offset (size_t offset)
 
static std::size_t align_to_page (std::size_t offset)
 

Detailed Description

Definition at line 82 of file allocator.hpp.

Constructor & Destructor Documentation

◆ contiguous_allocator() [1/2]

sysio::vm::contiguous_allocator::contiguous_allocator ( size_t size)
inline

Definition at line 92 of file allocator.hpp.

92 {
93 _size = align_to_page(size);
94 _base = (char*)mmap(NULL, _size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
95 SYS_VM_ASSERT(_base != MAP_FAILED, wasm_bad_alloc, "mmap failed.");
96 }
static std::size_t align_to_page(std::size_t offset)
Definition allocator.hpp:87
#define SYS_VM_ASSERT(expr, exc_type, msg)
Definition exceptions.hpp:8
Here is the call graph for this function:

◆ ~contiguous_allocator() [1/2]

sysio::vm::contiguous_allocator::~contiguous_allocator ( )
inline

Definition at line 97 of file allocator.hpp.

97{ munmap(_base, align_to_page(_size)); }
Here is the call graph for this function:

◆ contiguous_allocator() [2/2]

sysio::vm::contiguous_allocator::contiguous_allocator ( size_t size)
inline

Definition at line 92 of file allocator.hpp.

92 {
93 _size = align_to_page(size);
94 _base = (char*)mmap(NULL, _size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
95 SYS_VM_ASSERT(_base != MAP_FAILED, wasm_bad_alloc, "mmap failed.");
96 }
Here is the call graph for this function:

◆ ~contiguous_allocator() [2/2]

sysio::vm::contiguous_allocator::~contiguous_allocator ( )
inline

Definition at line 97 of file allocator.hpp.

97{ munmap(_base, align_to_page(_size)); }
Here is the call graph for this function:

Member Function Documentation

◆ align_offset() [1/2]

template<std::size_t align_amt>
static constexpr size_t sysio::vm::contiguous_allocator::align_offset ( size_t offset)
inlinestaticconstexpr

Definition at line 85 of file allocator.hpp.

85{ return (offset + align_amt - 1) & ~(align_amt - 1); }
Here is the caller graph for this function:

◆ align_offset() [2/2]

template<std::size_t align_amt>
static constexpr size_t sysio::vm::contiguous_allocator::align_offset ( size_t offset)
inlinestaticconstexpr

Definition at line 85 of file allocator.hpp.

85{ return (offset + align_amt - 1) & ~(align_amt - 1); }

◆ align_to_page() [1/2]

static std::size_t sysio::vm::contiguous_allocator::align_to_page ( std::size_t offset)
inlinestatic

Definition at line 87 of file allocator.hpp.

87 {
88 std::size_t pagesize = static_cast<std::size_t>(::sysconf(_SC_PAGESIZE));
89 return (offset + pagesize - 1) & ~(pagesize - 1);
90 }
Here is the caller graph for this function:

◆ align_to_page() [2/2]

static std::size_t sysio::vm::contiguous_allocator::align_to_page ( std::size_t offset)
inlinestatic

Definition at line 87 of file allocator.hpp.

87 {
88 std::size_t pagesize = static_cast<std::size_t>(::sysconf(_SC_PAGESIZE));
89 return (offset + pagesize - 1) & ~(pagesize - 1);
90 }

◆ alloc() [1/2]

template<typename T >
T * sysio::vm::contiguous_allocator::alloc ( size_t size = 0)
inline

Definition at line 100 of file allocator.hpp.

100 {
101 _offset = align_offset<alignof(T)>(_offset);
102 size_t aligned = (sizeof(T) * size) + _offset;
103 if (aligned > _size) {
104 size_t new_size = align_to_page(aligned);
105 char* new_base = (char*)mmap(NULL, new_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
106 SYS_VM_ASSERT(new_base != MAP_FAILED, wasm_bad_alloc, "mmap failed.");
107 memcpy(new_base, _base, _size);
108 munmap(_base, _size);
109 _size = new_size;
110 _base = new_base;
111 }
112 T* ptr = (T*)(_base + _offset);
113 _offset = aligned;
114 return ptr;
115 }
static constexpr size_t align_offset(size_t offset)
Definition allocator.hpp:85
#define T(meth, val, expected)
memcpy((char *) pInfo->slotDescription, s, l)
Here is the call graph for this function:

◆ alloc() [2/2]

template<typename T >
T * sysio::vm::contiguous_allocator::alloc ( size_t size = 0)
inline

Definition at line 100 of file allocator.hpp.

100 {
101 _offset = align_offset<alignof(T)>(_offset);
102 size_t aligned = (sizeof(T) * size) + _offset;
103 if (aligned > _size) {
104 size_t new_size = align_to_page(aligned);
105 char* new_base = (char*)mmap(NULL, new_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
106 SYS_VM_ASSERT(new_base != MAP_FAILED, wasm_bad_alloc, "mmap failed.");
107 memcpy(new_base, _base, _size);
108 munmap(_base, _size);
109 _size = new_size;
110 _base = new_base;
111 }
112 T* ptr = (T*)(_base + _offset);
113 _offset = aligned;
114 return ptr;
115 }
Here is the call graph for this function:

◆ free() [1/2]

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

Definition at line 118 of file allocator.hpp.

118{ /* noop for now */ }

◆ free() [2/2]

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

Definition at line 118 of file allocator.hpp.

118{ /* noop for now */ }

◆ reclaim() [1/2]

template<typename T >
void sysio::vm::contiguous_allocator::reclaim ( const T * ptr,
size_t size = 0 )
inline

Definition at line 117 of file allocator.hpp.

117{ /* noop for now */ }

◆ reclaim() [2/2]

template<typename T >
void sysio::vm::contiguous_allocator::reclaim ( const T * ptr,
size_t size = 0 )
inline

Definition at line 117 of file allocator.hpp.

117{ /* noop for now */ }

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