This is the mail archive of the java-discuss@sourceware.cygnus.com mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: sigcontext_struct


Here's a patch to make libgcj use siginfo style signal handlers.  THe
choice of siginfo rather than sigcontext is #ifdef'd on SA_SIGINFO,
which will have to be changed after Godmar's comments, so this is not
the final version of the patch.

In any case, I'd like you to try this patch on your system.

Thanks,
Andrew.

Index: include/i386-signal.h
===================================================================
RCS file: /cvs/java/libgcj/libjava/include/i386-signal.h,v
retrieving revision 1.5
diff -p -r1.5 i386-signal.h
*** i386-signal.h	1999/07/07 09:09:39	1.5
--- i386-signal.h	1999/10/19 12:50:51
*************** This software is copyrighted work licens
*** 8,16 ****
  Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
  details.  */
  
! /* This technique should work for all i386 based Unices which conform
!  * to iBCS2.  This includes all versions of Linux more recent than 1.3 
!  */
  
  
  #ifndef JAVA_SIGNAL_H
--- 8,16 ----
  Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
  details.  */
  
! /* There are two versions of the handlers here: old Linux kernels and
!  * newer SystemV sigcontext style signal handlers.  Unfortunately
!  * they are incompatible. */
  
  
  #ifndef JAVA_SIGNAL_H
*************** details.  */
*** 21,37 ****
  #define HANDLE_SEGV 1
  #define HANDLE_FPE 1
  
  #define SIGNAL_HANDLER(_name)	\
