build: use internal definitions to replace things pulled in from ucontext.h

pull/21/head
Ariadne Conill 2020-12-06 03:44:45 -06:00
parent 40c8016144
commit c31decc3d4
9 changed files with 46 additions and 55 deletions

View File

@ -13,7 +13,6 @@
#define _GNU_SOURCE #define _GNU_SOURCE
#include <stddef.h> #include <stddef.h>
#include <stdarg.h> #include <stdarg.h>
#include <ucontext.h>
#include <string.h> #include <string.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>

View File

@ -13,7 +13,6 @@
#define _GNU_SOURCE #define _GNU_SOURCE
#include <stddef.h> #include <stddef.h>
#include <stdarg.h> #include <stdarg.h>
#include <ucontext.h>
#include <string.h> #include <string.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>

View File

@ -13,7 +13,6 @@
#define _GNU_SOURCE #define _GNU_SOURCE
#include <stddef.h> #include <stddef.h>
#include <stdarg.h> #include <stdarg.h>
#include <ucontext.h>
#include <string.h> #include <string.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
@ -26,34 +25,34 @@ extern void libucontext_trampoline(void);
void void
libucontext_makecontext(libucontext_ucontext_t *ucp, void (*func)(void), int argc, ...) libucontext_makecontext(libucontext_ucontext_t *ucp, void (*func)(void), int argc, ...)
{ {
greg_t *sp; libucontext_greg_t *sp;
va_list va; va_list va;
int i; int i;
/* set up and align the stack. */ /* 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 -= (argc + 2);
sp = (greg_t *) (((uintptr_t) sp & ~0x3)); sp = (libucontext_greg_t *) (((uintptr_t) sp & ~0x3));
/* set up the ucontext structure */ /* 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_A6] = 0;
ucp->uc_mcontext.gregs[REG_D7] = argc; 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 */ /* return address */
*sp++ = (greg_t) libucontext_trampoline; *sp++ = (libucontext_greg_t) libucontext_trampoline;
va_start(va, argc); va_start(va, argc);
/* all arguments overflow into stack */ /* all arguments overflow into stack */
for (i = 0; i < argc; i++) for (i = 0; i < argc; i++)
*sp++ = va_arg (va, greg_t); *sp++ = va_arg (va, libucontext_greg_t);
va_end(va); va_end(va);
/* link pointer */ /* link pointer */
*sp++ = (greg_t) ucp->uc_link; *sp++ = (libucontext_greg_t) ucp->uc_link;
} }

View File

@ -13,7 +13,6 @@
#define _GNU_SOURCE #define _GNU_SOURCE
#include <stdarg.h> #include <stdarg.h>
#include <ucontext.h>
#include <stdint.h> #include <stdint.h>
@ -26,16 +25,16 @@ extern void libucontext_trampoline(void);
void void
libucontext_makecontext(ucontext_t *ucp, void (*func)(), int argc, ...) libucontext_makecontext(ucontext_t *ucp, void (*func)(), int argc, ...)
{ {
greg_t *sp; libucontext_greg_t *sp;
va_list va; va_list va;
int i; int i;
unsigned int stack_args; unsigned int stack_args;
stack_args = argc > 8 ? argc - 8 : 0; 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 -= 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_NIP] = (uintptr_t) func;
ucp->uc_mcontext.gregs[REG_LNK] = (uintptr_t) &libucontext_trampoline; 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++) { for (i = 0; i < argc; i++) {
if (i < 8) 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 else
sp[i-8 + 2] = va_arg (va, greg_t); sp[i-8 + 2] = va_arg (va, libucontext_greg_t);
} }
va_end(va); va_end(va);

View File

@ -13,7 +13,6 @@
#define _GNU_SOURCE #define _GNU_SOURCE
#include <stdarg.h> #include <stdarg.h>
#include <ucontext.h>
#include <stdint.h> #include <stdint.h>
@ -26,16 +25,16 @@ extern void libucontext_trampoline(void);
void void
libucontext_makecontext(ucontext_t *ucp, void (*func)(), int argc, ...) libucontext_makecontext(ucontext_t *ucp, void (*func)(), int argc, ...)
{ {
greg_t *sp; libucontext_greg_t *sp;
va_list va; va_list va;
int i; int i;
unsigned int stack_args; unsigned int stack_args;
stack_args = argc > 8 ? argc : 0; 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 -= 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_NIP] = (uintptr_t) func;
ucp->uc_mcontext.gp_regs[REG_LNK] = (uintptr_t) &libucontext_trampoline; 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++) { for (i = 0; i < argc; i++) {
if (i < 8) 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 else
sp[i + 4] = va_arg (va, greg_t); sp[i + 4] = va_arg (va, libucontext_greg_t);
} }
va_end(va); va_end(va);

View File

