vfork.S 2.6 KB

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