! static void _name (int _dummy)
  
  #define MAKE_THROW_FRAME						\
  do									\
  {									\
!   void **_p = (void **)&_dummy;						\
!   struct sigcontext_struct *_regs = (struct sigcontext_struct *)++_p;	\
! 									\
!   register unsigned long _ebp = _regs->ebp;				\
!   register unsigned char *_eip = (unsigned char *)_regs->eip;		\
  									\
    /* Advance the program counter so that it is after the start of the	\
       instruction:  the x86 exception handler expects			\
--- 21,84 ----
  #define HANDLE_SEGV 1
  #define HANDLE_FPE 1
  
+ #ifdef SA_SIGINFO
+ #include <sys/ucontext.h>
+ 
+ #define SIGNAL_HANDLER(_name)						\
+ static void _name (int _dummy, siginfo_t *_info, void *_dummy_context)
+ 
+ #define INSTALL_HANDLER(_signal, _handler)	\
+     struct sigaction act;			\
+     act.sa_sigaction = _handler;		\
+     act.sa_flags = SA_SIGINFO | SA_NODEFER;	\
+     sigemptyset (&act.sa_mask);			\
+     __sigaction (_signal, &act, NULL);
+ 
+ #define GET_CONTEXT						\
+   ucontext_t *_context = (ucontext_t *)_dummy_context;  	\
+   (void)_dummy;							\
+   (void)_info;							\
+ 								\
+   greg_t *_regs = _context->uc_mcontext.gregs;			\
+ 								\
+   register unsigned long *_ebp = (unsigned long *)_regs[EBP];	\
+   register unsigned char *_eip = (unsigned char *)_regs[EIP];
+ 
+ #define SIG_REG_EAX (_regs[EAX])
+ #define SIG_REG_EIP (_regs[EIP])
+ #define SIG_REG_EBP (_regs[EBP])
+ #define SIG_REG_EDX (_regs[EDX])
+ 
+ #else
+ 
  #define SIGNAL_HANDLER(_name)	\
! static void _name (int _dummy, struct sigcontext_struct _ctx)
! 
! #define INSTALL_HANDLER(_signal, _handler)		\
!     struct sigaction act;				\
!     *(void **)&act.sa_handler = (void *)_handler;	\
!     sigemptyset (&act.sa_mask);				\
!     act.sa_flags = 0;					\
!     __sigaction (_signal, &act, NULL);
! 
! #define GET_CONTEXT						\
!   (void)_dummy;							\
! 								\
!   register unsigned long *_ebp = (unsigned long *)_ctx.ebp;	\
!   register unsigned char *_eip = (unsigned char *)_ctx.eip;
! 
! #define SIG_REG_EAX (_ctx.eax)
! #define SIG_REG_EIP (_ctx.eip)
! #define SIG_REG_EBP (_ctx.ebp)
! #define SIG_REG_EDX (_ctx.edx)
! 
! #endif
  
+ 
  #define MAKE_THROW_FRAME						\
  do									\
  {									\
!   GET_CONTEXT								\
  									\
    /* Advance the program counter so that it is after the start of the	\
       instruction:  the x86 exception handler expects			\
*************** while (0)
*** 46,56 ****
  #define HANDLE_DIVIDE_OVERFLOW						\
  do									\
  {									\
!   void **_p = (void **)&_dummy;						\
!   struct sigcontext_struct *_regs = (struct sigcontext_struct *)++_p;	\
! 									\
!   register unsigned long *_ebp = (unsigned long *)_regs->ebp;		\
!   register unsigned char *_eip = (unsigned char *)_regs->eip;		\
  									\
    /* According to the JVM spec, "if the dividend is the negative	\
     * integer of the smallest magnitude and the divisor is -1, then	\
--- 93,99 ----
  #define HANDLE_DIVIDE_OVERFLOW						\
  do									\
  {									\
!   GET_CONTEXT								\
  									\
    /* According to the JVM spec, "if the dividend is the negative	\
     * integer of the smallest magnitude and the divisor is -1, then	\
*************** do									\
*** 69,78 ****
      {									\
        unsigned char _modrm = _eip[1];					\
  									\
!       if (_regs->eax == 0x80000000					\
  	  && ((_modrm >> 3) & 7) == 7) /* Signed divide */		\
  	{								\
! 	  _regs->edx = 0; /* the remainder is zero */			\
  	  switch (_modrm >> 6)						\
  	    {								\
  	    case 0:							\
--- 112,121 ----
      {									\
        unsigned char _modrm = _eip[1];					\
  									\
!       if ((unsigned long)SIG_REG_EAX == 0x80000000L			\
  	  && ((_modrm >> 3) & 7) == 7) /* Signed divide */		\
  	{								\
! 	  SIG_REG_EDX = 0; /* the remainder is zero */			\
  	  switch (_modrm >> 6)						\
  	    {								\
  	    case 0:							\
*************** do									\
*** 89,95 ****
  	      break;							\
  	    }								\
  	  _eip += 2;							\
! 	  _regs->eip = (unsigned long)_eip;				\
  	  return;							\
  	}								\
        else if (((_modrm >> 3) & 7) == 6) /* Unsigned divide */		\
--- 132,138 ----
  	      break;							\
  	    }								\
  	  _eip += 2;							\
! 	  SIG_REG_EIP = (unsigned long)_eip;				\
  	  return;							\
  	}								\
        else if (((_modrm >> 3) & 7) == 6) /* Unsigned divide */		\
*************** while (0)
*** 122,148 ****
  #define INIT_SEGV						\
  do								\
    {								\
!     nullp = new java::lang::NullPointerException ();    	\
!     struct sigaction act;					\
!     act.sa_handler = catch_segv;				\
!     sigemptyset (&act.sa_mask);					\
!     act.sa_flags = 0;						\
!     __sigaction (SIGSEGV, &act, NULL);				\
    }								\
! while (0)  
  
  #define INIT_FPE						\
  do								\
!   { 								\
      arithexception = new java::lang::ArithmeticException 	\
        (JvNewStringLatin1 ("/ by zero"));			\
!     struct sigaction act;					\
!     act.sa_handler = catch_fpe;					\
!     sigemptyset (&act.sa_mask);					\
!     act.sa_flags = 0;						\
!     __sigaction (SIGFPE, &act, NULL);				\
    }								\
! while (0)  
  
  #endif /* JAVA_SIGNAL_H */
    
--- 165,183 ----
  #define INIT_SEGV						\
  do								\
    {								\
!     nullp = new java::lang::NullPointerException ();		\
!     INSTALL_HANDLER(SIGSEGV, catch_segv)                        \
    }								\
! while (0)							
  
  #define INIT_FPE						\
  do								\
!   {								\
      arithexception = new java::lang::ArithmeticException 	\
        (JvNewStringLatin1 ("/ by zero"));			\
!     INSTALL_HANDLER(SIGFPE, catch_fpe)				\
    }								\
! while (0)
  
  #endif /* JAVA_SIGNAL_H */
    

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]