vfork.S 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * vfork for uClibc
  4. * Copyright (C) 2000-2006 by Erik Andersen <andersen@uclibc.org>
  5. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  6. */
  7. #include <features.h>
  8. #include <bits/arm_asm.h>
  9. #include <bits/arm_bx.h>
  10. #define _ERRNO_H
  11. #include <bits/errno.h>
  12. #include <sys/syscall.h>
  13. #ifndef SAVE_PID
  14. #define SAVE_PID
  15. #endif
  16. #ifndef RESTORE_PID
  17. #define RESTORE_PID
  18. #endif
  19. #ifdef __NR_fork
  20. .text
  21. .global __vfork
  22. .hidden __vfork
  23. .type __vfork,%function
  24. .align 4
  25. #if defined(__thumb__) && !defined(__thumb2__)
  26. .thumb_func
  27. __vfork:
  28. #ifdef __NR_vfork
  29. SAVE_PID
  30. DO_CALL (vfork)
  31. RESTORE_PID
  32. ldr r1, =0xfffff000
  33. cmp r0, r1
  34. bcs 1f
  35. bx lr
  36. 1:
  37. /* Check if vfork even exists. */
  38. ldr r1, =-ENOSYS
  39. cmp r0, r1
  40. bne __error
  41. /* If we don't have vfork, use fork. */
  42. DO_CALL (fork)
  43. ldr r1, =0xfffff000
  44. cmp r0, r1
  45. /* Syscall worked. Return to child/parent */
  46. bcs 1f
  47. bx lr
  48. 1:
  49. __error:
  50. push {r3, lr}
  51. bl __syscall_error
  52. POP_RET
  53. .pool
  54. #endif
  55. #else
  56. __vfork:
  57. #ifdef __NR_vfork
  58. SAVE_PID
  59. DO_CALL (vfork)
  60. RESTORE_PID
  61. cmn r0, #4096
  62. IT(t, cc)
  63. #if defined(__USE_BX__)
  64. bxcc lr
  65. #else
  66. movcc pc, lr
  67. #endif
  68. /* Check if vfork even exists. */
  69. ldr r1, =-ENOSYS
  70. teq r0, r1
  71. bne __error
  72. #endif
  73. /* If we don't have vfork, use fork. */
  74. DO_CALL (fork)
  75. cmn r0, #4096
  76. /* Syscall worked. Return to child/parent */
  77. IT(t, cc)
  78. #if defined(__USE_BX__)
  79. bxcc lr
  80. #else
  81. movcc pc, lr
  82. #endif
  83. __error:
  84. b __syscall_error
  85. #endif
  86. .size __vfork,.-__vfork
  87. weak_alias(__vfork,vfork)
  88. libc_hidden_def(vfork)
  89. #endif