Add a debug check for a non-empty FPU stack on x86 (see #4914)
authorSimon Marlow <marlowsd@gmail.com>
Wed, 30 Mar 2011 10:19:34 +0000 (10:19 +0000)
committerSimon Marlow <marlowsd@gmail.com>
Wed, 30 Mar 2011 10:19:34 +0000 (10:19 +0000)
rts/RtsStartup.c
rts/RtsUtils.c
rts/RtsUtils.h

index bc169ff..266c048 100644 (file)
@@ -345,6 +345,11 @@ hs_exit_(rtsBool wait_foreign)
     
     OnExitHook();
 
+    // sanity check
+#if defined(DEBUG)
+    checkFPUStack();
+#endif
+
     // Free the full argv storage
     freeFullProgArgv();
 
index 3df688f..8ef6c0d 100644 (file)
@@ -323,3 +323,18 @@ int rts_isProfiled(void)
     return 0;
 #endif
 }
+
+// Used for detecting a non-empty FPU stack on x86 (see #4914)
+void checkFPUStack(void)
+{
+#ifdef x86_HOST_ARCH
+    static unsigned char buf[108];
+    asm("FSAVE %0":"=m" (buf));
+
+    if(buf[8]!=255 || buf[9]!=255) {
+        errorBelch("NONEMPTY FPU Stack, TAG = %x %x\n",buf[8],buf[9]);
+        abort();
+    }
+#endif
+}
+
index 1bf840b..b571126 100644 (file)
@@ -46,6 +46,8 @@ void printRtsInfo(void);
 /* Alternate to raise(3) for threaded rts, for OpenBSD */
 int genericRaise(int sig);
 
+void checkFPUStack(void);
+
 #include "EndPrivate.h"
 
 #endif /* RTSUTILS_H */