public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
* [PATCH] Only construct ucontext for SA_SIGINFO signal handlers
@ 2015-04-02 19:30 Jon TURNEY
  2015-04-03 11:18 ` Corinna Vinschen
  0 siblings, 1 reply; 6+ messages in thread
From: Jon TURNEY @ 2015-04-02 19:30 UTC (permalink / raw)
  To: cygwin-patches; +Cc: Jon TURNEY

	* exceptions.cc (call_signal_handler): Only bother to construct
	the ucontext for signal handlers with SA_SIGINFO set.

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
---
 winsup/cygwin/ChangeLog     |  5 +++++
 winsup/cygwin/exceptions.cc | 46 ++++++++++++++++++++++++++-------------------
 2 files changed, 32 insertions(+), 19 deletions(-)

diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index 3b0e111..0ddc795 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,5 +1,10 @@
 2015-04-02  Jon TURNEY  <jon.turney@dronecode.org.uk>
 
+	* exceptions.cc (call_signal_handler): Only bother to construct
+	the ucontext for signal handlers with SA_SIGINFO set.
+
+2015-04-02  Jon TURNEY  <jon.turney@dronecode.org.uk>
+
 	* include/cygwin/signal.h (struct __mcontext): 16-byte align.
 	* include/sys/ucontext.h (ucontext_t): Ditto.
 
diff --git a/winsup/cygwin/exceptions.cc b/winsup/cygwin/exceptions.cc
index 0d1f36d..bac550c 100644
--- a/winsup/cygwin/exceptions.cc
+++ b/winsup/cygwin/exceptions.cc
@@ -1490,33 +1490,41 @@ _cygtls::call_signal_handler ()
       siginfo_t thissi = infodata;
       void (*thisfunc) (int, siginfo_t *, void *) = func;
 
-      ucontext_t thiscontext;
-      thiscontext.uc_link = 0;
-      thiscontext.uc_flags = 0;
-      if (thissi.si_cyg)
-        memcpy (&thiscontext.uc_mcontext, ((cygwin_exception *)thissi.si_cyg)->context(), sizeof(CONTEXT));
-      else
-        RtlCaptureContext ((CONTEXT *)&thiscontext.uc_mcontext);
-        /* FIXME: Really this should be the context which the signal interrupted? */
-
-      /* FIXME: If/when sigaltstack is implemented, this will need to do
-         something more complicated */
-      thiscontext.uc_stack.ss_sp = NtCurrentTeb ()->Tib.StackBase;
-      thiscontext.uc_stack.ss_flags = 0;
-      if (!NtCurrentTeb ()->DeallocationStack)
-        thiscontext.uc_stack.ss_size = (uintptr_t)NtCurrentTeb ()->Tib.StackLimit - (uintptr_t)NtCurrentTeb ()->Tib.StackBase;
-      else
-        thiscontext.uc_stack.ss_size = (uintptr_t)NtCurrentTeb ()->DeallocationStack - (uintptr_t)NtCurrentTeb ()->Tib.StackBase;
+      ucontext_t context;
+      ucontext_t *thiscontext = NULL;
+
+      /* Only make a context for SA_SIGINFO handlers */
+      if (this_sa_flags & SA_SIGINFO)
+        {
+          context.uc_link = 0;
+          context.uc_flags = 0;
+          if (thissi.si_cyg)
+            memcpy (&context.uc_mcontext, ((cygwin_exception *)thissi.si_cyg)->context(), sizeof(CONTEXT));
+          else
+            RtlCaptureContext ((CONTEXT *)&context.uc_mcontext);
+            /* FIXME: Really this should be the context which the signal interrupted? */
+
+          /* FIXME: If/when sigaltstack is implemented, this will need to do
+             something more complicated */
+          context.uc_stack.ss_sp = NtCurrentTeb ()->Tib.StackBase;
+          context.uc_stack.ss_flags = 0;
+          if (!NtCurrentTeb ()->DeallocationStack)
+            context.uc_stack.ss_size = (uintptr_t)NtCurrentTeb ()->Tib.StackLimit - (uintptr_t)NtCurrentTeb ()->Tib.StackBase;
+          else
+            context.uc_stack.ss_size = (uintptr_t)NtCurrentTeb ()->DeallocationStack - (uintptr_t)NtCurrentTeb ()->Tib.StackBase;
+
+          thiscontext = &context;
+        }
 
       sigset_t this_oldmask = set_process_mask_delta ();
-      thiscontext.uc_sigmask = this_oldmask;
+      context.uc_sigmask = this_oldmask;
       int this_errno = saved_errno;
       reset_signal_arrived ();
       incyg = false;
       sig = 0;		/* Flag that we can accept another signal */
       unlock ();	/* unlock signal stack */
 
-      thisfunc (thissig, &thissi, &thiscontext);
+      thisfunc (thissig, &thissi, thiscontext);
       incyg = true;
 
       set_signal_mask (_my_tls.sigmask, this_oldmask);
-- 
2.1.4

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-04-04 16:07 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-02 19:30 [PATCH] Only construct ucontext for SA_SIGINFO signal handlers Jon TURNEY
2015-04-03 11:18 ` Corinna Vinschen
2015-04-03 12:17   ` Corinna Vinschen
2015-04-03 12:51     ` Jon TURNEY
2015-04-03 14:08       ` Corinna Vinschen
2015-04-04 16:07         ` Jon TURNEY

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).