From d12381cb95f0a4a7bc07c1cef4141ad413260741 Mon Sep 17 00:00:00 2001 From: "R. Matthew Emerson" Date: Fri, 23 Nov 2018 15:39:00 -0800 Subject: [PATCH] Bring back the DarwinSigReturn hack for pre-Mojave systems --- lisp-kernel/platform-darwinx8632.h | 13 ++++++++++++- lisp-kernel/platform-darwinx8664.h | 14 +++++++++++--- lisp-kernel/pmcl-kernel.c | 2 +- lisp-kernel/x86-asmutils32.s | 8 ++++++++ lisp-kernel/x86-asmutils64.s | 11 ++++++++++- 5 files changed, 42 insertions(+), 6 deletions(-) diff --git a/lisp-kernel/platform-darwinx8632.h b/lisp-kernel/platform-darwinx8632.h index 9282f3207..abd03f85b 100644 --- a/lisp-kernel/platform-darwinx8632.h +++ b/lisp-kernel/platform-darwinx8632.h @@ -49,6 +49,17 @@ typedef ucontext_t ExceptionInformation; /* xp accessors, sigreturn stuff */ #define DARWIN_USE_PSEUDO_SIGRETURN 1 +extern void darwin_sigreturn(ExceptionInformation *, unsigned); +extern natural os_major_version; + +#define DarwinSigReturn(context) do { \ + if (os_major_version < 18) { /* Mojave */ \ + darwin_sigreturn(context, 0x1e); \ + Bug(context,"sigreturn returned"); \ + } \ +} while (0) + + #define xpGPRvector(x) ((natural *)(&(UC_MCONTEXT(x)->__ss))) #define xpGPR(x,gprno) (xpGPRvector(x)[gprno]) #define set_xpGPR(x,gpr,new) xpGPR((x),(gpr)) = (natural)(new) @@ -62,7 +73,7 @@ typedef ucontext_t ExceptionInformation; #define SIGNUM_FOR_INTN_TRAP SIGSEGV /* Not really, but our Mach handler fakes that */ #define IS_MAYBE_INT_TRAP(info,xp) ((UC_MCONTEXT(xp)->__es.__trapno == 0xd) && (((UC_MCONTEXT(xp)->__es.__err)&7)==2)) #define IS_PAGE_FAULT(info,xp) (UC_MCONTEXT(xp)->__es.__trapno == 0xe) -#define SIGRETURN(context) +#define SIGRETURN(context) DarwinSigReturn(context) #include #include diff --git a/lisp-kernel/platform-darwinx8664.h b/lisp-kernel/platform-darwinx8664.h index eb877d1fb..825ce739c 100644 --- a/lisp-kernel/platform-darwinx8664.h +++ b/lisp-kernel/platform-darwinx8664.h @@ -53,11 +53,19 @@ typedef ucontext_t ExceptionInformation; #define REG_RIP 16 #define REG_RFL 17 -extern void darwin_sigreturn(ExceptionInformation *,unsigned); - /* xp accessors, sigreturn stuff */ #define DARWIN_USE_PSEUDO_SIGRETURN 1 +extern void darwin_sigreturn(ExceptionInformation *, unsigned); +extern natural os_major_version; + +#define DarwinSigReturn(context) do { \ + if (os_major_version < 18) { /* Mojave */ \ + darwin_sigreturn(context, 0x1e); \ + Bug(context,"sigreturn returned"); \ + } \ +} while (0) + #define xpGPRvector(x) ((natural *)(&(UC_MCONTEXT(x)->__ss))) #define xpGPR(x,gprno) (xpGPRvector(x)[gprno]) #define set_xpGPR(x,gpr,new) xpGPR((x),(gpr)) = (natural)(new) @@ -71,7 +79,7 @@ extern void darwin_sigreturn(ExceptionInformation *,unsigned); #define SIGNUM_FOR_INTN_TRAP SIGSEGV /* Not really, but our Mach handler fakes that */ #define IS_MAYBE_INT_TRAP(info,xp) ((UC_MCONTEXT(xp)->__es.__trapno == 0xd) && (((UC_MCONTEXT(xp)->__es.__err)&7)==2)) #define IS_PAGE_FAULT(info,xp) (UC_MCONTEXT(xp)->__es.__trapno == 0xe) -#define SIGRETURN(context) +#define SIGRETURN(context) DarwinSigReturn(context) #include #include diff --git a/lisp-kernel/pmcl-kernel.c b/lisp-kernel/pmcl-kernel.c index 45a009153..ee54203a7 100644 --- a/lisp-kernel/pmcl-kernel.c +++ b/lisp-kernel/pmcl-kernel.c @@ -1455,7 +1455,7 @@ terminate_lisp() #endif #ifdef DARWIN -#define min_os_version "8.0" /* aka Tiger */ +#define min_os_version "13.0" /* Mavericks */ #endif #ifdef LINUX #ifdef PPC diff --git a/lisp-kernel/x86-asmutils32.s b/lisp-kernel/x86-asmutils32.s index 04f5c6961..9f6abb7e2 100644 --- a/lisp-kernel/x86-asmutils32.s +++ b/lisp-kernel/x86-asmutils32.s @@ -179,6 +179,14 @@ _exportfn(C(freebsd_sigreturn)) _endfn __endif + __ifdef(`DARWIN') + _exportfn(C(darwin_sigreturn)) + __(movl $0xb8,%eax) /* SYS_sigreturn */ + __(int $0x80) + __(ret) /* shouldn't return */ + _endfn + __endif + _exportfn(C(get_vector_registers)) __(ret) _endfn diff --git a/lisp-kernel/x86-asmutils64.s b/lisp-kernel/x86-asmutils64.s index 6ba713482..1d4653c65 100644 --- a/lisp-kernel/x86-asmutils64.s +++ b/lisp-kernel/x86-asmutils64.s @@ -183,7 +183,16 @@ _endfn _exportfn(C(put_vector_registers)) _endfn - + + __ifdef(`DARWIN') +_exportfn(C(darwin_sigreturn)) + .globl C(sigreturn) + __(movl $0x20000b8,%eax) + __(syscall) + __(ret) +_endfn + __endif + __ifdef(`WIN_64') /* %rcx = CONTEXT, %rdx = tcr, %r8 = old_valence. This pretty much has to be uninterruptible */