ARM64 fixes, Meson build system, and Maco-O support #22
14
Makefile
14
Makefile
|
@ -20,7 +20,7 @@ EXPORT_UNPREFIXED := yes
|
|||
FREESTANDING := no
|
||||
|
||||
ifeq ($(FREESTANDING),yes)
|
||||
CFLAGS += -DFREESTANDING -isystem arch/${ARCH}/freestanding
|
||||
CFLAGS += -DFREESTANDING
|
||||
EXPORT_UNPREFIXED = no
|
||||
endif
|
||||
|
||||
|
@ -31,7 +31,7 @@ endif
|
|||
LIBUCONTEXT_C_SRC = $(wildcard arch/${ARCH}/*.c)
|
||||
LIBUCONTEXT_S_SRC = $(wildcard arch/${ARCH}/*.S)
|
||||
|
||||
LIBUCONTEXT_VERSION := 0.13.1
|
||||
LIBUCONTEXT_VERSION := $(shell head VERSION)
|
||||
LIBUCONTEXT_OBJ = ${LIBUCONTEXT_C_SRC:.c=.o} ${LIBUCONTEXT_S_SRC:.S=.o}
|
||||
LIBUCONTEXT_SOVERSION = 0
|
||||
LIBUCONTEXT_NAME = libucontext.so
|
||||
|
@ -105,7 +105,7 @@ docs: ${MANPAGES}
|
|||
$(CC) -std=gnu99 -D_BSD_SOURCE -fPIC -DPIC ${CFLAGS} ${CPPFLAGS} -c -o $@ $<
|
||||
|
||||
.S.o:
|
||||
$(CC) -fPIC -DPIC -DLIBUCONTEXT_ASSEMBLY ${CFLAGS} ${CPPFLAGS} -c -o $@ $<
|
||||
$(CC) -fPIC -DPIC ${CFLAGS} ${CPPFLAGS} -c -o $@ $<
|
||||
|
||||
${LIBUCONTEXT_NAME}_clean:
|
||||
rm -f ${LIBUCONTEXT_NAME}
|
||||
|
@ -199,13 +199,13 @@ examples/cooperative_threading: examples/cooperative_threading.c ${LIBUCONTEXT_N
|
|||
|
||||
ifeq ($(FREESTANDING),no)
|
||||
|
||||
include/libucontext/bits.h: arch/common/bits.h
|
||||
cp arch/common/bits.h $@
|
||||
include/libucontext/bits.h: arch/common/include/libucontext/bits.h
|
||||
cp $< $@
|
||||
|
||||
else
|
||||
|
||||
include/libucontext/bits.h: arch/${ARCH}/freestanding/bits.h
|
||||
cp arch/${ARCH}/freestanding/bits.h $@
|
||||
include/libucontext/bits.h: arch/${ARCH}/include/libucontext/bits.h
|
||||
cp $< $@
|
||||
|
||||
endif
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#endif
|
||||
|
||||
#define FETCH_LINKPTR(dest) \
|
||||
asm("mov x0, %0" : "=rm" ((dest)))
|
||||
asm("mov %0, x19" : "=r" ((dest)))
|
||||
|
||||
#include "common-defs.h"
|
||||
|
||||
|
|
|
@ -14,7 +14,11 @@
|
|||
|
||||
ALIAS(getcontext, libucontext_getcontext)
|
||||
|
||||
FUNC(libucontext_getcontext)
|
||||
.global PROC_NAME(libucontext_getcontext);
|
||||
.align 2;
|
||||
TYPE(libucontext_getcontext)
|
||||
ENT(libucontext_getcontext)
|
||||
PROC_NAME(libucontext_getcontext):
|
||||
str xzr, [x0, #REG_OFFSET(0)]
|
||||
|
||||
/* save GPRs */
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
#ifndef LIBUCONTEXT_BITS_H
|
||||
#define LIBUCONTEXT_BITS_H
|
||||
|
||||
typedef unsigned long libucontext_greg_t;
|
||||
typedef unsigned long libucontext_gregset_t[34];
|
||||
typedef unsigned long long int libucontext_greg_t;
|
||||
typedef unsigned long int libucontext_sigset_t;
|
||||
|
||||
typedef struct {
|
||||
__uint128_t vregs[32];
|
||||
unsigned int fpsr;
|
||||
unsigned int fpcr;
|
||||
libucontext_greg_t fpsr;
|
||||
libucontext_greg_t fpcr;
|
||||
} libucontext_fpregset_t;
|
||||
|
||||
typedef struct sigcontext {
|
||||
unsigned long fault_address;
|
||||
unsigned long regs[31];
|
||||
unsigned long sp, pc, pstate;
|
||||
long double __reserved[256];
|
||||
typedef struct {
|
||||
libucontext_greg_t fault_address;
|
||||
libucontext_greg_t regs[31];
|
||||
libucontext_greg_t sp, pc, pstate;
|
||||
double __reserved[256];
|
||||
} libucontext_mcontext_t;
|
||||
|
||||
typedef struct {
|
||||
|
@ -27,6 +27,7 @@ typedef struct libucontext_ucontext {
|
|||
unsigned long uc_flags;
|
||||
struct libucontext_ucontext *uc_link;
|
||||
libucontext_stack_t uc_stack;
|
||||
libucontext_sigset_t uc_sigmask;
|
||||
unsigned char __pad[128];
|
||||
libucontext_mcontext_t uc_mcontext;
|
||||
} libucontext_ucontext_t;
|
|
@ -10,29 +10,38 @@
|
|||
* from the use of this software.
|
||||
*/
|
||||
|
||||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
#include <stddef.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include "defs.h"
|
||||
#include <libucontext/libucontext.h>
|
||||
|
||||
|
||||
extern void libucontext_trampoline(void);
|
||||
|
||||
_Static_assert(offsetof(libucontext_ucontext_t, uc_mcontext.regs[0]) == R0_OFFSET, "R0_OFFSET is invalid");
|
||||
_Static_assert(offsetof(libucontext_ucontext_t, uc_mcontext.sp) == SP_OFFSET, "SP_OFFSET is invalid");
|
||||
_Static_assert(offsetof(libucontext_ucontext_t, uc_mcontext.pc) == PC_OFFSET, "PC_OFFSET is invalid");
|
||||
_Static_assert(offsetof(libucontext_ucontext_t, uc_mcontext.pstate) == PSTATE_OFFSET, "PSTATE_OFFSET is invalid");
|
||||
|
||||
void
|
||||
libucontext_makecontext(libucontext_ucontext_t *ucp, void (*func)(void), int argc, ...)
|
||||
{
|
||||
unsigned long *sp;
|
||||
unsigned long *regp;
|
||||
// specs require only 'int' arguments so stack arguments are int type
|
||||
// while register argument take the full width of libucontext_greg_t
|
||||
int *sp;
|
||||
libucontext_greg_t *regp;
|
||||
va_list va;
|
||||
int i;
|
||||
|
||||
sp = (unsigned long *) ((uintptr_t) ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size);
|
||||
sp = (int *) ((uintptr_t) ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size);
|
||||
sp -= argc < 8 ? 0 : argc - 8;
|
||||
sp = (unsigned long *) (((uintptr_t) sp & -16L));
|
||||
sp = (int *) (((uintptr_t) sp & -16L));
|
||||
|
||||
ucp->uc_mcontext.sp = (uintptr_t) sp;
|
||||
ucp->uc_mcontext.pc = (uintptr_t) func;
|
||||
|
@ -44,13 +53,14 @@ libucontext_makecontext(libucontext_ucontext_t *ucp, void (*func)(void), int arg
|
|||
regp = &(ucp->uc_mcontext.regs[0]);
|
||||
|
||||
for (i = 0; (i < argc && i < 8); i++)
|
||||
*regp++ = va_arg (va, unsigned long);
|
||||
*regp++ = va_arg (va, int);
|
||||
|
||||
for (; i < argc; i++)
|
||||
*sp++ = va_arg (va, unsigned long);
|
||||
*sp++ = va_arg (va, int);
|
||||
|
||||
|
||||
va_end(va);
|
||||
}
|
||||
|
||||
|
||||
#ifdef EXPORT_UNPREFIXED
|
||||
extern __typeof(libucontext_makecontext) makecontext __attribute__((weak, __alias__("libucontext_makecontext")));
|
||||
#endif
|
||||
|
|
|
@ -14,7 +14,11 @@
|
|||
|
||||
ALIAS(setcontext, libucontext_setcontext)
|
||||
|
||||
FUNC(libucontext_setcontext)
|
||||
.global PROC_NAME(libucontext_setcontext);
|
||||
.align 2;
|
||||
TYPE(libucontext_setcontext)
|
||||
ENT(libucontext_setcontext)
|
||||
PROC_NAME(libucontext_setcontext):
|
||||
/* restore GPRs */
|
||||
ldp x18, x19, [x0, #REG_OFFSET(18)]
|
||||
ldp x20, x21, [x0, #REG_OFFSET(20)]
|
||||
|
|
|
@ -14,7 +14,11 @@
|
|||
|
||||
ALIAS(swapcontext, libucontext_swapcontext)
|
||||
|
||||
FUNC(libucontext_swapcontext)
|
||||
.global PROC_NAME(libucontext_swapcontext);
|
||||
.align 2;
|
||||
TYPE(libucontext_swapcontext)
|
||||
ENT(libucontext_swapcontext)
|
||||
PROC_NAME(libucontext_swapcontext):
|
||||
str xzr, [x0, #REG_OFFSET(0)]
|
||||
|
||||
/* save GPRs */
|
||||
|
@ -50,7 +54,7 @@ FUNC(libucontext_swapcontext)
|
|||
|
||||
/* move x1 to x0 and call setcontext */
|
||||
mov x0, x1
|
||||
bl libucontext_setcontext
|
||||
bl PROC_NAME(libucontext_setcontext)
|
||||
|
||||
/* hmm, we came back here try to return */
|
||||
mov x30, x28
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
#include "defs.h"
|
||||
#include <libucontext/libucontext.h>
|
||||
#include "common-trampoline.c"
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#define TYPE(__proc)
|
||||
|
||||
#define FETCH_LINKPTR(dest) \
|
||||
asm("movs r0, %0" : "=rm" ((dest)))
|
||||
asm("movs %0, r4" : "=r" ((dest)))
|
||||
|
||||
#include "common-defs.h"
|
||||
|
||||
|
|
|
@ -10,7 +10,9 @@
|
|||
* from the use of this software.
|
||||
*/
|
||||
|
||||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
#include <stddef.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
|
@ -19,6 +21,7 @@
|
|||
|
||||
|
||||
#include "defs.h"
|
||||
#include <libucontext/libucontext.h>
|
||||
|
||||
|
||||
extern void libucontext_trampoline(void);
|
||||
|
@ -56,5 +59,6 @@ libucontext_makecontext(libucontext_ucontext_t *ucp, void (*func)(void), int arg
|
|||
va_end(va);
|
||||
}
|
||||
|
||||
|
||||
#ifdef EXPORT_UNPREFIXED
|
||||
extern __typeof(libucontext_makecontext) makecontext __attribute__((weak, __alias__("libucontext_makecontext")));
|
||||
#endif
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
#include "defs.h"
|
||||
#include <libucontext/libucontext.h>
|
||||
#include "common-trampoline.c"
|
||||
|
|
|
@ -18,15 +18,27 @@
|
|||
#endif
|
||||
|
||||
#ifndef TYPE
|
||||
# define TYPE(__proc) .type __proc, @function;
|
||||
# ifdef __clang__
|
||||
# define TYPE(__proc) // .type not supported
|
||||
# else
|
||||
# define TYPE(__proc) .type __proc, @function;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef PROC_NAME
|
||||
# ifdef __MACH__
|
||||
# define PROC_NAME(__proc) _ ## __proc
|
||||
# else
|
||||
# define PROC_NAME(__proc) __proc
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#define FUNC(__proc) \
|
||||
.global __proc; \
|
||||
.global PROC_NAME(__proc); \
|
||||
.align 2; \
|
||||
TYPE(__proc) \
|
||||
ENT(__proc) \
|
||||
__proc: \
|
||||
PROC_NAME(__proc): \
|
||||
SETUP_FRAME(__proc)
|
||||
#ifdef __clang__
|
||||
#define END(__proc)
|
||||
|
@ -46,10 +58,4 @@ __proc: \
|
|||
|
||||
#define REG_OFFSET(__reg) (MCONTEXT_GREGS + ((__reg) * REG_SZ))
|
||||
|
||||
#ifndef LIBUCONTEXT_ASSEMBLY
|
||||
|
||||
#include <libucontext/libucontext.h>
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -19,6 +19,7 @@ libucontext_trampoline(void)
|
|||
{
|
||||
libucontext_ucontext_t *uc_link;
|
||||
|
||||
// FIXME: there's no guarantee that input is not clobbered!
|
||||
FETCH_LINKPTR(uc_link);
|
||||
|
||||
if (uc_link == NULL)
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
#define PC_OFFSET REG_OFFSET(REG_PC)
|
||||
|
||||
#define FETCH_LINKPTR(dest) \
|
||||
asm("mov.l (%%sp, %%d7.l * 4), %0" : "=rm" ((dest)))
|
||||
asm("mov.l (%%sp, %%d7.l * 4), %0" :: "r" ((dest)))
|
||||
|
||||
#include "common-defs.h"
|
||||
|
||||
|
|
|
@ -10,13 +10,16 @@
|
|||
* from the use of this software.
|
||||
*/
|
||||
|
||||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
#include <stddef.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include "defs.h"
|
||||
#include <libucontext/libucontext.h>
|
||||
|
||||
|
||||
extern void libucontext_trampoline(void);
|
||||
|
@ -55,5 +58,6 @@ libucontext_makecontext(libucontext_ucontext_t *ucp, void (*func)(void), int arg
|
|||
*sp++ = (libucontext_greg_t) ucp->uc_link;
|
||||
}
|
||||
|
||||
|
||||
#ifdef EXPORT_UNPREFIXED
|
||||
extern __typeof(libucontext_makecontext) makecontext __attribute__((weak, __alias__("libucontext_makecontext")));
|
||||
#endif
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
#include "defs.h"
|
||||
#include <libucontext/libucontext.h>
|
||||
#include "common-trampoline.c"
|
||||
|
|
|
@ -11,12 +11,15 @@
|
|||
* from the use of this software.
|
||||
*/
|
||||
|
||||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
#include "defs.h"
|
||||
#include <libucontext/libucontext.h>
|
||||
|
||||
|
||||
extern void libucontext_trampoline(void);
|
||||
|
@ -55,5 +58,6 @@ libucontext_makecontext(libucontext_ucontext_t *ucp, void (*func)(), int argc, .
|
|||
va_end(va);
|
||||
}
|
||||
|
||||
|
||||
#ifdef EXPORT_UNPREFIXED
|
||||
extern __typeof(libucontext_makecontext) makecontext __attribute__((weak, __alias__("libucontext_makecontext")));
|
||||
#endif
|
||||
|
|
|
@ -11,12 +11,15 @@
|
|||
* from the use of this software.
|
||||
*/
|
||||
|
||||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
#include "defs.h"
|
||||
#include <libucontext/libucontext.h>
|
||||
|
||||
|
||||
extern void libucontext_trampoline(void);
|
||||
|
@ -56,5 +59,6 @@ libucontext_makecontext(libucontext_ucontext_t *ucp, void (*func)(), int argc, .
|
|||
va_end(va);
|
||||
}
|
||||
|
||||
|
||||
#ifdef EXPORT_UNPREFIXED
|
||||
extern __typeof(libucontext_makecontext) makecontext __attribute__((weak, __alias__("libucontext_makecontext")));
|
||||
#endif
|
||||
|
|
|
@ -48,7 +48,7 @@
|
|||
#define PC_OFFSET REG_OFFSET(REG_PC)
|
||||
|
||||
#define FETCH_LINKPTR(dest) \
|
||||
asm("mv %0, s1" : "=rm" ((dest)))
|
||||
asm("mv %0, s1" : "=r" ((dest)))
|
||||
|
||||
#include "common-defs.h"
|
||||
|
||||
|
|
|
@ -10,13 +10,16 @@
|
|||
* from the use of this software.
|
||||
*/
|
||||
|
||||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
#include <stddef.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include "defs.h"
|
||||
#include <libucontext/libucontext.h>
|
||||
|
||||
|
||||
extern void libucontext_trampoline(void);
|
||||
|
@ -56,5 +59,6 @@ libucontext_makecontext(libucontext_ucontext_t *ucp, void (*func)(void), int arg
|
|||
va_end(va);
|
||||
}
|
||||
|
||||
|
||||
#ifdef EXPORT_UNPREFIXED
|
||||
extern __typeof(libucontext_makecontext) makecontext __attribute__((weak, __alias__("libucontext_makecontext")));
|
||||
#endif
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
#include "defs.h"
|
||||
#include <libucontext/libucontext.h>
|
||||
#include "common-trampoline.c"
|
||||
|
|
|
@ -10,7 +10,9 @@
|
|||
* from the use of this software.
|
||||
*/
|
||||
|
||||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
#include <stddef.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
|
@ -18,6 +20,7 @@
|
|||
|
||||
|
||||
#include "defs.h"
|
||||
#include <libucontext/libucontext.h>
|
||||
|
||||
|
||||
extern void libucontext_trampoline(void);
|
||||
|
@ -62,5 +65,6 @@ libucontext_makecontext(libucontext_ucontext_t *ucp, void (*func)(void), int arg
|
|||
ucp->uc_mcontext.gregs[15] = (uintptr_t) sp;
|
||||
}
|
||||
|
||||
|
||||
#ifdef EXPORT_UNPREFIXED
|
||||
extern __typeof(libucontext_makecontext) makecontext __attribute__((weak, __alias__("libucontext_makecontext")));
|
||||
#endif
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#define REG_MACL (21)
|
||||
|
||||
#define FETCH_LINKPTR(dest) \
|
||||
asm("mov r8, %0" : "=rm" (dest));
|
||||
asm("mov r8, %0" : "=r" (dest));
|
||||
|
||||
#include "common-defs.h"
|
||||
|
||||
|
|
|
@ -10,13 +10,16 @@
|
|||
* from the use of this software.
|
||||
*/
|
||||
|
||||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
#include <stddef.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include "defs.h"
|
||||
#include <libucontext/libucontext.h>
|
||||
|
||||
|
||||
extern void libucontext_trampoline(void);
|
||||
|
@ -53,5 +56,6 @@ libucontext_makecontext(libucontext_ucontext_t *ucp, void (*func)(void), int arg
|
|||
va_end(va);
|
||||
}
|
||||
|
||||
|
||||
#ifdef EXPORT_UNPREFIXED
|
||||
extern __typeof(libucontext_makecontext) makecontext __attribute__((weak, __alias__("libucontext_makecontext")));
|
||||
#endif
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
#include "defs.h"
|
||||
#include <libucontext/libucontext.h>
|
||||
#include "common-trampoline.c"
|
||||
|
|
|
@ -60,7 +60,7 @@
|
|||
#define MCONTEXT_GREGS (20)
|
||||
|
||||
#define FETCH_LINKPTR(dest) \
|
||||
asm("movl (%%esp, %%ebx, 4), %0" : "=rm" ((dest)));
|
||||
asm("movl (%%esp, %%ebx, 4), %0" : "=r" ((dest)));
|
||||
|
||||
#include "common-defs.h"
|
||||
|
||||
|
|
|
@ -11,12 +11,15 @@
|
|||
* from the use of this software.
|
||||
*/
|
||||
|
||||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
#include <stddef.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include "defs.h"
|
||||
#include <libucontext/libucontext.h>
|
||||
|
||||
|
||||
extern void libucontext_trampoline(void);
|
||||
|
@ -53,5 +56,6 @@ libucontext_makecontext(libucontext_ucontext_t *ucp, void (*func)(void), int arg
|
|||
*argp++ = (uintptr_t) ucp->uc_link;
|
||||
}
|
||||
|
||||
|
||||
#ifdef EXPORT_UNPREFIXED
|
||||
extern __typeof(libucontext_makecontext) makecontext __attribute__((weak, __alias__("libucontext_makecontext")));
|
||||
#endif
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
#include "defs.h"
|
||||
#include <libucontext/libucontext.h>
|
||||
#include "common-trampoline.c"
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
#define REG_SZ (8)
|
||||
|
||||
#define FETCH_LINKPTR(dest) \
|
||||
asm("movq (%%rbx), %0" : "=rm" ((dest)));
|
||||
asm("movq (%%rbx), %0" : "=r" ((dest)));
|
||||
|
||||
#include "common-defs.h"
|
||||
|
||||
|
|
|
@ -10,13 +10,16 @@
|
|||
* from the use of this software.
|
||||
*/
|
||||
|
||||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
#include <stddef.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "defs.h"
|
||||
#include <libucontext/libucontext.h>
|
||||
|
||||
extern void libucontext_trampoline(void);
|
||||
|
||||
|
@ -73,5 +76,6 @@ libucontext_makecontext(libucontext_ucontext_t *ucp, void (*func)(void), int arg
|
|||
va_end(va);
|
||||
}
|
||||
|
||||
|
||||
#ifdef EXPORT_UNPREFIXED
|
||||
extern __typeof(libucontext_makecontext) makecontext __attribute__((weak, __alias__("libucontext_makecontext")));
|
||||
#endif
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
#include "defs.h"
|
||||
#include <libucontext/libucontext.h>
|
||||
#include "common-trampoline.c"
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef LIBUCONTEXT_LIBUCONTEXT_H
|
||||
#define LIBUCONTEXT_LIBUCONTEXT_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <libucontext/bits.h>
|
||||
|
||||
int libucontext_getcontext(libucontext_ucontext_t *);
|
||||
|
|
|
@ -0,0 +1,175 @@
|
|||
project(
|
||||
'libucontext',
|
||||
'c',
|
||||
meson_version : '>=0.55.0',
|
||||
version : run_command('head', files('VERSION')).stdout()
|
||||
)
|
||||
|
||||
cpu = host_machine.cpu_family()
|
||||
if cpu == 'sh4'
|
||||
cpu = 'sh'
|
||||
endif
|
||||
|
||||
project_description = 'Portable implementation of ucontext'
|
||||
|
||||
project_headers = [
|
||||
'include/libucontext/libucontext.h'
|
||||
]
|
||||
|
||||
project_source_files = [
|
||||
'arch' / cpu / 'getcontext.S',
|
||||
'arch' / cpu / 'setcontext.S',
|
||||
'arch' / cpu / 'swapcontext.S',
|
||||
]
|
||||
if cpu in ['mips', 'mips64']
|
||||
project_source_files += [
|
||||
'arch' / cpu / 'makecontext.S'
|
||||
]
|
||||
else
|
||||
project_source_files += [
|
||||
'arch' / cpu / 'makecontext.c'
|
||||
]
|
||||
endif
|
||||
if cpu in ['ppc', 'ppc64']
|
||||
project_source_files += [
|
||||
'arch' / cpu / 'retfromsyscall.c'
|
||||
]
|
||||
endif
|
||||
if cpu not in ['mips', 'mips64', 'ppc', 'ppc64', 's390x']
|
||||
project_source_files += [
|
||||
'arch' / cpu / 'trampoline.c'
|
||||
]
|
||||
endif
|
||||
|
||||
project_includes = [
|
||||
'include',
|
||||
'arch/common'
|
||||
]
|
||||
|
||||
build_args = [
|
||||
'-std=gnu99',
|
||||
'-D_BSD_SOURCE',
|
||||
'-fPIC',
|
||||
'-DPIC'
|
||||
]
|
||||
|
||||
|
||||
# ===================================================================
|
||||
|
||||
# ======
|
||||
# Options
|
||||
# ======
|
||||
|
||||
freestanding = get_option('freestanding')
|
||||
export_unprefixed = get_option('export_unprefixed')
|
||||
build_posix = true
|
||||
|
||||
if freestanding
|
||||
build_args += '-DFREESTANDING'
|
||||
build_posix = false
|
||||
export_unprefixed = false
|
||||
project_headers += ['arch' / cpu / 'include/libucontext/bits.h']
|
||||
project_includes += ['arch' / cpu / 'include']
|
||||
else
|
||||
project_headers += ['arch/common/include/libucontext/bits.h']
|
||||
project_includes += ['arch/common/include']
|
||||
endif
|
||||
|
||||
if export_unprefixed
|
||||
build_args += '-DEXPORT_UNPREFIXED'
|
||||
endif
|
||||
|
||||
# ======
|
||||
# Target
|
||||
# ======
|
||||
|
||||
headers = include_directories(project_includes)
|
||||
is_subproject = meson.is_subproject()
|
||||
# Build only static library if subproject
|
||||
|
||||
libucontext_target = both_libraries(
|
||||
'ucontext',
|
||||
project_source_files,
|
||||
version: meson.project_version(),
|
||||
install : not is_subproject,
|
||||
c_args : build_args,
|
||||
include_directories : headers,
|
||||
)
|
||||
if is_subproject
|
||||
libucontext_target = libucontext_target.get_static_lib()
|
||||
endif
|
||||
libucontext_dep = declare_dependency(
|
||||
include_directories: headers,
|
||||
link_with : libucontext_target
|
||||
)
|
||||
|
||||
if build_posix
|
||||
libucontext_posix_target = both_libraries(
|
||||
'ucontext_posix',
|
||||
project_source_files + ['libucontext_posix.c'],
|
||||
version: meson.project_version(),
|
||||
install : not is_subproject,
|
||||
c_args : build_args,
|
||||
include_directories : headers,
|
||||
)
|
||||
if is_subproject
|
||||
libucontext_posix_target = libucontext_posix_target.get_static_lib()
|
||||
endif
|
||||
libucontext_posix_dep = declare_dependency(
|
||||
include_directories: headers,
|
||||
link_with : libucontext_posix_target
|
||||
)
|
||||
endif
|
||||
|
||||
# =======
|
||||
# Project
|
||||
# =======
|
||||
|
||||
if not is_subproject
|
||||
# Make this library usable from the system's
|
||||
# package manager.
|
||||
install_headers(project_headers, subdir : meson.project_name())
|
||||
|
||||
pkg_mod = import('pkgconfig')
|
||||
pkg_mod.generate(
|
||||
name : meson.project_name(),
|
||||
filebase : meson.project_name(),
|
||||
description : project_description,
|
||||
subdirs : meson.project_name(),
|
||||
libraries : libucontext_target,
|
||||
)
|
||||
endif
|
||||
|
||||
# ====
|
||||
# Docs
|
||||
# ====
|
||||
|
||||
# TODO: meson.build for docs
|
||||
if not is_subproject
|
||||
#subdir('docs')
|
||||
endif
|
||||
|
||||
# ==========
|
||||
# Unit Tests
|
||||
# ==========
|
||||
|
||||
if not is_subproject
|
||||
test('test_libucontext',
|
||||
executable(
|
||||
'test_libucontext',
|
||||
files('test_libucontext.c'),
|
||||
dependencies : libucontext_dep,
|
||||
install : false
|
||||
)
|
||||
)
|
||||
if build_posix
|
||||
test('test_libucontext_posix',
|
||||
executable(
|
||||
'test_libucontext_posix',
|
||||
files('test_libucontext_posix.c'),
|
||||
dependencies : libucontext_posix_dep,
|
||||
install : false
|
||||
)
|
||||
)
|
||||
endif
|
||||
endif
|
|
@ -0,0 +1,4 @@
|
|||
option('freestanding', type : 'boolean', value : false,
|
||||
description: 'Do not use system headers')
|
||||
option('export_unprefixed', type : 'boolean', value : true,
|
||||
description: 'Export POSIX 2004 ucontext names as alises')
|
Loading…
Reference in New Issue
What happens if we pass a pointer as a stack argument to makecontext then?
Wouldn’t be allowed according to the man pages https://man7.org/linux/man-pages/man3/makecontext.3.html
The NetBSD and glibc implementations also do not narrow the arguments like this code is doing. The macOS implementation also does not appear to do so. What problem are you trying to solve here?
Well you need to choose some size or the stack layout won’t work. The old code doesn’t work because it assumed every register is 4 bytes so I bumped the register arguments to 8 bytes and kept the stack arguments at 4 bytes. You can make everything 8 bytes as I originally tried but then I read the man pages and realized it expects ‘int’ which is 4 bytes for all arguments.
To clarify I didn’t “narrow” any arguments. I widened it for the register arguments. unsigned long is 4 bytes on arm and arm64.
Yeah, I was misreading what the patch did. This is fine.
Wait what?
On my
aarch64
machine,unsigned long
is definitely 8 bytes:Apple says
unsigned long
is 8 bytes on Darwin ARM64 too. https://developer.apple.com/documentation/xcode/writing_arm64_code_for_apple_platformsIt seems to me that having it any other way would break alignment assumptions made by aarch64 CPUs? So I'm back to being confused about the two ARM-specific patches.