makecontext or swapcontext Subroutine

Purpose

Modifies the context specified by ucp.

Library

(libc.a)

Syntax

#include <ucontext.h>

void makecontext (ucontext_t *ucp, (void *func) (), int argc, ...); int swapcontext (uncontext_t *oucp, const uncontext_t *ucp);

Description

The makecontext subroutine modifies the context specified by ucp, which has been initialized using getcontext subroutine. When this context is resumed using swapcontext subroutine or setcontext subroutine, program execution continues by calling func parameter, passing it the arguments that follow argc in the makecontext subroutine.

Before a call is made to makecontext subroutine, the context being modified should have a stack allocated for it. The value of argc must match the number of integer argument passed to func parameter, otherwise the behavior is undefined.

The uc_link member is used to determine the context that will be resumed when the context being modified by makecontext subroutine returns. The uc_link member should be initialized prior to the call to makecontext subroutine.

The swapcontext subroutine function saves the current context in the context structure pointed to by oucp parameter and sets the context to the context structure pointed to by ucp.

Parameters

Item Description
ucp A pointer to a user structure.
oucp A pointer to a user structure.
func A pointer to a function to be called when ucp is restored.
argc The number of arguments being passed to func parameter.

Return Values

On successful completion, swapcontext subroutine returns 0. Otherwise, a value of -1 is returned and errno is set to indicate the error.

Item Description
-1 Not successful and the errno global variable is set to one of the following error codes.

Error Codes

Item Description
ENOMEM The ucp argument does not have enough stack left to complete the operation.