Skip to content

Commit

Permalink
Change syscall.POLL to syscall.PPOLL.
Browse files Browse the repository at this point in the history
syscall.POLL is not supported on arm64, using syscall.PPOLL
to support both the x86 and arm64. refs #63

Signed-off-by: Haibo Xu <haibo.xu@arm.com>
Change-Id: I2c81a063d3ec4e7e6b38fe62f17a0924977f505e
COPYBARA_INTEGRATE_REVIEW=#543 from xiaobo55x:master ba598263fd3748d1addd48e4194080aa12085164
PiperOrigin-RevId: 260752049
  • Loading branch information
Haibo Xu authored and gvisor-bot committed Jul 30, 2019
1 parent 8da9f8a commit 1decf76
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 17 deletions.
8 changes: 7 additions & 1 deletion pkg/fdnotifier/poll_unsafe.go
Expand Up @@ -35,8 +35,14 @@ func NonBlockingPoll(fd int32, mask waiter.EventMask) waiter.EventMask {
events: int16(mask.ToLinux()),
}

ts := syscall.Timespec{
Sec: 0,
Nsec: 0,
}

for {
n, _, err := syscall.RawSyscall(syscall.SYS_POLL, uintptr(unsafe.Pointer(&e)), 1, 0)
n, _, err := syscall.RawSyscall6(syscall.SYS_PPOLL, uintptr(unsafe.Pointer(&e)), 1,
uintptr(unsafe.Pointer(&ts)), 0, 0, 0)
// Interrupted by signal, try again.
if err == syscall.EINTR {
continue
Expand Down
2 changes: 1 addition & 1 deletion pkg/seccomp/seccomp_test_victim.go
Expand Up @@ -70,7 +70,7 @@ func main() {
syscall.SYS_NANOSLEEP: {},
syscall.SYS_NEWFSTATAT: {},
syscall.SYS_OPEN: {},
syscall.SYS_POLL: {},
syscall.SYS_PPOLL: {},
syscall.SYS_PREAD64: {},
syscall.SYS_PSELECT6: {},
syscall.SYS_PWRITE64: {},
Expand Down
2 changes: 1 addition & 1 deletion pkg/tcpip/link/fdbased/mmap_amd64.go
Expand Up @@ -134,7 +134,7 @@ func (d *packetMMapDispatcher) readMMappedPacket() ([]byte, *tcpip.Error) {
FD: int32(d.fd),
Events: unix.POLLIN | unix.POLLERR,
}
if _, errno := rawfile.BlockingPoll(&event, 1, -1); errno != 0 {
if _, errno := rawfile.BlockingPoll(&event, 1, nil); errno != 0 {
if errno == syscall.EINTR {
continue
}
Expand Down
7 changes: 4 additions & 3 deletions pkg/tcpip/link/rawfile/blockingpoll_amd64.s
Expand Up @@ -14,17 +14,18 @@

#include "textflag.h"

// BlockingPoll makes the poll() syscall while calling the version of
// BlockingPoll makes the ppoll() syscall while calling the version of
// entersyscall that relinquishes the P so that other Gs can run. This is meant
// to be called in cases when the syscall is expected to block.
//
// func BlockingPoll(fds *PollEvent, nfds int, timeout int64) (n int, err syscall.Errno)
// func BlockingPoll(fds *PollEvent, nfds int, timeout *syscall.Timespec) (n int, err syscall.Errno)
TEXT ·BlockingPoll(SB),NOSPLIT,$0-40
CALL ·callEntersyscallblock(SB)
MOVQ fds+0(FP), DI
MOVQ nfds+8(FP), SI
MOVQ timeout+16(FP), DX
MOVQ $0x7, AX // SYS_POLL
MOVQ $0x0, R10 // sigmask parameter which isn't used here
MOVQ $0x10f, AX // SYS_PPOLL
SYSCALL
CMPQ AX, $0xfffffffffffff001
JLS ok
Expand Down
2 changes: 1 addition & 1 deletion pkg/tcpip/link/rawfile/blockingpoll_amd64_unsafe.go
Expand Up @@ -26,7 +26,7 @@ import (
)

//go:noescape
func BlockingPoll(fds *PollEvent, nfds int, timeout int64) (int, syscall.Errno)
func BlockingPoll(fds *PollEvent, nfds int, timeout *syscall.Timespec) (int, syscall.Errno)

// Use go:linkname to call into the runtime. As of Go 1.12 this has to
// be done from Go code so that we make an ABIInternal call to an
Expand Down
8 changes: 5 additions & 3 deletions pkg/tcpip/link/rawfile/blockingpoll_unsafe.go
Expand Up @@ -21,9 +21,11 @@ import (
"unsafe"
)

// BlockingPoll is just a stub function that forwards to the poll() system call
// BlockingPoll is just a stub function that forwards to the ppoll() system call
// on non-amd64 platforms.
func BlockingPoll(fds *PollEvent, nfds int, timeout int64) (int, syscall.Errno) {
n, _, e := syscall.Syscall(syscall.SYS_POLL, uintptr(unsafe.Pointer(fds)), uintptr(nfds), uintptr(timeout))
func BlockingPoll(fds *PollEvent, nfds int, timeout *syscall.Timespec) (int, syscall.Errno) {
n, _, e := syscall.Syscall6(syscall.SYS_PPOLL, uintptr(unsafe.Pointer(fds)),
uintptr(nfds), uintptr(unsafe.Pointer(timeout)), 0, 0, 0)

return int(n), e
}
6 changes: 3 additions & 3 deletions pkg/tcpip/link/rawfile/rawfile_unsafe.go
Expand Up @@ -123,7 +123,7 @@ func BlockingRead(fd int, b []byte) (int, *tcpip.Error) {
Events: 1, // POLLIN
}

_, e = BlockingPoll(&event, 1, -1)
_, e = BlockingPoll(&event, 1, nil)
if e != 0 && e != syscall.EINTR {
return 0, TranslateErrno(e)
}
Expand All @@ -145,7 +145,7 @@ func BlockingReadv(fd int, iovecs []syscall.Iovec) (int, *tcpip.Error) {
Events: 1, // POLLIN
}

_, e = BlockingPoll(&event, 1, -1)
_, e = BlockingPoll(&event, 1, nil)
if e != 0 && e != syscall.EINTR {
return 0, TranslateErrno(e)
}
Expand Down Expand Up @@ -175,7 +175,7 @@ func BlockingRecvMMsg(fd int, msgHdrs []MMsgHdr) (int, *tcpip.Error) {
Events: 1, // POLLIN
}

if _, e := BlockingPoll(&event, 1, -1); e != 0 && e != syscall.EINTR {
if _, e := BlockingPoll(&event, 1, nil); e != 0 && e != syscall.EINTR {
return 0, TranslateErrno(e)
}
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/unet/unet_unsafe.go
Expand Up @@ -16,7 +16,6 @@ package unet

import (
"io"
"math"
"sync/atomic"
"syscall"
"unsafe"
Expand Down Expand Up @@ -53,7 +52,7 @@ func (s *Socket) wait(write bool) error {
events[0].Events = unix.POLLOUT
}

_, _, e := syscall.Syscall(syscall.SYS_POLL, uintptr(unsafe.Pointer(&events[0])), 2, uintptr(math.MaxUint64))
_, _, e := syscall.Syscall6(syscall.SYS_PPOLL, uintptr(unsafe.Pointer(&events[0])), 2, 0, 0, 0, 0)
if e == syscall.EINTR {
continue
}
Expand Down
2 changes: 1 addition & 1 deletion runsc/boot/filter/config.go
Expand Up @@ -207,7 +207,7 @@ var allowedSyscalls = seccomp.SyscallRules{
syscall.SYS_MPROTECT: {},
syscall.SYS_MUNMAP: {},
syscall.SYS_NANOSLEEP: {},
syscall.SYS_POLL: {},
syscall.SYS_PPOLL: {},
syscall.SYS_PREAD64: {},
syscall.SYS_PWRITE64: {},
syscall.SYS_READ: {},
Expand Down
2 changes: 1 addition & 1 deletion runsc/fsgofer/filter/config.go
Expand Up @@ -138,7 +138,7 @@ var allowedSyscalls = seccomp.SyscallRules{
syscall.SYS_NANOSLEEP: {},
syscall.SYS_NEWFSTATAT: {},
syscall.SYS_OPENAT: {},
syscall.SYS_POLL: {},
syscall.SYS_PPOLL: {},
syscall.SYS_PREAD64: {},
syscall.SYS_PWRITE64: {},
syscall.SYS_READ: {},
Expand Down

0 comments on commit 1decf76

Please sign in to comment.