This is the mail archive of the
cygwin-patches
mailing list for the Cygwin project.
[PATCH 2/2] Make CONTEXT available to signal handlers
- From: Jon TURNEY <jon dot turney at dronecode dot org dot uk>
- To: cygwin-patches at cygwin dot com
- Cc: Jon TURNEY <jon dot turney at dronecode dot org dot uk>
- Date: Mon, 30 Mar 2015 18:32:37 +0100
- Subject: [PATCH 2/2] Make CONTEXT available to signal handlers
- Authentication-results: sourceware.org; auth=none
- References: <20150330102129 dot GH29875 at calimero dot vinschen dot de> <1427736757-13884-1-git-send-email-jon dot turney at dronecode dot org dot uk>
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 : New header.
* include/ucontext.h : Ditto.
* exceptions.cc (call_signal_handler): Provide ucontext_t
parameter to signal handler function, if available.
---
winsup/cygwin/ChangeLog | 7 +++++++
winsup/cygwin/exceptions.cc | 13 +++++++++++--
winsup/cygwin/include/sys/ucontext.h | 22 ++++++++++++++++++++++
winsup/cygwin/include/ucontext.h | 16 ++++++++++++++++
4 files changed, 56 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 cfc29a8..8da5fa2 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,5 +1,12 @@
2015-03-30 Jon TURNEY <jon.turney@dronecode.org.uk>
+ * include/sys/ucontext.h : New header.
+ * include/ucontext.h : Ditto.
+ * exceptions.cc (call_signal_handler): Provide ucontext_t
+ parameter to signal handler function, if available.
+
+2015-03-30 Jon TURNEY <jon.turney@dronecode.org.uk>
+
* include/cygwin/signal.h : Rename struct ucontext to struct mcontext.
Remove unused member oldmask and simplify __COPY_CONTEXT_SIZE.
diff --git a/winsup/cygwin/exceptions.cc b/winsup/cygwin/exceptions.cc
index af53457..80899d1 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,17 @@ _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 */
+ if (thissi.si_cyg)
+ {
+ memcpy(&context.uc_mcontext, ((cygwin_exception *)thissi.si_cyg)->context(), sizeof(CONTEXT));
+ thiscontext = &context;
+ }
+
sigset_t this_oldmask = set_process_mask_delta ();
int this_errno = saved_errno;
reset_signal_arrived ();
@@ -1496,8 +1506,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..df9b32b
--- /dev/null
+++ b/winsup/cygwin/include/sys/ucontext.h
@@ -0,0 +1,22 @@
+/* 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 mcontext_t;
+
+typedef struct ucontext {
+ 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