vfork.S 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. ! Copyright (C) 2013 Imagination Technologies Ltd.
  2. ! Licensed under LGPL v2.1 or later, see the file COPYING.LIB in this tarball.
  3. #include <asm/unistd.h>
  4. #define _ERRNO_H
  5. #include <bits/errno.h>
  6. #include <sys/syscall.h>
  7. #ifdef __NR_vfork
  8. #define __VFORK_NR __NR_vfork
  9. #else
  10. #define __VFORK_NR __NR_fork
  11. #endif
  12. /* Clone the calling process, but without copying the whole address space.
  13. The calling process is suspended until the new process exits or is
  14. replaced by a call to `execve'. Return -1 for errors, 0 to the new process,
  15. and the process ID of the new process to the old process. */
  16. .balign 4
  17. .global ___vfork
  18. .hidden ___vfork
  19. .type ___vfork, @function
  20. ___vfork:
  21. MOV D1Ar1, #0x4111 /* CLONE_VM | CLONE_VFORK | SIGCHLD */
  22. MOV D0Ar2, #0
  23. MOV D1Ar3, #0
  24. MOV D0Ar4, #0
  25. MOV D1Ar5, #0
  26. MOV D0Ar6, #0
  27. MOV D1Re0, #__NR_clone
  28. SWITCH #0x440001
  29. MOVT D1Re0, #HI(-4096)
  30. ADD D1Re0, D1Re0, #LO(-4096)
  31. CMP D1Re0, D0Re0
  32. BCS error
  33. /* Syscall worked. Return to child/parent */
  34. MOV PC, D1RtP
  35. error:
  36. MOV D1Ar1, D0Re0
  37. #ifdef __PIC__
  38. B ___syscall_error@PLT
  39. #else
  40. B ___syscall_error
  41. #endif
  42. .size ___vfork,.-___vfork
  43. weak_alias(__vfork,vfork)
  44. libc_hidden_weak(vfork)