Coarse grained memory allocation, in C++.
Coarse grained memory allocation, in C++.
#include <cstdio>
#include <cstring>
static int allocate_mem(unsigned long size_in_bytes, unsigned long flags,
void **virt_addr)
{
int r;
if ((r =
L4Re::Env::env()->mem_alloc()->alloc(size_in_bytes, d, flags)))
return r;
*virt_addr = 0;
return r;
return 0;
}
static int free_mem(void *virt_addr)
{
int r;
return r;
return 0;
}
int main(void)
{
void *virt;
return 1;
printf("Allocated memory.\n");
printf("Touched memory.\n");
if (free_mem(virt))
return 2;
printf("Freed and done. Bye.\n");
return 0;
}
Interface for memory-like objects.
static Env const * env() noexcept
Returns the initial environment for the current task.
@ Super_pages
Allocate super pages.
bool is_valid() const noexcept
Test whether the capability is a valid capability index (i.e., not L4_INVALID_CAP).
C++ interface for capabilities.
#define L4_SUPERPAGESHIFT
Size of a large page, log2-based.
l4_addr_t l4_trunc_page(l4_addr_t address) L4_NOTHROW
Round an address down to the next lower page boundary.
#define L4_PAGESIZE
Minimal page size (in bytes).
#define L4_PAGESHIFT
Size of a page, log2-based.
_Cap_alloc & cap_alloc
Capability allocator.
Memory allocator interface.
Cap< T > make_cap_rw(L4::Cap< T > cap) noexcept
Make an L4::Ipc::Cap<T> for the given capability with L4_CAP_FPAGE_RW rights.
@ RW
Readable and writable region.
@ Search_addr
Search for a suitable address range.