Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Class protected_fixedsize_stack

Boost.Fiber provides the class protected_fixedsize_stack which models the stack-allocator 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.

[Important] Important

Using protected_fixedsize_stack is expensive. Launching a new fiber with a stack of this type incurs the overhead of setting the memory protection; once allocated, this stack is just as efficient to use as fixedsize_stack.

[Note] Note

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

#include <boost/fiber/protected_fixedsize.hpp>

struct protected_fixedsize {
    protected_fixesize(std::size_t size = traits_type::default_size());

    stack_context allocate();

    void deallocate( stack_context &);
}
stack_context allocate()

Preconditions:

traits_type::minimum_size() <= size and traits_type::is_unbounded() || ( size <= traits_type::maximum_size() ).

Effects:

Allocates memory of at least size bytes and stores a pointer to the stack and its actual size in sctx. Depending on the architecture (the stack grows downwards/upwards) the stored address is the highest/lowest address of the stack.

void deallocate( stack_context & sctx)

Preconditions:

sctx.sp is valid, traits_type::minimum_size() <= sctx.size and traits_type::is_unbounded() || ( sctx.size <= traits_type::maximum_size() ).

Effects:

Deallocates the stack space.


PrevUpHomeNext