Implement handling of traps under macOS.
authorChris Hanson <org/chris-hanson/cph>
Mon, 19 Nov 2018 05:01:47 +0000 (21:01 -0800)
committerChris Hanson <org/chris-hanson/cph>
Mon, 19 Nov 2018 05:01:47 +0000 (21:01 -0800)
src/microcode/uxsig.c
src/microcode/uxtrap.h

index 0b899ffb334837d7c0e9bae7ec18d32bb529074c..2d4be9dfbab42702eb702f9eb87d006a8025d112 100644 (file)
@@ -56,10 +56,6 @@ extern void UX_reinitialize_tty (void);
 #  endif
 #endif
 
-#ifndef __APPLE__
-#  define HAVE_SIGFPE
-#endif
-
 static Tsignal_handler
 current_handler (int signo)
 {
@@ -340,9 +336,7 @@ initialize_signal_descriptors (void)
   defsignal (SIGTRAP, "SIGTRAP",       dfl_terminate,  CORE_DUMP);
   defsignal (SIGIOT, "SIGIOT",         dfl_terminate,  CORE_DUMP);
   defsignal (SIGEMT, "SIGEMT",         dfl_terminate,  CORE_DUMP);
-#ifdef HAVE_SIGFPE
   defsignal (SIGFPE, "SIGFPE",         dfl_terminate,  CORE_DUMP);
-#endif
   defsignal (SIGKILL, "SIGKILL",       dfl_terminate,  (NOIGNORE | NOBLOCK | NOCATCH));
   defsignal (SIGBUS, "SIGBUS",         dfl_terminate,  CORE_DUMP);
   defsignal (SIGSEGV, "SIGSEGV",       dfl_terminate,  CORE_DUMP);
@@ -553,7 +547,6 @@ DEFUN_STD_HANDLER (sighnd_terminate,
     ? (find_signal_name (signo))
     : 0)))
 \f
-#ifdef HAVE_SIGFPE
 extern void clear_float_exceptions (void);
 
 static
@@ -562,7 +555,6 @@ DEFUN_STD_HANDLER (sighnd_fpe,
   clear_float_exceptions ();
   trap_handler ("floating-point exception", signo, info, scp);
 })
