vfork.S 2.1 KB

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