Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/winsup
diff options
context:
space:
mode:
authorJon TURNEY <jon.turney@dronecode.org.uk>2015-03-30 22:31:13 +0300
committerJon TURNEY <jon.turney@dronecode.org.uk>2015-04-01 21:09:28 +0300
commit28e457cd717d630d6ac13dba7b8f2a162156effb (patch)
treea09c609a66e5ee4b45787f22eb4d3fb6147dfbf1 /winsup
parentf992ae6f4da99b6a200cfc146b96e8e921ca1e70 (diff)
Provide ucontext to signal handlers
Add ucontext.h header, defining ucontext_t and mcontext_t types. Provide sigaction sighandlers with a ucontext_t parameter, containing stack and context information. * include/sys/ucontext.h : New header. * include/ucontext.h : Ditto. * exceptions.cc (call_signal_handler): Provide ucontext_t parameter to signal handler function. Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Diffstat (limited to 'winsup')
-rw-r--r--winsup/cygwin/ChangeLog7
-rw-r--r--winsup/cygwin/exceptions.cc23
-rw-r--r--winsup/cygwin/include/sys/ucontext.h26
-rw-r--r--winsup/cygwin/include/ucontext.h16
4 files changed, 70 insertions, 2 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index 3aa43af9e..4ed8b2f57 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,5 +1,12 @@
2015-04-01 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.
+
+2015-04-01 Jon TURNEY <jon.turney@dronecode.org.uk>
+
* external.cc (cygwin_internal): Add operation to retrieve a copy
of the EXCEPTION_RECORD from a siginfo_t *.
* include/sys/cygwin.h (cygwin_getinfo_types): Ditto.
diff --git a/winsup/cygwin/exceptions.cc b/winsup/cygwin/exceptions.cc
index af534574b..0d1f36d50 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"
@@ -1489,15 +1490,33 @@ _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;
+
sigset_t this_oldmask = set_process_mask_delta ();
+ thiscontext.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 */
- /* 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 000000000..9362d90cd
--- /dev/null
+++ b/winsup/cygwin/include/sys/ucontext.h
@@ -0,0 +1,26 @@
+/* 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 {
+ struct __ucontext *uc_link;
+ sigset_t uc_sigmask;
+ stack_t uc_stack;
+ mcontext_t uc_mcontext;
+ unsigned long int uc_flags;
+} 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 000000000..4240597b8
--- /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 */