getcontext.S 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* Save current context.
  2. Copyright (C) 2002-2012 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. Contributed by Andreas Jaeger <aj@suse.de>, 2002.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; if not, see
  15. <http://www.gnu.org/licenses/>. */
  16. #include <sysdep.h>
  17. #include "ucontext_i.h"
  18. /* int __getcontext (ucontext_t *ucp)
  19. Saves the machine context in UCP such that when it is activated,
  20. it appears as if __getcontext() returned again.
  21. This implementation is intended to be used for *synchronous* context
  22. switches only. Therefore, it does not have to save anything
  23. other than the PRESERVED state. */
  24. ENTRY(__getcontext)
  25. /* Save the preserved registers, the registers used for passing
  26. args, and the return address. */
  27. movq %rbx, oRBX(%rdi)
  28. movq %rbp, oRBP(%rdi)
  29. movq %r12, oR12(%rdi)
  30. movq %r13, oR13(%rdi)
  31. movq %r14, oR14(%rdi)
  32. movq %r15, oR15(%rdi)
  33. movq %rdi, oRDI(%rdi)
  34. movq %rsi, oRSI(%rdi)
  35. movq %rdx, oRDX(%rdi)
  36. movq %rcx, oRCX(%rdi)
  37. movq %r8, oR8(%rdi)
  38. movq %r9, oR9(%rdi)
  39. movq (%rsp), %rcx
  40. movq %rcx, oRIP(%rdi)
  41. leaq 8(%rsp), %rcx /* Exclude the return address. */
  42. movq %rcx, oRSP(%rdi)
  43. /* We have separate floating-point register content memory on the
  44. stack. We use the __fpregs_mem block in the context. Set the
  45. links up correctly. */
  46. leaq oFPREGSMEM(%rdi), %rcx
  47. movq %rcx, oFPREGS(%rdi)
  48. /* Save the floating-point environment. */
  49. fnstenv (%rcx)
  50. fldenv (%rcx)
  51. stmxcsr oMXCSR(%rdi)
  52. /* Save the current signal mask with
  53. rt_sigprocmask (SIG_BLOCK, NULL, set,_NSIG/8). */
  54. leaq oSIGMASK(%rdi), %rdx
  55. xorl %esi,%esi
  56. #if SIG_BLOCK == 0
  57. xorl %edi, %edi
  58. #else
  59. movl $SIG_BLOCK, %edi
  60. #endif
  61. movl $_NSIG8,%r10d
  62. movl $__NR_rt_sigprocmask, %eax
  63. syscall
  64. cmpq $-4095, %rax /* Check %rax for error. */
  65. jae SYSCALL_ERROR_LABEL /* Jump to error handler if error. */
  66. /* All done, return 0 for success. */
  67. xorl %eax, %eax
  68. L(pseudo_end):
  69. ret
  70. PSEUDO_END(__getcontext)
  71. weak_alias (__getcontext, getcontext)