fix mips clone() on real linux kernel
authorRich Felker <dalias@aerifal.cx>
Thu, 12 Jul 2012 02:59:43 +0000 (22:59 -0400)
committerRich Felker <dalias@aerifal.cx>
Thu, 12 Jul 2012 02:59:43 +0000 (22:59 -0400)
the old code worked in qemu app-level emulation, but not on real
kernels where the clone syscall does not copy the register values to
the new thread. save arguments on the new thread stack instead.

src/thread/mips/clone.s

index a7c2d90..fab90dc 100644 (file)
@@ -2,9 +2,10 @@
 .global __clone
 .type   __clone,@function
 __clone:
-       # Save function pointer and argument pointer
-       move $25, $4
-       move $8, $7
+       # Save function pointer and argument pointer on new thread stack
+       subu $5, $5, 16
+       sw $4, 0($5)
+       sw $7, 4($5)
        # Shuffle (fn,sp,fl,arg,ptid,tls,ctid) to (fl,sp,ptid,tls,ctid)
        move $4, $6
        lw $6, 16($sp)
@@ -21,6 +22,8 @@ __clone:
        nop
        jr $ra
        nop
-1:     move $4, $8
+1:     lw $25, 0($sp)
+       lw $4, 4($sp)
        jr $25
+       addu $sp, $sp, 16
        nop