#include <allocator.hpp>
|
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) |
|
Definition at line 82 of file allocator.hpp.
◆ contiguous_allocator() [1/2]
sysio::vm::contiguous_allocator::contiguous_allocator |
( |
size_t | size | ) |
|
|
inline |
Definition at line 92 of file allocator.hpp.
92 {
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)
#define SYS_VM_ASSERT(expr, exc_type, msg)
◆ ~contiguous_allocator() [1/2]
sysio::vm::contiguous_allocator::~contiguous_allocator |
( |
| ) |
|
|
inline |
◆ contiguous_allocator() [2/2]
sysio::vm::contiguous_allocator::contiguous_allocator |
( |
size_t | size | ) |
|
|
inline |
Definition at line 92 of file allocator.hpp.
92 {
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 }
◆ ~contiguous_allocator() [2/2]
sysio::vm::contiguous_allocator::~contiguous_allocator |
( |
| ) |
|
|
inline |
◆ 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); }
◆ 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 }
◆ 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]
T * sysio::vm::contiguous_allocator::alloc |
( |
size_t | size = 0 | ) |
|
|
inline |
Definition at line 100 of file allocator.hpp.
100 {
102 size_t aligned = (
sizeof(
T) * size) + _offset;
103 if (aligned > _size) {
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)
#define T(meth, val, expected)
memcpy((char *) pInfo->slotDescription, s, l)
◆ alloc() [2/2]
T * sysio::vm::contiguous_allocator::alloc |
( |
size_t | size = 0 | ) |
|
|
inline |
Definition at line 100 of file allocator.hpp.
100 {
102 size_t aligned = (
sizeof(
T) * size) + _offset;
103 if (aligned > _size) {
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 }
◆ free() [1/2]
void sysio::vm::contiguous_allocator::free |
( |
| ) |
|
|
inline |
◆ free() [2/2]
void sysio::vm::contiguous_allocator::free |
( |
| ) |
|
|
inline |
◆ reclaim() [1/2]
void sysio::vm::contiguous_allocator::reclaim |
( |
const T * | ptr, |
|
|
size_t | size = 0 ) |
|
inline |
◆ reclaim() [2/2]
void sysio::vm::contiguous_allocator::reclaim |
( |
const T * | ptr, |
|
|
size_t | size = 0 ) |
|
inline |
The documentation for this class was generated from the following files: