summaryrefslogtreecommitdiff
path: root/lib/libc
diff options
context:
space:
mode:
authorpooka <pooka@NetBSD.org>2007-04-12 12:33:26 +0000
committerpooka <pooka@NetBSD.org>2007-04-12 12:33:26 +0000
commit65ec9d356d1ecd1a3ddf7c7cb1f487b6e88bfcfc (patch)
treeffc1193726d5677e03ff36699cf72bede2676339 /lib/libc
parentee87345f90854091b31e07b349417550c5f3a1ad (diff)
Don't clobber callee save registers r12 & r13 in swapcontext. They
were saved in the stack, but the subsequent swapcontext would return to the earlier stack frame and never restore them. Fixes puffs with default compiler flags on amd64. Thanks to Mihai Chelaru for providing access to an amd64 machine for debugging this problem.
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/arch/x86_64/gen/swapcontext.S24
1 files changed, 11 insertions, 13 deletions
diff --git a/lib/libc/arch/x86_64/gen/swapcontext.S b/lib/libc/arch/x86_64/gen/swapcontext.S
index 171f1f0985a..49744bf0733 100644
--- a/lib/libc/arch/x86_64/gen/swapcontext.S
+++ b/lib/libc/arch/x86_64/gen/swapcontext.S
@@ -1,4 +1,4 @@
-/* $NetBSD: swapcontext.S,v 1.3 2004/12/01 01:08:18 ws Exp $ */
+/* $NetBSD: swapcontext.S,v 1.4 2007/04/12 12:33:26 pooka Exp $ */
/*
* Copyright (c) 2003 Wasabi Systems, Inc.
@@ -38,7 +38,7 @@
#include <machine/asm.h>
#if defined(LIBC_SCCS) && !defined(lint)
- RCSID("$NetBSD: swapcontext.S,v 1.3 2004/12/01 01:08:18 ws Exp $")
+ RCSID("$NetBSD: swapcontext.S,v 1.4 2007/04/12 12:33:26 pooka Exp $")
#endif /* LIBC_SCCS && !lint */
/*
@@ -48,28 +48,26 @@
*/
ENTRY(swapcontext)
- pushq %r12
- pushq %r13
- movq %rdi,%r12 /* preserve oucp */
- movq %rsi,%r13 /* preserve ucp */
+ pushq %rdi /* preserve oucp */
+ pushq %rsi /* preserve ucp */
#ifdef PIC
call PIC_PLT(_C_LABEL(_getcontext))
#else
call _C_LABEL(_getcontext)
#endif
+ popq %rsi
+ popq %rdi
testl %eax,%eax
jnz 2f
- movq 16(%rsp),%r11
- movq %r11,(56 + 21 * 8)(%r12)
- leaq 24(%rsp),%r11
- movq %r11,(56 + 24 * 8)(%r12)
- movq %r13,%rdi
+ movq 0(%rsp),%r11
+ movq %r11,(56 + 21 * 8)(%rdi)
+ leaq 8(%rsp),%r11
+ movq %r11,(56 + 24 * 8)(%rdi)
+ movq %rsi,%rdi
#ifdef PIC
call PIC_PLT(_C_LABEL(setcontext))
#else
call _C_LABEL(setcontext)
#endif
2:
- popq %r13
- popq %r12
ret