vfork.S 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * Copyright (C) 2016-2017 Andes Technology, Inc.
  3. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  4. */
  5. /* Copyright (C) 1999, 2002, 2003 Free Software Foundation, Inc.
  6. Contributed by Philip Blundell <philb@gnu.org>.
  7. The GNU C Library is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU Lesser General Public
  9. License as published by the Free Software Foundation; either
  10. version 2.1 of the License, or (at your option) any later version.
  11. The GNU C Library is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. Lesser General Public License for more details.
  15. You should have received a copy of the GNU Lesser General Public
  16. License along with the GNU C Library; if not, write to the Free
  17. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  18. 02111-1307 USA. */
  19. #include <sysdep.h>
  20. #define _ERRNO_H 1
  21. #include <bits/errno.h>
  22. #ifndef SAVE_PID
  23. #define SAVE_PID
  24. #endif
  25. #ifndef RESTORE_PID
  26. #define RESTORE_PID
  27. #endif
  28. /* Clone the calling process, but without copying the whole address space.
  29. The calling process is suspended until the new process exits or is
  30. replaced by a call to `execve'. Return -1 for errors, 0 to the new process,
  31. and the process ID of the new process to the old process. */
  32. ENTRY (__vfork)
  33. #ifdef PIC
  34. .pic
  35. #endif
  36. #ifdef __NR_vfork
  37. # ifdef SAVE_PID
  38. SAVE_PID
  39. # endif
  40. syscall __NR_vfork
  41. # ifdef RESTORE_PID
  42. RESTORE_PID
  43. # endif
  44. bltz $r0, 2f
  45. 1:
  46. ret
  47. 2:
  48. sltsi $r1, $r0, -4096
  49. bnez $r1, 1b;
  50. # ifdef __ASSUME_VFORK_SYSCALL
  51. # ifdef PIC
  52. pushm $gp, $lp
  53. cfi_adjust_cfa_offset(8)
  54. cfi_rel_offset(gp, 0)
  55. cfi_rel_offset(lp, 4)
  56. mfusr $r15, $PC
  57. sethi $gp, hi20(_GLOBAL_OFFSET_TABLE_+4)
  58. ori $gp, $gp, lo12(_GLOBAL_OFFSET_TABLE_+8)
  59. add $gp, $gp, $r15
  60. ! r15=C_SYMBOL_NAME(__syscall_error)@PLT
  61. sethi $r15, hi20(C_SYMBOL_NAME(__syscall_error)@PLT)
  62. ori $r15, $r15, lo12(C_SYMBOL_NAME(__syscall_error)@PLT)
  63. add $r15, $r15, $gp
  64. ! jump to SYSCALL_ERROR
  65. jral $r15
  66. popm $gp, $lp
  67. cfi_adjust_cfa_offset(-8)
  68. cfi_restore(lp)
  69. cfi_restore(gp)
  70. ret
  71. # else
  72. j C_SYMBOL_NAME(__syscall_error)
  73. # endif
  74. # else
  75. /* Check if vfork syscall is known at all. */
  76. li $r1, -ENOSYS
  77. beq $r0, $r1, 1f
  78. # ifdef PIC
  79. 3:
  80. pushm $gp, $lp
  81. cfi_adjust_cfa_offset(8)
  82. cfi_rel_offset(gp, 0)
  83. cfi_rel_offset(lp, 4)
  84. mfusr $r15, $PC
  85. sethi $gp, hi20(_GLOBAL_OFFSET_TABLE_+4)
  86. ori $gp, $gp, lo12(_GLOBAL_OFFSET_TABLE_+8)
  87. add $gp, $gp, $r15
  88. ! r15=C_SYMBOL_NAME(__syscall_error)@PLT
  89. sethi $r15, hi20(C_SYMBOL_NAME(__syscall_error)@PLT)
  90. ori $r15, $r15, lo12(C_SYMBOL_NAME(__syscall_error)@PLT)
  91. add $r15, $r15, $gp
  92. ! jump to SYSCALL_ERROR
  93. jral $r15
  94. popm $gp, $lp
  95. cfi_adjust_cfa_offset(-8)
  96. cfi_restore(lp)
  97. cfi_restore(gp)
  98. ret
  99. # else
  100. j C_SYMBOL_NAME(__syscall_error)
  101. # endif
  102. 1:
  103. # endif
  104. #endif
  105. #ifndef __ASSUME_VFORK_SYSCALL
  106. /* If we don't have vfork, fork is close enough. */
  107. syscall __NR_fork
  108. bgez $r0, 1f
  109. sltsi $r1, $r0, -4096
  110. bnez $r1, 1f
  111. # ifdef PIC
  112. b 3b
  113. # else
  114. j C_SYMBOL_NAME(__syscall_error)
  115. # endif
  116. 1:
  117. ret
  118. #elif !defined __NR_vfork
  119. # error "__NR_vfork not available and __ASSUME_VFORK_SYSCALL defined"
  120. #endif
  121. PSEUDO_END (__vfork)
  122. weak_alias (__vfork, vfork)
  123. libc_hidden_def (vfork)