From: Chris Hanson Date: Mon, 27 Jun 2005 06:03:43 +0000 (+0000) Subject: Another clarification of SIGCONTEXT stuff, this time to incorporate X-Git-Tag: 20090517-FFI~1267 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=fd5976a2a1c0ad132c4d128f239a80e8b2940374;p=mit-scheme.git Another clarification of SIGCONTEXT stuff, this time to incorporate standardized context information from _POSIX_REALTIME_SIGNALS. --- diff --git a/v7/src/microcode/ux.h b/v7/src/microcode/ux.h index e552f88f9..cc83ff4e0 100644 --- a/v7/src/microcode/ux.h +++ b/v7/src/microcode/ux.h @@ -1,9 +1,10 @@ /* -*-C-*- -$Id: ux.h,v 1.77 2003/05/17 02:21:22 cph Exp $ +$Id: ux.h,v 1.78 2005/06/27 06:03:10 cph Exp $ Copyright 1990,1991,1992,1993,1994,1995 Massachusetts Institute of Technology Copyright 1996,1997,1998,1999,2000,2003 Massachusetts Institute of Technology +Copyright 2005 Massachusetts Institute of Technology This file is part of MIT/GNU Scheme. @@ -270,7 +271,12 @@ USA. #include "syscall.h" typedef RETSIGTYPE Tsignal_handler_result; -typedef RETSIGTYPE (*Tsignal_handler) (); + +#ifdef _POSIX_REALTIME_SIGNALS + typedef void (*Tsignal_handler) (int, siginfo_t *, void *); +#else + typedef RETSIGTYPE EXFUN ((*Tsignal_handler), (int)); +#endif #ifdef VOID_SIGNAL_HANDLERS # define SIGNAL_HANDLER_RETURN() return diff --git a/v7/src/microcode/uxsig.c b/v7/src/microcode/uxsig.c index 3127eadeb..52f39da9d 100644 --- a/v7/src/microcode/uxsig.c +++ b/v7/src/microcode/uxsig.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Id: uxsig.c,v 1.40 2005/06/26 04:34:48 cph Exp $ +$Id: uxsig.c,v 1.41 2005/06/27 06:03:21 cph Exp $ Copyright 1990,1991,1992,1993,1994,1996 Massachusetts Institute of Technology Copyright 2000,2001,2005 Massachusetts Institute of Technology @@ -45,28 +45,42 @@ extern void EXFUN (tty_set_next_interrupt_char, (cc_t c)); #ifdef HAVE_POSIX_SIGNALS +#ifdef _POSIX_REALTIME_SIGNALS +# define SIGACT_HANDLER(act) ((act) -> sa_sigaction) +#else +# define SIGACT_HANDLER(act) ((act) -> sa_handler) +# ifndef SA_SIGINFO +# define SA_SIGINFO 0 +# endif +#endif + static Tsignal_handler DEFUN (current_handler, (signo), int signo) { struct sigaction act; UX_sigaction (signo, 0, (&act)); - return (act . sa_handler); + return (SIGACT_HANDLER (&act)); } -#ifndef SA_SIGINFO -#define SA_SIGINFO 0 -#endif - void DEFUN (INSTALL_HANDLER, (signo, handler), int signo AND Tsignal_handler handler) { struct sigaction act; - (act . sa_handler) = handler; + if ((handler == ((Tsignal_handler) SIG_IGN)) + || (handler == ((Tsignal_handler) SIG_DFL))) + { + (act . sa_handler) = ((PTR) handler); + (act . sa_flags) = 0; + } + else + { + (SIGACT_HANDLER (&act)) = handler; + (act . sa_flags) = SA_SIGINFO; + } UX_sigemptyset (& (act . sa_mask)); UX_sigaddset ((& (act . sa_mask)), signo); - (act . sa_flags) = SA_SIGINFO; UX_sigaction (signo, (&act), 0); } @@ -166,7 +180,7 @@ DEFUN_VOID (unblock_signals) void DEFUN (deactivate_handler, (signo), int signo) { - INSTALL_HANDLER (signo, SIG_IGN); + INSTALL_HANDLER (signo, ((Tsignal_handler) SIG_IGN)); } void @@ -392,7 +406,7 @@ DEFUN_STD_HANDLER (sighnd_control_b, tty_set_next_interrupt_char (CONTROL_B_INTERRUPT_CHAR); }) -static void EXFUN (interactive_interrupt_handler, (FULL_SIGCONTEXT_T * scp)); +static void EXFUN (interactive_interrupt_handler, (SIGCONTEXT_T * scp)); static DEFUN_STD_HANDLER (sighnd_interactive, @@ -418,7 +432,7 @@ DEFUN (stop_signal_default, (signo), int signo) /* Temporarily unbind this handler. */ handler = (current_handler (signo)); - INSTALL_HANDLER (signo, SIG_DFL); + INSTALL_HANDLER (signo, ((Tsignal_handler) SIG_DFL)); /* Perform the default action for this signal. */ UX_sigemptyset (&signo_mask); @@ -613,12 +627,15 @@ DEFUN (bind_handler, (signo, handler), int signo AND Tsignal_handler handler) { - Tsignal_handler - old_handler = ((signo == 0) ? SIG_DFL : (current_handler (signo))); + Tsignal_handler old_handler + = ((signo == 0) + ? ((Tsignal_handler) SIG_DFL) + : (current_handler (signo))); if ((signo != 0) - && ((old_handler == SIG_DFL) - || ((old_handler == SIG_IGN) && (signo == SIGCHLD))) + && ((old_handler == ((Tsignal_handler) SIG_DFL)) + || ((old_handler == ((Tsignal_handler) SIG_IGN)) + && (signo == SIGCHLD))) && ((handler != ((Tsignal_handler) sighnd_stop)) || (UX_SC_JOB_CONTROL ()))) INSTALL_HANDLER (signo, handler); @@ -663,7 +680,7 @@ DEFUN_VOID (UX_initialize_signals) /* If this signal is ignored, then the system call that would have caused it will return EPIPE instead. This is much easier for us to handle. */ - bind_handler (SIGPIPE, SIG_IGN); + bind_handler (SIGPIPE, ((Tsignal_handler) SIG_IGN)); if ((isatty (STDIN_FILENO)) || option_emacs_subprocess) { if (getenv ("USE_SCHEMATIK_STYLE_INTERRUPTS")) @@ -720,7 +737,7 @@ DEFUN_VOID (UX_initialize_child_signals) unblock_all_signals (); /* SIGPIPE was ignored above; we must set it back to the default because some programs depend on this. */ - INSTALL_HANDLER (SIGPIPE, SIG_DFL); + INSTALL_HANDLER (SIGPIPE, ((Tsignal_handler) SIG_DFL)); } /* Interactive Interrupt Handler */ @@ -737,7 +754,7 @@ DEFUN (OS_tty_map_interrupt_char, (int_char), cc_t int_char) static void EXFUN (print_interactive_help, (void)); static void EXFUN (print_interrupt_chars, (void)); static void EXFUN (examine_memory, (void)); -static void EXFUN (reset_query, (FULL_SIGCONTEXT_T * scp)); +static void EXFUN (reset_query, (SIGCONTEXT_T * scp)); static void EXFUN (interactive_back_trace, (void)); #define INTERACTIVE_NEWLINE() \ @@ -750,7 +767,7 @@ static void EXFUN (interactive_back_trace, (void)); } static void -DEFUN (interactive_interrupt_handler, (scp), FULL_SIGCONTEXT_T * scp) +DEFUN (interactive_interrupt_handler, (scp), SIGCONTEXT_T * scp) { if (!option_emacs_subprocess) { @@ -1038,7 +1055,7 @@ DEFUN (invoke_soft_reset, (name), char * name) } static void -DEFUN (reset_query, (scp), FULL_SIGCONTEXT_T * scp) +DEFUN (reset_query, (scp), SIGCONTEXT_T * scp) { putc ('\n', stdout); fflush (stdout); @@ -1322,15 +1339,15 @@ DEFUN (signal, (signo, handler), struct sigaction act; struct sigaction oact; - (act . sa_handler) = handler; + (SIGACT_HANDLER (&act)) = handler; UX_sigemptyset (& (act . sa_mask)); (act . sa_flags) = (SA_RESETHAND | SA_NODEFER); - if (handler == SIG_IGN) + if (handler == ((Tsignal_handler) SIG_IGN)) (act . sa_flags) |= SA_NOCLDWAIT; if ((UX_sigaction (signo, (&act), (&oact))) < 0) return (SIG_ERR); else - return (oact . sa_handler); + return (SIGACT_HANDLER (&oact)); } /* It is best to reinstall the SIGCHLD handler after `grantpt' is diff --git a/v7/src/microcode/uxsig.h b/v7/src/microcode/uxsig.h index b8b22ceb0..8fbbbac9c 100644 --- a/v7/src/microcode/uxsig.h +++ b/v7/src/microcode/uxsig.h @@ -1,6 +1,6 @@ /* -*-C-*- -$Id: uxsig.h,v 1.9 2005/06/26 04:34:56 cph Exp $ +$Id: uxsig.h,v 1.10 2005/06/27 06:03:29 cph Exp $ Copyright 1993,1994,2000,2005 Massachusetts Institute of Technology @@ -28,9 +28,7 @@ USA. #ifndef SCM_UXSIG_H #define SCM_UXSIG_H -#ifdef HAVE_POSIX_SIGNALS - extern void EXFUN (INSTALL_HANDLER, (int, Tsignal_handler)); -#else +#ifndef HAVE_POSIX_SIGNALS # ifdef HAVE_SIGHOLD # define INSTALL_HANDLER UX_sigset # define NEED_HANDLER_TRANSACTION @@ -53,11 +51,10 @@ Tsignal_handler_result \ DEFUN (name, (signo, info, pscp), \ int signo AND \ SIGINFO_T info AND \ - SIGCONTEXT_T * pscp) \ + SIGCONTEXT_ARG_T * pscp) \ { \ int STD_HANDLER_abortp; \ - DECLARE_FULL_SIGCONTEXT (scp); \ - INITIALIZE_FULL_SIGCONTEXT (pscp, scp); \ + DECLARE_SIGCONTEXT (scp, pscp); \ record_signal_delivery (signo); \ STD_HANDLER_abortp = (enter_interruption_extent ()); \ statement; \ @@ -79,11 +76,10 @@ Tsignal_handler_result \ DEFUN (name, (signo, info, pscp), \ int signo AND \ SIGINFO_T info AND \ - SIGCONTEXT_T * pscp) \ + SIGCONTEXT_ARG_T * pscp) \ { \ int STD_HANDLER_abortp; \ - DECLARE_FULL_SIGCONTEXT (scp); \ - INITIALIZE_FULL_SIGCONTEXT (pscp, scp); \ + DECLARE_SIGCONTEXT (scp, pscp); \ ENTER_HANDLER (signo); \ record_signal_delivery (signo); \ STD_HANDLER_abortp = (enter_interruption_extent ()); \ diff --git a/v7/src/microcode/uxtrap.c b/v7/src/microcode/uxtrap.c index 4c84b98f0..d391399f5 100644 --- a/v7/src/microcode/uxtrap.c +++ b/v7/src/microcode/uxtrap.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Id: uxtrap.c,v 1.40 2005/06/26 04:35:03 cph Exp $ +$Id: uxtrap.c,v 1.41 2005/06/27 06:03:36 cph Exp $ Copyright 1990,1991,1992,1993,1995,1997 Massachusetts Institute of Technology Copyright 2000,2001,2002,2003,2005 Massachusetts Institute of Technology @@ -33,10 +33,9 @@ USA. #ifdef HAS_COMPILER_SUPPORT # include "gccode.h" -#endif - -#if defined(HAVE_STRUCT_SIGCONTEXT) && defined(HAS_COMPILER_SUPPORT) && !defined(USE_STACKLETS) -# define ENABLE_TRAP_RECOVERY 1 +# if defined(HAVE_SIGCONTEXT) && !defined(USE_STACKLETS) +# define ENABLE_TRAP_RECOVERY 1 +# endif #endif extern CONST char * EXFUN (find_signal_name, (int signo)); @@ -65,6 +64,9 @@ static struct ux_sig_code_desc ux_signal_codes [64]; i += 1; \ } +#define DECLARE_GENERIC_SIGNAL_CODE(v, n) \ + DECLARE_UX_SIGNAL_CODE ((-1), (~ 0L), v, n) + enum pc_location { pcl_heap, @@ -90,10 +92,10 @@ static enum trap_state user_trap_state; static enum trap_state saved_trap_state; static int saved_signo; static SIGINFO_T saved_info; -static DECLARE_FULL_SIGCONTEXT (saved_scp); +static SIGCONTEXT_T * saved_scp; static void EXFUN - (continue_from_trap, (int, SIGINFO_T, FULL_SIGCONTEXT_T *)); + (continue_from_trap, (int, SIGINFO_T, SIGCONTEXT_T *)); static SCHEME_OBJECT * EXFUN (find_heap_address, (unsigned long)); static SCHEME_OBJECT * EXFUN (find_constant_address, (unsigned long)); @@ -106,14 +108,14 @@ static SCHEME_OBJECT * EXFUN static void EXFUN (setup_trap_frame, (int, SIGINFO_T, - FULL_SIGCONTEXT_T *, + SIGCONTEXT_T *, struct trap_recovery_info *, SCHEME_OBJECT *)); static void EXFUN (initialize_ux_signal_codes, (void)); static SCHEME_OBJECT EXFUN - (find_signal_code_name, (int, SIGINFO_T, FULL_SIGCONTEXT_T *)); + (find_signal_code_name, (int, SIGINFO_T, SIGCONTEXT_T *)); static enum pc_location EXFUN (classify_pc, (unsigned long, SCHEME_OBJECT **, unsigned int *)); @@ -141,7 +143,7 @@ DEFUN (OS_set_trap_state, (state), enum trap_state state) } void -DEFUN (hard_reset, (scp), FULL_SIGCONTEXT_T * scp) +DEFUN (hard_reset, (scp), SIGCONTEXT_T * scp) { /* 0 is an invalid signal, it means a user requested reset. */ continue_from_trap (0, 0, scp); @@ -196,7 +198,7 @@ DEFUN (trap_handler, (message, signo, info, scp), CONST char * message AND int signo AND SIGINFO_T info AND - FULL_SIGCONTEXT_T * scp) + SIGCONTEXT_T * scp) { int code = ((SIGINFO_VALID_P (info)) ? (SIGINFO_CODE (info)) : 0); Boolean stack_overflowed_p = (STACK_OVERFLOWED_P ()); @@ -346,9 +348,9 @@ static void DEFUN (continue_from_trap, (signo, info, scp), int signo AND SIGINFO_T info AND - FULL_SIGCONTEXT_T * scp) + SIGCONTEXT_T * scp) { - unsigned long pc = (FULL_SIGCONTEXT_PC (scp)); + unsigned long pc = (SIGCONTEXT_PC (scp)); SCHEME_OBJECT primitive = (Registers[REGBLOCK_PRIMITIVE]); SCHEME_OBJECT * block_addr; int index; @@ -372,8 +374,8 @@ DEFUN (continue_from_trap, (signo, info, scp), case pcl_heap: case pcl_constant: - new_sp = ((SCHEME_OBJECT *) (FULL_SIGCONTEXT_SCHSP (scp))); - Free = ((SCHEME_OBJECT *) (FULL_SIGCONTEXT_RFREE (scp))); + new_sp = ((SCHEME_OBJECT *) (SIGCONTEXT_SCHSP (scp))); + Free = ((SCHEME_OBJECT *) (SIGCONTEXT_RFREE (scp))); SET_RECOVERY_INFO (STATE_COMPILED_CODE, (MAKE_POINTER_OBJECT (TC_COMPILED_CODE_BLOCK, block_addr)), @@ -389,8 +391,8 @@ DEFUN (continue_from_trap, (signo, info, scp), break; case pcl_builtin: - new_sp = ((SCHEME_OBJECT *) (FULL_SIGCONTEXT_SCHSP (scp))); - Free = ((SCHEME_OBJECT *) (FULL_SIGCONTEXT_RFREE (scp))); + new_sp = ((SCHEME_OBJECT *) (SIGCONTEXT_SCHSP (scp))); + Free = ((SCHEME_OBJECT *) (SIGCONTEXT_RFREE (scp))); SET_RECOVERY_INFO (STATE_BUILTIN, (LONG_TO_UNSIGNED_FIXNUM (index)), @@ -432,13 +434,13 @@ DEFUN (continue_from_trap, (signo, info, scp), (recovery_info . extra_trap_info) = (MAKE_POINTER_OBJECT (TC_NON_MARKED_VECTOR, Free)); (*Free++) = - (MAKE_OBJECT (TC_MANIFEST_NM_VECTOR, (2 + FULL_SIGCONTEXT_NREGS))); + (MAKE_OBJECT (TC_MANIFEST_NM_VECTOR, (2 + SIGCONTEXT_NREGS))); (*Free++) = ((SCHEME_OBJECT) pc); - (*Free++) = ((SCHEME_OBJECT) (FULL_SIGCONTEXT_SP (scp))); + (*Free++) = ((SCHEME_OBJECT) (SIGCONTEXT_SP (scp))); { unsigned long * scan - = ((unsigned long *) (FULL_SIGCONTEXT_FIRST_REG (scp))); - unsigned long * end = (scan + FULL_SIGCONTEXT_NREGS); + = ((unsigned long *) (SIGCONTEXT_FIRST_REG (scp))); + unsigned long * end = (scan + SIGCONTEXT_NREGS); while (scan < end) (*Free++) = ((SCHEME_OBJECT) (*scan++)); } @@ -574,7 +576,7 @@ static void DEFUN (continue_from_trap, (signo, info, scp), int signo AND SIGINFO_T info AND - FULL_SIGCONTEXT_T * scp) + SIGCONTEXT_T * scp) { if (Free < MemTop) Free = MemTop; @@ -599,7 +601,7 @@ static void DEFUN (setup_trap_frame, (signo, info, scp, trinfo, new_stack_pointer), int signo AND SIGINFO_T info AND - FULL_SIGCONTEXT_T * scp AND + SIGCONTEXT_T * scp AND struct trap_recovery_info * trinfo AND SCHEME_OBJECT * new_stack_pointer) { @@ -673,14 +675,28 @@ DEFUN_VOID (initialize_ux_signal_codes) { unsigned int i = 0; INITIALIZE_UX_SIGNAL_CODES (); - DECLARE_UX_SIGNAL_CODE (0, 0, 0, ((char *) 0)); + +#ifdef _POSIX_REALTIME_SIGNALS + DECLARE_GENERIC_SIGNAL_CODE + (SI_USER, "signal sent by kill"); + DECLARE_GENERIC_SIGNAL_CODE + (SI_QUEUE, "signal sent by sigqueue"); + DECLARE_GENERIC_SIGNAL_CODE + (SI_TIMER, "signal generated by timer expiration"); + DECLARE_GENERIC_SIGNAL_CODE + (SI_ASYNCIO, "signal generated by asynchronous I/O completion"); + DECLARE_GENERIC_SIGNAL_CODE + (SI_MESGQ, "signal generated by message queue arrival"); +#endif /* _POSIX_REALTIME_SIGNALS */ + + DECLARE_UX_SIGNAL_CODE (0, 0, 0, 0); } static SCHEME_OBJECT DEFUN (find_signal_code_name, (signo, info, scp), int signo AND SIGINFO_T info AND - FULL_SIGCONTEXT_T * scp) + SIGCONTEXT_T * scp) { unsigned long code = 0; char * name = 0; @@ -692,7 +708,7 @@ DEFUN (find_signal_code_name, (signo, info, scp), { struct ux_sig_code_desc * entry = (& (ux_signal_codes[0])); while ((entry -> signo) != 0) - if (((entry -> signo) == signo) + if ((((entry -> signo) < 0) || ((entry -> signo) == signo)) && (((entry -> code_mask) & code) == (entry -> code_value))) { name = (entry -> name); diff --git a/v7/src/microcode/uxtrap.h b/v7/src/microcode/uxtrap.h index 29c6cbd16..8b571f6c4 100644 --- a/v7/src/microcode/uxtrap.h +++ b/v7/src/microcode/uxtrap.h @@ -1,6 +1,6 @@ /* -*-C-*- -$Id: uxtrap.h,v 1.34 2005/06/26 04:35:11 cph Exp $ +$Id: uxtrap.h,v 1.35 2005/06/27 06:03:43 cph Exp $ Copyright 1990,1991,1992,1993,1996,1998 Massachusetts Institute of Technology Copyright 2000,2001,2004,2005 Massachusetts Institute of Technology @@ -37,14 +37,13 @@ USA. #include #include -#define FULL_SIGCONTEXT_NREGS GPR_REGS /* Missing sp */ - -#define RFREE AR5 -#define SIGCONTEXT_T struct full_sigcontext +#define HAVE_SIGCONTEXT +#define SIGCONTEXT_ARG_T struct full_sigcontext +#define SIGCONTEXT_NREGS GPR_REGS /* Missing sp */ +#define SIGCONTEXT_FIRST_REG(scp) (&((scp)->fs_regs[GPR_START])) #define SIGCONTEXT_SP(scp) ((scp)->fs_context.sc_sp) #define SIGCONTEXT_PC(scp) ((scp)->fs_context.sc_pc) -#define FULL_SIGCONTEXT_RFREE(scp) ((scp)->fs_regs[RFREE]) -#define FULL_SIGCONTEXT_FIRST_REG(scp) (&((scp)->fs_regs[GPR_START])) +#define SIGCONTEXT_RFREE(scp) ((scp)->fs_regs[AR5]) #define INITIALIZE_UX_SIGNAL_CODES() \ { \ @@ -86,7 +85,7 @@ USA. They should be masked away before looking at the PC. */ -#define PC_VALUE_MASK ((~0) << 2) +#define PC_VALUE_MASK ((~0) << 2) /* pcoq is the offset (32 bit in 64 bit virtual address space) in the space included in the corresponding sc_pcsq. @@ -99,30 +98,31 @@ USA. #ifdef __HPUX__ -/* HPUX 09.x does not have siginfo, but HPUX 10.x does. This can be -tested by the definition of SA_SIGINFO. Since we want to support -both, we use the no-siginfo way */ +/* HPUX 9.x does not have siginfo, but HPUX 10.x does. This can be + tested by the definition of SA_SIGINFO. Since we want to support + both, we use the no-siginfo way. */ #ifdef SA_SIGINFO -#undef SA_SIGINFO +# undef SA_SIGINFO #endif -# include +#include /* See included by */ +#ifndef sc_pc +# define sc_pc sc_pcoq_head +#endif -# ifndef sc_pc -# define sc_pc sc_pcoq_head -# endif /* sc_pc */ - -# define ss_gr0 ss_flags /* not really true */ -# define ss_rfree ss_gr21 /* or some such */ -# define ss_schsp ss_gr22 +#define ss_gr0 ss_flags /* not really true */ -# define FULL_SIGCONTEXT_RFREE(scp) ((scp)->sc_sl.sl_ss.ss_rfree) -# define FULL_SIGCONTEXT_SCHSP(scp) ((scp)->sc_sl.sl_ss.ss_schsp) -# define FULL_SIGCONTEXT_FIRST_REG(scp) (&((scp)->sc_sl.sl_ss.ss_gr0)) -# define FULL_SIGCONTEXT_NREGS 32 +#define HAVE_SIGCONTEXT +#define SIGCONTEXT_ARG_T struct sigcontext +#define SIGCONTEXT_NREGS 32 +#define SIGCONTEXT_FIRST_REG(scp) (&((scp)->sc_sl.sl_ss.ss_gr0)) +#define SIGCONTEXT_SP(scp) ((scp) -> sc_sp) +#define SIGCONTEXT_PC(scp) ((scp) -> sc_pc) +#define SIGCONTEXT_RFREE(scp) ((scp)->sc_sl.sl_ss.ss_gr21) +#define SIGCONTEXT_SCHSP(scp) ((scp)->sc_sl.sl_ss.ss_gr22) # define INITIALIZE_UX_SIGNAL_CODES() \ { \ @@ -191,66 +191,59 @@ both, we use the no-siginfo way */ #ifdef sun3 -#define FULL_SIGCONTEXT_NREGS 15 /* missing sp */ - struct full_sigcontext { struct sigcontext * fs_original; - int fs_regs[FULL_SIGCONTEXT_NREGS]; + unsigned long fs_regs [SIGCONTEXT_NREGS]; }; -#define RFREE (8 + 5) /* A5 */ -#define FULL_SIGCONTEXT_T struct full_sigcontext -#define FULL_SIGCONTEXT_SP(scp) (scp->fs_original->sc_sp) -#define FULL_SIGCONTEXT_PC(scp) (scp->fs_original->sc_pc) -#define FULL_SIGCONTEXT_RFREE(scp) (scp->fs_regs[RFREE]) -#define FULL_SIGCONTEXT_FIRST_REG(scp) (&((scp)->fs_regs[0])) - -#define DECLARE_FULL_SIGCONTEXT(name) FULL_SIGCONTEXT_T name [1] - -#define INITIALIZE_FULL_SIGCONTEXT(partial, full) \ -{ \ - static void EXFUN (sun3_save_regs, (int * regs)); \ - sun3_save_regs (& ((((full) [0]) . fs_regs) [0])); \ - (((full) [0]) . fs_original) = (partial); \ -} +#define HAVE_SIGCONTEXT +#define SIGCONTEXT_ARG_T struct sigcontext +#define SIGCONTEXT_T struct full_sigcontext +#define SIGCONTEXT_NREGS 15 /* missing sp */ +#define SIGCONTEXT_FIRST_REG(scp) (& (((scp) -> fs_regs) [0])) +#define SIGCONTEXT_SP(scp) ((scp)->fs_original->sc_sp) +#define SIGCONTEXT_PC(scp) ((scp)->fs_original->sc_pc) +#define SIGCONTEXT_RFREE(scp) (((scp) -> fs_regs) [8 + 5]) /* A5 */ + +#define DECLARE_SIGCONTEXT(scp, arg) \ + SIGCONTEXT_T scp [1]; \ + static void EXFUN (sun3_save_regs, (int *)); \ + sun3_save_regs (& ((((scp) [0]) . fs_regs) [0])); \ + (((scp) [0]) . fs_original) = (arg) #endif /* sun3 */ #ifdef vax -#define FULL_SIGCONTEXT_NREGS 16 - struct full_sigcontext { struct sigcontext * fs_original; - int fs_regs [FULL_SIGCONTEXT_NREGS]; + int fs_regs [SIGCONTEXT_NREGS]; }; -#define RFREE 12 /* fp */ -#define FULL_SIGCONTEXT_T struct full_sigcontext -#define FULL_SIGCONTEXT_SP(scp) ((scp)->fs_original->sc_sp) -#define FULL_SIGCONTEXT_PC(scp) ((scp)->fs_original->sc_pc) -#define FULL_SIGCONTEXT_RFREE(scp) ((scp)->fs_regs[RFREE]) -#define FULL_SIGCONTEXT_FIRST_REG(scp) (&((scp)->fs_regs[0])) - -#define DECLARE_FULL_SIGCONTEXT(name) FULL_SIGCONTEXT_T name [1] +#define HAVE_SIGCONTEXT +#define SIGCONTEXT_ARG_T struct sigcontext +#define SIGCONTEXT_T struct full_sigcontext +#define SIGCONTEXT_NREGS 16 +#define SIGCONTEXT_FIRST_REG(scp) (&((scp)->fs_regs[0])) +#define SIGCONTEXT_SP(scp) ((scp)->fs_original->sc_sp) +#define SIGCONTEXT_PC(scp) ((scp)->fs_original->sc_pc) +#define SIGCONTEXT_RFREE(scp) ((scp)->fs_regs[12]) /* fp */ /* r0 has to be kludged. */ - -#define INITIALIZE_FULL_SIGCONTEXT(partial, full) \ -{ \ +#define DECLARE_SIGCONTEXT(partial, full) \ + SIGCONTEXT_T scp [1]; \ static int EXFUN (vax_get_r0, (void)); \ - static int * EXFUN (vax_save_start, (int * regs, int r0)); \ + static int * EXFUN (vax_save_start, (int *, int)); \ static void EXFUN \ - (vax_save_finish, (int * fp, \ - struct sigcontext * pscp, \ - struct full_sigcontext * scp)); \ + (vax_save_finish, (int *, \ + struct sigcontext *, \ + struct full_sigcontext *)); \ vax_save_finish ((vax_save_start ((& ((((full) [0]) . fs_regs) [0])), \ (vax_get_r0 ()))), \ (partial), \ - (&(full)[0])); \ -} + (&(full)[0])) #endif /* vax */ @@ -259,17 +252,14 @@ struct full_sigcontext /* Information on sigcontext structure in signal.h */ -#ifndef sc_sp -#define sc_sp sc_regs[29] -#endif - -#define sc_rfree sc_regs[9] -#define sc_schsp sc_regs[3] - -#define FULL_SIGCONTEXT_RFREE(scp) ((scp)->sc_rfree) -#define FULL_SIGCONTEXT_SCHSP(scp) ((scp)->sc_schsp) -#define FULL_SIGCONTEXT_FIRST_REG(scp) (&((scp)->sc_regs[0])) -#define FULL_SIGCONTEXT_NREGS 32 +#define HAVE_SIGCONTEXT +#define SIGCONTEXT_ARG_T struct sigcontext +#define SIGCONTEXT_NREGS 32 +#define SIGCONTEXT_FIRST_REG(scp) (& (((scp) -> sc_regs) [0])) +#define SIGCONTEXT_SP(scp) (((scp) -> sc_regs) [29]) +#define SIGCONTEXT_PC(scp) ((scp) -> sc_pc) +#define SIGCONTEXT_RFREE(scp) (((scp) -> sc_regs) [9]) +#define SIGCONTEXT_SCHSP(scp) (((scp) -> sc_regs) [3]) #define INITIALIZE_UX_SIGNAL_CODES() \ { \ @@ -292,19 +282,14 @@ struct full_sigcontext #else /* not __IRIX__ */ #ifndef _SYSV4 -/* Information on sigcontext structure in signal.h */ - -#ifndef sc_sp -#define sc_sp sc_regs[29] -#endif - -#define sc_rfree sc_regs[9] -#define sc_schsp sc_regs[3] - -#define FULL_SIGCONTEXT_RFREE(scp) ((scp)->sc_rfree) -#define FULL_SIGCONTEXT_SCHSP(scp) ((scp)->sc_schsp) -#define FULL_SIGCONTEXT_FIRST_REG(scp) (&((scp)->sc_regs[0])) -#define FULL_SIGCONTEXT_NREGS 32 +#define HAVE_SIGCONTEXT +#define SIGCONTEXT_ARG_T struct sigcontext +#define SIGCONTEXT_NREGS 32 +#define SIGCONTEXT_FIRST_REG(scp) (& (((scp) -> sc_regs) [0])) +#define SIGCONTEXT_SP(scp) (((scp) -> sc_regs) [29]) +#define SIGCONTEXT_PC(scp) ((scp) -> sc_pc) +#define SIGCONTEXT_RFREE(scp) (((scp) -> sc_regs) [9]) +#define SIGCONTEXT_SCHSP(scp) (((scp) -> sc_regs) [3]) #define INITIALIZE_UX_SIGNAL_CODES() \ { \ @@ -345,21 +330,24 @@ struct full_sigcontext /* For Sony NEWS-OS 5.0.1 and earlier: */ #if defined(sonyrisc) && !defined(_CFE) -#define gregs gpregs +# define gregs gpregs #endif #define SIGINFO_T siginfo_t * #define SIGINFO_VALID_P(info) ((info) != 0) #define SIGINFO_CODE(info) ((info) -> si_code) -#define SIGCONTEXT_T ucontext_t -#define SIGCONTEXT_SP(scp) ((((scp) -> uc_mcontext) . gregs) [CXT_SP]) -#define SIGCONTEXT_PC(scp) ((((scp) -> uc_mcontext) . gregs) [CXT_EPC]) +#define __SIGCONTEXT_REG(scp, ir) ((((scp) -> uc_mcontext) . gregs) [(ir)]) -#define FULL_SIGCONTEXT_RFREE(scp) ((((scp) -> uc_mcontext) . gregs) [CXT_T1]) -#define FULL_SIGCONTEXT_SCHSP(scp) ((((scp) -> uc_mcontext) . gregs) [CXT_V1]) -#define FULL_SIGCONTEXT_FIRST_REG(scp) (((scp) -> uc_mcontext) . gregs) -#define FULL_SIGCONTEXT_NREGS NGREG +#define HAVE_SIGCONTEXT +#define SIGCONTEXT_ARG_T void +#define SIGCONTEXT_T ucontext_t +#define SIGCONTEXT_NREGS NGREG +#define SIGCONTEXT_FIRST_REG(scp) (& (__SIGCONTEXT_REG (scp, 0))) +#define SIGCONTEXT_SP(scp) (__SIGCONTEXT_REG (scp, CXT_SP)) +#define SIGCONTEXT_PC(scp) (__SIGCONTEXT_REG (scp, CXT_EPC)) +#define SIGCONTEXT_RFREE(scp) (__SIGCONTEXT_REG (scp, CXT_T1)) +#define SIGCONTEXT_SCHSP(scp) (__SIGCONTEXT_REG (scp, CXT_V1)) #define INITIALIZE_UX_SIGNAL_CODES() \ { \ @@ -405,21 +393,19 @@ struct full_sigcontext #ifdef __linux__ -#define SIGINFO_T siginfo_t * -#define SIGINFO_VALID_P(info) ((info) != 0) -#define SIGINFO_CODE(info) ((info) -> si_code) +/* This isn't really the right test: what we really want to know is if + the kernel supports the newer signal-delivery mechanism. */ -#define SIGCONTEXT_T ucontext_t -#define __SIGCONTEXT_REG(scp, ir) \ - ((unsigned long) ((((scp) -> uc_mcontext) . gregs) [(ir)])) +#ifdef _POSIX_REALTIME_SIGNALS + +#define __SIGCONTEXT_REG(scp, ir) ((((scp) -> uc_mcontext) . gregs) [(ir)]) +#define HAVE_SIGCONTEXT +#define SIGCONTEXT_NREGS NGREG +#define SIGCONTEXT_FIRST_REG(scp) (& (__SIGCONTEXT_REG (scp, REG_GS))) #define SIGCONTEXT_SP(scp) (__SIGCONTEXT_REG (scp, REG_ESP)) #define SIGCONTEXT_PC(scp) (__SIGCONTEXT_REG (scp, REG_EIP)) - -/* Grab them all. Nobody looks at them, but grab them anyway. */ -#define FULL_SIGCONTEXT_NREGS NGREG -#define FULL_SIGCONTEXT_FIRST_REG(scp) (((scp) -> uc_mcontext) . gregs) -#define FULL_SIGCONTEXT_RFREE(scp) (__SIGCONTEXT_REG (scp, REG_EDI)) +#define SIGCONTEXT_RFREE(scp) (__SIGCONTEXT_REG (scp, REG_EDI)) #define INITIALIZE_UX_SIGNAL_CODES() \ { \ @@ -457,19 +443,75 @@ struct full_sigcontext (SIGILL, (~ 0L), ILL_BADSTK, "bad stack trap"); \ } +#else /* not _POSIX_REALTIME_SIGNALS */ + +/* In Linux 2.0 and earlier, signal handlers are called with one + argument. There's an "iBCS2 signal stack" register dump just above + it. Thus, the fictitious `info' argument to the handler is + actually the first member of this register dump (described by + linux_sigcontext_t, below). Unfortunately, kludging SIGINFO_CODE + to access the sc_trapno will fail later on when looking at the + saved_info. */ + +typedef struct +{ + unsigned short gs, __gsh; + unsigned short fs, __fsh; + unsigned short es, __esh; + unsigned short ds, __dsh; + unsigned long edi; + unsigned long esi; + unsigned long ebp; + unsigned long esp; + unsigned long ebx; + unsigned long edx; + unsigned long ecx; + unsigned long eax; + unsigned long trapno; + unsigned long err; + unsigned long eip; + unsigned short cs, __csh; + unsigned long eflags; + unsigned long esp_at_signal; + unsigned short ss, __ssh; + void * fpstate; +} linux_sigcontext_t; + +#define HAVE_SIGCONTEXT +#define SIGCONTEXT_T linux_sigcontext_t +#define SIGCONTEXT_NREGS 19 +#define SIGCONTEXT_FIRST_REG(scp) (scp) +#define SIGCONTEXT_SP(scp) ((scp) -> esp) +#define SIGCONTEXT_PC(scp) ((scp) -> eip) +#define SIGCONTEXT_RFREE(scp) ((scp) -> edi) + +/* DECLARE_SIGCONTEXT gives us a chance to generate a pointer to the + register dump, since it is used at the beginning of STD_HANDLER's. + In terms of the expected arguments to the STD_ signal HANDLER's, + the register dump is right above `signo', at `info', one long below + `pscp', which is what DECLARE_SIGCONTEXT is getting for `arg'. + Thus, our pointer to a scp is initialized to the address of `arg' + minus 1 long. */ + +#define DECLARE_SIGCONTEXT(scp, arg) \ + SIGCONTEXT_T * scp; \ + scp = ((SIGCONTEXT_T *) (((unsigned long *) (& (arg))) - 1)) + +#endif /* not _POSIX_REALTIME_SIGNALS */ + #endif /* __linux__ */ #ifdef _MACH_UNIX /* The following are true for Mach (BSD 4.3 compatible). I don't know about SCO or other versions. */ -#define FULL_SIGCONTEXT_NREGS 8 - -#define SIGCONTEXT_T struct sigcontext -#define SIGCONTEXT_SP(scp) ((scp)->sc_esp) -#define SIGCONTEXT_PC(scp) ((scp)->sc_eip) -#define FULL_SIGCONTEXT_RFREE(scp) ((scp)->sc_edi) -#define FULL_SIGCONTEXT_FIRST_REG(scp) (&((scp)->sc_edi)) +#define HAVE_SIGCONTEXT +#define SIGCONTEXT_ARG_T struct sigcontext +#define SIGCONTEXT_NREGS 8 +#define SIGCONTEXT_FIRST_REG(scp) (& ((scp) -> sc_edi)) +#define SIGCONTEXT_SP(scp) ((scp) -> sc_esp) +#define SIGCONTEXT_PC(scp) ((scp) -> sc_eip) +#define SIGCONTEXT_RFREE(scp) ((scp) -> sc_edi) /* INITIALIZE_UX_SIGNAL_CODES should be defined. */ @@ -479,14 +521,14 @@ struct full_sigcontext #ifdef __alpha -#define sc_sp sc_regs[30] -#define sc_rfree sc_regs[4] -#define sc_schsp sc_regs[2] - -#define FULL_SIGCONTEXT_RFREE(scp) ((scp)->sc_rfree) -#define FULL_SIGCONTEXT_SCHSP(scp) ((scp)->sc_schsp) -#define FULL_SIGCONTEXT_FIRST_REG(scp) (&((scp)->sc_regs[0])) -#define FULL_SIGCONTEXT_NREGS 32 +#define HAVE_SIGCONTEXT +#define SIGCONTEXT_ARG_T struct sigcontext +#define SIGCONTEXT_NREGS 32 +#define SIGCONTEXT_FIRST_REG(scp) (& (((scp) -> sc_regs) [0])) +#define SIGCONTEXT_SP(scp) (((scp) -> sc_regs) [30]) +#define SIGCONTEXT_PC(scp) ((scp) -> sc_pc) +#define SIGCONTEXT_RFREE(scp) (((scp) -> sc_regs) [4]) +#define SIGCONTEXT_SCHSP(scp) (((scp) -> sc_regs) [2]) #ifdef FPE_COMPLETE_FAULT #define STUPID_FIRST_SIGNAL() \ @@ -516,50 +558,57 @@ struct full_sigcontext } #endif /* __alpha */ - -#ifdef _AIX -/* For now */ -# define SIGCONTEXT_T struct sigcontext -# define SIGCONTEXT_SP(scp) 0 -# define SIGCONTEXT_PC(scp) 0 -#endif /* _AIX */ +#ifdef _POSIX_REALTIME_SIGNALS +# define SIGINFO_T siginfo_t * +# define SIGINFO_VALID_P(info) (1) +# define SIGINFO_CODE(info) ((info) -> si_code) +# define SIGCONTEXT_ARG_T void +# define SIGCONTEXT_T ucontext_t +#endif + #ifndef SIGINFO_T # define SIGINFO_T int -# define SIGINFO_VALID_P(info) (1) -# define SIGINFO_CODE(info) (info) +# define SIGINFO_VALID_P(info) (0) +# define SIGINFO_CODE(info) (0) #endif -#ifndef HAVE_STRUCT_SIGCONTEXT - struct sigcontext { long sc_sp; long sc_pc; }; +#ifndef SIGCONTEXT_ARG_T +# define SIGCONTEXT_ARG_T int #endif #ifndef SIGCONTEXT_T -# define SIGCONTEXT_T struct sigcontext -# define SIGCONTEXT_SP(scp) ((scp) -> sc_sp) -# define SIGCONTEXT_PC(scp) ((scp) -> sc_pc) +# define SIGCONTEXT_T SIGCONTEXT_ARG_T +#endif + +#ifndef DECLARE_SIGCONTEXT +# define DECLARE_SIGCONTEXT(scp, arg) \ + SIGCONTEXT_T * scp; \ + scp = ((SIGCONTEXT_T *) (arg)) +#endif + +#ifndef SIGCONTEXT_NREGS +# define SIGCONTEXT_NREGS (0) +#endif + +#ifndef SIGCONTEXT_FIRST_REG +# define SIGCONTEXT_FIRST_REG(scp) (0) #endif -#ifndef FULL_SIGCONTEXT_T -# define FULL_SIGCONTEXT_T SIGCONTEXT_T -# define FULL_SIGCONTEXT_SP SIGCONTEXT_SP -# define FULL_SIGCONTEXT_PC SIGCONTEXT_PC -# define DECLARE_FULL_SIGCONTEXT(name) FULL_SIGCONTEXT_T * name -# define INITIALIZE_FULL_SIGCONTEXT(partial, full) \ - ((full) = ((FULL_SIGCONTEXT_T *) (partial))) +#ifndef SIGCONTEXT_SP +# define SIGCONTEXT_SP(scp) (0) #endif -#ifndef FULL_SIGCONTEXT_NREGS -# define FULL_SIGCONTEXT_NREGS 0 -# define FULL_SIGCONTEXT_FIRST_REG(scp) ((int *) 0) +#ifndef SIGCONTEXT_PC +# define SIGCONTEXT_PC(scp) (0) #endif -#ifndef FULL_SIGCONTEXT_RFREE -# define FULL_SIGCONTEXT_RFREE ((unsigned long) MemTop) +#ifndef SIGCONTEXT_RFREE +# define SIGCONTEXT_RFREE ((unsigned long) MemTop) #endif -#ifndef FULL_SIGCONTEXT_SCHSP -# define FULL_SIGCONTEXT_SCHSP FULL_SIGCONTEXT_SP +#ifndef SIGCONTEXT_SCHSP +# define SIGCONTEXT_SCHSP SIGCONTEXT_SP #endif #ifndef INITIALIZE_UX_SIGNAL_CODES @@ -568,7 +617,7 @@ struct full_sigcontext /* PCs must be aligned according to this. */ -#define PC_ALIGNMENT_MASK ((1 << PC_ZERO_BITS) - 1) +#define PC_ALIGNMENT_MASK ((1 << PC_ZERO_BITS) - 1) #ifndef HAS_COMPILER_SUPPORT # define PLAUSIBLE_CC_BLOCK_P(block) 0 @@ -591,7 +640,7 @@ struct full_sigcontext #endif #ifndef ADDRESS_UCODE_P -# define ADDRESS_UCODE_P(addr) 0 +# define ADDRESS_UCODE_P(addr) (0) #endif /* Machine/OS-independent section */ @@ -609,10 +658,10 @@ enum trap_state extern void EXFUN (UX_initialize_trap_recovery, (void)); extern enum trap_state EXFUN (OS_set_trap_state, (enum trap_state state)); -extern void EXFUN (hard_reset, (FULL_SIGCONTEXT_T * scp)); +extern void EXFUN (hard_reset, (SIGCONTEXT_T * scp)); extern void EXFUN (soft_reset, (void)); extern void EXFUN - (trap_handler, (CONST char *, int, SIGINFO_T, FULL_SIGCONTEXT_T *)); + (trap_handler, (CONST char *, int, SIGINFO_T, SIGCONTEXT_T *)); extern SCHEME_OBJECT find_ccblock (unsigned long); #define STATE_UNKNOWN (LONG_TO_UNSIGNED_FIXNUM (0))