Bug 538339 In fpehandler() mask cw and back to the faulting x87 instruction on Solaris r=gal,bsmedberg
authorGinn Chen <ginn.chen@sun.com>
Wed, 13 Jan 2010 17:04:52 +0800
changeset 37137 8f38c5ae4aab0867483042ee35902e357cffa9a1
parent 37136 876262d3038bef34d4e567ff5468184953946450
child 37138 942185a891541c2ec7faa0e32c261c3bec61cac6
push idunknown
push userunknown
push dateunknown
reviewersgal, bsmedberg
bugs538339
milestone1.9.3a1pre
Bug 538339 In fpehandler() mask cw and back to the faulting x87 instruction on Solaris r=gal,bsmedberg
toolkit/xre/nsSigHandlers.cpp
toolkit/xre/nsSigHandlers.h
--- a/toolkit/xre/nsSigHandlers.cpp
+++ b/toolkit/xre/nsSigHandlers.cpp
@@ -59,16 +59,17 @@
 #include <sys/resource.h>
 #include <unistd.h>
 #include <stdlib.h> // atoi
 #include <ucontext.h>
 #endif
 
 #if defined(SOLARIS)
 #include <sys/resource.h>
+#include <ucontext.h>
 #endif
 
 #ifdef XP_BEOS
 #include <be/app/Application.h>
 #include <string.h>
 #include "nsCOMPtr.h"
 #include "nsIServiceManager.h"
 #include "nsIAppStartup.h"
@@ -254,16 +255,42 @@ static void fpehandler(int signum, sigin
   __uint16_t *sw = &uc->uc_mcontext.fpregs->swd;
   *sw &= ~FPU_STATUS_FLAGS;
 
   __uint32_t *mxcsr = &uc->uc_mcontext.fpregs->mxcsr;
   *mxcsr |= SSE_EXCEPTION_MASK; /* disable all SSE exceptions */
   *mxcsr &= ~SSE_STATUS_FLAGS; /* clear all pending SSE exceptions */
 #endif
 #endif
+#ifdef SOLARIS
+  ucontext_t *uc = (ucontext_t *)context;
+
+#if defined(__i386)
+  uint32_t *cw = &uc->uc_mcontext.fpregs.fp_reg_set.fpchip_state.state[0];
+  *cw |= FPU_EXCEPTION_MASK;
+
+  uint32_t *sw = &uc->uc_mcontext.fpregs.fp_reg_set.fpchip_state.state[1];
+  *sw &= ~FPU_STATUS_FLAGS;
+
+  /* address of the instruction that caused the exception */
+  uint32_t *ip = &uc->uc_mcontext.fpregs.fp_reg_set.fpchip_state.state[3];
+  uc->uc_mcontext.gregs[REG_PC] = *ip;
+#endif
+#if defined(__amd64__)
+  uint16_t *cw = &uc->uc_mcontext.fpregs.fp_reg_set.fpchip_state.cw;
+  *cw |= FPU_EXCEPTION_MASK;
+
+  uint16_t *sw = &uc->uc_mcontext.fpregs.fp_reg_set.fpchip_state.sw;
+  *sw &= ~FPU_STATUS_FLAGS;
+
+  uint32_t *mxcsr = &uc->uc_mcontext.fpregs.fp_reg_set.fpchip_state.mxcsr;
+  *mxcsr |= SSE_EXCEPTION_MASK; /* disable all SSE exceptions */
+  *mxcsr &= ~SSE_STATUS_FLAGS; /* clear all pending SSE exceptions */
+#endif
+#endif
 }
 
 void InstallSignalHandlers(const char *ProgramName)
 {
   PL_strncpy(_progname,ProgramName, (sizeof(_progname)-1) );
 
   const char *gdbSleep = PR_GetEnv("MOZ_GDB_SLEEP");
   if (gdbSleep && *gdbSleep)
--- a/toolkit/xre/nsSigHandlers.h
+++ b/toolkit/xre/nsSigHandlers.h
@@ -31,17 +31,17 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
-#if defined(_M_IX86) || defined(__i386__) || defined(__amd64__)
+#if defined(_M_IX86) || defined(__i386__) || defined(__i386) || defined(__amd64__)
 
 /*
  * x87 FPU Control Word:
  *
  * 0 -> IM  Invalid Operation
  * 1 -> DM  Denormalized Operand
  * 2 -> ZM  Zero Divide
  * 3 -> OM  Overflow