vfork.S 733 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include <features.h>
  2. #define _ERRNO_H
  3. #include <bits/errno.h>
  4. #include <asm/unistd.h>
  5. #define _SIGNAL_H
  6. #include <bits/signum.h>
  7. #define CLONE_VM 0x00000100 /* set if VM shared between processes */
  8. #define CLONE_VFORK 0x00004000 /* set if the parent wants the child to */
  9. .text
  10. .global __vfork
  11. .hidden __vfork
  12. .type __vfork,%function
  13. .align 4
  14. __vfork:
  15. mvi r2, 0
  16. mvi r3, CLONE_VFORK | CLONE_VM | SIGCHLD
  17. mvi r8, __NR_clone
  18. scall
  19. mvi r2, -4096
  20. bgeu r2, r1, 1f
  21. addi sp, sp, -8
  22. sw (sp+4), ra
  23. sw (sp+8), r1
  24. calli __errno_location
  25. lw r2, (sp+8)
  26. lw ra, (sp+4)
  27. sub r2, r0, r2
  28. sw (r1+0), r2
  29. addi sp, sp, 8
  30. mvi r1, -1
  31. 1:
  32. ret
  33. .size __vfork,.-__vfork
  34. weak_alias(__vfork,vfork)
  35. libc_hidden_weak(vfork)