forked from ariadne/libucontext
build: use internal definitions to replace things pulled in from ucontext.h
parent
40c8016144
commit
c31decc3d4
|
@ -13,7 +13,6 @@
|
|||
#define _GNU_SOURCE
|
||||
#include <stddef.h>
|
||||
#include <stdarg.h>
|
||||
#include <ucontext.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
#define _GNU_SOURCE
|
||||
#include <stddef.h>
|
||||
#include <stdarg.h>
|
||||
#include <ucontext.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
#define _GNU_SOURCE
|
||||
#include <stddef.h>
|
||||
#include <stdarg.h>
|
||||
#include <ucontext.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
@ -26,34 +25,34 @@ extern void libucontext_trampoline(void);
|
|||
void
|
||||
libucontext_makecontext(libucontext_ucontext_t *ucp, void (*func)(void), int argc, ...)
|
||||
{
|
||||
greg_t *sp;
|
||||
libucontext_greg_t *sp;
|
||||
va_list va;
|
||||
int i;
|
||||
|
||||
/* set up and align the stack. */
|
||||
sp = (greg_t *) ((uintptr_t) ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size);
|
||||
sp = (libucontext_greg_t *) ((uintptr_t) ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size);
|
||||
sp -= (argc + 2);
|
||||
sp = (greg_t *) (((uintptr_t) sp & ~0x3));
|
||||
sp = (libucontext_greg_t *) (((uintptr_t) sp & ~0x3));
|
||||
|
||||
/* set up the ucontext structure */
|
||||
ucp->uc_mcontext.gregs[REG_SP] = (greg_t) sp;
|
||||
ucp->uc_mcontext.gregs[REG_SP] = (libucontext_greg_t) sp;
|
||||
ucp->uc_mcontext.gregs[REG_A6] = 0;
|
||||
ucp->uc_mcontext.gregs[REG_D7] = argc;
|
||||
ucp->uc_mcontext.gregs[REG_PC] = (greg_t) func;
|
||||
ucp->uc_mcontext.gregs[REG_PC] = (libucontext_greg_t) func;
|
||||
|
||||
/* return address */
|
||||
*sp++ = (greg_t) libucontext_trampoline;
|
||||
*sp++ = (libucontext_greg_t) libucontext_trampoline;
|
||||
|
||||
va_start(va, argc);
|
||||
|
||||
/* all arguments overflow into stack */
|
||||
for (i = 0; i < argc; i++)
|
||||
*sp++ = va_arg (va, greg_t);
|
||||
*sp++ = va_arg (va, libucontext_greg_t);
|
||||
|
||||
va_end(va);
|
||||
|
||||
/* link pointer */
|
||||
*sp++ = (greg_t) ucp->uc_link;
|
||||
*sp++ = (libucontext_greg_t) ucp->uc_link;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
|
||||
#define _GNU_SOURCE
|
||||
#include <stdarg.h>
|
||||
#include <ucontext.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
|
@ -26,16 +25,16 @@ extern void libucontext_trampoline(void);
|
|||
void
|
||||
libucontext_makecontext(ucontext_t *ucp, void (*func)(), int argc, ...)
|
||||
{
|
||||
greg_t *sp;
|
||||
libucontext_greg_t *sp;
|
||||
va_list va;
|
||||
int i;
|
||||
unsigned int stack_args;
|
||||
|
||||
stack_args = argc > 8 ? argc - 8 : 0;
|
||||
|
||||
sp = (greg_t *) ((uintptr_t) ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size);
|
||||
sp = (libucontext_greg_t *) ((uintptr_t) ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size);
|
||||
sp -= stack_args + 2;
|
||||
sp = (greg_t *) ((uintptr_t) sp & -16L);
|
||||
sp = (libucontext_greg_t *) ((uintptr_t) sp & -16L);
|
||||
|
||||
ucp->uc_mcontext.gregs[REG_NIP] = (uintptr_t) func;
|
||||
ucp->uc_mcontext.gregs[REG_LNK] = (uintptr_t) &libucontext_trampoline;
|
||||
|
@ -48,9 +47,9 @@ libucontext_makecontext(ucontext_t *ucp, void (*func)(), int argc, ...)
|
|||
|
||||
for (i = 0; i < argc; i++) {
|
||||
if (i < 8)
|
||||
ucp->uc_mcontext.gregs[i + 3] = va_arg (va, greg_t);
|
||||
ucp->uc_mcontext.gregs[i + 3] = va_arg (va, libucontext_greg_t);
|
||||
else
|
||||
sp[i-8 + 2] = va_arg (va, greg_t);
|
||||
sp[i-8 + 2] = va_arg (va, libucontext_greg_t);
|
||||
}
|
||||
|
||||
va_end(va);
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
|
||||
#define _GNU_SOURCE
|
||||
#include <stdarg.h>
|
||||
#include <ucontext.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
|
@ -26,16 +25,16 @@ extern void libucontext_trampoline(void);
|
|||
void
|
||||
libucontext_makecontext(ucontext_t *ucp, void (*func)(), int argc, ...)
|
||||
{
|
||||
greg_t *sp;
|
||||
libucontext_greg_t *sp;
|
||||
va_list va;
|
||||
int i;
|
||||
unsigned int stack_args;
|
||||
|
||||
stack_args = argc > 8 ? argc : 0;
|
||||
|
||||
sp = (greg_t *) ((uintptr_t) ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size);
|
||||
sp = (libucontext_greg_t *) ((uintptr_t) ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size);
|
||||
sp -= stack_args + 4;
|
||||
sp = (greg_t *) ((uintptr_t) sp & -16L);
|
||||
sp = (libucontext_greg_t *) ((uintptr_t) sp & -16L);
|
||||
|
||||
ucp->uc_mcontext.gp_regs[REG_NIP] = (uintptr_t) func;
|
||||
ucp->uc_mcontext.gp_regs[REG_LNK] = (uintptr_t) &libucontext_trampoline;
|
||||
|
@ -49,9 +48,9 @@ libucontext_makecontext(ucontext_t *ucp, void (*func)(), int argc, ...)
|
|||
|
||||
for (i = 0; i < argc; i++) {
|
||||
if (i < 8)
|
||||
ucp->uc_mcontext.gp_regs[i + 3] = va_arg (va, greg_t);
|
||||
ucp->uc_mcontext.gp_regs[i + 3] = va_arg (va, libucontext_greg_t);
|
||||
else
|
||||
sp[i + 4] = va_arg (va, greg_t);
|
||||
sp[i + 4] = va_arg (va, libucontext_greg_t);
|
||||
}
|
||||
|
||||
va_end(va);
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
#define _GNU_SOURCE
|
||||
#include <stddef.h>
|
||||
#include <stdarg.h>
|
||||
#include <ucontext.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
@ -26,21 +25,21 @@ extern void libucontext_trampoline(void);
|
|||
void
|
||||
libucontext_makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...)
|
||||
{
|
||||
greg_t *sp, *regp;
|
||||
libucontext_greg_t *sp, *regp;
|
||||
va_list va;
|
||||
int i;
|
||||
|
||||
/* set up and align the stack. */
|
||||
sp = (greg_t *) ((uintptr_t) ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size);
|
||||
sp = (libucontext_greg_t *) ((uintptr_t) ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size);
|
||||
sp -= argc < 8 ? 0 : argc - 8;
|
||||
sp = (greg_t *) (((uintptr_t) sp & -16L));
|
||||
sp = (libucontext_greg_t *) (((uintptr_t) sp & -16L));
|
||||
|
||||
/* set up the ucontext structure */
|
||||
ucp->uc_mcontext.__gregs[REG_RA] = (greg_t) libucontext_trampoline;
|
||||
ucp->uc_mcontext.__gregs[REG_RA] = (libucontext_greg_t) libucontext_trampoline;
|
||||
ucp->uc_mcontext.__gregs[REG_S0] = 0;
|
||||
ucp->uc_mcontext.__gregs[REG_S1] = (greg_t) func;
|
||||
ucp->uc_mcontext.__gregs[REG_S2] = (greg_t) ucp->uc_link;
|
||||
ucp->uc_mcontext.__gregs[REG_SP] = (greg_t) sp;
|
||||
ucp->uc_mcontext.__gregs[REG_S1] = (libucontext_greg_t) func;
|
||||
ucp->uc_mcontext.__gregs[REG_S2] = (libucontext_greg_t) ucp->uc_link;
|
||||
ucp->uc_mcontext.__gregs[REG_SP] = (libucontext_greg_t) sp;
|
||||
ucp->uc_mcontext.__gregs[REG_PC] = 0;
|
||||
|
||||
va_start(va, argc);
|
||||
|
@ -49,11 +48,11 @@ libucontext_makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...)
|
|||
regp = &(ucp->uc_mcontext.__gregs[REG_A0]);
|
||||
|
||||
for (i = 0; (i < argc && i < 8); i++)
|
||||
*regp++ = va_arg (va, greg_t);
|
||||
*regp++ = va_arg (va, libucontext_greg_t);
|
||||
|
||||
/* remainder overflows into stack */
|
||||
for (; i < argc; i++)
|
||||
*sp++ = va_arg (va, greg_t);
|
||||
*sp++ = va_arg (va, libucontext_greg_t);
|
||||
|
||||
va_end(va);
|
||||
}
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
#define _GNU_SOURCE
|
||||
#include <stddef.h>
|
||||
#include <stdarg.h>
|
||||
#include <ucontext.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
@ -28,12 +27,12 @@ extern int libucontext_setcontext(const ucontext_t *ucp);
|
|||
void
|
||||
libucontext_makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...)
|
||||
{
|
||||
greg_t *sp;
|
||||
libucontext_greg_t *sp;
|
||||
va_list va;
|
||||
int i;
|
||||
|
||||
sp = (greg_t *) ((uintptr_t) ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size);
|
||||
sp = (greg_t *) (((uintptr_t) sp & -8L));
|
||||
sp = (libucontext_greg_t *) ((uintptr_t) ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size);
|
||||
sp = (libucontext_greg_t *) (((uintptr_t) sp & -8L));
|
||||
|
||||
ucp->uc_mcontext.gregs[7] = (uintptr_t) func;
|
||||
ucp->uc_mcontext.gregs[8] = (uintptr_t) ucp->uc_link;
|
||||
|
@ -43,14 +42,14 @@ libucontext_makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...)
|
|||
va_start(va, argc);
|
||||
|
||||
for (i = 0; i < argc && i < 5; i++)
|
||||
ucp->uc_mcontext.gregs[i + 2] = va_arg (va, greg_t);
|
||||
ucp->uc_mcontext.gregs[i + 2] = va_arg (va, libucontext_greg_t);
|
||||
|
||||
if (argc > 5)
|
||||
{
|
||||
sp -= argc - 5;
|
||||
|
||||
for (i = 5; i < argc; i++)
|
||||
sp[i - 5] = va_arg (va, greg_t);
|
||||
sp[i - 5] = va_arg (va, libucontext_greg_t);
|
||||
}
|
||||
|
||||
va_end(va);
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
#define _GNU_SOURCE
|
||||
#include <stddef.h>
|
||||
#include <stdarg.h>
|
||||
#include <ucontext.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
@ -25,16 +24,16 @@ extern void libucontext_trampoline(void);
|
|||
void
|
||||
libucontext_makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...)
|
||||
{
|
||||
greg_t *sp, *argp;
|
||||
libucontext_greg_t *sp, *argp;
|
||||
va_list va;
|
||||
int i;
|
||||
unsigned int uc_link;
|
||||
|
||||
uc_link = (argc > 6 ? argc - 6 : 0) + 1;
|
||||
|
||||
sp = (greg_t *) ((uintptr_t) ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size);
|
||||
sp = (libucontext_greg_t *) ((uintptr_t) ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size);
|
||||
sp -= uc_link;
|
||||
sp = (greg_t *) (((uintptr_t) sp & -16L) - 8);
|
||||
sp = (libucontext_greg_t *) (((uintptr_t) sp & -16L) - 8);
|
||||
|
||||
ucp->uc_mcontext.gregs[REG_EIP] = (uintptr_t) func;
|
||||
ucp->uc_mcontext.gregs[REG_EBX] = (uintptr_t) argc;
|
||||
|
@ -46,7 +45,7 @@ libucontext_makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...)
|
|||
va_start(va, argc);
|
||||
|
||||
for (i = 0; i < argc; i++)
|
||||
*argp++ = va_arg (va, greg_t);
|
||||
*argp++ = va_arg (va, libucontext_greg_t);
|
||||
|
||||
va_end(va);
|
||||
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
#define _GNU_SOURCE
|
||||
#include <stddef.h>
|
||||
#include <stdarg.h>
|
||||
#include <ucontext.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
@ -25,16 +24,16 @@ extern void libucontext_trampoline(void);
|
|||
void
|
||||
libucontext_makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...)
|
||||
{
|
||||
greg_t *sp;
|
||||
libucontext_greg_t *sp;
|
||||
va_list va;
|
||||
int i;
|
||||
unsigned int uc_link;
|
||||
|
||||
uc_link = (argc > 6 ? argc - 6 : 0) + 1;
|
||||
|
||||
sp = (greg_t *) ((uintptr_t) ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size);
|
||||
sp = (libucontext_greg_t *) ((uintptr_t) ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size);
|
||||
sp -= uc_link;
|
||||
sp = (greg_t *) (((uintptr_t) sp & -16L) - 8);
|
||||
sp = (libucontext_greg_t *) (((uintptr_t) sp & -16L) - 8);
|
||||
|
||||
ucp->uc_mcontext.gregs[REG_RIP] = (uintptr_t) func;
|
||||
ucp->uc_mcontext.gregs[REG_RBX] = (uintptr_t) &sp[uc_link];
|
||||
|
@ -49,25 +48,25 @@ libucontext_makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...)
|
|||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
ucp->uc_mcontext.gregs[REG_RDI] = va_arg (va, greg_t);
|
||||
ucp->uc_mcontext.gregs[REG_RDI] = va_arg (va, libucontext_greg_t);
|
||||
break;
|
||||
case 1:
|
||||
ucp->uc_mcontext.gregs[REG_RSI] = va_arg (va, greg_t);
|
||||
ucp->uc_mcontext.gregs[REG_RSI] = va_arg (va, libucontext_greg_t);
|
||||
break;
|
||||
case 2:
|
||||
ucp->uc_mcontext.gregs[REG_RDX] = va_arg (va, greg_t);
|
||||
ucp->uc_mcontext.gregs[REG_RDX] = va_arg (va, libucontext_greg_t);
|
||||
break;
|
||||
case 3:
|
||||
ucp->uc_mcontext.gregs[REG_RCX] = va_arg (va, greg_t);
|
||||
ucp->uc_mcontext.gregs[REG_RCX] = va_arg (va, libucontext_greg_t);
|
||||
break;
|
||||
case 4:
|
||||
ucp->uc_mcontext.gregs[REG_R8] = va_arg (va, greg_t);
|
||||
ucp->uc_mcontext.gregs[REG_R8] = va_arg (va, libucontext_greg_t);
|
||||
break;
|
||||
case 5:
|
||||
ucp->uc_mcontext.gregs[REG_R9] = va_arg (va, greg_t);
|
||||
ucp->uc_mcontext.gregs[REG_R9] = va_arg (va, libucontext_greg_t);
|
||||
break;
|
||||
default:
|
||||
sp[i - 5] = va_arg (va, greg_t);
|
||||
sp[i - 5] = va_arg (va, libucontext_greg_t);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue