vfork.S 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* Copyright (C) 2003 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-cancel.h>
  15. #define _ERRNO_H 1
  16. #include <bits/errno.h>
  17. #include <bits/kernel-features.h>
  18. /* Clone the calling process, but without copying the whole address space.
  19. The calling process is suspended until the new process exits or is
  20. replaced by a call to `execve'. Return -1 for errors, 0 to the new process,
  21. and the process ID of the new process to the old process. */
  22. #ifdef SHARED
  23. .section ".toc","aw"
  24. .LC0:
  25. .tc __libc_pthread_functions[TC],__libc_pthread_functions
  26. .section ".text"
  27. .align 2
  28. #endif
  29. ENTRY (__vfork)
  30. #ifdef __NR_vfork
  31. # ifdef SHARED
  32. ld 10,.LC0@toc(2)
  33. ld 10,0(10)
  34. cmpwi 10,0
  35. bne- HIDDEN_JUMPTARGET(fork)
  36. # else
  37. .weak pthread_create
  38. lis 10,pthread_create@highest
  39. ori 10,10,pthread_create@higher
  40. sldi 10,10,32
  41. oris 10,10,pthread_create@h
  42. ori 10,10,pthread_create@l
  43. cmpwi 10,0
  44. bne- .Lhidden_fork
  45. # endif
  46. DO_CALL (SYS_ify (vfork));
  47. # ifdef __ASSUME_VFORK_SYSCALL
  48. PSEUDO_RET
  49. # else
  50. bnslr+
  51. /* Check if vfork syscall is known at all. */
  52. cmpdi r3,ENOSYS
  53. # ifdef SHARED
  54. bne JUMPTARGET(__syscall_error)
  55. # else
  56. bne- .Lsyscall_error
  57. # endif
  58. # endif
  59. #endif
  60. #ifndef __ASSUME_VFORK_SYSCALL
  61. /* If we don't have vfork, fork is close enough. */
  62. DO_CALL (SYS_ify (fork));
  63. PSEUDO_RET
  64. #endif
  65. # ifndef SHARED
  66. .Lhidden_fork:
  67. b HIDDEN_JUMPTARGET(fork)
  68. .Lsyscall_error:
  69. b JUMPTARGET(__syscall_error)
  70. # endif
  71. PSEUDO_END (__vfork)
  72. libc_hidden_def (__vfork)
  73. weak_alias (__vfork, vfork)