Pyrogenesis  trunk
Macros | Functions | Variables
page_aligned.cpp File Reference
#include "precompiled.h"
#include "lib/allocators/page_aligned.h"
#include "lib/alignment.h"
#include "lib/sysdep/cpu.h"
Include dependency graph for page_aligned.cpp:

Macros

#define MAP_ANONYMOUS   MAP_ANON
 

Functions

static Status StatusFromMap (void *ret)
 
Status mem_Reserve (size_t size, u8 **pp)
 
Status mem_Release (u8 *p, size_t size)
 
Status mem_Commit (u8 *p, size_t size, int prot)
 
Status mem_Decommit (u8 *p, size_t size)
 
Status mem_Protect (u8 *p, size_t size, int prot)
 
void * page_aligned_alloc (size_t size)
 allocate memory aligned to the system page size. More...
 
void page_aligned_free (void *p, size_t size)
 free a previously allocated page-aligned region. More...
 

Variables

static const int mmap_flags = MAP_PRIVATE|MAP_ANONYMOUS
 

Macro Definition Documentation

#define MAP_ANONYMOUS   MAP_ANON

Function Documentation

Status mem_Commit ( u8 p,
size_t  size,
int  prot 
)
Status mem_Decommit ( u8 p,
size_t  size 
)
Status mem_Protect ( u8 p,
size_t  size,
int  prot 
)
Status mem_Release ( u8 p,
size_t  size 
)
Status mem_Reserve ( size_t  size,
u8 **  pp 
)
void* page_aligned_alloc ( size_t  unaligned_size)

allocate memory aligned to the system page size.

this is useful for file_cache_alloc, which uses this allocator to get sector-aligned (hopefully; see sys_max_sector_size) IO buffers.

note that this allocator is stateless and very little error checking can be performed.

the memory is initially writable and you can use mprotect to set other access permissions if desired.

Parameters
unaligned_sizeminimum size [bytes] to allocate.
Returns
page-aligned and -padded memory or 0 on error / out of memory.
void page_aligned_free ( void *  p,
size_t  unaligned_size 
)

free a previously allocated page-aligned region.

Parameters
pExact value returned from page_aligned_alloc
unaligned_sizeExact value passed to page_aligned_alloc
static Status StatusFromMap ( void *  ret)
inlinestatic

Variable Documentation

const int mmap_flags = MAP_PRIVATE|MAP_ANONYMOUS
static