arrfab / rpms / glibc

Forked from rpms/glibc 5 years ago
Clone

Blame SOURCES/glibc-aa64-setcontext.patch

147e83
Backport
147e83
147e83
37d350073888887637aa67dddf988d9c4b226032 \
147e83
  aarch64: Re-implement setcontext without rt_sigreturn syscall
147e83
03ea4d9b6916857e3c2a021f55d2a853cb837398 \
147e83
  [AArch64] Simplify getcontext pstate initialization.
147e83
6e445a3d2bdf152ebf57d1c92bfea1828e070743 \
147e83
  [AArch64] Ensure getcontext() initializes PSTATE.
147e83
147e83
147e83
diff --git glibc-2.17-c758a686/ports/sysdeps/unix/sysv/linux/aarch64/getcontext.S glibc-2.17-c758a686/ports/sysdeps/unix/sysv/linux/aarch64/getcontext.S
147e83
index aff2e32..70b2e32 100644
147e83
--- glibc-2.17-c758a686/ports/sysdeps/unix/sysv/linux/aarch64/getcontext.S
147e83
+++ glibc-2.17-c758a686/ports/sysdeps/unix/sysv/linux/aarch64/getcontext.S
147e83
@@ -1,6 +1,6 @@
147e83
 /* Save current context.
147e83
 
147e83
-   Copyright (C) 2009-2012 Free Software Foundation, Inc.
147e83
+   Copyright (C) 2009-2014 Free Software Foundation, Inc.
147e83
 
147e83
    This file is part of the GNU C Library.
147e83
 
147e83
@@ -53,6 +53,9 @@ ENTRY(__getcontext)
147e83
 	mov	x2, sp
147e83
 	str     x2, [x0, oSP]
147e83
 
147e83
+	/* Initialize the pstate.  */
147e83
+	str	xzr, [x0, oPSTATE]
147e83
+
147e83
 	/* Figure out where to place the first context extension
147e83
 	   block.  */
147e83
 	add     x2, x0, #oEXTENSION
147e83
diff --git glibc-2.17-c758a686/ports/sysdeps/unix/sysv/linux/aarch64/setcontext.S glibc-2.17-c758a686/ports/sysdeps/unix/sysv/linux/aarch64/setcontext.S
147e83
index a98f67f..f45a655 100644
147e83
--- glibc-2.17-c758a686/ports/sysdeps/unix/sysv/linux/aarch64/setcontext.S
147e83
+++ glibc-2.17-c758a686/ports/sysdeps/unix/sysv/linux/aarch64/setcontext.S
147e83
@@ -1,6 +1,6 @@
147e83
 /* Set current context.
147e83
 
147e83
-   Copyright (C) 2009-2012 Free Software Foundation, Inc.
147e83
+   Copyright (C) 2009-2014 Free Software Foundation, Inc.
147e83
 
147e83
    This file is part of the GNU C Library.
147e83
 
147e83
@@ -22,68 +22,108 @@
147e83
 #include "ucontext_i.h"
147e83
 #include "ucontext-internal.h"
147e83
 
147e83
-/* int setcontext (const ucontext_t *ucp) */
147e83
+/*  int __setcontext (const ucontext_t *ucp)
147e83
 
147e83
-	.text
147e83
-
147e83
-ENTRY(__setcontext)
147e83
-
147e83
-	/* Create a signal frame on the stack:
147e83
-
147e83
-		fp
147e83
-		lr
147e83
-		...
147e83
-	   sp-> rt_sigframe
147e83
-	 */
147e83
-
147e83
-	stp     x29, x30, [sp, -16]!
147e83
-	cfi_adjust_cfa_offset (16)
147e83
-	cfi_rel_offset (x29, 0)
147e83
-	cfi_rel_offset (x30, 8)
147e83
-
147e83
-        mov     x29, sp
147e83
-	cfi_def_cfa_register (x29)
147e83
-
147e83
-	/* Allocate space for the sigcontext.  */
147e83
-	mov	w3, #((RT_SIGFRAME_SIZE + SP_ALIGN_SIZE) & SP_ALIGN_MASK)
147e83
-	sub	sp, sp,	x3
147e83
+  Restores the machine context in UCP and thereby resumes execution
147e83
+  in that context.
147e83
 
