Skip to content

Commit 324e137

Browse files
Riku Voipioianlancetaylor
authored andcommitted
unix: fix EpollWait for arm64
epoll_wait syscall doesn't exist on arm64. Implement it with by callign epoll_pwait(). According to man epoll_pwait, calling epoll_pwait with sigmask of NULL is identical to epoll_wait. Testing exposed that EpollEvent needs padding on arm64 like on arm. This changeset is to fix: fsnotify/fsnotify#130 Testcase: go test with fsnotify ported from syscall to x/sys: https://github.com/suihkulokki/fsnotify/tree/go-sys Change-Id: I76136bf4c82c2ee597549133848f490da46dd488 Reviewed-on: https://go-review.googlesource.com/21971 Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 9eef40a commit 324e137

17 files changed

Lines changed: 144 additions & 138 deletions

unix/syscall_linux.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,6 @@ func Mount(source string, target string, fstype string, flags uintptr, data stri
872872
//sysnb EpollCreate(size int) (fd int, err error)
873873
//sysnb EpollCreate1(flag int) (fd int, err error)
874874
//sysnb EpollCtl(epfd int, op int, fd int, event *EpollEvent) (err error)
875-
//sys EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error)
876875
//sys Exit(code int) = SYS_EXIT_GROUP
877876
//sys Faccessat(dirfd int, path string, mode uint32, flags int) (err error)
878877
//sys Fallocate(fd int, mode uint32, off int64, len int64) (err error)

unix/syscall_linux_386.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ func Pipe2(p []int, flags int) (err error) {
9191
//sys Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err error) = SYS__NEWSELECT
9292

9393
//sys mmap2(addr uintptr, length uintptr, prot int, flags int, fd int, pageOffset uintptr) (xaddr uintptr, err error)
94+
//sys EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error)
9495

9596
func mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error) {
9697
page := uintptr(offset / 4096)

unix/syscall_linux_amd64.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ package unix
99
import "syscall"
1010

1111
//sys Dup2(oldfd int, newfd int) (err error)
12+
//sys EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error)
1213
//sys Fadvise(fd int, offset int64, length int64, advice int) (err error) = SYS_FADVISE64
1314
//sys Fchown(fd int, uid int, gid int) (err error)
1415
//sys Fstat(fd int, stat *Stat_t) (err error)

unix/syscall_linux_arm.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ func Seek(fd int, offset int64, whence int) (newoffset int64, err error) {
108108

109109
// Vsyscalls on amd64.
110110
//sysnb Gettimeofday(tv *Timeval) (err error)
111+
//sys EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error)
111112

112113
func Time(t *Time_t) (Time_t, error) {
113114
var tv Timeval

unix/syscall_linux_arm64.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package unix
88

99
const _SYS_dup = SYS_DUP3
1010

11+
//sys EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) = SYS_EPOLL_PWAIT
1112
//sys Fchown(fd int, uid int, gid int) (err error)
1213
//sys Fstat(fd int, stat *Stat_t) (err error)
1314
//sys Fstatat(fd int, path string, stat *Stat_t, flags int) (err error)

unix/syscall_linux_mips64x.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ package unix
1414
// Lookup linux_dirent{,64} in kernel source code for details.
1515
const _SYS_getdents = SYS_GETDENTS
1616

17+
//sys EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error)
1718
//sys Fchown(fd int, uid int, gid int) (err error)
1819
//sys Fstatfs(fd int, buf *Statfs_t) (err error)
1920
//sys Ftruncate(fd int, length int64) (err error)

unix/syscall_linux_ppc64x.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
package unix
99

10+
//sys EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error)
1011
//sys Dup2(oldfd int, newfd int) (err error)
1112
//sys Fchown(fd int, uid int, gid int) (err error)
1213
//sys Fstat(fd int, stat *Stat_t) (err error)

unix/types_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ typedef struct user_regs_struct PtraceRegs;
109109
// The real epoll_event is a union, and godefs doesn't handle it well.
110110
struct my_epoll_event {
111111
uint32_t events;
112-
#ifdef __ARM_EABI__
112+
#if defined(__ARM_EABI__) || defined(__aarch64__)
113113
// padding is not specified in linux/eventpoll.h but added to conform to the
114114
// alignment requirements of EABI
115115
int32_t padFd;

unix/zsyscall_linux_386.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -370,23 +370,6 @@ func EpollCtl(epfd int, op int, fd int, event *EpollEvent) (err error) {
370370

371371
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
372372

373-
func EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) {
374-
var _p0 unsafe.Pointer
375-
if len(events) > 0 {
376-
_p0 = unsafe.Pointer(&events[0])
377-
} else {
378-
_p0 = unsafe.Pointer(&_zero)
379-
}
380-
r0, _, e1 := Syscall6(SYS_EPOLL_WAIT, uintptr(epfd), uintptr(_p0), uintptr(len(events)), uintptr(msec), 0, 0)
381-
n = int(r0)
382-
if e1 != 0 {
383-
err = errnoErr(e1)
384-
}
385-
return
386-
}
387-
388-
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
389-
390373
func Exit(code int) {
391374
Syscall(SYS_EXIT_GROUP, uintptr(code), 0, 0)
392375
return
@@ -1582,6 +1565,23 @@ func mmap2(addr uintptr, length uintptr, prot int, flags int, fd int, pageOffset
15821565

15831566
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
15841567

1568+
func EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) {
1569+
var _p0 unsafe.Pointer
1570+
if len(events) > 0 {
1571+
_p0 = unsafe.Pointer(&events[0])
1572+
} else {
1573+
_p0 = unsafe.Pointer(&_zero)
1574+
}
1575+
r0, _, e1 := Syscall6(SYS_EPOLL_WAIT, uintptr(epfd), uintptr(_p0), uintptr(len(events)), uintptr(msec), 0, 0)
1576+
n = int(r0)
1577+
if e1 != 0 {
1578+
err = errnoErr(e1)
1579+
}
1580+
return
1581+
}
1582+
1583+
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
1584+
15851585
func getrlimit(resource int, rlim *rlimit32) (err error) {
15861586
_, _, e1 := RawSyscall(SYS_GETRLIMIT, uintptr(resource), uintptr(unsafe.Pointer(rlim)), 0)
15871587
if e1 != 0 {

unix/zsyscall_linux_amd64.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -370,23 +370,6 @@ func EpollCtl(epfd int, op int, fd int, event *EpollEvent) (err error) {
370370

371371
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
372372

373-
func EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) {
374-
var _p0 unsafe.Pointer
375-
if len(events) > 0 {
376-
_p0 = unsafe.Pointer(&events[0])
377-
} else {
378-
_p0 = unsafe.Pointer(&_zero)
379-
}
380-
r0, _, e1 := Syscall6(SYS_EPOLL_WAIT, uintptr(epfd), uintptr(_p0), uintptr(len(events)), uintptr(msec), 0, 0)
381-
n = int(r0)
382-
if e1 != 0 {
383-
err = errnoErr(e1)
384-
}
385-
return
386-
}
387-
388-
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
389-
390373
func Exit(code int) {
391374
Syscall(SYS_EXIT_GROUP, uintptr(code), 0, 0)
392375
return
@@ -1226,6 +1209,23 @@ func Dup2(oldfd int, newfd int) (err error) {
12261209

12271210
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
12281211

1212+
func EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) {
1213+
var _p0 unsafe.Pointer
1214+
if len(events) > 0 {
1215+
_p0 = unsafe.Pointer(&events[0])
1216+
} else {
1217+
_p0 = unsafe.Pointer(&_zero)
1218+
}
1219+
r0, _, e1 := Syscall6(SYS_EPOLL_WAIT, uintptr(epfd), uintptr(_p0), uintptr(len(events)), uintptr(msec), 0, 0)
1220+
n = int(r0)
1221+
if e1 != 0 {
1222+
err = errnoErr(e1)
1223+
}
1224+
return
1225+
}
1226+
1227+
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
1228+
12291229
func Fadvise(fd int, offset int64, length int64, advice int) (err error) {
12301230
_, _, e1 := Syscall6(SYS_FADVISE64, uintptr(fd), uintptr(offset), uintptr(length), uintptr(advice), 0, 0)
12311231
if e1 != 0 {

0 commit comments

Comments
 (0)