vfork.S 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. /* Clone the calling process, but without copying the whole address space.
  23. The calling process is suspended until the new process exits or is
  24. replaced by a call to `execve'. Return -1 for errors, 0 to the new process,
  25. and the process ID of the new process to the old process. */
  26. ENTRY (__vfork)
  27. #ifdef PIC
  28. .pic
  29. #endif
  30. #ifdef __NR_vfork
  31. syscall __NR_vfork
  32. bltz $r0, 2f
  33. 1:
  34. ret
  35. 2:
  36. sltsi $r1, $r0, -4096
  37. bnez $r1, 1b;
  38. # ifdef __ASSUME_VFORK_SYSCALL
  39. # ifdef PIC
  40. pushm $gp, $lp
  41. cfi_adjust_cfa_offset(8)
  42. cfi_rel_offset(gp, 0)
  43. cfi_rel_offset(lp, 4)
  44. mfusr $r15, $PC
  45. sethi $gp, hi20(_GLOBAL_OFFSET_TABLE_+4)
  46. ori $gp, $gp, lo12(_GLOBAL_OFFSET_TABLE_+8)
  47. add $gp, $gp, $r15
  48. ! r15=C_SYMBOL_NAME(__syscall_error)@PLT
  49. sethi $r15, hi20(C_SYMBOL_NAME(__syscall_error)@PLT)
  50. ori $r15, $r15, lo12(C_SYMBOL_NAME(__syscall_error)@PLT)
  51. add $r15, $r15, $gp
  52. ! jump to SYSCALL_ERROR
  53. jral $r15
  54. popm $gp, $lp
  55. cfi_adjust_cfa_offset(-8)
  56. cfi_restore(lp)
  57. cfi_restore(gp)
  58. ret
  59. # else
  60. j C_SYMBOL_NAME(__syscall_error)
  61. # endif
  62. # else
  63. /* Check if vfork syscall is known at all. */
  64. li $r1, -ENOSYS
  65. beq $r0, $r1, 1f
  66. # ifdef PIC
  67. 3:
  68. pushm $gp, $lp
  69. cfi_adjust_cfa_offset(8)
  70. cfi_rel_offset(gp, 0)
  71. cfi_rel_offset(lp, 4)
  72. mfusr $r15, $PC
  73. sethi $gp, hi20(_GLOBAL_OFFSET_TABLE_+4)
  74. ori $gp, $gp, lo12(_GLOBAL_OFFSET_TABLE_+8)
  75. add $gp, $gp, $r15
  76. ! r15=C_SYMBOL_NAME(__syscall_error)@PLT
  77. sethi $r15, hi20(C_SYMBOL_NAME(__syscall_error)@PLT)
  78. ori $r15, $r15, lo12(C_SYMBOL_NAME(__syscall_error)@PLT)
  79. add $r15, $r15, $gp
  80. ! jump to SYSCALL_ERROR
  81. jral $r15
  82. popm $gp, $lp
  83. cfi_adjust_cfa_offset(-8)
  84. cfi_restore(lp)
  85. cfi_restore(gp)
  86. ret
  87. # else
  88. j C_SYMBOL_NAME(__syscall_error)
  89. # endif
  90. 1:
  91. # endif
  92. #endif
  93. #ifndef __ASSUME_VFORK_SYSCALL
  94. /* If we don't have vfork, fork is close enough. */
  95. syscall __NR_fork
  96. bgez $r0, 1f
  97. sltsi $r1, $r0, -4096
  98. bnez $r1, 1f
  99. # ifdef PIC
  100. b 3b
  101. # else
  102. j C_SYMBOL_NAME(__syscall_error)
  103. # endif
  104. 1:
  105. ret
  106. #elif !defined __NR_vfork
  107. # error "__NR_vfork not available and __ASSUME_VFORK_SYSCALL defined"
  108. #endif
  109. PSEUDO_END (__vfork)
  110. weak_alias (__vfork, vfork)
  111. libc_hidden_def (vfork)