From 726fe05c132b60e2927c880a9df571fd629fe904 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Sun, 3 Aug 2014 19:12:47 +0200 Subject: [PATCH] use portable ucontext on linux/amd64 --- asm.S | 6 ++++++ context.c | 5 +++++ taskimpl.h | 23 +++++++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/asm.S b/asm.S index e120f1e..205b0b8 100644 --- a/asm.S +++ b/asm.S @@ -28,6 +28,12 @@ #endif #endif +#if defined(__linux__) && defined(__amd64__) +#define NEEDAMD64CONTEXT 1 +#define SET setmcontext +#define GET getmcontext +#endif + #if defined(__linux__) && defined(__arm__) #define NEEDARMCONTEXT 1 #define SET setmcontext diff --git a/context.c b/context.c index db338d4..e975014 100644 --- a/context.c +++ b/context.c @@ -25,6 +25,11 @@ #define NEEDSWAPCONTEXT #endif +#if defined(__linux__) && defined(__amd64__) +#define NEEDSWAPCONTEXT +#define NEEDAMD64MAKECONTEXT +#endif + #if defined(__linux__) && defined(__arm__) #define NEEDSWAPCONTEXT #define NEEDARMMAKECONTEXT diff --git a/taskimpl.h b/taskimpl.h index 08a971b..e54f9e7 100644 --- a/taskimpl.h +++ b/taskimpl.h @@ -18,6 +18,13 @@ #define USE_UCONTEXT 0 #endif +#if defined(__linux__) && defined(__amd64__) +#define _UCONTEXT_H 1 +#define _SYS_UCONTEXT_H 1 +#undef USE_UCONTEXT +#define USE_UCONTEXT 0 +#endif + #if defined(__APPLE__) #include #if defined(MAC_OS_X_VERSION_10_5) @@ -97,6 +104,22 @@ extern int swapcontext(ucontext_t*, const ucontext_t*); extern void makecontext(ucontext_t*, void(*)(), int, ...); #endif +#if defined(__linux__) && defined(__amd64__) +typedef struct mcontext mcontext_t; +typedef struct ucontext ucontext_t; +extern int getmcontext(mcontext_t*); +extern void setmcontext(const mcontext_t*); +#define setcontext(u) setmcontext(&(u)->uc_mcontext) +#define getcontext(u) getmcontext(&(u)->uc_mcontext) +extern int swapcontext(ucontext_t*, const ucontext_t*); +extern void makecontext(ucontext_t*, void(*)(), int, ...); +# if defined(__i386__) +# include "386-ucontext.h" +# elif defined(__x86_64__) +# include "amd64-ucontext.h" +# endif +#endif + #if defined(__APPLE__) # define mcontext libthread_mcontext # define mcontext_t libthread_mcontext_t