getcontext-linux.S 2.6 KB

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