[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[patches] Fix ARM signal unwinding for newer kernels



The ARM signal frame layout changed in kernel version 2.6.18, and for EABI 
unwinding from signal handlers depends on unwind information in libc 
matching the kernel's signal frame layout.

I've applied this patch to make libc support both old and new layouts 
depending on the kernel version at runtime, with --enable-kernel=2.6.18 
reducing things back to a single function for each of realtime and 
non-realtime signal frames.

Index: sysdeps/unix/sysv/linux/arm/kernel-features.h
===================================================================
--- sysdeps/unix/sysv/linux/arm/kernel-features.h	(revision 2135)
+++ sysdeps/unix/sysv/linux/arm/kernel-features.h	(working copy)
@@ -46,4 +46,9 @@
 # define __ASSUME_VFORK_SYSCALL		1
 #endif
 
+/* The signal frame layout changed in 2.6.18.  */
+#if __LINUX_KERNEL_VERSION >= 132626
+# define __ASSUME_SIGFRAME_V2	1
+#endif
+
 #include_next <kernel-features.h>
Index: sysdeps/unix/sysv/linux/arm/sigaction.c
===================================================================
--- sysdeps/unix/sysv/linux/arm/sigaction.c	(revision 2135)
+++ sysdeps/unix/sysv/linux/arm/sigaction.c	(working copy)
@@ -36,8 +36,27 @@
 
 #define SA_RESTORER	0x04000000
 
+#ifdef __ARM_EABI__
+extern void __default_sa_restorer_v1(void);
+extern void __default_sa_restorer_v2(void);
+extern void __default_rt_sa_restorer_v1(void);
+extern void __default_rt_sa_restorer_v2(void);
+# ifdef __ASSUME_SIGFRAME_V2
+#  define __default_sa_restorer __default_sa_restorer_v2
+#  define __default_rt_sa_restorer __default_rt_sa_restorer_v2
+# else
+#  include <ldsodefs.h>
+#  define __default_sa_restorer (GLRO(dl_osversion) >= 0x020612	\
+				 ? __default_sa_restorer_v2	\
+				 : __default_sa_restorer_v1)
+#  define __default_rt_sa_restorer (GLRO(dl_osversion) >= 0x020612	\
+				    ? __default_rt_sa_restorer_v2	\
+				    : __default_rt_sa_restorer_v1)
+# endif
+#else
 extern void __default_sa_restorer(void);
 extern void __default_rt_sa_restorer(void);
+#endif
 
 /* When RT signals are in use we need to use a different return stub.  */
 #ifdef __NR_rt_sigreturn
Index: sysdeps/unix/sysv/linux/arm/eabi/sigrestorer.S
===================================================================
--- sysdeps/unix/sysv/linux/arm/eabi/sigrestorer.S	(revision 2135)
+++ sysdeps/unix/sysv/linux/arm/eabi/sigrestorer.S	(working copy)
@@ -29,26 +29,51 @@
 
    Start the unwind tables at least one instruction before the signal
    trampoline, because the unwinder will assume we are returning after
-   a call site.  */
+   a call site.
 
+   Because the signal frame layout changed in 2.6.18, we provide two
+   copies of these functions with different unwind information.  */
+
+#ifndef __ASSUME_SIGFRAME_V2
 	.fnstart
 	.save {r0-r15}
 	.pad #12
 	nop
-ENTRY(__default_sa_restorer)
+ENTRY(__default_sa_restorer_v1)
 	mov	r7, $SYS_ify(sigreturn)
 	swi	0x0
 	.fnend
+#endif
 
+	.fnstart
+	.save {r0-r15}
+	.pad #32
+	nop
+ENTRY(__default_sa_restorer_v2)
+	mov	r7, $SYS_ify(sigreturn)
+	swi	0x0
+	.fnend
+
 #ifdef __NR_rt_sigreturn
 
+#ifndef __ASSUME_SIGFRAME_V2
 	.fnstart
 	.save {r0-r15}
 	.pad #168
 	nop
-ENTRY(__default_rt_sa_restorer)
+ENTRY(__default_rt_sa_restorer_v1)
 	mov	r7, $SYS_ify(rt_sigreturn)
 	swi	0x0
 	.fnend
+#endif
 
+	.fnstart
+	.save {r0-r15}
+	.pad #160
+	nop
+ENTRY(__default_rt_sa_restorer_v2)
+	mov	r7, $SYS_ify(rt_sigreturn)
+	swi	0x0
+	.fnend
+
 #endif
Index: sysdeps/unix/sysv/linux/arm/nptl/Versions
===================================================================
--- sysdeps/unix/sysv/linux/arm/nptl/Versions	(revision 2135)
+++ sysdeps/unix/sysv/linux/arm/nptl/Versions	(working copy)
@@ -2,5 +2,7 @@
   GLIBC_PRIVATE {
     # A copy of sigaction lives in NPTL, and needs these.
     __default_sa_restorer; __default_rt_sa_restorer;
+    __default_sa_restorer_v1; __default_rt_sa_restorer_v1;
+    __default_sa_restorer_v2; __default_rt_sa_restorer_v2;
   }
 }
Index: ChangeLog.eglibc
===================================================================
--- ChangeLog.eglibc	(revision 2135)
+++ ChangeLog.eglibc	(working copy)
@@ -1,3 +1,25 @@
+2007-05-01  Joseph Myers  <joseph@xxxxxxxxxxxxxxxx>
+
+	* sysdeps/unix/sysv/linux/arm/kernel-features.h
+	(__ASSUME_SIGFRAME_V2): Define for 2.6.18 and later.
+	* sysdeps/unix/sysv/linux/arm/eabi/sigrestorer.S
+	(__default_sa_restorer): Rename to __default_sa_restorer_v1.
+	Don't define if __ASSUME_SIGFRAME_V2.
+	(__default_rt_sa_restorer): Rename to
+	__default_rt_sa_restorer_v1.  Don't define if
+	__ASSUME_SIGFRAME_V2.
+	(__default_sa_restorer_v2, __default_rt_sa_restorer_v2): New.
+	* sysdeps/unix/sysv/linux/arm/nptl/Versions
+	(__default_sa_restorer_v1, __default_rt_sa_restorer_v1,
+	__default_sa_restorer_v2, __default_rt_sa_restorer_v2): Add to
+	GLIBC_PRIVATE.
+	* sysdeps/unix/sysv/linux/arm/sigaction.c [__ARM_EABI__]
+	(__default_sa_restorer_v1, __default_sa_restorer_v2,
+	__default_rt_sa_restorer_v1, __default_rt_sa_restorer_v2):
+	Declare.
+	(__default_sa_restorer, __default_rt_sa_restorer): Define as
+	macros depending on kernel version.
+
 2007-04-16  Joseph Myers  <joseph@xxxxxxxxxxxxxxxx>
 
 	* sysdeps/unix/sysv/linux/powerpc/powerpc32/e500/fpu/getcontext-extra.S:

-- 
Joseph S. Myers
joseph@xxxxxxxxxxxxxxxx