[project @ 1997-10-05 20:28:54 by sof]
authorsof <unknown>
Sun, 5 Oct 1997 20:28:54 +0000 (20:28 +0000)
committersof <unknown>
Sun, 5 Oct 1997 20:28:54 +0000 (20:28 +0000)
Use GetThreadContext() to fish out faulting address for segv handlers under cygwin32

ghc/runtime/main/Signals.lc

index 97fb56b..f473cae 100644 (file)
@@ -206,24 +206,28 @@ install_segv_handler(STG_NO_ARGS)
 # elif defined(cygwin32_TARGET_OS)
 
 /*
- The signal handlers in cygwin32 (beta14) are only passed the signal
+ The signal handlers in cygwin32  are only passed the signal
  number, no sigcontext/siginfo is passed as event data..sigh. For
  SIGSEGV, to get at the violating address, we need to use the Win32's
- WaitForDebugEvent() to get out any status information. 
+ GetThreadContext() to get at the faulting address.
 */
 static void
 segv_handler(sig)
  int sig;
 {
-    /* From gdb/win32-nat.c */
-    DEBUG_EVENT event;
-    BOOL t = WaitForDebugEvent (&event, INFINITE);
+    CONTEXT context;
+    HANDLE hThread;
+    BOOL t;
+
+    context.ContextFlags = CONTEXT_CONTROL;
+    hThread = GetCurrentThread(); /* cannot fail */
+    t = GetThreadContext(hThread,&context);
 
     fflush(stdout);
     if (t == FALSE) {
         fprintf(stderr, "Segmentation fault caught, address unknown\n");
     } else {
-        void *si_addr = event.u.Exception.ExceptionRecord.ExceptionAddress;
+        void *si_addr = context.Eip; /* magic */
         if (si_addr >= (void *) stks_space
           && si_addr < (void *) (stks_space + RTSflags.GcFlags.stksSize))
             StackOverflow();
@@ -239,7 +243,6 @@ install_segv_handler()
     return (int) signal(SIGSEGV, segv_handler) == -1;
 }
 
-
 # else /* ! (cygwin32|irix6|sunos4|linux*|*bsd|aix) */
 
 #  if defined(irix_TARGET_OS)