a pool of stacks for a threading package.
More...
Detailed Description
a pool of stacks for a threading package.
Typedef Documentation
Function Documentation
int STACKS_destroy |
( |
STACKS * |
stack | ) |
|
M_INLINE size_t STACKS_get_stack_size |
( |
STACKS * |
stack | ) |
|
int STACKS_init |
( |
STACKS * |
stack, |
|
|
int |
num_stacks, |
|
|
int |
pages_per_stack |
|
) |
| |
Definition at line 22 of file stacks.c.
{
int page_size;
size_t len, one_stack_size;
STACK_DIR dir;
STACK_ENTRY *entry;
uint8_t *mapping, *stack_start;
uint8_t *guard_page;
int i;
page_size = sysconf( _SC_PAGE_SIZE );
one_stack_size = page_size * pages_per_stack;
len = num_stacks * one_stack_size;
dir = stack_direction();
mapping = (uint8_t *) mmap( 0 , len, PROT_READ|PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS
#if 0
#ifdef MAP_STACK
| MAP_STACK
#endif
#endif
, -1, 0 );
if (!mapping) {
return -1;
}
stack->mapping = mapping;
stack->mapping_length = len;
stack->num_stacks = num_stacks;
stack->one_stack_size = one_stack_size - page_size;
DLIST_init( &stack->root );
for( i = 0; i < num_stacks; i ++ ) {
stack_start = mapping + ( i * one_stack_size);
if (dir == STACK_DIR_GROWING_DOWN) {
guard_page = mapping + (i * one_stack_size);
} else {
guard_page = mapping + ( i + 1 ) * one_stack_size - page_size;
}
if (mprotect( guard_page , page_size, PROT_NONE )) {
return -1;
}
entry = (STACK_ENTRY *) malloc( sizeof( STACK_ENTRY ) );
if (!entry) {
return -1;
}
entry->stack_start = stack_start;
entry->stacks = stack;
DLIST_push_back( &stack->root, &entry->entry );
}
return 0;
}
Variable Documentation