libthread: use libc functions in ucontext for macOS (#417)
This commit is contained in:
parent
c3d31baca0
commit
329831171d
3 changed files with 3 additions and 81 deletions
|
|
@ -1,44 +0,0 @@
|
||||||
.text
|
|
||||||
.align 8
|
|
||||||
|
|
||||||
.globl _libthread_getmcontext
|
|
||||||
_libthread_getmcontext:
|
|
||||||
movq $1, 0*8(%rdi) // rax
|
|
||||||
movq %rbx, 1*8(%rdi)
|
|
||||||
movq %rcx, 2*8(%rdi)
|
|
||||||
movq %rdx, 3*8(%rdi)
|
|
||||||
movq %rsi, 4*8(%rdi)
|
|
||||||
movq %rdi, 5*8(%rdi)
|
|
||||||
movq %rbp, 6*8(%rdi)
|
|
||||||
movq %rsp, 7*8(%rdi)
|
|
||||||
movq %r8, 8*8(%rdi)
|
|
||||||
movq %r9, 9*8(%rdi)
|
|
||||||
movq %r10, 10*8(%rdi)
|
|
||||||
movq %r11, 11*8(%rdi)
|
|
||||||
movq %r12, 12*8(%rdi)
|
|
||||||
movq %r13, 13*8(%rdi)
|
|
||||||
movq %r14, 14*8(%rdi)
|
|
||||||
movq %r15, 15*8(%rdi)
|
|
||||||
movq $0, %rax
|
|
||||||
ret
|
|
||||||
|
|
||||||
.globl _libthread_setmcontext
|
|
||||||
_libthread_setmcontext:
|
|
||||||
movq 0*8(%rdi), %rax
|
|
||||||
movq 1*8(%rdi), %rbx
|
|
||||||
movq 2*8(%rdi), %rcx
|
|
||||||
movq 3*8(%rdi), %rdx
|
|
||||||
movq 4*8(%rdi), %rsi
|
|
||||||
// %rdi later
|
|
||||||
movq 6*8(%rdi), %rbp
|
|
||||||
movq 7*8(%rdi), %rsp
|
|
||||||
movq 8*8(%rdi), %r8
|
|
||||||
movq 9*8(%rdi), %r9
|
|
||||||
movq 10*8(%rdi), %r10
|
|
||||||
movq 11*8(%rdi), %r11
|
|
||||||
movq 12*8(%rdi), %r12
|
|
||||||
movq 13*8(%rdi), %r13
|
|
||||||
movq 14*8(%rdi), %r14
|
|
||||||
movq 15*8(%rdi), %r15
|
|
||||||
movq 5*8(%rdi), %rdi
|
|
||||||
ret
|
|
||||||
|
|
@ -15,14 +15,14 @@ esac
|
||||||
|
|
||||||
# Various libc don't supply swapcontext, makecontext, so we do.
|
# Various libc don't supply swapcontext, makecontext, so we do.
|
||||||
case "$SYSNAME-$OBJTYPE" in
|
case "$SYSNAME-$OBJTYPE" in
|
||||||
Darwin-x86_64 | Linux-arm | Linux-sparc64 | NetBSD-arm | OpenBSD-386 | OpenBSD-power | OpenBSD-x86_64)
|
Linux-arm | Linux-sparc64 | NetBSD-arm | OpenBSD-386 | OpenBSD-power | OpenBSD-x86_64)
|
||||||
echo $OBJTYPE-ucontext.o
|
echo $OBJTYPE-ucontext.o
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# A few libc don't supply setcontext, getcontext, so we do.
|
# A few libc don't supply setcontext, getcontext, so we do.
|
||||||
case "$SYSNAME-$OBJTYPE" in
|
case "$SYSNAME-$OBJTYPE" in
|
||||||
Darwin-x86_64 | Linux-arm | Linux-sparc64 | OpenBSD-386 | OpenBSD-power | OpenBSD-x86_64)
|
Linux-arm | Linux-sparc64 | OpenBSD-386 | OpenBSD-power | OpenBSD-x86_64)
|
||||||
echo $SYSNAME-$OBJTYPE-asm.o
|
echo $SYSNAME-$OBJTYPE-asm.o
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
|
||||||
|
|
@ -15,31 +15,6 @@
|
||||||
#include "libc.h"
|
#include "libc.h"
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
|
|
||||||
#if defined(__APPLE__)
|
|
||||||
/*
|
|
||||||
* OS X before 10.5 (Leopard) does not provide
|
|
||||||
* swapcontext nor makecontext, so we have to use our own.
|
|
||||||
* In theory, Leopard does provide them, but when we use
|
|
||||||
* them, they seg fault. Maybe we're using them wrong.
|
|
||||||
* So just use our own versions, even on Leopard.
|
|
||||||
*/
|
|
||||||
# define mcontext libthread_mcontext
|
|
||||||
# define mcontext_t libthread_mcontext_t
|
|
||||||
# define ucontext libthread_ucontext
|
|
||||||
# define ucontext_t libthread_ucontext_t
|
|
||||||
# define swapcontext libthread_swapcontext
|
|
||||||
# define makecontext libthread_makecontext
|
|
||||||
# if defined(__i386__)
|
|
||||||
# include "386-ucontext.h"
|
|
||||||
# elif defined(__x86_64__)
|
|
||||||
# include "x86_64-ucontext.h"
|
|
||||||
# elif defined(__ppc__) || defined(__power__)
|
|
||||||
# include "power-ucontext.h"
|
|
||||||
# else
|
|
||||||
# error "unknown architecture"
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(__OpenBSD__)
|
#if defined(__OpenBSD__)
|
||||||
# define mcontext libthread_mcontext
|
# define mcontext libthread_mcontext
|
||||||
# define mcontext_t libthread_mcontext_t
|
# define mcontext_t libthread_mcontext_t
|
||||||
|
|
@ -82,15 +57,6 @@ enum
|
||||||
struct Context
|
struct Context
|
||||||
{
|
{
|
||||||
ucontext_t uc;
|
ucontext_t uc;
|
||||||
#ifdef __APPLE__
|
|
||||||
/*
|
|
||||||
* On Snow Leopard, etc., the context routines exist,
|
|
||||||
* so we use them, but apparently they write past the
|
|
||||||
* end of the ucontext_t. Sigh. We put some extra
|
|
||||||
* scratch space here for them.
|
|
||||||
*/
|
|
||||||
uchar buf[1024];
|
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Execjob
|
struct Execjob
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue