Package: glibc / 2.30-2

hurd-i386/git-ONSTACK.diff Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
From: Samuel Thibault <samuel.thibault@ens-lyon.org>
Subject: [PATCH] Fix SS_ONSTACK support

* sysdeps/mach/hurd/i386/sigreturn.c (__sigreturn2): New function,
unlocks SS and returns to the saved PC.
(__sigreturn): Do not unlock SS, and "return" into __sigreturn2 on the
thread stack instead of the saved PC.

---
 sysdeps/mach/hurd/i386/sigreturn.c | 68 +++++++++++++++++++++++---------------
 1 file changed, 42 insertions(+), 26 deletions(-)

diff --git a/sysdeps/mach/hurd/i386/sigreturn.c b/sysdeps/mach/hurd/i386/sigreturn.c
index 83c0246..204bd47 100644
--- a/sysdeps/mach/hurd/i386/sigreturn.c
+++ b/sysdeps/mach/hurd/i386/sigreturn.c
@@ -24,6 +24,36 @@ register int *sp asm ("%esp");
 #include <stdlib.h>
 #include <string.h>
 
+/* This is run on the thread stack after restoring it, to be able to
+   unlock SS off sigstack.  */
+static void
+__sigreturn2 (int *usp)
+{
+  struct hurd_sigstate *ss = _hurd_self_sigstate ();
+  __spin_unlock (&ss->lock);
+
+  sp = usp;
+#define A(line) asm volatile (#line)
+  /* The members in the sigcontext are arranged in this order
+     so we can pop them easily.  */
+
+  /* Pop the segment registers (except %cs and %ss, done last).  */
+  A (popl %gs);
+  A (popl %fs);
+  A (popl %es);
+  A (popl %ds);
+  /* Pop the general registers.  */
+  A (popa);
+  /* Pop the processor flags.  */
+  A (popf);
+  /* Return to the saved PC.  */
+  A (ret);
+
+  /* Firewall.  */
+  A (hlt);
+#undef A
+}
+
 int
 __sigreturn (struct sigcontext *scp)
 {
@@ -67,13 +97,7 @@ __sigreturn (struct sigcontext *scp)
     }
 
   if (scp->sc_onstack)
-    {
-      ss->sigaltstack.ss_flags &= ~SS_ONSTACK;
-      /* XXX cannot unlock until off sigstack */
-      abort ();
-    }
-  else
-    __spin_unlock (&ss->lock);
+    ss->sigaltstack.ss_flags &= ~SS_ONSTACK;
 
   /* Destroy the MiG reply port used by the signal handler, and restore the
      reply port in use by the thread when interrupted.  */
@@ -108,27 +132,19 @@ __sigreturn (struct sigcontext *scp)
     *--usp = scp->sc_efl;
     memcpy (usp -= 12, &scp->sc_i386_thread_state, 12 * sizeof (int));
 
-    sp = usp;
-
-#define A(line) asm volatile (#line)
-    /* The members in the sigcontext are arranged in this order
-       so we can pop them easily.  */
-
-    /* Pop the segment registers (except %cs and %ss, done last).  */
-    A (popl %gs);
-    A (popl %fs);
-    A (popl %es);
-    A (popl %ds);
-    /* Pop the general registers.  */
-    A (popa);
-    /* Pop the processor flags.  */
-    A (popf);
-    /* Return to the saved PC.  */
-    A (ret);
+    /* Pass usp to __sigreturn2 so it can unwind itself easily.  */
+    *(usp-1) = (int) usp;
+    --usp;
+    /* Bogus return address for __sigreturn2 */
+    *--usp = 0;
+    *--usp = (int) __sigreturn2;
 
+    /* Restore thread stack */
+    sp = usp;
+    /* Return into __sigreturn2.  */
+    asm volatile ("ret");
     /* Firewall.  */
-    A (hlt);
-#undef A
+    asm volatile ("hlt");
   }
 
   /* NOTREACHED */
-- 
tg: (ab44f81..) t/ONSTACK (depends on: t/tls-threadvar t/hurdsig-global-dispositions)