vfork.S 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. BXC(cc, lr)
  64. /* Check if vfork even exists. */
  65. ldr r1, =-ENOSYS
  66. teq r0, r1
  67. bne __error
  68. #endif
  69. /* If we don't have vfork, use fork. */
  70. DO_CALL (fork)
  71. cmn r0, #4096
  72. /* Syscall worked. Return to child/parent */
  73. IT(t, cc)
  74. BXC(cc, lr)
  75. __error:
  76. b __syscall_error
  77. #endif
  78. .size __vfork,.-__vfork
  79. weak_alias(__vfork,vfork)
  80. libc_hidden_def(vfork)
  81. #endif