[MIPS] Fix syscall clone implementation
After compiling lss with Clang/LLVM, two issues came up:
a) clang complains about named register __r7 being listed both as input
argument and input-output argument, and
b) clang does weird things if input argument is not actually initialized
before asm block.
This change fixes those two issues by removing __r7 from the input argument
list and by moving __v0 initialization out of asm block.
Review URL: https://codereview.chromium.org/913723002/
git-svn-id: http://linux-syscall-support.googlecode.com/svn/trunk/lss@34 829466d3-f3f5-3ae4-62ad-de35cf9bba21
diff --git a/linux_syscall_support.h b/linux_syscall_support.h
index 35272ed..d09e3a0 100644
--- a/linux_syscall_support.h
+++ b/linux_syscall_support.h
@@ -2695,7 +2695,7 @@
LSS_INLINE int LSS_NAME(clone)(int (*fn)(void *), void *child_stack,
int flags, void *arg, int *parent_tidptr,
void *newtls, int *child_tidptr) {
- register unsigned long __v0 __asm__("$2");
+ register unsigned long __v0 __asm__("$2") = -EINVAL;
register unsigned long __r7 __asm__("$7") = (unsigned long)newtls;
{
register int __flags __asm__("$4") = flags;
@@ -2714,25 +2714,24 @@
/* if (fn == NULL || child_stack == NULL)
* return -EINVAL;
*/
- "li %0,%2\n"
+ "beqz %4,1f\n"
"beqz %5,1f\n"
- "beqz %6,1f\n"
/* Push "arg" and "fn" onto the stack that will be
* used by the child.
*/
#if _MIPS_SIM == _MIPS_SIM_ABI32 && _MIPS_SZPTR == 32
- "subu %6,32\n"
- "sw %5,0(%6)\n"
- "sw %8,4(%6)\n"
+ "subu %5,32\n"
+ "sw %4,0(%5)\n"
+ "sw %7,4(%5)\n"
#elif _MIPS_SIM == _MIPS_SIM_NABI32
- "sub %6,32\n"
- "sw %5,0(%6)\n"
- "sw %8,8(%6)\n"
+ "sub %5,32\n"
+ "sw %4,0(%5)\n"
+ "sw %7,8(%5)\n"
#else
- "dsubu %6,32\n"
- "sd %5,0(%6)\n"
- "sd %8,8(%6)\n"
+ "dsubu %5,32\n"
+ "sd %4,0(%5)\n"
+ "sd %7,8(%5)\n"
#endif
/* $7 = syscall($4 = flags,
@@ -2741,7 +2740,7 @@
* $7 = newtls,
* $8 = child_tidptr)
*/
- "li $2,%3\n"
+ "li $2,%2\n"
"syscall\n"
/* if ($7 != 0)
@@ -2767,7 +2766,7 @@
/* Call _exit($2)
*/
"move $4,$2\n"
- "li $2,%4\n"
+ "li $2,%3\n"
"syscall\n"
"1:\n"
@@ -2779,9 +2778,9 @@
"daddu $29,16\n"
#endif
: "+r" (__v0), "+r" (__r7)
- : "i"(-EINVAL), "i"(__NR_clone), "i"(__NR_exit),
- "r"(fn), "r"(__stack), "r"(__flags), "r"(arg),
- "r"(__ptid), "r"(__r7), "r"(__ctid)
+ : "i"(__NR_clone), "i"(__NR_exit), "r"(fn),
+ "r"(__stack), "r"(__flags), "r"(arg),
+ "r"(__ptid), "r"(__ctid)
: "$9", "$10", "$11", "$12", "$13", "$14", "$15",
"$24", "$25", "memory");
}