vfork.S 2.2 KB

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