vfork.S 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /* Copyright (C) 2005-2013 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, see
  13. <http://www.gnu.org/licenses/>. */
  14. #include "sysdep.h"
  15. #include <sys/syscall.h>
  16. #define _SIGNAL_H
  17. #include <bits/signum.h>
  18. #define __ASSEMBLY__
  19. #include <linux/sched.h>
  20. /*
  21. Clone the calling process, but without copying the whole address space.
  22. The calling process is suspended until the new process exits or is
  23. replaced by a call to `execve'. Return -1 for errors, 0 to the new process,
  24. and the process ID of the new process to the old process.
  25. Note that it is important that we don't create a new stack frame for the
  26. caller.
  27. */
  28. /*
  29. pid_t vfork(void);
  30. Implemented as __clone_syscall(CLONE_VFORK | CLONE_VM | SIGCHLD, 0)
  31. */
  32. HIDDEN_ENTRY (__vfork)
  33. #if defined(__XTENSA_WINDOWED_ABI__)
  34. .literal .Ljumptable, 0, .L4, .L8, .L12
  35. mov a3, a0 # move return address out of the way
  36. movi a0, .Ljumptable
  37. extui a2, a3, 30, 2 # call-size: call4/8/12 = 1/2/3
  38. addx4 a0, a2, a0 # find return address in jumptable
  39. l32i a0, a0, 0
  40. # exchange top 2 bits of a0 and a3:
  41. xor a2, a0, a3
  42. extui a2, a2, 30, 2
  43. slli a2, a2, 30
  44. xor a0, a0, a2
  45. xor a3, a3, a2
  46. retw
  47. /* a7: return address */
  48. .L4: mov a12, a2
  49. mov a13, a3
  50. /* use syscall 'clone' and set new stack pointer to the same address */
  51. movi a2, SYS_ify(clone)
  52. movi a3, 0
  53. movi a6, CLONE_VM | CLONE_VFORK | SIGCHLD
  54. syscall
  55. movi a5, -4096
  56. mov a6, a2
  57. mov a2, a12
  58. mov a3, a13
  59. bgeu a6, a5, 1f
  60. jx a7
  61. 1: call4 .Lerr
  62. /* a11: return address */
  63. .L8: mov a12, a2
  64. mov a13, a3
  65. mov a14, a6
  66. movi a2, SYS_ify(clone)
  67. movi a3, 0
  68. movi a6, CLONE_VM | CLONE_VFORK | SIGCHLD
  69. syscall
  70. movi a9, -4096
  71. mov a10, a2
  72. mov a2, a12
  73. mov a3, a13
  74. mov a6, a14
  75. bgeu a10, a9, 1f
  76. jx a11
  77. 1: call8 .Lerr
  78. /* a15: return address */
  79. .L12: mov a12, a2
  80. mov a13, a3
  81. mov a14, a6
  82. movi a2, SYS_ify(clone)
  83. movi a3, 0
  84. movi a6, CLONE_VM | CLONE_VFORK | SIGCHLD
  85. syscall
  86. mov a3, a13
  87. movi a13, -4096
  88. mov a6, a14
  89. mov a14, a2
  90. mov a2, a12
  91. bgeu a14, a13, 1f
  92. jx a15
  93. 1: call12 .Lerr
  94. .align 4
  95. .Lerr: entry a1, 16
  96. /* Restore return address */
  97. extui a4, a0, 30, 2
  98. slli a4, a4, 30
  99. or a0, a3, a4
  100. PSEUDO_END (__vfork)
  101. .Lpseudo_end:
  102. retw
  103. #elif defined(__XTENSA_CALL0_ABI__)
  104. /* Use syscall 'clone'. Set new stack pointer to the same address. */
  105. movi a2, SYS_ify (clone)
  106. movi a3, 0
  107. movi a6, CLONE_VM | CLONE_VFORK | SIGCHLD
  108. syscall
  109. movi a3, -4096
  110. bgeu a2, a3, 1f
  111. ret
  112. 1:
  113. PSEUDO_END (__vfork)
  114. .Lpseudo_end:
  115. ret
  116. #else
  117. #error Unsupported Xtensa ABI
  118. #endif
  119. weak_alias (__vfork, vfork)
  120. libc_hidden_def(vfork)