clone.S 651 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include <features.h>
  2. #include <sys/syscall.h>
  3. #define _ERRNO_H 1
  4. #include <bits/errno.h>
  5. #ifdef __NR_clone
  6. .text
  7. .global clone
  8. .type clone,@function
  9. .align 4
  10. clone:
  11. be r1, r0, 2f
  12. be r2, r0, 2f
  13. mvi r8, __NR_clone
  14. scall
  15. mvi r3, -4095
  16. bgeu r1, r3, 1f
  17. be r1, r0, __thread_start
  18. ret
  19. __thread_start:
  20. mvi fp, 0
  21. call r2
  22. calli HIDDEN_JUMPTARGET(_exit)
  23. /* Stop the unstoppable. */
  24. 9:
  25. bi 9b
  26. 2:
  27. mvi r1, -EINVAL
  28. 1:
  29. addi sp, sp, -8
  30. sw (sp+4), ra
  31. sw (sp+8), r1
  32. calli __errno_location
  33. lw r2, (sp+8)
  34. lw ra, (sp+4)
  35. sub r2, r0, r2
  36. sw (r1+0), r2
  37. mvi r1, -1
  38. addi sp, sp, 8
  39. ret
  40. #endif /* __NR_clone */