Back to index

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

Go to the source code of this file.

Functions

void __makecontext (ucontext_t *ucp, void(*func)(void), int argc,...)
 asm (".text\n"".type __makecontext_ret,@function\n""__makecontext_ret:\n"" basr %r14,%r7\n"" lr %r2,%r8\n"" br %r9\n"".size __makecontext_ret, .-__makecontext_ret")

Function Documentation

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

Definition at line 54 of file makecontext.c.

{
  extern void __makecontext_ret (void);
  unsigned long *sp;
  va_list ap;
  int i;

  sp = (unsigned long *) (((unsigned long) ucp->uc_stack.ss_sp
                        + ucp->uc_stack.ss_size) & -8L);

  /* Set the return address to trampoline.  */
  ucp->uc_mcontext.gregs[14] = (long) __makecontext_ret;

  /* Set register parameters.  */
  va_start (ap, argc);
  for (i = 0; (i < argc) && (i < 5); i++)
    ucp->uc_mcontext.gregs[2+i] = va_arg (ap, long);

  /* The remaining arguments go to the overflow area.  */
  if (argc > 5) {
    sp -= argc - 5;
    for (i = 5; i < argc; i++)
      sp[i] = va_arg(ap, long);
  }
  va_end (ap);

  /* Make room for the save area and set the backchain.  */
  sp -= 24;
  *sp = 0;

  /* Pass (*func) to __start_context in %r7.  */
  ucp->uc_mcontext.gregs[7] = (long) func;

  /* Pass ucp->uc_link to __start_context in %r8.  */
  ucp->uc_mcontext.gregs[8] = (long) ucp->uc_link;

  /* Pass address of setcontext in %r9.  */
  ucp->uc_mcontext.gregs[9] = (long) &setcontext;

  /* Set stack pointer.  */
  ucp->uc_mcontext.gregs[15] = (long) sp;
}

Here is the call graph for this function:

asm ( ".text\n"".type  __makecontext_ret,
@function\n""__makecontext_ret:\n""basr%  r14,
%r7\n""lr%  r2,
%r8\n""br% r9\n"".size  __makecontext_ret,
.-__makecontext_ret"   
)