From f67ecc163a74fbeea4cb1db0a101dcd07201464a Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Sun, 29 Apr 2018 09:29:05 +0200 Subject: [PATCH] unix: use Fstatat for Stat on linux/amd64 The stat syscall is disallowed by Android's seccomp policy on linux/amd64. Use the fstatat syscall with AT_FDCWD and zero flags to achieve the same behavior. CL 109835 did the same for package syscall. Change-Id: Iaa7d0dbf17ade4803f59b4361973ce627bcb65b4 Reviewed-on: https://go-review.googlesource.com/110061 Run-TryBot: Tobias Klauser TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- unix/syscall_linux_amd64.go | 7 ++++++- unix/zsyscall_linux_amd64.go | 15 --------------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/unix/syscall_linux_amd64.go b/unix/syscall_linux_amd64.go index 86a7393f..d1211063 100644 --- a/unix/syscall_linux_amd64.go +++ b/unix/syscall_linux_amd64.go @@ -48,7 +48,12 @@ func Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err //sysnb Setreuid(ruid int, euid int) (err error) //sys Shutdown(fd int, how int) (err error) //sys Splice(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n int64, err error) -//sys Stat(path string, stat *Stat_t) (err error) + +func Stat(path string, stat *Stat_t) (err error) { + // Use fstatat, because Android's seccomp policy blocks stat. + return Fstatat(AT_FDCWD, path, stat, 0) +} + //sys Statfs(path string, buf *Statfs_t) (err error) //sys SyncFileRange(fd int, off int64, n int64, flags int) (err error) //sys Truncate(path string, length int64) (err error) diff --git a/unix/zsyscall_linux_amd64.go b/unix/zsyscall_linux_amd64.go index 02e45b48..33c02b26 100644 --- a/unix/zsyscall_linux_amd64.go +++ b/unix/zsyscall_linux_amd64.go @@ -1897,21 +1897,6 @@ func Splice(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n i // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Stat(path string, stat *Stat_t) (err error) { - var _p0 *byte - _p0, err = BytePtrFromString(path) - if err != nil { - return - } - _, _, e1 := Syscall(SYS_STAT, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), 0) - if e1 != 0 { - err = errnoErr(e1) - } - return -} - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - func Statfs(path string, buf *Statfs_t) (err error) { var _p0 *byte _p0, err = BytePtrFromString(path)