147e83
-	/* Compute the base address of the ucontext structure.  */
147e83
-	add	x1, sp, #RT_SIGFRAME_UCONTEXT
147e83
+  This implementation is intended to be used for *synchronous* context
147e83
+  switches only.  Therefore, it does not have to restore anything
147e83
+  other than the PRESERVED state.  */
147e83
 
147e83
-	/* Only ucontext is required in the frame, *copy* it in.  */
147e83
-
147e83
-#if UCONTEXT_SIZE % 16
147e83
-#error The implementation of setcontext.S assumes sizeof(ucontext_t) % 16 == 0
147e83
-#endif
147e83
-
147e83
-	mov	x2, #UCONTEXT_SIZE / 16
147e83
-0:
147e83
-	ldp	x3, x4, [x0], #16
147e83
-	stp	x3, x4, [x1], #16
147e83
-	sub	x2, x2, 1
147e83
-	cbnz	x2, 0b
147e83
+	.text
147e83
 
147e83
-	/* rt_sigreturn () -- no arguments, sp points to struct rt_sigframe.  */
147e83
-	mov	x8, SYS_ify (rt_sigreturn)
147e83
+ENTRY (__setcontext)
147e83
+	/* Save a copy of UCP.  */
147e83
+	mov	x9, x0
147e83
+
147e83
+	/* Set the signal mask with
147e83
+	   rt_sigprocmask (SIG_SETMASK, mask, NULL, _NSIG/8).  */
147e83
+	mov	x0, #SIG_SETMASK
147e83
+	add	x1, x9, #UCONTEXT_SIGMASK
147e83
+	mov	x2, #0
147e83
+	mov	x3, #_NSIG8
147e83
+	mov	x8, SYS_ify (rt_sigprocmask)
147e83
 	svc	0
