From ad7ff929ddd2ae4a1837e244e19452409799c13f Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Sat, 10 May 2008 17:16:09 +0000 Subject: [PATCH] Reimplemented setjmp(). It no longer offsets the caller's esp. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25428 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/system/libroot/posix/arch/x86/Jamfile | 1 - src/system/libroot/posix/arch/x86/setjmp.S | 20 ----------- src/system/libroot/posix/arch/x86/sigsetjmp.S | 33 ++++++++++++++++--- 3 files changed, 28 insertions(+), 26 deletions(-) delete mode 100644 src/system/libroot/posix/arch/x86/setjmp.S diff --git a/src/system/libroot/posix/arch/x86/Jamfile b/src/system/libroot/posix/arch/x86/Jamfile index 7d647140f2..07225f0140 100644 --- a/src/system/libroot/posix/arch/x86/Jamfile +++ b/src/system/libroot/posix/arch/x86/Jamfile @@ -7,7 +7,6 @@ local genericSources = ; MergeObject posix_arch_$(TARGET_ARCH).o : - setjmp.S sigsetjmp.S siglongjmp.S diff --git a/src/system/libroot/posix/arch/x86/setjmp.S b/src/system/libroot/posix/arch/x86/setjmp.S deleted file mode 100644 index 7ca9a69eef..0000000000 --- a/src/system/libroot/posix/arch/x86/setjmp.S +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright 2004-2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved. - * Distributed under the terms of the MIT License. - */ - - -#include "setjmp_internal.h" - - -/* int setjmp(jmp_buf buffer) */ -FUNCTION(setjmp): - pop %eax // pop argument and return pointer from stack - pop %ecx - pushl $0 // push new argument (for saveMask) and old stuff - push %ecx // back onto the stack - push %eax - jmp __sigsetjmp // let sigsetjmp() do the actual work - -#pragma weak _setjmp=setjmp - diff --git a/src/system/libroot/posix/arch/x86/sigsetjmp.S b/src/system/libroot/posix/arch/x86/sigsetjmp.S index cd91fe4c1c..4e1d56e97c 100644 --- a/src/system/libroot/posix/arch/x86/sigsetjmp.S +++ b/src/system/libroot/posix/arch/x86/sigsetjmp.S @@ -1,4 +1,5 @@ /* + * Copyright 2008, Ingo Weinhold, ingo_weinhold@gmx.de. * Copyright 2004-2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved. * Distributed under the terms of the MIT License. */ @@ -15,23 +16,45 @@ * if it was asked to do this. */ - /* int sigsetjmp(jmp_buf buffer, int saveMask) */ FUNCTION(__sigsetjmp): FUNCTION(sigsetjmp): + // return address to %edx, stack pointer for return to %ecx (both are + // scratch registers) + mov 0(%esp), %edx + lea 4(%esp), %ecx + + // buffer to %eax mov 4(%esp), %eax - // fill __jmp_buf structure with current registers (%ecx can be clobbered) +sigsetjmp_setjmp_entry: + // fill __jmp_buf structure with current registers mov %ebx, JMP_REGS_EBX(%eax) mov %esi, JMP_REGS_ESI(%eax) mov %edi, JMP_REGS_EDI(%eax) mov %ebp, JMP_REGS_EBP(%eax) // save stack and return address (because that's where we intend to jump to) - lea 4(%esp,1), %ecx mov %ecx, JMP_REGS_ESP(%eax) - mov 0(%esp), %ecx - mov %ecx, JMP_REGS_PC(%eax) + mov %edx, JMP_REGS_PC(%eax) jmp __setjmp_save_sigs + +/* int setjmp(jmp_buf buffer) */ +FUNCTION(setjmp): + // prepare %edx, %ecx, and %eax for sigsetjmp + mov 0(%esp), %edx + lea 4(%esp), %ecx + mov (%ecx), %eax + + // let sigsetjmp do the real work + pushl $0 // saveMask + push %eax // buffer + call sigsetjmp_setjmp_entry + add $8, %esp + + ret + + +#pragma weak _setjmp=setjmp