-#endif
 
 static
 DEFUN_STD_HANDLER (sighnd_hardware_trap,
@@ -676,9 +668,7 @@ UX_initialize_signals (void)
   initialize_signal_descriptors ();
   initialize_signal_debugging ();
   bind_handler (SIGINT,                sighnd_control_g);
-#ifdef HAVE_SIGFPE
   bind_handler (SIGFPE,                sighnd_fpe);
-#endif
   bind_handler (SIGALRM,       sighnd_timer);
   bind_handler (SIGVTALRM,     sighnd_timer);
   bind_handler (SIGTERM,       sighnd_control_g);
index 970561912d6e685174f74351980d250b7d3c78b0..190a1a07401744d458be2b7c0a90d1dedb33928e 100644 (file)
@@ -735,8 +735,78 @@ typedef struct
 #endif /* __NetBSD_Version__ >= 200000000 */
 #endif /* __NetBSD__ */
 \f
-#ifdef _POSIX_REALTIME_SIGNALS
-#  define HAVE_SIGACTION_SIGINFO_SIGNALS
+#ifdef __APPLE__
+
+#  ifdef __IA32__
+#    define HAVE_SIGCONTEXT
+#    define SIGCONTEXT_FIRST_REG(scp) (& ((scp) -> uc_mcontext -> __ss))
+#    define SIGCONTEXT_NREGS                                           \
+  (((sizeof (_STRUCT_X86_THREAD_STATE32)) + (SIZEOF_UNSIGNED_LONG - 1))        \
+   / SIZEOF_UNSIGNED_LONG)
+#    define SIGCONTEXT_SP(scp) (((scp) -> uc_mcontext -> __ss) . __esp)
+#    define SIGCONTEXT_PC(scp) (((scp) -> uc_mcontext -> __ss) . __eip)
+#    define SIGCONTEXT_RFREE(scp) (((scp) -> uc_mcontext -> __ss) . __edi)
+#  endif /* __IA32__ */
+
+#  ifdef __x86_64__
+#    define HAVE_SIGCONTEXT
+#    define SIGCONTEXT_FIRST_REG(scp) (& ((scp) -> uc_mcontext -> __ss))
+#    define SIGCONTEXT_NREGS                                           \
+  (((sizeof (_STRUCT_X86_THREAD_STATE64)) + (SIZEOF_UNSIGNED_LONG - 1))        \
+   / SIZEOF_UNSIGNED_LONG)
+#    define SIGCONTEXT_SP(scp) (((scp) -> uc_mcontext -> __ss) . __rsp)
+#    define SIGCONTEXT_PC(scp) (((scp) -> uc_mcontext -> __ss) . __rip)
+#    define SIGCONTEXT_RFREE(scp) (((scp) -> uc_mcontext -> __ss) . __rdi)
+#  endif /* __x86_64__ */
+
+#  define INITIALIZE_UX_SIGNAL_CODES() do                              \
+{                                                                      \
+  DECLARE_UX_SIGNAL_CODE                                               \
+    (SIGILL, (~0L), ILL_ILLOPC, "Illegal opcode");                     \
+  DECLARE_UX_SIGNAL_CODE                                               \
+    (SIGILL, (~0L), ILL_ILLTRP, "Illegal trap");                       \
+  DECLARE_UX_SIGNAL_CODE                                               \
+    (SIGILL, (~0L), ILL_PRVOPC, "Privileged opcode");                  \
+  DECLARE_UX_SIGNAL_CODE                                               \
+    (SIGILL, (~0L), ILL_COPROC, "Coprocessor error");                  \
+  DECLARE_UX_SIGNAL_CODE                                               \
+    (SIGILL, (~0L), ILL_BADSTK, "Internal stack error");               \
+  DECLARE_UX_SIGNAL_CODE                                               \
+    (SIGFPE, (~0L), FPE_FLTDIV, "Floating-point divide by zero");      \
+  DECLARE_UX_SIGNAL_CODE                                               \
+    (SIGFPE, (~0L), FPE_FLTOVF, "Floating-point overflow");            \
+  DECLARE_UX_SIGNAL_CODE                                               \
+    (SIGFPE, (~0L), FPE_FLTUND, "Floating-point underflow");           \
+  DECLARE_UX_SIGNAL_CODE                                               \
+    (SIGFPE, (~0L), FPE_FLTRES, "Floating-point inexact result");      \
+  DECLARE_UX_SIGNAL_CODE                                               \
+    (SIGFPE, (~0L), FPE_FLTINV, "Invalid floating-point operation");   \
+  DECLARE_UX_SIGNAL_CODE                                               \
+    (SIGFPE, (~0L), FPE_FLTSUB, "Subscript out of range");             \
+  DECLARE_UX_SIGNAL_CODE                                               \
+    (SIGFPE, (~0L), FPE_INTDIV, "Integer divide by zero");             \
+  DECLARE_UX_SIGNAL_CODE                                               \
+    (SIGFPE, (~0L), FPE_INTOVF, "Integer overflow");                   \
+  DECLARE_UX_SIGNAL_CODE                                               \
+    (SIGSEGV, (~0L), SEGV_MAPERR, "Address not mapped to object");     \
+  DECLARE_UX_SIGNAL_CODE                                               \
+    (SIGSEGV, (~0L), SEGV_ACCERR, "Invalid permissions for mapped object"); \
+  DECLARE_UX_SIGNAL_CODE                                               \
+    (SIGBUS, (~0L), BUS_ADRALN, "Invalid address alignment");          \
+  DECLARE_UX_SIGNAL_CODE                                               \
+    (SIGBUS, (~0L), BUS_ADRERR, "Nonexistent physical address");       \
+  DECLARE_UX_SIGNAL_CODE                                               \
+    (SIGBUS, (~0L), BUS_OBJERR, "Object-specific hardware error");     \
+  DECLARE_UX_SIGNAL_CODE                                               \
+    (SIGTRAP, (~0L), TRAP_BRKPT, "Process breakpoint");                        \
+  DECLARE_UX_SIGNAL_CODE                                               \
+    (SIGTRAP, (~0L), TRAP_TRACE, "Process trace trap");                        \
+} while (0)
+
+#endif /* __APPLE__ */
+\f
+#if !(defined (HAVE_SIGACTION_SIGINFO_SIGNALS)) && (defined (_POSIX_REALTIME_SIGNALS))
+#  define HAVE_SIGACTION_SIGINFO_SIGNALS 1
 #endif
 
 #ifdef HAVE_SIGACTION_SIGINFO_SIGNALS