fcontext_t and related functions

| Home | Libraries | People | FAQ | More

### `fcontext_t` and related functions

    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`

Member:

  Pointer to the beginning of the stack (depending of the architecture the stack grows downwards or upwards).

##### `size`

Member:

  Size of the stack in bytes.

##### `fc_stack`

Member:

  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)`

Effects:

  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.

Returns:

  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))`

Precondition:

  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.

Effects:

  Creates an fcontext_t on top of the stack and prepares the stack to execute the context-function `fn`.

Returns:

  Returns a fcontext_t which is placed on the stack.