vfork.S 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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/syscall.h>
  16. #include <sys/asm.h>
  17. #include <sysdep.h>
  18. #ifdef __NR_fork
  19. /* int vfork() */
  20. .text
  21. .hidden __vfork
  22. LOCALSZ= 1
  23. FRAMESZ= (((NARGSAVE+LOCALSZ)*SZREG)+ALSZ)&ALMASK
  24. GPOFF= FRAMESZ-(1*SZREG)
  25. NESTED(__vfork,FRAMESZ,sp)
  26. #ifdef __PIC__
  27. SETUP_GP
  28. #endif
  29. PTR_SUBU sp, FRAMESZ
  30. SETUP_GP64 (a5, __vfork)
  31. #ifdef __PIC__
  32. SAVE_GP (GPOFF)
  33. #endif
  34. PTR_ADDU sp, FRAMESZ
  35. li a0, 0x4112 /* CLONE_VM | CLONE_VFORK | SIGCHLD */
  36. move a1, sp
  37. /* Do the system call */
  38. li v0,__NR_clone
  39. syscall
  40. bnez a3,L(error)
  41. /* Successful return from the parent or child. */
  42. RESTORE_GP64
  43. j ra
  44. nop
  45. /* Something bad happened -- no child created. */
  46. L(error):
  47. move a0, v0
  48. #ifdef __PIC__
  49. PTR_LA t9, __syscall_error
  50. RESTORE_GP64
  51. jr t9
  52. #else
  53. RESTORE_GP64
  54. j __syscall_error
  55. #endif
  56. END(__vfork)
  57. weak_alias(__vfork,vfork)
  58. libc_hidden_def(vfork)
  59. #endif