vfork.S 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. #define _ERRNO_H
  10. #include <bits/errno.h>
  11. #include <sys/syscall.h>
  12. #ifndef SAVE_PID
  13. #define SAVE_PID
  14. #endif
  15. #ifndef RESTORE_PID
  16. #define RESTORE_PID
  17. #endif
  18. #ifdef __NR_fork
  19. .text
  20. .global __vfork
  21. .hidden __vfork
  22. .type __vfork,%function
  23. .align 4
  24. #if defined(__thumb__) && !defined(__thumb2__)
  25. .thumb_func
  26. __vfork:
  27. #ifdef __NR_vfork
  28. SAVE_PID
  29. DO_CALL (vfork)
  30. RESTORE_PID
  31. ldr r1, =0xfffff000
  32. cmp r0, r1
  33. bcs 1f
  34. bx lr
  35. 1:
  36. /* Check if vfork even exists. */
  37. ldr r1, =-ENOSYS
  38. cmp r0, r1
  39. bne __error
  40. /* If we don't have vfork, use fork. */
  41. DO_CALL (fork)
  42. ldr r1, =0xfffff000
  43. cmp r0, r1
  44. /* Syscall worked. Return to child/parent */
  45. bcs 1f
  46. bx lr
  47. 1:
  48. __error:
  49. push {r3, lr}
  50. bl __syscall_error
  51. POP_RET
  52. .pool
  53. #endif
  54. #else
  55. __vfork:
  56. #ifdef __NR_vfork
  57. SAVE_PID
  58. DO_CALL (vfork)
  59. RESTORE_PID
  60. cmn r0, #4096
  61. IT(t, cc)
  62. #if defined(__USE_BX__)
  63. bxcc lr
  64. #else
  65. movcc pc, lr
  66. #endif
  67. /* Check if vfork even exists. */
  68. ldr r1, =-ENOSYS
  69. teq r0, r1
  70. bne __error
  71. #endif
  72. /* If we don't have vfork, use fork. */
  73. DO_CALL (fork)
  74. cmn r0, #4096
  75. /* Syscall worked. Return to child/parent */
  76. IT(t, cc)
  77. #if defined(__USE_BX__)
  78. bxcc lr
  79. #else
  80. movcc pc, lr
  81. #endif
  82. __error:
  83. b __syscall_error
  84. #endif
  85. .size __vfork,.-__vfork
  86. weak_alias(__vfork,vfork)
  87. libc_hidden_weak(vfork)
  88. #endif