vfork.S 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /* Copyright (C) 1999, 2002, 2003 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Andreas Schwab <schwab@gnu.org>.
  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-cancel.h>
  16. #define _ERRNO_H 1
  17. #include <bits/errno.h>
  18. #include <bits/kernel-features.h>
  19. /* Clone the calling process, but without copying the whole address space.
  20. The calling process is suspended until the new process exits or is
  21. replaced by a call to `execve'. Return -1 for errors, 0 to the new process,
  22. and the process ID of the new process to the old process. */
  23. ENTRY (__vfork)
  24. #ifdef __NR_vfork
  25. # ifdef SHARED
  26. # if !defined HAVE_HIDDEN || !defined __UCLIBC_HAS_TLS__
  27. SETUP_PIC_REG (cx)
  28. # else
  29. call __i686.get_pc_thunk.cx
  30. # endif
  31. addl $_GLOBAL_OFFSET_TABLE_, %ecx
  32. cmpl $0, __libc_pthread_functions@GOTOFF(%ecx)
  33. # else
  34. .weak pthread_create
  35. movl $pthread_create, %eax
  36. testl %eax, %eax
  37. # endif
  38. jne HIDDEN_JUMPTARGET (fork)
  39. /* Pop the return PC value into ECX. */
  40. popl %ecx
  41. /* Stuff the syscall number in EAX and enter into the kernel. */
  42. movl $SYS_ify (vfork), %eax
  43. int $0x80
  44. /* Jump to the return PC. Don't jump directly since this
  45. disturbs the branch target cache. Instead push the return
  46. address back on the stack. */
  47. pushl %ecx
  48. cmpl $-4095, %eax
  49. /* Branch forward if it failed. */
  50. # ifdef __ASSUME_VFORK_SYSCALL
  51. jae SYSCALL_ERROR_LABEL
  52. .Lpseudo_end:
  53. # else
  54. jae .Lerror
  55. # endif
  56. ret
  57. # ifndef __ASSUME_VFORK_SYSCALL
  58. .Lerror:
  59. /* Check if vfork syscall is known at all. */
  60. cmpl $-ENOSYS, %eax
  61. jne SYSCALL_ERROR_LABEL
  62. # endif
  63. #endif
  64. #ifndef __ASSUME_VFORK_SYSCALL
  65. /* If we don't have vfork, fork is close enough. */
  66. movl $SYS_ify (fork), %eax
  67. int $0x80
  68. cmpl $-4095, %eax
  69. jae SYSCALL_ERROR_LABEL
  70. .Lpseudo_end:
  71. ret
  72. #elif !defined __NR_vfork
  73. # error "__NR_vfork not available and __ASSUME_VFORK_SYSCALL defined"
  74. #endif
  75. PSEUDO_END (__vfork)
  76. libc_hidden_def (__vfork)
  77. weak_alias (__vfork, vfork)