Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of boost. Click here for the latest Boost documentation.
PrevUpHomeNext

Class guarded_stack_allocator

Boost.Context provides the class guarded_stack_allocator which models the StackAllocator concept concept. It appends a guard-page at the end of each stack to protect against exceeding the stack. If the guard page is accessed (read or write operation) a segmentation fault/access violation is generated by the operating system.

[Note] Note

The appended guard page is not mapped to physical memory, only virtual addresses are used.

class guarded_stack_allocator
{
    static bool is_stack_unbound();

    static std::size_t maximum_stacksize();

    static std::size_t default_stacksize();

    static std::size_t minimum_stacksize();

    void * allocate( std::size_t size);

    void deallocate( void * sp, std::size_t size);
}
static bool is_stack_unbound()

Returns:

Returns true if the environment defines no limit for the size of a stack.

static std::size_t maximum_stacksize()

Preconditions:

is_stack_unbound() returns false.

Returns:

Returns the maximum size in bytes of stack defined by the environment.

static std::size_t default_stacksize()

Returns:

Returns a default stack size, which may be platform specific. If the stack is unbound then the present implementation returns the maximum of 64 kB and minimum_stacksize().

static std::size_t minimum_stacksize()

Returns:

Returns the minimum size in bytes of stack defined by the environment (Win32 4kB/Win64 8kB, defined by rlimit on POSIX).

void * allocate( std::size_t size)

Preconditions:

minimum_stacksize() > size and ! is_stack_unbound() && ( maximum_stacksize() < size).

Effects:

Allocates memory of size Bytes and appends one guard page at the end of the allocated memory.

Returns:

Returns pointer to the start address of the new stack. Depending on the architecture the stack grows downwards/upwards the returned address is the highest/lowest address of the stack.

void deallocate( void * sp, std::size_t size)

Preconditions:

sp is valid, minimum_stacksize() > size and ! is_stack_unbound() && ( maximum_stacksize() < size).

Effects:

Deallocates the stack space.


PrevUpHomeNext