147e83
-
147e83
-	/* Ooops we failed.  Recover the stack */
147e83
-
147e83
-	mov	sp, x29
147e83
-	cfi_def_cfa_register (sp)
147e83
-
147e83
-        ldp     x29, x30, [sp], 16
147e83
-	cfi_adjust_cfa_offset (16)
147e83
-	cfi_restore (x29)
147e83
-	cfi_restore (x30)
147e83
-	b	C_SYMBOL_NAME(__syscall_error)
147e83
-
147e83
+	cbz	x0, 1f
147e83
+	b	C_SYMBOL_NAME (__syscall_error)
147e83
+1:
147e83
+	/* Restore the general purpose registers.  */
147e83
+	mov	x0, x9
147e83
+	cfi_def_cfa (x0, 0)
147e83
+	cfi_offset (x18, oX0 + 18 * SZREG)
147e83
+	cfi_offset (x19, oX0 + 19 * SZREG)
147e83
+	cfi_offset (x20, oX0 + 20 * SZREG)
147e83
+	cfi_offset (x21, oX0 + 21 * SZREG)
147e83
+	cfi_offset (x22, oX0 + 22 * SZREG)
147e83
+	cfi_offset (x23, oX0 + 23 * SZREG)
147e83
+	cfi_offset (x24, oX0 + 24 * SZREG)
147e83
+	cfi_offset (x25, oX0 + 25 * SZREG)
147e83
+	cfi_offset (x26, oX0 + 26 * SZREG)
147e83
+	cfi_offset (x27, oX0 + 27 * SZREG)
147e83
+	cfi_offset (x28, oX0 + 28 * SZREG)
147e83
+	cfi_offset (x29, oX0 + 29 * SZREG)
147e83
+	cfi_offset (x30, oX0 + 30 * SZREG)
147e83
+
147e83
+	cfi_offset ( d8, oV0 + 8 * SZVREG)
147e83
+	cfi_offset ( d9, oV0 + 9 * SZVREG)
147e83
+	cfi_offset (d10, oV0 + 10 * SZVREG)
147e83
+	cfi_offset (d11, oV0 + 11 * SZVREG)
147e83
+	cfi_offset (d12, oV0 + 12 * SZVREG)
147e83
+	cfi_offset (d13, oV0 + 13 * SZVREG)
147e83
+	cfi_offset (d14, oV0 + 14 * SZVREG)
147e83
+	cfi_offset (d15, oV0 + 15 * SZVREG)
147e83
+	ldp	x18, x19, [x0, oX0 + 18 * SZREG]
147e83
+	ldp	x20, x21, [x0, oX0 + 20 * SZREG]
147e83
+	ldp	x22, x23, [x0, oX0 + 22 * SZREG]
147e83
+	ldp	x24, x25, [x0, oX0 + 24 * SZREG]
147e83
+	ldp	x26, x27, [x0, oX0 + 26 * SZREG]
147e83
+	ldp	x28, x29, [x0, oX0 + 28 * SZREG]
147e83
+	ldr     x30,      [x0, oX0 + 30 * SZREG]
147e83
+	ldr     x2, [x0, oSP]
147e83
+	mov	sp, x2
147e83
+
147e83
+	/* Check for FP SIMD context.  We don't support restoring
147e83
+	   contexts created by the kernel, so this context must have
147e83
+	   been created by getcontext.  Hence we can rely on the
147e83
+	   first extension block being the FP SIMD context.  */
147e83
+	add     x2, x0, #oEXTENSION
147e83
+
147e83
+	mov	w3, #(FPSIMD_MAGIC & 0xffff)
147e83
+	movk	w3, #(FPSIMD_MAGIC >> 16), lsl #16
147e83
+	ldr	w1, [x2, #oHEAD + oMAGIC]
147e83
+	cmp	w1, w3
147e83
+	b.ne	2f
147e83
+
147e83
+	/* Restore the FP SIMD context.  */
147e83
+	add	x3, x2, #oV0 + 8 * SZVREG
147e83
+	ldp	 d8,  d9, [x3], #2 * SZVREG
147e83
+	ldp	d10, d11, [x3], #2 * SZVREG
147e83
+	ldp	d12, d13, [x3], #2 * SZVREG
147e83
+	ldp	d14, d15, [x3], #2 * SZVREG
147e83
+
147e83
+	add	x3, x2, oFPSR
147e83
+
147e83
+	ldr	w4, [x3]
147e83
+	msr	fpsr, x4
147e83
+
147e83
+	ldr	w4, [x3, oFPCR - oFPSR]
147e83
+	msr	fpcr, x4
147e83
+
147e83
+2:
147e83
+	ldr     x16, [x0, oPC]
147e83
+	/* Restore arg registers.  */
147e83
+	ldp	x2, x3, [x0, oX0 + 2 * SZREG]
147e83
+	ldp	x4, x5, [x0, oX0 + 4 * SZREG]
147e83
+	ldp	x6, x7, [x0, oX0 + 6 * SZREG]
147e83
+	ldp	x0, x1, [x0, oX0 + 0 * SZREG]
147e83
+	/* Jump to the new pc value.  */
147e83
+	br	x16
147e83
 PSEUDO_END (__setcontext)
147e83
 weak_alias (__setcontext, setcontext)
147e83
 
147e83
-ENTRY(__startcontext)
147e83
+ENTRY (__startcontext)
147e83
 	mov	x0, x19
147e83
 	cbnz	x0, __setcontext
147e83
-1:	b       HIDDEN_JUMPTARGET(_exit)
147e83
-END(__startcontext)
147e83
+1:	b       HIDDEN_JUMPTARGET (_exit)
147e83
+END (__startcontext)
147e83
diff --git glibc-2.17-c758a686/ports/sysdeps/unix/sysv/linux/aarch64/ucontext_i.sym glibc-2.17-c758a686/ports/sysdeps/unix/sysv/linux/aarch64/ucontext_i.sym
147e83
index 1afff78..ab3930c 100644
147e83
--- glibc-2.17-c758a686/ports/sysdeps/unix/sysv/linux/aarch64/ucontext_i.sym
147e83
+++ glibc-2.17-c758a686/ports/sysdeps/unix/sysv/linux/aarch64/ucontext_i.sym
147e83
@@ -37,6 +37,7 @@ STACK_FLAGS			stack (ss_flags)
147e83
 oX0				mcontext (regs)
147e83
 oSP				mcontext (sp)
147e83
 oPC				mcontext (pc)
147e83
+oPSTATE				mcontext (pstate)
147e83
 oEXTENSION                      mcontext (__reserved)
147e83
 
147e83
 #define fpsimd_context(member)  offsetof (struct fpsimd_context, member)