Back to index

glibc  2.9
Functions
makecontext.c File Reference
#include <libintl.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <sysdep.h>
#include <ucontext.h>

Go to the source code of this file.

Functions

void __makecontext (ucontext_t *ucp, void(*func)(void), int argc,...)

Function Documentation

void __makecontext ( ucontext_t ucp,
void(*)(void)  func,
int  argc,
  ... 
)

Definition at line 31 of file makecontext.c.

{
  unsigned int *sp;
  va_list ap;
  int i;

  if (argc > 8)
    {
      fprintf (stderr, _("\
makecontext: does not know how to handle more than 8 arguments\n"));
      exit (-1);
    }

  /* Get stack pointer.  */
  sp = (unsigned int *) ucp->uc_stack.ss_sp;

  /* Store address to jump to.  */
  ucp->uc_mcontext.sc_gr[2] = (unsigned long) func;

  va_start (ap, argc);
  /* Handle arguments.  */
  for (i = 0; i < argc; ++i)
    switch (i)
      {
      case 0:
      case 1:
      case 2:
      case 3:
       ucp->uc_mcontext.sc_gr[26-i] = va_arg (ap, int);
       break;
      case 4:
      case 5:
      case 6:
      case 7:
       if (sizeof(unsigned long) == 4) {
              /* 32bit: put arg7-arg4 on stack.  */
              sp[7-i] = va_arg (ap, int);
       } else {
              /* 64bit: r19-r22 are arg7-arg4.  */
              ucp->uc_mcontext.sc_gr[22+4-i] = va_arg (ap, int);
       }
       break;
      }
  va_end (ap);

}

Here is the call graph for this function: