vfork.S 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright (C) 2016 Andes Technology, Inc.
  3. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  4. */
  5. /* Copyright (C) 1999, 2002, 2003 Free Software Foundation, Inc.
  6. Contributed by Philip Blundell <philb@gnu.org>.
  7. The GNU C Library is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU Lesser General Public
  9. License as published by the Free Software Foundation; either
  10. version 2.1 of the License, or (at your option) any later version.
  11. The GNU C Library is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. Lesser General Public License for more details.
  15. You should have received a copy of the GNU Lesser General Public
  16. License along with the GNU C Library; if not, write to the Free
  17. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  18. 02111-1307 USA. */
  19. #include <sys/syscall.h>
  20. #include <sysdep.h>
  21. #define _ERRNO_H 1
  22. /* Clone the calling process, but without copying the whole address space.
  23. The calling process is suspended until the new process exits or is
  24. replaced by a call to `execve'. Return -1 for errors, 0 to the new process,
  25. and the process ID of the new process to the old process. */
  26. ENTRY (__vfork)
  27. #ifdef PIC
  28. .pic
  29. #endif
  30. #ifdef __NR_vfork
  31. syscall __NR_vfork
  32. bltz $r0, 2f
  33. 1:
  34. ret
  35. 2:
  36. sltsi $r1, $r0, -4096
  37. bnez $r1, 1b;
  38. # ifdef PIC
  39. #ifdef __NDS32_N1213_43U1H__
  40. ! save lp
  41. addi $r2, $lp, 0
  42. ! set r1 as gp
  43. jal 1b
  44. sethi $r1, hi20(_GLOBAL_OFFSET_TABLE_)
  45. ori $r1, $r1, lo12(_GLOBAL_OFFSET_TABLE_+4)
  46. add $r1, $lp, $r1
  47. ! restore lp
  48. addi $lp, $r2, 0
  49. #else
  50. ! set r1 as gp
  51. mfusr $r15, $PC
  52. sethi $r1, hi20(_GLOBAL_OFFSET_TABLE_+4)
  53. ori $r1, $r1, lo12(_GLOBAL_OFFSET_TABLE_+8)
  54. add $r1, $r1, $r15
  55. #endif
  56. ! r15=C_SYMBOL_NAME(__syscall_error)@PLT
  57. sethi $r15, hi20(C_SYMBOL_NAME(__syscall_error)@PLT)
  58. ori $r15, $r15, lo12(C_SYMBOL_NAME(__syscall_error)@PLT)
  59. add $r15, $r15, $r1
  60. ! jump to SYSCALL_ERROR
  61. jr $r15
  62. # else
  63. j C_SYMBOL_NAME(__syscall_error)
  64. # endif
  65. #else
  66. # error "__NR_vfork not available"
  67. #endif
  68. PSEUDO_END (__vfork)
  69. weak_alias (__vfork, vfork)
  70. libc_hidden_def(vfork)