vfork.S 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. #ifndef SAVE_PID
  8. #define SAVE_PID
  9. #endif
  10. #ifndef RESTORE_PID
  11. #define RESTORE_PID
  12. #endif
  13. #ifdef __NR_vfork
  14. #define __VFORK_NR __NR_vfork
  15. #else
  16. #define __VFORK_NR __NR_fork
  17. #endif
  18. /* Clone the calling process, but without copying the whole address space.
  19. The calling process is suspended until the new process exits or is
  20. replaced by a call to `execve'. Return -1 for errors, 0 to the new process,
  21. and the process ID of the new process to the old process. */
  22. .balign 4
  23. .global ___vfork
  24. .hidden ___vfork
  25. .type ___vfork, @function
  26. ___vfork:
  27. SAVE_PID
  28. MOV D1Ar1, #0x4111 /* CLONE_VM | CLONE_VFORK | SIGCHLD */
  29. MOV D0Ar2, #0
  30. MOV D1Ar3, #0
  31. MOV D0Ar4, #0
  32. MOV D1Ar5, #0
  33. MOV D0Ar6, #0
  34. MOV D1Re0, #__NR_clone
  35. SWITCH #0x440001
  36. RESTORE_PID
  37. MOVT D1Re0, #HI(-4096)
  38. ADD D1Re0, D1Re0, #LO(-4096)
  39. CMP D1Re0, D0Re0
  40. BCS error
  41. /* Syscall worked. Return to child/parent */
  42. MOV PC, D1RtP
  43. error:
  44. MOV D1Ar1, D0Re0
  45. #ifdef __PIC__
  46. B ___syscall_error@PLT
  47. #else
  48. B ___syscall_error
  49. #endif
  50. .size ___vfork,.-___vfork
  51. weak_alias(__vfork,vfork)
  52. libc_hidden_weak(vfork)