setcontext.S 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /* Set current context.
  2. Copyright (C) 2015-2019 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #include <sysdep.h>
  16. #include "ucontext_i.h"
  17. /* int setcontext (const ucontext_t *ucp) */
  18. .text
  19. ENTRY(__setcontext)
  20. ldw r5, UCONTEXT_FLAGS(r4)
  21. movi r6, 1
  22. bne r5, r6, .Lsigreturn
  23. mov r10, r4
  24. /* Restore signal mask. */
  25. /* rt_sigprocmask (SIG_SETMASK, &ucp->uc_sigmask, NULL, _NSIG8) */
  26. movi r7, _NSIG8
  27. addi r5, r4, UCONTEXT_SIGMASK
  28. mov r6, zero
  29. movi r4, SIG_SETMASK
  30. movi r2, SYS_ify (rt_sigprocmask)
  31. trap
  32. bne r7, zero, SYSCALL_ERROR_LABEL
  33. /* Restore argument registers, for the makecontext() case. */
  34. ldw r4, (UCONTEXT_MCONTEXT + 4*4)(r10)
  35. ldw r5, (UCONTEXT_MCONTEXT + 5*4)(r10)
  36. ldw r6, (UCONTEXT_MCONTEXT + 6*4)(r10)
  37. ldw r7, (UCONTEXT_MCONTEXT + 7*4)(r10)
  38. ldw r16, (UCONTEXT_MCONTEXT + 16*4)(r10)
  39. ldw r17, (UCONTEXT_MCONTEXT + 17*4)(r10)
  40. ldw r18, (UCONTEXT_MCONTEXT + 18*4)(r10)
  41. ldw r19, (UCONTEXT_MCONTEXT + 19*4)(r10)
  42. ldw r20, (UCONTEXT_MCONTEXT + 20*4)(r10)
  43. ldw r21, (UCONTEXT_MCONTEXT + 21*4)(r10)
  44. ldw r22, (UCONTEXT_MCONTEXT + 22*4)(r10)
  45. ldw ra, (UCONTEXT_MCONTEXT + 24*4)(r10)
  46. ldw fp, (UCONTEXT_MCONTEXT + 25*4)(r10)
  47. ldw gp, (UCONTEXT_MCONTEXT + 26*4)(r10)
  48. /* Load address to continue execution. */
  49. ldw r3, (UCONTEXT_MCONTEXT + 28*4)(r10)
  50. ldw sp, (UCONTEXT_MCONTEXT + 29*4)(r10)
  51. mov r2, zero
  52. jmp r3
  53. .Lsigreturn:
  54. addi sp, sp, -RT_SIGFRAME_SIZE
  55. cfi_adjust_cfa_offset (RT_SIGFRAME_SIZE)
  56. addi r2, sp, RT_SIGFRAME_UCONTEXT
  57. movi r3, UCONTEXT_SIZE-4
  58. 1:
  59. add r6, r4, r3
  60. ldw r5, 0(r6)
  61. add r7, r2, r3
  62. addi r3, r3, -4
  63. stw r5, 0(r7)
  64. bgt r3, zero, 1b
  65. movi r2, SYS_ify (rt_sigreturn)
  66. trap
  67. addi sp, sp, RT_SIGFRAME_SIZE
  68. cfi_adjust_cfa_offset (-RT_SIGFRAME_SIZE)
  69. br SYSCALL_ERROR_LABEL
  70. PSEUDO_END (__setcontext)
  71. weak_alias (__setcontext, setcontext)
  72. /* We add an NOP here to separate between __setcontext/__startcontext.
  73. The wanted behavior that happens is: when unwinding from a function
  74. called inside a makecontext() context, FDE lookup will use
  75. '&__startcontext - 1', then returns NULL for no FDE found,
  76. and immediately ends the unwind, in a normal fashion.
  77. If this NOP word does not exist, FDE lookup just repeatedly finds
  78. __setcontext's FDE in an infinite loop, due to the convention of
  79. using 'address - 1' for FDE lookup. Modifiying/deleting the below
  80. __startcontext's FDE has no help on this. */
  81. nop
  82. ENTRY(__startcontext)
  83. mov r4, r16
  84. bne r4, zero, __setcontext
  85. /* If uc_link == zero, call exit. */
  86. #ifdef PIC
  87. nextpc r22
  88. 1: movhi r8, %hiadj(_gp_got - 1b)
  89. addi r8, r8, %lo(_gp_got - 1b)
  90. add r22, r22, r8
  91. ldw r8, %call(HIDDEN_JUMPTARGET(exit))(r22)
  92. jmp r8
  93. #else
  94. jmpi exit
  95. #endif
  96. END(__startcontext)