1/* libunwind - a platform-independent unwind library 2 Copyright (C) 2009 Google, Inc 3 Contributed by Paul Pluzhnikov <ppluzhnikov@google.com> 4 5This file is part of libunwind. 6 7Permission is hereby granted, free of charge, to any person obtaining 8a copy of this software and associated documentation files (the 9"Software"), to deal in the Software without restriction, including 10without limitation the rights to use, copy, modify, merge, publish, 11distribute, sublicense, and/or sell copies of the Software, and to 12permit persons to whom the Software is furnished to do so, subject to 13the following conditions: 14 15The above copyright notice and this permission notice shall be 16included in all copies or substantial portions of the Software. 17 18THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 22LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 24WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 25 26#include "offsets.h" 27 28/* int _Ux86_getcontext (ucontext_t *ucp) 29 30 Saves the machine context in UCP necessary for libunwind. 31 Unlike the libc implementation, we don't save the signal mask 32 and hence avoid the cost of a system call per unwind. 33 34*/ 35 36 .global _Ux86_getcontext 37 .type _Ux86_getcontext, @function 38_Ux86_getcontext: 39 .cfi_startproc 40 mov 4(%esp),%eax /* ucontext_t* */ 41 42 /* EAX is not preserved. */ 43 movl $0, (LINUX_UC_MCONTEXT_OFF+LINUX_SC_EAX_OFF)(%eax) 44 45 movl %ebx, (LINUX_UC_MCONTEXT_OFF+LINUX_SC_EBX_OFF)(%eax) 46 movl %ecx, (LINUX_UC_MCONTEXT_OFF+LINUX_SC_ECX_OFF)(%eax) 47 movl %edx, (LINUX_UC_MCONTEXT_OFF+LINUX_SC_EDX_OFF)(%eax) 48 movl %edi, (LINUX_UC_MCONTEXT_OFF+LINUX_SC_EDI_OFF)(%eax) 49 movl %esi, (LINUX_UC_MCONTEXT_OFF+LINUX_SC_ESI_OFF)(%eax) 50 movl %ebp, (LINUX_UC_MCONTEXT_OFF+LINUX_SC_EBP_OFF)(%eax) 51 52 movl (%esp), %ecx 53 movl %ecx, (LINUX_UC_MCONTEXT_OFF+LINUX_SC_EIP_OFF)(%eax) 54 55 leal 4(%esp), %ecx /* Exclude the return address. */ 56 movl %ecx, (LINUX_UC_MCONTEXT_OFF+LINUX_SC_ESP_OFF)(%eax) 57 58 /* glibc getcontext saves FS, but not GS */ 59 xorl %ecx, %ecx 60 movw %fs, %cx 61 movl %ecx, (LINUX_UC_MCONTEXT_OFF+LINUX_SC_FS_OFF)(%eax) 62 63 leal LINUX_UC_FPREGS_MEM_OFF(%eax), %ecx 64 movl %ecx, (LINUX_UC_MCONTEXT_OFF+LINUX_SC_FPSTATE_OFF)(%eax) 65 fnstenv (%ecx) 66 fldenv (%ecx) 67 68 xor %eax, %eax 69 ret 70 .cfi_endproc 71 .size _Ux86_getcontext, . - _Ux86_getcontext 72 73 /* We do not need executable stack. */ 74 .section .note.GNU-stack,"",@progbits 75