mips archs: fix runaway execution if start fn passed to clone returns
[musl] / src / thread / mips64 / clone.s
1 .set    noreorder
2 .global __clone
3 .type   __clone,@function
4 __clone:
5         # Save function pointer and argument pointer on new thread stack
6         and     $5, $5, -16     # aligning stack to double word
7         dsubu   $5, $5, 16
8         sd      $4, 0($5)       # save function pointer
9         sd      $7, 8($5)       # save argument pointer
10
11         # Shuffle (fn,sp,fl,arg,ptid,tls,ctid) to (fl,sp,ptid,tls,ctid)
12         # sys_clone(u64 flags, u64 ustack_base, u64 parent_tidptr, u64 child_tidptr, u64 tls)
13         move    $4, $6
14         move    $6, $8
15         move    $7, $9
16         move    $8, $10
17         li      $2, 5055
18         syscall
19         beq     $7, $0, 1f
20         nop
21         jr      $ra
22         dsubu   $2, $0, $2
23 1:      beq     $2, $0, 1f
24         nop
25         jr      $ra
26         nop
27 1:      ld      $25, 0($sp)     # function pointer
28         ld      $4, 8($sp)      # argument pointer
29         jalr    $25             # call the user's function
30         nop
31         move    $4, $2
32         li      $2, 5058
33         syscall