vfork.S 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /* Copyright (C) 2005 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. /* vfork() is just a special case of clone(). */
  15. #include <sys/syscall.h>
  16. #include <sys/asm.h>
  17. #include <sysdep.h>
  18. #ifndef SAVE_PID
  19. #define SAVE_PID
  20. #endif
  21. #ifndef RESTORE_PID
  22. #define RESTORE_PID
  23. #endif
  24. #ifdef __NR_fork
  25. /* int vfork() */
  26. .text
  27. .hidden __vfork
  28. LOCALSZ= 1
  29. FRAMESZ= (((NARGSAVE+LOCALSZ)*SZREG)+ALSZ)&ALMASK
  30. GPOFF= FRAMESZ-(1*SZREG)
  31. NESTED(__vfork,FRAMESZ,sp)
  32. #ifdef __PIC__
  33. SETUP_GP
  34. #endif
  35. PTR_SUBU sp, FRAMESZ
  36. SETUP_GP64 (a5, __vfork)
  37. #ifdef __PIC__
  38. SAVE_GP (GPOFF)
  39. #endif
  40. #ifdef PROF
  41. # if (_MIPS_SIM != _ABIO32)
  42. PTR_S a5, GPOFF(sp)
  43. # endif
  44. .set noat
  45. move $1, ra
  46. # if (_MIPS_SIM == _ABIO32)
  47. subu sp,sp,8
  48. # endif
  49. jal _mcount
  50. .set at
  51. # if (_MIPS_SIM != _ABIO32)
  52. PTR_L a5, GPOFF(sp)
  53. # endif
  54. #endif
  55. PTR_ADDU sp, FRAMESZ
  56. SAVE_PID
  57. li a0, 0x4112 /* CLONE_VM | CLONE_VFORK | SIGCHLD */
  58. move a1, sp
  59. /* Do the system call */
  60. li v0,__NR_clone
  61. syscall
  62. RESTORE_PID
  63. bnez a3,L(error)
  64. /* Successful return from the parent or child. */
  65. RESTORE_GP64
  66. j ra
  67. nop
  68. /* Something bad happened -- no child created. */
  69. L(error):
  70. move a0, v0
  71. #ifdef __PIC__
  72. PTR_LA t9, __syscall_error
  73. RESTORE_GP64
  74. jr t9
  75. #else
  76. RESTORE_GP64
  77. j __syscall_error
  78. #endif
  79. END(__vfork)
  80. weak_alias(__vfork,vfork)
  81. libc_hidden_def(vfork)
  82. #endif