This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Re: {make,set,swap}context broken on powerpc32


Jakub Jelinek wrote:
>On Wed, Dec 13, 2006 at 09:47:57AM +0100, Jakub Jelinek wrote:
>  
>>>Could you strace your test program and see whether it is using
>>>sys_swapcontext or sys_rt_sigreturn?
>>>      
>>It uses sys_swapcontext to fill it up (i.e. in getcontext calls)
>>and apparently sys_rt_sigreturn in setcontext (sorry I haven't noticed that),
>>will look why:
>>    
>
>The reason for this is a bug in glibc, while getcontext/swapcontext both
>include kernel-features.h and thus __ASSUME_SWAPCONTEXT_SYSCALL is defined
>in --enable-kernel=2.6.9 builds, setcontext does not and therefore it
>always uses other methods.  Sorry for thinking it was making a swapcontext
>syscall even the third time, I saw it is making some syscall under gdb
>and looking at the source I it appeared it would use swapcontext.
>While this cures the testcase I posted (r2 is no longer restored by
>swapcontext), I still don't like the realignment.  Either the kernel
>has a bug and should always align, or makecontext needs to memmove when it
>realigns.
>
>  
This patch is more complete where it forces alignment for of uc_regs for
__ASSUME_SWAPCONTEXT_SYSCALL version of  __getcontext and swapcontext
and allows makecontext to assume the uc_regs is set and aligned. This
version passes Jakub's test case on on the 2.6 kernels I have tried so far.

We still need to verify that on ppc970 the kernel is aligning the
uc_regs pointer when VMX regs are present.
2006-12-13  Steven Munroe  <sjmunroe@us.ibm.com>

	* sysdeps/unix/sysv/linux/powerpc/powerpc32/getcontext.S
	[__ASSUME_SWAPCONTEXT_SYSCALL] (__getcontext): Align reg_space
	and set uc_regs.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/setcontext.S
	[__ASSUME_SWAPCONTEXT_SYSCALL] (__setcontext): Align reg_space
	and set uc_regs.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/swapcontext.S
	[__ASSUME_SWAPCONTEXT_SYSCALL] (__swapcontext): Align reg_space
	and set uc_regs.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/makecontext.S
	(__makecontext): Assume uc_regs set and aligned.

diff -urN libc25-cvstip-20061129/sysdeps/unix/sysv/linux/powerpc/powerpc32/getcontext.S libc24/sysdeps/unix/sysv/linux/powerpc/powerpc32/getcontext.S
--- libc25-cvstip-20061129/sysdeps/unix/sysv/linux/powerpc/powerpc32/getcontext.S	2005-12-29 15:02:31.000000000 -0600
+++ libc24/sysdeps/unix/sysv/linux/powerpc/powerpc32/getcontext.S	2006-12-13 17:11:08.763208616 -0600
@@ -1,5 +1,5 @@
 /* Save current context.
-   Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2004, 2005, 2006 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -36,6 +36,10 @@
 #ifdef __ASSUME_SWAPCONTEXT_SYSCALL
 	.section ".text";
 ENTRY (__getcontext)
+/* Insure that the _UC_REGS starts on a quadword boundary.  */
+	addi	r0,r3,_UC_REG_SPACE+12
+	clrrwi  r0,r0,4
+	stw	r0,_UC_REGS_PTR(r3)
 	li	r4,0
 	li	r5,_UC_SIZE_2_3_4;
 	DO_CALL (SYS_ify (swapcontext));
diff -urN libc25-cvstip-20061129/sysdeps/unix/sysv/linux/powerpc/powerpc32/makecontext.S libc24/sysdeps/unix/sysv/linux/powerpc/powerpc32/makecontext.S
--- libc25-cvstip-20061129/sysdeps/unix/sysv/linux/powerpc/powerpc32/makecontext.S	2006-01-06 21:51:11.000000000 -0600
+++ libc24/sysdeps/unix/sysv/linux/powerpc/powerpc32/makecontext.S	2006-12-13 10:27:02.000000000 -0600
@@ -26,9 +26,7 @@
 
 ENTRY(__makecontext)
 	/* Set up the first 7 args to the function in its registers */
-	addi	r11,r3,_UC_REG_SPACE+12
-	clrrwi  r11,r11,4
-	stw	r11,_UC_REGS_PTR(r3)
+	lwz	r11,_UC_REGS_PTR(r3)
 	stw	r6,_UC_GREGS+(PT_R3*4)(r11)
 	stw	r7,_UC_GREGS+(PT_R4*4)(r11)
 	stw	r8,_UC_GREGS+(PT_R5*4)(r11)
diff -urN libc25-cvstip-20061129/sysdeps/unix/sysv/linux/powerpc/powerpc32/setcontext.S libc24/sysdeps/unix/sysv/linux/powerpc/powerpc32/setcontext.S
--- libc25-cvstip-20061129/sysdeps/unix/sysv/linux/powerpc/powerpc32/setcontext.S	2005-12-29 15:03:38.000000000 -0600
+++ libc24/sysdeps/unix/sysv/linux/powerpc/powerpc32/setcontext.S	2006-12-13 17:16:39.544244032 -0600
@@ -1,5 +1,5 @@
 /* Jump to a new context.
-   Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2004, 2005, 2006 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -20,6 +20,7 @@
 #include <sysdep.h>
 #include <rtld-global-offsets.h>
 #include <shlib-compat.h>
+#include <kernel-features.h>
 
 #define __ASSEMBLY__
 #include <asm/ptrace.h>
diff -urN libc25-cvstip-20061129/sysdeps/unix/sysv/linux/powerpc/powerpc32/swapcontext.S libc24/sysdeps/unix/sysv/linux/powerpc/powerpc32/swapcontext.S
--- libc25-cvstip-20061129/sysdeps/unix/sysv/linux/powerpc/powerpc32/swapcontext.S	2005-12-29 15:04:28.000000000 -0600
+++ libc24/sysdeps/unix/sysv/linux/powerpc/powerpc32/swapcontext.S	2006-12-13 17:11:34.938224360 -0600
@@ -1,5 +1,5 @@
 /* Save current context and jump to a new context.
-   Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2004, 2005, 2006 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -36,6 +36,10 @@
 #ifdef __ASSUME_SWAPCONTEXT_SYSCALL
 	.section ".text";
 ENTRY (__swapcontext)
+/* Insure that the _UC_REGS starts on a quadword boundary.  */
+	addi	r0,r3,_UC_REG_SPACE+12
+	clrrwi  r0,r0,4
+	stw	r0,_UC_REGS_PTR(r3)
 	li	r5,_UC_SIZE_2_3_4;
 	DO_CALL (SYS_ify (swapcontext));
 	bso-	cr0,1f

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]