vfork.S 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. /* int vfork() */
  25. .text
  26. LOCALSZ= 1
  27. FRAMESZ= (((NARGSAVE+LOCALSZ)*SZREG)+ALSZ)&ALMASK
  28. GPOFF= FRAMESZ-(1*SZREG)
  29. NESTED(__vfork,FRAMESZ,sp)
  30. #ifdef __PIC__
  31. SETUP_GP
  32. #endif
  33. PTR_SUBU sp, FRAMESZ
  34. SETUP_GP64 (a5, __vfork)
  35. #ifdef __PIC__
  36. SAVE_GP (GPOFF)
  37. #endif
  38. #ifdef PROF
  39. # if (_MIPS_SIM != _ABIO32)
  40. PTR_S a5, GPOFF(sp)
  41. # endif
  42. .set noat
  43. move $1, ra
  44. # if (_MIPS_SIM == _ABIO32)
  45. subu sp,sp,8
  46. # endif
  47. jal _mcount
  48. .set at
  49. # if (_MIPS_SIM != _ABIO32)
  50. PTR_L a5, GPOFF(sp)
  51. # endif
  52. #endif
  53. PTR_ADDU sp, FRAMESZ
  54. SAVE_PID
  55. li a0, 0x4112 /* CLONE_VM | CLONE_VFORK | SIGCHLD */
  56. move a1, sp
  57. /* Do the system call */
  58. li v0,__NR_clone
  59. syscall
  60. RESTORE_PID
  61. bnez a3,L(error)
  62. /* Successful return from the parent or child. */
  63. RESTORE_GP64
  64. j ra
  65. nop
  66. /* Something bad happened -- no child created. */
  67. L(error):
  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. END(__vfork)
  77. .weak vfork;
  78. vfork = __vfork