...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
struct stack_t { void* sp; std::size_t size; }; typedef <opaque pointer > fcontext_t; intptr_t jump_fcontext(fcontext_t* ofc,fcontext_t nfc,intptr_t vp,bool preserve_fpu=true); fcontext_t make_fcontext(void* sp,std::size_t size,void(*fn)(intptr_t));
sp
Pointer to the beginning of the stack (depending of the architecture the stack grows downwards or upwards).
size
Size of the stack in bytes.
fc_stack
Tracks the memory for the context's stack.
intptr_t jump_fcontext(fcontext_t* ofc,fcontext_t nfc,intptr_t p,bool
preserve_fpu=true)
Stores the current context data (stack pointer, instruction pointer,
and CPU registers) to *ofc
and restores the context data
from nfc
, which implies
jumping to nfc
's execution
context. The intptr_t argument, p
,
is passed to the current context to be returned by the most recent
call to jump_fcontext()
in the same thread. The last argument
controls if fpu registers have to be preserved.
The third pointer argument passed to the most recent call to jump_fcontext()
,
if any.
fcontext_t make_fcontext(void*
sp,std::size_t
size,void(*fn)(intptr_t))
Stack sp
and function
pointer fn
are valid
(depending on the architecture sp
points to the top or bottom of the stack) and size
> 0.
Creates an fcontext_t on top of the stack and prepares the stack to
execute the context-function fn
.
Returns a fcontext_t which is placed on the stack.