vfork.S 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 SHARED
  25. tstl (__libc_pthread_functions@GOTPC, %pc)
  26. #else
  27. .weak pthread_create
  28. movel #pthread_create, %d0
  29. #endif
  30. jbne HIDDEN_JUMPTARGET (fork)
  31. #ifdef __NR_vfork
  32. /* Pop the return PC value into A0. */
  33. movel %sp@+, %a0
  34. /* Stuff the syscall number in D0 and trap into the kernel. */
  35. movel #SYS_ify (vfork), %d0
  36. trap #0
  37. tstl %d0
  38. jmi .Lerror /* Branch forward if it failed. */
  39. /* Jump to the return PC. */
  40. jmp %a0@
  41. .Lerror:
  42. /* Push back the return PC. */
  43. movel %a0,%sp@-
  44. # ifdef __ASSUME_VFORK_SYSCALL
  45. # ifndef __PIC__
  46. jbra SYSCALL_ERROR_LABEL
  47. # endif
  48. # else
  49. /* Check if vfork syscall is known at all. */
  50. movel #-ENOSYS,%d1
  51. cmpl %d0,%d1
  52. jne SYSCALL_ERROR_LABEL
  53. # endif
  54. #endif
  55. #ifndef __ASSUME_VFORK_SYSCALL
  56. /* If we don't have vfork, fork is close enough. */
  57. movel #SYS_ify (fork), %d0
  58. trap #0
  59. tstl %d0
  60. jmi SYSCALL_ERROR_LABEL
  61. rts
  62. #endif
  63. PSEUDO_END (__vfork)
  64. libc_hidden_def (__vfork)
  65. weak_alias (__vfork, vfork)