diff mbox series

[v2,10/21] nptl: s390: Fix Race conditions in pthread cancellation (BZ#12683)

Message ID 1519679016-12241-11-git-send-email-adhemerval.zanella@linaro.org
State New
Headers show
Series nptl: Fix Race conditions in pthread cancellation (BZ#12683) | expand

Commit Message

Adhemerval Zanella Feb. 26, 2018, 9:03 p.m. UTC
From: Adhemerval Zanella <adhemerval.zanella@linaro.com>


This patch adds the s390 modifications required for the BZ#12683 fix.
It basically adds the required ucontext_get_pc function.

The built cancelable syscall wrapper for s390 using GCC 7.2.1 and
default configuration flags shows the wrappers on expected corrected
places:

---
__GI___syscall_cancel_arch:
.LFB39:
        .cfi_startproc
        stm     %r6,%r15,24(%r15)
        .cfi_offset 6, -72
        .cfi_offset 7, -68
        .cfi_offset 8, -64
        .cfi_offset 9, -60
        .cfi_offset 10, -56
        .cfi_offset 11, -52
        .cfi_offset 12, -48
        .cfi_offset 13, -44
        .cfi_offset 14, -40
        .cfi_offset 15, -36
        ahi     %r15,-96
        .cfi_def_cfa_offset 192

        .global __syscall_cancel_arch_start
.type __syscall_cancel_arch_start,@function
__syscall_cancel_arch_start:
        l       %r0,0(%r2)
        tml     %r0,4
        jne     .L5
        lr      %r1,%r3
        lr      %r2,%r4
        lr      %r3,%r5
        lr      %r4,%r6
        l       %r5,192(%r15)
        l       %r6,196(%r15)
        l       %r7,200(%r15)
        svc    0

        .global __syscall_cancel_arch_end
.type __syscall_cancel_arch_end,@function
__syscall_cancel_arch_end:
        l       %r4,152(%r15)
        lm      %r6,%r15,120(%r15)
        .cfi_remember_state
        .cfi_restore 15
        .cfi_restore 14
        .cfi_restore 13
        .cfi_restore 12
        .cfi_restore 11
        .cfi_restore 10
        .cfi_restore 9
        .cfi_restore 8
        .cfi_restore 7
        .cfi_restore 6
        .cfi_def_cfa_offset 96
        br      %r4
.L5:
        .cfi_restore_state
        brasl   %r14,__syscall_do_cancel
        .cfi_endproc
---

The s390x version also shows similar placement:

---
__GI___syscall_cancel_arch:
        .cfi_startproc
        stmg    %r6,%r15,48(%r15)
        .cfi_offset 6, -112
        .cfi_offset 7, -104
        .cfi_offset 8, -96
        .cfi_offset 9, -88
        .cfi_offset 10, -80
        .cfi_offset 11, -72
        .cfi_offset 12, -64
        .cfi_offset 13, -56
        .cfi_offset 14, -48
        .cfi_offset 15, -40
        aghi    %r15,-160
        .cfi_def_cfa_offset 320

        .global __syscall_cancel_arch_start
.type __syscall_cancel_arch_start,@function
__syscall_cancel_arch_start:
        l       %r0,0(%r2)
        tmll    %r0,4
        jne     .L5
        lgr     %r1,%r3
        lgr     %r2,%r4
        lgr     %r3,%r5
        lgr     %r4,%r6
        lg      %r5,320(%r15)
        lg      %r6,328(%r15)
        lg      %r7,336(%r15)
        svc    0

        .global __syscall_cancel_arch_end
.type __syscall_cancel_arch_end,@function
__syscall_cancel_arch_end:
        lg      %r4,272(%r15)
        lmg     %r6,%r15,208(%r15)
        .cfi_remember_state
        .cfi_restore 15
        .cfi_restore 14
        .cfi_restore 13
        .cfi_restore 12
        .cfi_restore 11
        .cfi_restore 10
        .cfi_restore 9
        .cfi_restore 8
        .cfi_restore 7
        .cfi_restore 6
        .cfi_def_cfa_offset 160
        br      %r4
.L5:
        .cfi_restore_state
        brasl   %r14,__syscall_do_cancel
        .cfi_endproc
---

Checked with a s390-linux-gnu and s390x-linux-gnu build with
run-tests-built=no.

	[BZ #12683]
	* sysdeps/unix/sysv/linux/s390/sigcontextinfo.h (ucontext_get_pc):
	New function.
---
 ChangeLog                                     |  5 ++++-
 sysdeps/unix/sysv/linux/s390/sigcontextinfo.h | 17 +++++++++++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)

-- 
2.7.4
diff mbox series

Patch

diff --git a/sysdeps/unix/sysv/linux/s390/sigcontextinfo.h b/sysdeps/unix/sysv/linux/s390/sigcontextinfo.h
index 2533e63..89e6c47 100644
--- a/sysdeps/unix/sysv/linux/s390/sigcontextinfo.h
+++ b/sysdeps/unix/sysv/linux/s390/sigcontextinfo.h
@@ -16,7 +16,11 @@ 
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#ifndef _SIGCONTEXTINFO_H
+#define _SIGCONTEXTINFO_H
+
 #include <signal.h>
+#include <stdint.h>
 
 #define SIGCONTEXT struct sigcontext *
 #define SIGCONTEXT_EXTRA_ARGS
@@ -25,3 +29,16 @@ 
 #define GET_STACK(ctx)	((void *)((ctx)->sregs->regs.gprs[15]))
 #define CALL_SIGHANDLER(handler, signo, ctx) \
   (handler)((signo), SIGCONTEXT_EXTRA_ARGS (ctx))
+
+static inline uintptr_t
+ucontext_get_pc (const ucontext_t *uc)
+{
+#ifdef __s390x__
+  return uc->uc_mcontext.psw.addr;
+#else
+  /* We have 31bit addresses, remove bit 0.  */
+  return uc->uc_mcontext.psw.addr & 0x7FFFFFFF;
+#endif
+}
+
+#endif