This is the mail archive of the cygwin-cvs@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[newlib-cygwin] Fix ucontext creation in call_signal handler


https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=b2df1577c7b62d9f6f9c06f41037e9bd09f2174d

commit b2df1577c7b62d9f6f9c06f41037e9bd09f2174d
Author: Corinna Vinschen <corinna@vinschen.de>
Date:   Fri Jul 17 18:29:52 2015 +0200

    Fix ucontext creation in call_signal handler
    
            * exceptions.cc (__unwind_single_frame): Define empty macro on i686.
            (_cygtls::call_signal_handler): Try to make sure signal context makes
            sense in case we're generating context here.  Add comment to explain.
    
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>

Diff:
---
 winsup/cygwin/ChangeLog     |  6 ++++++
 winsup/cygwin/exceptions.cc | 19 +++++++++++++++----
 2 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index 65adef5..eb89f67 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,5 +1,11 @@
 2015-07-17  Corinna Vinschen  <corinna@vinschen.de>
 
+	* exceptions.cc (__unwind_single_frame): Define empty macro on i686.
+	(_cygtls::call_signal_handler): Try to make sure signal context makes
+	sense in case we're generating context here.  Add comment to explain.
+
+2015-07-17  Corinna Vinschen  <corinna@vinschen.de>
+
 	* exceptions.cc (getcontext/x86_64): Drop comment on RtlCaptureContext.
 	(swapcontext/x86_64): Fix comment yet again.
 	(getcontext/i686): Move comment from x86_64 getcontext, slightly
diff --git a/winsup/cygwin/exceptions.cc b/winsup/cygwin/exceptions.cc
index 6e9890e..d69dbf7 100644
--- a/winsup/cygwin/exceptions.cc
+++ b/winsup/cygwin/exceptions.cc
@@ -300,6 +300,8 @@ __unwind_single_frame (PCONTEXT ctx)
       ctx->Rsp += 8;
     }
 }
+#else
+#define __unwind_single_frame(ctx)
 #endif
 
 /* Walk the stack.
@@ -1667,11 +1669,20 @@ _cygtls::call_signal_handler ()
 		    sizeof (CONTEXT));
 	  else
 	    {
-	      /* FIXME: Really this should be the context which the signal
-		 interrupted? */
-	      memset(&context.uc_mcontext, 0, sizeof (struct __mcontext));
+	      /* Software-generated signal.  We're fetching the current
+		 context, unwind to the caller and in case we're called
+		 from sigdelayed, fix rip/eip accordingly. */
 	      context.uc_mcontext.ctxflags = CONTEXT_FULL;
-	      RtlCaptureContext ((CONTEXT *) &context.uc_mcontext);
+	      RtlCaptureContext ((PCONTEXT) &context.uc_mcontext);
+	      __unwind_single_frame ((PCONTEXT) &context.uc_mcontext);
+	      if (stackptr > stack)
+		{
+#ifdef __x86_64__
+		  context.uc_mcontext.rip = retaddr ();
+#else
+		  context.uc_mcontext.eip = retaddr ();
+#endif
+		}
 	    }
 
 	  if (this_sa_flags & SA_ONSTACK


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