From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/11377 Path: news.gmane.org!.POSTED!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: mips64 fstatat broken Date: Wed, 31 May 2017 12:32:31 -0400 Message-ID: <20170531163231.GI1627@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="4Ckj6UjgE2iN1+kY" X-Trace: blaine.gmane.org 1496248369 4904 195.159.176.226 (31 May 2017 16:32:49 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 31 May 2017 16:32:49 +0000 (UTC) User-Agent: Mutt/1.5.21 (2010-09-15) To: musl@lists.openwall.com Original-X-From: musl-return-11390-gllmg-musl=m.gmane.org@lists.openwall.com Wed May 31 18:32:45 2017 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1dG6Y9-00013u-My for gllmg-musl@m.gmane.org; Wed, 31 May 2017 18:32:45 +0200 Original-Received: (qmail 10118 invoked by uid 550); 31 May 2017 16:32:47 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 10071 invoked from network); 31 May 2017 16:32:43 -0000 Content-Disposition: inline Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:11377 Archived-At: --4Ckj6UjgE2iN1+kY Content-Type: text/plain; charset=us-ascii Content-Disposition: inline The mips64 port requires 'struct stat' conversion due to incorrect 32-bit fields where time_t should be in the kernel version of the structure. The mips64 port performs the correct translation for stat, fstat, and lstat syscalls, but omits any special handling for fstatat. I'm planning to commit the attached patch to fix it; casual testing (linking toybox against the resulting libc and running toybox ls) seems to show it works. I also plan to remove (in a separate commit) the old __clang__ check that suppresses inline syscalls on mips and mips64; it seems the relevant bug in clang was fixed long before clang was safe for compiling musl. Rich --4Ckj6UjgE2iN1+kY Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="mips64stat.diff" diff --git a/arch/mips64/syscall_arch.h b/arch/mips64/syscall_arch.h index 1bd6c18..bb73dc3 100644 --- a/arch/mips64/syscall_arch.h +++ b/arch/mips64/syscall_arch.h @@ -149,13 +149,15 @@ static inline long __syscall4(long n, long a, long b, long c, long d) register long r7 __asm__("$7"); register long r2 __asm__("$2"); + r4 = a; r5 = b; + r6 = c; + r7 = d; if (n == SYS_stat || n == SYS_fstat || n == SYS_lstat) r5 = (long) &kst; + if (n == SYS_newfstatat) + r6 = (long) &kst; - r4 = a; - r6 = c; - r7 = d; __asm__ __volatile__ ( "daddu $2,$0,%2 ; syscall" : "=&r"(r2), "=r"(r7) : "ir"(n), "0"(r2), "1"(r7), @@ -168,6 +170,8 @@ static inline long __syscall4(long n, long a, long b, long c, long d) if (n == SYS_stat || n == SYS_fstat || n == SYS_lstat) __stat_fix(&kst, (struct stat *)b); + if (n == SYS_newfstatat) + __stat_fix(&kst, (struct stat *)c); return ret; } @@ -224,16 +228,21 @@ static inline long __syscall4(long n, long a, long b, long c, long d) { long r2; long old_b = b; + long old_c = c; struct kernel_stat kst; if (n == SYS_stat || n == SYS_fstat || n == SYS_lstat) b = (long) &kst; + if (n == SYS_newfstatat) + c = (long) &kst; r2 = (__syscall)(n, a, b, c, d); if (r2 > -4096UL) return r2; if (n == SYS_stat || n == SYS_fstat || n == SYS_lstat) __stat_fix(&kst, (struct stat *)old_b); + if (n == SYS_newfstatat) + __stat_fix(&kst, (struct stat *)old_c); return r2; } @@ -244,16 +253,21 @@ static inline long __syscall5(long n, long a, long b, long c, long d, long e) { long r2; long old_b = b; + long old_c = c; struct kernel_stat kst; if (n == SYS_stat || n == SYS_fstat || n == SYS_lstat) b = (long) &kst; + if (n == SYS_newfstatat) + c = (long) &kst; r2 = (__syscall)(n, a, b, c, d, e); if (r2 > -4096UL) return r2; if (n == SYS_stat || n == SYS_fstat || n == SYS_lstat) __stat_fix(&kst, (struct stat *)old_b); + if (n == SYS_newfstatat) + __stat_fix(&kst, (struct stat *)old_c); return r2; } @@ -262,16 +276,21 @@ static inline long __syscall6(long n, long a, long b, long c, long d, long e, lo { long r2; long old_b = b; + long old_c = c; struct kernel_stat kst; if (n == SYS_stat || n == SYS_fstat || n == SYS_lstat) b = (long) &kst; + if (n == SYS_newfstatat) + c = (long) &kst; r2 = (__syscall)(n, a, b, c, d, e, f); if (r2 > -4096UL) return r2; if (n == SYS_stat || n == SYS_fstat || n == SYS_lstat) __stat_fix(&kst, (struct stat *)old_b); + if (n == SYS_newfstatat) + __stat_fix(&kst, (struct stat *)old_c); return r2; } --4Ckj6UjgE2iN1+kY--