vfork.S 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright (C) 2005 Atmel Corporation
  3. *
  4. * This file is subject to the terms and conditions of the GNU Lesser General
  5. * Public License. See the file "COPYING.LIB" in the main directory of this
  6. * archive for more details.
  7. */
  8. /*
  9. * Clone the process without copying the address space. The
  10. * calling process is suspended until the child either exits
  11. * or calls execve.
  12. *
  13. * This all means that we cannot rely on the stack to store
  14. * away registers, since they will be overwritten by the child
  15. * as soon as it makes another function call (e.g. execve()).
  16. * Fortunately, the Linux kernel preserves LR across system calls.
  17. */
  18. #include <features.h>
  19. #include <sys/syscall.h>
  20. .global __vfork
  21. .type __vfork,@function
  22. .align 1
  23. __vfork:
  24. mov r8, __NR_vfork
  25. scall
  26. cp.w r12, -4096
  27. retls r12
  28. /* vfork failed, so we may use the stack freely */
  29. pushm r4-r7,lr
  30. #ifdef __PIC__
  31. lddpc r6, .L_GOT
  32. rsub r4, r12, 0
  33. .L_RGOT:
  34. rsub r6, pc
  35. mcall r6[__errno_location@got]
  36. #else
  37. rsub r4, r12, 0
  38. mcall .L__errno_location
  39. #endif
  40. st.w r12[0], r4
  41. popm r4-r7,pc,r12=-1
  42. .align 2
  43. #ifdef __PIC__
  44. .L_GOT:
  45. .long .L_RGOT - _GLOBAL_OFFSET_TABLE_
  46. #else
  47. .L__errno_location:
  48. .long __errno_location
  49. #endif
  50. .size __vfork, . - __vfork
  51. weak_alias(__vfork,vfork)
  52. libc_hidden_weak(vfork)