vfork.S 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* Copyright (C) 2005-2018 Free Software Foundation, Inc.
  2. The GNU C Library is free software; you can redistribute it and/or
  3. modify it under the terms of the GNU Lesser General Public
  4. License as published by the Free Software Foundation; either
  5. version 2.1 of the License, or (at your option) any later version.
  6. The GNU C Library is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  9. Lesser General Public License for more details.
  10. You should have received a copy of the GNU Lesser General Public
  11. License along with the GNU C Library. If not, see
  12. <http://www.gnu.org/licenses/>. */
  13. #include <sysdep.h>
  14. #define _ERRNO_H 1
  15. #include <bits/errno.h>
  16. /* Clone the calling process, but without copying the whole address space.
  17. The calling process is suspended until the new process exits or is
  18. replaced by a call to `execve'. Return -1 for errors, 0 to the new process,
  19. and the process ID of the new process to the old process. */
  20. .Lthread_start: ASM_LINE_SEP
  21. /* r26, r25, r24, r23 are free since vfork has no arguments */
  22. ENTRY(__vfork)
  23. /* We must not create a frame. When the child unwinds to call
  24. exec it will clobber the same frame that the parent
  25. needs to unwind. */
  26. /* Save the PIC register. */
  27. #ifdef __PIC__
  28. copy %r19, %r25 /* parent */
  29. #endif
  30. /* Syscall saves and restores all register states */
  31. ble 0x100(%sr2,%r0)
  32. ldi __NR_vfork,%r20
  33. /* Check for error */
  34. ldi -4096,%r1
  35. comclr,>>= %r1,%ret0,%r0 /* Note: unsigned compare. */
  36. b,n .Lerror
  37. /* Return, and DO NOT restore rp. The child may have called
  38. functions that updated the frame's rp. This works because
  39. the kernel ensures rp is preserved across the vfork
  40. syscall. */
  41. bv,n %r0(%rp)
  42. .Lerror:
  43. /* Now we need a stack to call a function. We are assured
  44. that there is no child now, so it's safe to create
  45. a frame. */
  46. stw %rp, -20(%sp)
  47. .cfi_offset 2, -20
  48. stwm %r3, 64(%sp)
  49. .cfi_def_cfa_offset -64
  50. .cfi_offset 3, 0
  51. stw %sp, -4(%sp)
  52. sub %r0,%ret0,%r3
  53. SYSCALL_ERROR_HANDLER
  54. /* Restore the PIC register (in delay slot) on error */
  55. #ifdef __PIC__
  56. copy %r25, %r19 /* parent */
  57. #else
  58. nop
  59. #endif
  60. /* Write syscall return into errno location */
  61. stw %r3, 0(%ret0)
  62. ldw -84(%sp), %rp
  63. bv %r0(%rp)
  64. ldwm -64(%sp), %r3
  65. PSEUDO_END (__vfork)
  66. libc_hidden_def(vfork)
  67. weak_alias (__vfork, vfork)