@ -13,7 +13,6 @@
#define _GNU_SOURCE #define _GNU_SOURCE
#include <stddef.h> #include <stddef.h>
#include <stdarg.h> #include <stdarg.h>
#include <ucontext.h>
#include <string.h> #include <string.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
@ -26,21 +25,21 @@ extern void libucontext_trampoline(void);
void void
libucontext_makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...) libucontext_makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...)
{ {
greg_t *sp, *regp; libucontext_greg_t *sp, *regp;
va_list va; va_list va;
int i; int i;
/* set up and align the stack. */ /* 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 -= 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 */ /* 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_S0] = 0;
ucp->uc_mcontext.__gregs[REG_S1] = (greg_t) func; ucp->uc_mcontext.__gregs[REG_S1] = (libucontext_greg_t) func;
ucp->uc_mcontext.__gregs[REG_S2] = (greg_t) ucp->uc_link; ucp->uc_mcontext.__gregs[REG_S2] = (libucontext_greg_t) ucp->uc_link;
ucp->uc_mcontext.__gregs[REG_SP] = (greg_t) sp; ucp->uc_mcontext.__gregs[REG_SP] = (libucontext_greg_t) sp;
ucp->uc_mcontext.__gregs[REG_PC] = 0; ucp->uc_mcontext.__gregs[REG_PC] = 0;
va_start(va, argc); 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]); regp = &(ucp->uc_mcontext.__gregs[REG_A0]);
for (i = 0; (i < argc && i < 8); i++) 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 */ /* remainder overflows into stack */
for (; i < argc; i++) for (; i < argc; i++)
*sp++ = va_arg (va, greg_t); *sp++ = va_arg (va, libucontext_greg_t);
va_end(va); va_end(va);
} }

View File

@ -13,7 +13,6 @@
#define _GNU_SOURCE #define _GNU_SOURCE
#include <stddef.h> #include <stddef.h>
#include <stdarg.h> #include <stdarg.h>
#include <ucontext.h>
#include <string.h> #include <string.h>
#include <stdint.h> #include <stdint.h>
@ -28,12 +27,12 @@ extern int libucontext_setcontext(const ucontext_t *ucp);
void void
libucontext_makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...) libucontext_makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...)
{ {
greg_t *sp; libucontext_greg_t *sp;
va_list va; va_list va;
int i; int i;
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 = (greg_t *) (((uintptr_t) sp & -8L)); sp = (libucontext_greg_t *) (((uintptr_t) sp & -8L));
ucp->uc_mcontext.gregs[7] = (uintptr_t) func; ucp->uc_mcontext.gregs[7] = (uintptr_t) func;
ucp->uc_mcontext.gregs[8] = (uintptr_t) ucp->uc_link; 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); va_start(va, argc);
for (i = 0; i < argc && i < 5; i++) 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) if (argc > 5)
{ {
sp -= argc - 5; sp -= argc - 5;
for (i = 5; i < argc; i++) 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); va_end(va);

View File

@ -14,7 +14,6 @@
#define _GNU_SOURCE #define _GNU_SOURCE
#include <stddef.h> #include <stddef.h>
#include <stdarg.h> #include <stdarg.h>
#include <ucontext.h>
#include <string.h> #include <string.h>
#include <stdint.h> #include <stdint.h>
@ -25,16 +24,16 @@ extern void libucontext_trampoline(void);
void void
libucontext_makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...) libucontext_makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...)
{ {
greg_t *sp, *argp; libucontext_greg_t *sp, *argp;
va_list va; va_list va;
int i; int i;
unsigned int uc_link; unsigned int uc_link;
uc_link = (argc > 6 ? argc - 6 : 0) + 1; 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 -= 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_EIP] = (uintptr_t) func;
ucp->uc_mcontext.gregs[REG_EBX] = (uintptr_t) argc; 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); va_start(va, argc);
for (i = 0; i < argc; i++) for (i = 0; i < argc; i++)
*argp++ = va_arg (va, greg_t); *argp++ = va_arg (va, libucontext_greg_t);
va_end(va); va_end(va);

View File

@ -13,7 +13,6 @@
#define _GNU_SOURCE #define _GNU_SOURCE
#include <stddef.h> #include <stddef.h>
#include <stdarg.h> #include <stdarg.h>
#include <ucontext.h>
#include <string.h> #include <string.h>
#include <stdint.h> #include <stdint.h>
@ -25,16 +24,16 @@ extern void libucontext_trampoline(void);
void void
libucontext_makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...) libucontext_makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...)
{ {
greg_t *sp; libucontext_greg_t *sp;
va_list va; va_list va;
int i; int i;
unsigned int uc_link; unsigned int uc_link;
uc_link = (argc > 6 ? argc - 6 : 0) + 1; 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 -= 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_RIP] = (uintptr_t) func;
ucp->uc_mcontext.gregs[REG_RBX] = (uintptr_t) &sp[uc_link]; 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) switch (i)
{ {
case 0: 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; break;
case 1: 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; break;
case 2: 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; break;
case 3: 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; break;
case 4: 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; break;
case 5: 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; break;
default: default:
sp[i - 5] = va_arg (va, greg_t); sp[i - 5] = va_arg (va, libucontext_greg_t);
break; break;
} }