Skip to content

Commit 67b6956

Browse files
tklauserandybons
authored andcommitted
[release-branch.go1.10] syscall: use Android O friendly fstatat syscall to implement Stat on linux/amd64
The Android O seccomp policy disallows the stat syscall on amd64, see https://android.googlesource.com/platform/bionic/+/android-4.2.2_r1.2/libc/SYSCALLS.TXT Use the fstatat syscall with AT_FDCWD and zero flags instead to achieve the same behavior. Fixes #24403 Change-Id: I36fc9ec9bc938cd8e9de30f66c0eb9d2e24debf6 Reviewed-on: https://go-review.googlesource.com/100878 Run-TryBot: Tobias Klauser <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]> Reviewed-by: Elias Naur <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-on: https://go-review.googlesource.com/102976 Run-TryBot: Andrew Bonventre <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 8d90bb4 commit 67b6956

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

src/syscall/syscall_linux_amd64.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ const (
3939
//sysnb Setreuid(ruid int, euid int) (err error)
4040
//sys Shutdown(fd int, how int) (err error)
4141
//sys Splice(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n int64, err error)
42-
//sys Stat(path string, stat *Stat_t) (err error)
4342
//sys Statfs(path string, buf *Statfs_t) (err error)
4443
//sys SyncFileRange(fd int, off int64, n int64, flags int) (err error)
4544
//sys Truncate(path string, length int64) (err error)
4645
//sys accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error)
4746
//sys accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error)
4847
//sys bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)
4948
//sys connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)
49+
//sys fstatat(fd int, path string, stat *Stat_t, flags int) (err error) = SYS_NEWFSTATAT
5050
//sysnb getgroups(n int, list *_Gid_t) (nn int, err error)
5151
//sysnb setgroups(n int, list *_Gid_t) (err error)
5252
//sys getsockopt(s int, level int, name int, val unsafe.Pointer, vallen *_Socklen) (err error)
@@ -61,6 +61,10 @@ const (
6161
//sys sendmsg(s int, msg *Msghdr, flags int) (n int, err error)
6262
//sys mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error)
6363

64+
func Stat(path string, stat *Stat_t) (err error) {
65+
return fstatat(_AT_FDCWD, path, stat, 0)
66+
}
67+
6468
//go:noescape
6569
func gettimeofday(tv *Timeval) (err Errno)
6670

src/syscall/zsyscall_linux_amd64.go

+15-15
Original file line numberDiff line numberDiff line change
@@ -1476,21 +1476,6 @@ func Splice(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n i
14761476

14771477
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
14781478

1479-
func Stat(path string, stat *Stat_t) (err error) {
1480-
var _p0 *byte
1481-
_p0, err = BytePtrFromString(path)
1482-
if err != nil {
1483-
return
1484-
}
1485-
_, _, e1 := Syscall(SYS_STAT, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), 0)
1486-
if e1 != 0 {
1487-
err = errnoErr(e1)
1488-
}
1489-
return
1490-
}
1491-
1492-
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
1493-
14941479
func Statfs(path string, buf *Statfs_t) (err error) {
14951480
var _p0 *byte
14961481
_p0, err = BytePtrFromString(path)
@@ -1573,6 +1558,21 @@ func connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) {
15731558

15741559
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
15751560

1561+
func fstatat(fd int, path string, stat *Stat_t, flags int) (err error) {
1562+
var _p0 *byte
1563+
_p0, err = BytePtrFromString(path)
1564+
if err != nil {
1565+
return
1566+
}
1567+
_, _, e1 := Syscall6(SYS_NEWFSTATAT, uintptr(fd), uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), uintptr(flags), 0, 0)
1568+
if e1 != 0 {
1569+
err = errnoErr(e1)
1570+
}
1571+
return
1572+
}
1573+
1574+
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
1575+
15761576
func getgroups(n int, list *_Gid_t) (nn int, err error) {
15771577
r0, _, e1 := RawSyscall(SYS_GETGROUPS, uintptr(n), uintptr(unsafe.Pointer(list)), 0)
15781578
nn = int(r0)

0 commit comments

Comments
 (0)