setcontext.S 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* Install given context.
  2. Copyright (C) 2001-2012 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. Contributed by Ulrich Drepper <drepper@redhat.com>, 2001.
  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. ENTRY(__setcontext)
  19. /* Load address of the context data structure. */
  20. movl 4(%esp), %eax
  21. /* Get the current signal mask. Note that we preserve EBX in case
  22. the system call fails and we return from the function with an
  23. error. */
  24. pushl %ebx
  25. cfi_adjust_cfa_offset (4)
  26. xorl %edx, %edx
  27. leal oSIGMASK(%eax), %ecx
  28. movl $SIG_SETMASK, %ebx
  29. cfi_rel_offset (ebx, 0)
  30. movl $__NR_sigprocmask, %eax
  31. ENTER_KERNEL
  32. popl %ebx
  33. cfi_adjust_cfa_offset (-4)
  34. cfi_restore (ebx)
  35. cmpl $-4095, %eax /* Check %eax for error. */
  36. jae SYSCALL_ERROR_LABEL /* Jump to error handler if error. */
  37. /* EAX was modified, reload it. */
  38. movl 4(%esp), %eax
  39. /* Restore the floating-point context. Not the registers, only the
  40. rest. */
  41. movl oFPREGS(%eax), %ecx
  42. fldenv (%ecx)
  43. /* Restore the FS segment register. We don't touch the GS register
  44. since it is used for threads. */
  45. movl oFS(%eax), %ecx
  46. movw %cx, %fs
  47. /* Fetch the address to return to. */
  48. movl oEIP(%eax), %ecx
  49. /* Load the new stack pointer. */
  50. cfi_def_cfa (eax, 0)
  51. cfi_offset (edi, oEDI)
  52. cfi_offset (esi, oESI)
  53. cfi_offset (ebp, oEBP)
  54. cfi_offset (ebx, oEBX)
  55. cfi_offset (edx, oEDX)
  56. cfi_offset (ecx, oECX)
  57. movl oESP(%eax), %esp
  58. /* Push the return address on the new stack so we can return there. */
  59. pushl %ecx
  60. /* Load the values of all the 32-bit registers (except ESP).
  61. Since we are loading from EAX, it must be last. */
  62. movl oEDI(%eax), %edi
  63. movl oESI(%eax), %esi
  64. movl oEBP(%eax), %ebp
  65. movl oEBX(%eax), %ebx
  66. movl oEDX(%eax), %edx
  67. movl oECX(%eax), %ecx
  68. movl oEAX(%eax), %eax
  69. /* End FDE here, we fall into another context. */
  70. cfi_endproc
  71. cfi_startproc
  72. /* The following 'ret' will pop the address of the code and jump
  73. to it. */
  74. L(pseudo_end):
  75. ret
  76. PSEUDO_END(__setcontext)
  77. weak_alias (__setcontext, setcontext)