vfork.S 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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, write to the Free
  13. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  14. 02111-1307 USA. */
  15. /* vfork() is just a special case of clone(). */
  16. #include <sys/asm.h>
  17. #include <sysdep.h>
  18. #include <asm/unistd.h>
  19. /* int vfork() */
  20. .text
  21. LOCALSZ= 1
  22. FRAMESZ= (((NARGSAVE+LOCALSZ)*SZREG)+ALSZ)&ALMASK
  23. GPOFF= FRAMESZ-(1*SZREG)
  24. NESTED(__vfork,FRAMESZ,sp)
  25. #ifdef __PIC__
  26. SETUP_GP
  27. #endif
  28. PTR_SUBU sp, FRAMESZ
  29. SETUP_GP64 (a5, __vfork)
  30. #ifdef __PIC__
  31. SAVE_GP (GPOFF)
  32. #endif
  33. #ifdef PROF
  34. # if (_MIPS_SIM != _ABIO32)
  35. PTR_S a5, GPOFF(sp)
  36. # endif
  37. .set noat
  38. move $1, ra
  39. # if (_MIPS_SIM == _ABIO32)
  40. subu sp,sp,8
  41. # endif
  42. jal _mcount
  43. .set at
  44. # if (_MIPS_SIM != _ABIO32)
  45. PTR_L a5, GPOFF(sp)
  46. # endif
  47. #endif
  48. /* If libpthread is loaded, we need to call fork instead. */
  49. #ifdef SHARED
  50. PTR_L a0, __libc_pthread_functions
  51. #else
  52. .weak pthread_create
  53. PTR_LA a0, pthread_create
  54. #endif
  55. PTR_ADDU sp, FRAMESZ
  56. bnez a0, L(call_fork)
  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. bnez a3,L(error)
  63. /* Successful return from the parent or child. */
  64. RESTORE_GP64
  65. ret
  66. /* Something bad happened -- no child created. */
  67. L(error):
  68. move a0, v0
  69. #ifdef __PIC__
  70. PTR_LA t9, __syscall_error
  71. RESTORE_GP64
  72. jr t9
  73. #else
  74. RESTORE_GP64
  75. j __syscall_error
  76. #endif
  77. L(call_fork):
  78. #ifdef __PIC__
  79. PTR_LA t9, fork
  80. RESTORE_GP64
  81. jr t9
  82. #else
  83. RESTORE_GP64
  84. j fork
  85. #endif
  86. END(__vfork)
  87. libc_hidden_def(__vfork)
  88. weak_alias (__vfork, vfork)