1# __clone(func, stack, flags, arg, ptid, tls, ctid) 2# a0, a1, a2, a3, a4, a5, a6 3 4# syscall(SYS_clone, flags, stack, ptid, tls, ctid) 5# a7 a0, a1, a2, a3, a4 6 7.global __clone 8.type __clone, %function 9__clone: 10 # Save func and arg to stack 11 addi a1, a1, -16 12 sd a0, 0(a1) 13 sd a3, 8(a1) 14 15 # Call SYS_clone 16 mv a0, a2 17 mv a2, a4 18 mv a3, a5 19 mv a4, a6 20 li a7, 220 # SYS_clone 21 ecall 22 23 beqz a0, 1f 24 # Parent 25 ret 26 27 # Child 281: ld a1, 0(sp) 29 ld a0, 8(sp) 30 jalr a1 31 32 # Exit 33 li a7, 93 # SYS_exit 34 ecall 35