diff mbox series

[hurd,commited] hurd: Fix SS_ONSTACK support

Message ID 20190829234913.32035-1-samuel.thibault@ens-lyon.org
State New
Headers show
Series [hurd,commited] hurd: Fix SS_ONSTACK support | expand

Commit Message

Samuel Thibault Aug. 29, 2019, 11:49 p.m. UTC
* 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.
---
 ChangeLog                          |  5 +++
 sysdeps/mach/hurd/i386/sigreturn.c | 68 ++++++++++++++++++------------
 2 files changed, 47 insertions(+), 26 deletions(-)

Comments

Joseph Myers Aug. 30, 2019, 4:26 p.m. UTC | #1
I'm seeing build failures with build-many-glibcs.py:

../sysdeps/mach/hurd/i386/sigreturn.c: In function '__sigreturn2':
../sysdeps/mach/hurd/i386/sigreturn.c:33:18: error: passing argument 1 of 
'__spin_unlock' from incompatible pointer type 
[-Werror=incompatible-pointer-types]
   __spin_unlock (ss);
                  ^~
In file included from ../sysdeps/mach/include/lock-intern.h:2,
                 from ../mach/spin-lock.h:22,
                 from 
/scratch/jmyers/glibc-bot/install/compilers/i686-gnu/sysroot/include/cthreads.h:344,
                 from ../hurd/hurd/signal.h:40,
                 from ../sysdeps/hurd/include/hurd/signal.h:7,
                 from ../hurd/hurd/userlink.h:29,
                 from ../hurd/hurd/port.h:25,
                 from ../sysdeps/hurd/include/hurd/port.h:2,
                 from ../hurd/hurd.h:41,
                 from ../sysdeps/hurd/include/hurd.h:2,
                 from ../sysdeps/mach/hurd/i386/sigreturn.c:20:
../mach/lock-intern.h:69:31: note: expected '__spin_lock_t *' {aka 
'unsigned int *'} but argument is of type 'struct hurd_sigstate *'
 __spin_unlock (__spin_lock_t *__lock)
                ~~~~~~~~~~~~~~~^~~~~~

https://sourceware.org/ml/libc-testresults/2019-q3/msg00250.html
https://sourceware.org/ml/libc-testresults/2019-q3/msg00251.html
Samuel Thibault Aug. 30, 2019, 4:31 p.m. UTC | #2
Joseph Myers, le ven. 30 août 2019 16:26:29 +0000, a ecrit:
> I'm seeing build failures with build-many-glibcs.py:
> 
> ../sysdeps/mach/hurd/i386/sigreturn.c: In function '__sigreturn2':
> ../sysdeps/mach/hurd/i386/sigreturn.c:33:18: error: passing argument 1 of 
> '__spin_unlock' from incompatible pointer type 
> [-Werror=incompatible-pointer-types]
>    __spin_unlock (ss);

Ah, sorry, that was indeed a last-minute merge fix which went wrong.  I
have pushed a fix.

Samuel
diff mbox series

Patch

diff --git a/ChangeLog b/ChangeLog
index 98a86369d5..12d183dbc3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -24,6 +24,11 @@ 
 	* sysdeps/mach/hurd/mmap.c (__mmap): Remove optimizing anonymous maps
 	as __vm_allocate.
 
+	* 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.
+
 2019-08-30  Richard Braun  <rbraun@sceen.net>
 
 	* hurd/hurdselect.c (_hurd_select): Always call __io_select with no
diff --git a/sysdeps/mach/hurd/i386/sigreturn.c b/sysdeps/mach/hurd/i386/sigreturn.c
index be7153e202..c9eaf96f7d 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);
+
+  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 */