This is the mail archive of the cygwin-patches 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]

[PATCH] Make EXCEPTION_POINTERS available to signal handlers


Add ucontext.h header, defining ucontext_t and mcontext_t types.

Provide sigaction sighandlers with a ucontext_t parameter containing a
mcontext_t with exception context information, if available.

	* include/sys/ucontext.h (__ucontext): New header.
	* include/ucontext.h (_UCONTEXT_H): Ditto.
	* exception.h (cygwin_exception): Add exception_record accessor.
	* exceptions.cc (call_signal_handler): Provide ucontext_t
	parameter to signal handler function, if available.

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
---
 winsup/cygwin/ChangeLog              |  8 ++++++++
 winsup/cygwin/exception.h            |  1 +
 winsup/cygwin/exceptions.cc          | 16 ++++++++++++++--
 winsup/cygwin/include/sys/ucontext.h | 27 +++++++++++++++++++++++++++
 winsup/cygwin/include/ucontext.h     | 16 ++++++++++++++++
 5 files changed, 66 insertions(+), 2 deletions(-)
 create mode 100644 winsup/cygwin/include/sys/ucontext.h
 create mode 100644 winsup/cygwin/include/ucontext.h

diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index 869beee..ce09390 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,3 +1,11 @@
+2015-03-26  Jon TURNEY  <jon.turney@dronecode.org.uk>
+
+	* include/sys/ucontext.h (__ucontext): New header.
+	* include/ucontext.h (_UCONTEXT_H): Ditto.
+	* exception.h (cygwin_exception): Add exception_record accessor.
+	* exceptions.cc (call_signal_handler): Provide ucontext_t
+	parameter to signal handler function, if available.
+
 2015-03-25  Corinna Vinschen  <corinna@vinschen.de>
 
 	* include/sys/termios.h: Add CMIN and CTIME.
diff --git a/winsup/cygwin/exception.h b/winsup/cygwin/exception.h
index 3686bb0..0478daf 100644
--- a/winsup/cygwin/exception.h
+++ b/winsup/cygwin/exception.h
@@ -175,4 +175,5 @@ public:
     framep (in_framep), ctx (in_ctx), e (in_e), h (NULL) {}
   void dumpstack ();
   PCONTEXT context () const {return ctx;}
+  EXCEPTION_RECORD *exception_record () const {return e;}
 };
diff --git a/winsup/cygwin/exceptions.cc b/winsup/cygwin/exceptions.cc
index 3af9a54..33ff989 100644
--- a/winsup/cygwin/exceptions.cc
+++ b/winsup/cygwin/exceptions.cc
@@ -16,6 +16,7 @@ details. */
 #include <stdlib.h>
 #include <syslog.h>
 #include <wchar.h>
+#include <ucontext.h>
 
 #include "cygtls.h"
 #include "pinfo.h"
@@ -1487,8 +1488,20 @@ _cygtls::call_signal_handler ()
       /* Save information locally on stack to pass to handler. */
       int thissig = sig;
       siginfo_t thissi = infodata;
+      ucontext_t *thiscontext = NULL;
       void (*thisfunc) (int, siginfo_t *, void *) = func;
 
+      ucontext_t context;
+      memset(&context, 0, sizeof(ucontext_t)); /* no ucontext_t information provided yet */
+      EXCEPTION_POINTERS ep;
+      if (thissi.si_cyg)
+        {
+          ep.ExceptionRecord = ((cygwin_exception *)thissi.si_cyg)->exception_record();
+          ep.ContextRecord = ((cygwin_exception *)thissi.si_cyg)->context();
+          context.uc_mcontext.ep = &ep;
+          thiscontext = &context;
+        }
+
       sigset_t this_oldmask = set_process_mask_delta ();
       int this_errno = saved_errno;
       reset_signal_arrived ();
@@ -1496,8 +1509,7 @@ _cygtls::call_signal_handler ()
       sig = 0;		/* Flag that we can accept another signal */
       unlock ();	/* unlock signal stack */
 
-      /* no ucontext_t information provided yet, so third arg is NULL */
-      thisfunc (thissig, &thissi, NULL);
+      thisfunc (thissig, &thissi, thiscontext);
       incyg = true;
 
       set_signal_mask (_my_tls.sigmask, this_oldmask);
diff --git a/winsup/cygwin/include/sys/ucontext.h b/winsup/cygwin/include/sys/ucontext.h
new file mode 100644
index 0000000..a44f854
--- /dev/null
+++ b/winsup/cygwin/include/sys/ucontext.h
@@ -0,0 +1,27 @@
+/* ucontext.h
+
+   Copyright 2015 Red Hat, Inc.
+
+This file is part of Cygwin.
+
+This software is a copyrighted work licensed under the terms of the
+Cygwin license.  Please consult the file "CYGWIN_LICENSE" for
+details. */
+
+#ifndef _SYS_UCONTEXT_H_
+#define _SYS_UCONTEXT_H_
+
+#include <signal.h>
+
+typedef struct __mcontext {
+	EXCEPTION_POINTERS *ep;
+} mcontext_t;
+
+typedef struct __ucontext {
+	struct __ucontext *uc_link;
+	sigset_t	uc_sigmask;
+	// We don't have a type stack_t, so we don't have a uc_stack member
+	mcontext_t	uc_mcontext;
+} ucontext_t;
+
+#endif /* !_SYS_UCONTEXT_H_ */
diff --git a/winsup/cygwin/include/ucontext.h b/winsup/cygwin/include/ucontext.h
new file mode 100644
index 0000000..4240597
--- /dev/null
+++ b/winsup/cygwin/include/ucontext.h
@@ -0,0 +1,16 @@
+/* ucontext.h
+
+   Copyright 2015 Red Hat, Inc.
+
+This file is part of Cygwin.
+
+This software is a copyrighted work licensed under the terms of the
+Cygwin license.  Please consult the file "CYGWIN_LICENSE" for
+details. */
+
+#ifndef _UCONTEXT_H
+#define _UCONTEXT_H
+
+#include <sys/ucontext.h>
+
+#endif /* _UCONTEXT_H */
-- 
2.1.4


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