Back to index

glibc  2.9
Functions
makecontext.c File Reference
#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 (" \n\ .text \n\ .type __makecontext_ret, #function \n\ __makecontext_ret: \n\ mov 1, %o1 \n\ call __setcontext \n\ mov %i0, %o0 \n\ unimp 0 \n\ .size __makecontext_ret, .-__makecontext_ret \n\ ")

Function Documentation

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

Definition at line 26 of file makecontext.c.

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

  sp = (long *) ((long) ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size);
  sp -= (argc > 6 ? argc : 6) + 32;
  sp = (long *) (((long) sp) & -16L);
  topsp = sp + (argc > 6 ? argc : 6) + 16;

  ucp->uc_mcontext.mc_gregs[MC_PC] = (long) func;
  ucp->uc_mcontext.mc_gregs[MC_NPC] = ((long) func) + 4;
  ucp->uc_mcontext.mc_gregs[MC_O6] = ((long) sp) - 0x7ff;
  ucp->uc_mcontext.mc_gregs[MC_O7] = ((long) __makecontext_ret) - 8;
  ucp->uc_mcontext.mc_fp = ((long) topsp) - 0x7ff;
  ucp->uc_mcontext.mc_i7 = 0;
  topsp[14] = 0;
  topsp[15] = 0;
  sp[8] = (long) ucp->uc_link;
  va_start (ap, argc);
  for (i = 0; i < argc; ++i)
    if (i < 6)
      ucp->uc_mcontext.mc_gregs[MC_O0 + i] = va_arg (ap, long);
    else
      sp[16 + i] = va_arg (ap, long);
  va_end (ap);
}
asm ( " \n\ .text \n\ .type  __makecontext_ret,
#function\n\__makecontext_ret:\n\mov  1,
%o1\n\call __setcontext\n\mov%  i0,
%o0\n\unimp 0\n\.size  __makecontext_ret,
.-__makecontext_ret\n\"   
)