commit fcf42a69afdbf932a56efcf6c2d0dafc5c8faa12 Author: Daniel Dorau Date: Mon Oct 21 16:26:47 2019 +0200 Fix Backtrace aus syscall5,6,7 Damit syscall5,6,7 den stack pointer nicht mehrmals ändern und damit der Backtracer eine falsche frame-Größe annimmt, den Syscall in einer separaten Assemblerfunktion durchführen. Inspririert durch: https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=319cbbf633ae60d7b4b89fcbb11a734f4d7d22f0 diff --git a/arch/mips/syscall_arch.h b/arch/mips/syscall_arch.h index 43bcdee..6503e56 100644 --- a/arch/mips/syscall_arch.h +++ b/arch/mips/syscall_arch.h @@ -100,22 +100,14 @@ static inline long __syscall4(long n, long a, long b, long c, long d) return ret; } +extern long __mips_syscall5 (long a, long b, long c, long d, long e, long n); + static inline long __syscall5(long n, long a, long b, long c, long d, long e) { - register long r4 __asm__("$4") = a; - register long r5 __asm__("$5") = b; - register long r6 __asm__("$6") = c; - register long r7 __asm__("$7") = d; - register long r8 __asm__("$8") = e; - register long r2 __asm__("$2"); - __asm__ __volatile__ ( - "subu $sp,$sp,32 ; sw $8,16($sp) ; " - "addu $2,$0,%3 ; syscall ;" - "addu $sp,$sp,32" - : "=&r"(r2), "=r"(r7), "+r"(r8) - : "ir"(n), "0"(r2), "1"(r7), "r"(r4), "r"(r5), "r"(r6) - : "$1", "$3", "$9", "$10", "$11", "$12", "$13", - "$14", "$15", "$24", "$25", "hi", "lo", "memory"); + register long r7 __asm__("$7"); // a3 + register long r2 __asm__("$2"); // v0 + + __mips_syscall5(a, b, c, d, e, n); if (r7) return -r2; long ret = r2; if (n == SYS_stat64 || n == SYS_fstat64 || n == SYS_lstat64) __stat_fix(b); @@ -123,23 +115,14 @@ static inline long __syscall5(long n, long a, long b, long c, long d, long e) return r2; } +extern long __mips_syscall6 (long a, long b, long c, long d, long e, long f, long n); + static inline long __syscall6(long n, long a, long b, long c, long d, long e, long f) { - register long r4 __asm__("$4") = a; - register long r5 __asm__("$5") = b; - register long r6 __asm__("$6") = c; - register long r7 __asm__("$7") = d; - register long r8 __asm__("$8") = e; - register long r9 __asm__("$9") = f; - register long r2 __asm__("$2"); - __asm__ __volatile__ ( - "subu $sp,$sp,32 ; sw $8,16($sp) ; sw $9,20($sp) ; " - "addu $2,$0,%4 ; syscall ;" - "addu $sp,$sp,32" - : "=&r"(r2), "=r"(r7), "+r"(r8), "+r"(r9) - : "ir"(n), "0"(r2), "1"(r7), "r"(r4), "r"(r5), "r"(r6) - : "$1", "$3", "$10", "$11", "$12", "$13", - "$14", "$15", "$24", "$25", "hi", "lo", "memory"); + register long r7 __asm__("$7"); // a3 + register long r2 __asm__("$2"); // v0 + + __mips_syscall6(a, b, c, d, e, f, n); if (r7) return -r2; long ret = r2; if (n == SYS_stat64 || n == SYS_fstat64 || n == SYS_lstat64) __stat_fix(b); @@ -147,24 +130,14 @@ static inline long __syscall6(long n, long a, long b, long c, long d, long e, lo return r2; } +extern long __mips_syscall7 (long a, long b, long c, long d, long e, long f, long g, long n); + static inline long __syscall7(long n, long a, long b, long c, long d, long e, long f, long g) { - register long r4 __asm__("$4") = a; - register long r5 __asm__("$5") = b; - register long r6 __asm__("$6") = c; - register long r7 __asm__("$7") = d; - register long r8 __asm__("$8") = e; - register long r9 __asm__("$9") = f; - register long r10 __asm__("$10") = g; - register long r2 __asm__("$2"); - __asm__ __volatile__ ( - "subu $sp,$sp,32 ; sw $8,16($sp) ; sw $9,20($sp) ; sw $10,24($sp) ; " - "addu $2,$0,%5 ; syscall ;" - "addu $sp,$sp,32" - : "=&r"(r2), "=r"(r7), "+r"(r8), "+r"(r9), "+r"(r10) - : "ir"(n), "0"(r2), "1"(r7), "r"(r4), "r"(r5), "r"(r6) - : "$1", "$3", "$11", "$12", "$13", - "$14", "$15", "$24", "$25", "hi", "lo", "memory"); + register long r7 __asm__("$7"); // a3 + register long r2 __asm__("$2"); // v0 + + __mips_syscall7(a, b, c, d, e, f, g, n); if (r7) return -r2; long ret = r2; if (n == SYS_stat64 || n == SYS_fstat64 || n == SYS_lstat64) __stat_fix(b); diff --git a/src/misc/mips/syscall5.s b/src/misc/mips/syscall5.s new file mode 100644 index 0000000..54a99c0 --- /dev/null +++ b/src/misc/mips/syscall5.s @@ -0,0 +1,12 @@ +.set nomips16 + +.global __mips_syscall5 +.type __mips_syscall5,@function + +/* long __mips_syscall5 (long a, long b, long c, long d, long e, long n) */ + +__mips_syscall5: + lw $v0, 20($sp) + syscall + move $v1, $a3 + jr $ra diff --git a/src/misc/mips/syscall6.s b/src/misc/mips/syscall6.s new file mode 100644 index 0000000..c02a89d --- /dev/null +++ b/src/misc/mips/syscall6.s @@ -0,0 +1,12 @@ +.set nomips16 + +.global __mips_syscall6 +.type __mips_syscall6,@function + +/* long __mips_syscall6 (long a, long b, long c, long d, long e, long f, long n) */ + +__mips_syscall6: + lw $v0, 24($sp) + syscall + move $v1, $a3 + jr $ra diff --git a/src/misc/mips/syscall7.s b/src/misc/mips/syscall7.s new file mode 100644 index 0000000..97f282d --- /dev/null +++ b/src/misc/mips/syscall7.s @@ -0,0 +1,12 @@ +.set nomips16 + +.global __mips_syscall7 +.type __mips_syscall7,@function + +/* long __mips_syscall7 (long a, long b, long c, long d, long e, long f, long g, long n) */ + +__mips_syscall7: + lw $v0, 28($sp) + syscall + move $v1, $a3 + jr $ra