diff options
Diffstat (limited to 'asmrun/signals_osdep.h')
-rw-r--r-- | asmrun/signals_osdep.h | 134 |
1 files changed, 39 insertions, 95 deletions
diff --git a/asmrun/signals_osdep.h b/asmrun/signals_osdep.h index f34863b39b..ceefc7161f 100644 --- a/asmrun/signals_osdep.h +++ b/asmrun/signals_osdep.h @@ -87,9 +87,16 @@ sigact.sa_flags = SA_SIGINFO #include <sys/ucontext.h> + #include <AvailabilityMacros.h> - #define CONTEXT_STATE (((struct ucontext *)context)->uc_mcontext->ss) - #define CONTEXT_PC (CONTEXT_STATE.eip) +#if !defined(MAC_OS_X_VERSION_10_5) || MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5 + #define CONTEXT_REG(r) r + #else + #define CONTEXT_REG(r) __##r + #endif + + #define CONTEXT_STATE (((ucontext_t *)context)->uc_mcontext->CONTEXT_REG(ss)) + #define CONTEXT_PC (CONTEXT_STATE.CONTEXT_REG(eip)) #define CONTEXT_FAULTING_ADDRESS ((char *) info->si_addr) /****************** MIPS, all OS */ @@ -113,106 +120,43 @@ #elif defined(TARGET_power) && defined(SYS_rhapsody) -#ifdef __ppc64__ - #define DECLARE_SIGNAL_HANDLER(name) \ static void name(int sig, siginfo_t * info, void * context) - #define SET_SIGACT(sigact,name) \ - sigact.sa_sigaction = (name); \ - sigact.sa_flags = SA_SIGINFO | SA_64REGSET - - typedef unsigned long long context_reg; - #include <sys/ucontext.h> - - #define CONTEXT_STATE (((struct ucontext64 *)context)->uc_mcontext64->ss) - - #define CONTEXT_PC (CONTEXT_STATE.srr0) - #define CONTEXT_EXCEPTION_POINTER (CONTEXT_STATE.r29) - #define CONTEXT_YOUNG_LIMIT (CONTEXT_STATE.r30) - #define CONTEXT_YOUNG_PTR (CONTEXT_STATE.r31) - #define CONTEXT_FAULTING_ADDRESS ((char *) info->si_addr) - #define CONTEXT_SP (CONTEXT_STATE.r1) - -#else - - #include <sys/utsname.h> - - #define DECLARE_SIGNAL_HANDLER(name) \ - static void name(int sig, siginfo_t * info, void * context) - - #define SET_SIGACT(sigact,name) \ - sigact.sa_handler = (void (*)(int)) (name); \ - sigact.sa_flags = SA_SIGINFO - - typedef unsigned long context_reg; - - #define CONTEXT_PC (*context_gpr_p(context, -2)) - #define CONTEXT_EXCEPTION_POINTER (*context_gpr_p(context, 29)) - #define CONTEXT_YOUNG_LIMIT (*context_gpr_p(context, 30)) - #define CONTEXT_YOUNG_PTR (*context_gpr_p(context, 31)) - #define CONTEXT_FAULTING_ADDRESS ((char *) info->si_addr) - #define CONTEXT_SP (*context_gpr_p(context, 1)) - - static int ctx_version = 0; - static void init_ctx (void) - { - struct utsname name; - if (uname (&name) == 0){ - if (name.release[1] == '.' && name.release[0] <= '5'){ - ctx_version = 1; - }else{ - ctx_version = 2; - } - }else{ - caml_fatal_error ("cannot determine SIGCONTEXT format"); - } - } - - #ifdef DARWIN_VERSION_6 - #include <sys/ucontext.h> - static unsigned long *context_gpr_p (void *ctx, int regno) - { - unsigned long *regs; - if (ctx_version == 0) init_ctx (); - if (ctx_version == 1){ - /* old-style context (10.0 and 10.1) */ - regs = (unsigned long *)(((struct sigcontext *)ctx)->sc_regs); - }else{ - Assert (ctx_version == 2); - /* new-style context (10.2) */ - regs = (unsigned long *)&(((struct ucontext *)ctx)->uc_mcontext->ss); - } - return &(regs[2 + regno]); - } + #include <AvailabilityMacros.h> + + #ifdef __LP64__ + #define SET_SIGACT(sigact,name) \ + sigact.sa_sigaction = (name); \ + sigact.sa_flags = SA_SIGINFO | SA_64REGSET + + typedef unsigned long long context_reg; + + #define CONTEXT_MCONTEXT (((ucontext64_t *)context)->uc_mcontext64) #else - #define SA_SIGINFO 0x0040 - struct ucontext { - int uc_onstack; - sigset_t uc_sigmask; - struct sigaltstack uc_stack; - struct ucontext *uc_link; - size_t uc_mcsize; - unsigned long *uc_mcontext; - }; - static unsigned long *context_gpr_p (void *ctx, int regno) - { - unsigned long *regs; - if (ctx_version == 0) init_ctx (); - if (ctx_version == 1){ - /* old-style context (10.0 and 10.1) */ - regs = (unsigned long *)(((struct sigcontext *)ctx)->sc_regs); - }else{ - Assert (ctx_version == 2); - /* new-style context (10.2) */ - regs = (unsigned long *)((struct ucontext *)ctx)->uc_mcontext + 8; - } - return &(regs[2 + regno]); - } + #define SET_SIGACT(sigact,name) \ + sigact.sa_sigaction = (name); \ + sigact.sa_flags = SA_SIGINFO + + typedef unsigned long context_reg; + + #define CONTEXT_MCONTEXT (((ucontext_t *)context)->uc_mcontext) + #endif + +#if !defined(MAC_OS_X_VERSION_10_5) || MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5 + #define CONTEXT_REG(r) r + #else + #define CONTEXT_REG(r) __##r #endif -#endif + #define CONTEXT_STATE (CONTEXT_MCONTEXT->CONTEXT_REG(ss)) + #define CONTEXT_PC (CONTEXT_STATE.CONTEXT_REG(srr0)) + #define CONTEXT_EXCEPTION_POINTER (CONTEXT_STATE.CONTEXT_REG(r29)) + #define CONTEXT_YOUNG_LIMIT (CONTEXT_STATE.CONTEXT_REG(r30)) + #define CONTEXT_YOUNG_PTR (CONTEXT_STATE.CONTEXT_REG(r31)) + #define CONTEXT_SP (CONTEXT_STATE.CONTEXT_REG(r1)) + #define CONTEXT_FAULTING_ADDRESS ((char *) info->si_addr) /****************** PowerPC, ELF (Linux) */ |