vfork.S 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. #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. LOCALSZ= 1
  28. FRAMESZ= (((NARGSAVE+LOCALSZ)*SZREG)+ALSZ)&ALMASK
  29. GPOFF= FRAMESZ-(1*SZREG)
  30. NESTED(__vfork,FRAMESZ,sp)
  31. #ifdef __PIC__
  32. SETUP_GP
  33. #endif
  34. PTR_SUBU sp, FRAMESZ
  35. SETUP_GP64 (a5, __vfork)
  36. #ifdef __PIC__
  37. SAVE_GP (GPOFF)
  38. #endif
  39. #ifdef PROF
  40. # if (_MIPS_SIM != _ABIO32)
  41. PTR_S a5, GPOFF(sp)
  42. # endif
  43. .set noat
  44. move $1, ra
  45. # if (_MIPS_SIM == _ABIO32)
  46. subu sp,sp,8
  47. # endif
  48. jal _mcount
  49. .set at
  50. # if (_MIPS_SIM != _ABIO32)
  51. PTR_L a5, GPOFF(sp)
  52. # endif
  53. #endif
  54. PTR_ADDU sp, FRAMESZ
  55. SAVE_PID
  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. RESTORE_PID
  62. bnez a3,L(error)
  63. /* Successful return from the parent or child. */
  64. RESTORE_GP64
  65. j ra
  66. nop
  67. /* Something bad happened -- no child created. */
  68. L(error):
  69. move a0, v0
  70. #ifdef __PIC__
  71. PTR_LA t9, __syscall_error
  72. RESTORE_GP64
  73. jr t9
  74. #else
  75. RESTORE_GP64
  76. j __syscall_error
  77. #endif
  78. END(__vfork)
  79. weak_alias(__vfork,vfork)
  80. libc_hidden_weak(vfork)
  81. #endif