summaryrefslogtreecommitdiffhomepage
path: root/pkg
diff options
context:
space:
mode:
authorIan Gudger <igudger@google.com>2018-07-06 10:57:37 -0700
committerShentubot <shentubot@google.com>2018-07-06 10:58:37 -0700
commit5c88e6a15d46bba6237a44d98c4e172237c9aea3 (patch)
treea8b993439892d9607525bae17d88e409eef30ab0 /pkg
parentf107a5b1a0e264d518617c57f0cf310b63e8b59c (diff)
Add non-AMD64 support to rawfile
PiperOrigin-RevId: 203499064 Change-Id: I2cd5189638e94ce926f1e82c1264a8d3ece9dfa5
Diffstat (limited to 'pkg')
-rw-r--r--pkg/tcpip/link/rawfile/BUILD2
-rw-r--r--pkg/tcpip/link/rawfile/blockingpoll_amd64.s2
-rw-r--r--pkg/tcpip/link/rawfile/blockingpoll_unsafe.go17
-rw-r--r--pkg/tcpip/link/rawfile/blockingpoll_unsafe_amd64.go14
-rw-r--r--pkg/tcpip/link/rawfile/errors.go2
-rw-r--r--pkg/tcpip/link/rawfile/rawfile_unsafe.go27
6 files changed, 48 insertions, 16 deletions
diff --git a/pkg/tcpip/link/rawfile/BUILD b/pkg/tcpip/link/rawfile/BUILD
index 4c63af0ea..b43de5530 100644
--- a/pkg/tcpip/link/rawfile/BUILD
+++ b/pkg/tcpip/link/rawfile/BUILD
@@ -6,6 +6,8 @@ go_library(
name = "rawfile",
srcs = [
"blockingpoll_amd64.s",
+ "blockingpoll_unsafe.go",
+ "blockingpoll_unsafe_amd64.go",
"errors.go",
"rawfile_unsafe.go",
],
diff --git a/pkg/tcpip/link/rawfile/blockingpoll_amd64.s b/pkg/tcpip/link/rawfile/blockingpoll_amd64.s
index d6778dafe..7635900a5 100644
--- a/pkg/tcpip/link/rawfile/blockingpoll_amd64.s
+++ b/pkg/tcpip/link/rawfile/blockingpoll_amd64.s
@@ -8,7 +8,7 @@
// 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 unsafe.Pointer, nfds int, timeout int64) (n int, err syscall.Errno)
+// func blockingPoll(fds *pollEvent, nfds int, timeout int64) (n int, err syscall.Errno)
TEXT ·blockingPoll(SB),NOSPLIT,$0-40
CALL runtime·entersyscallblock(SB)
MOVQ fds+0(FP), DI
diff --git a/pkg/tcpip/link/rawfile/blockingpoll_unsafe.go b/pkg/tcpip/link/rawfile/blockingpoll_unsafe.go
new file mode 100644
index 000000000..659bfbe03
--- /dev/null
+++ b/pkg/tcpip/link/rawfile/blockingpoll_unsafe.go
@@ -0,0 +1,17 @@
+// Copyright 2018 The Netstack Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build linux,!amd64
+
+package rawfile
+
+import (
+ "syscall"
+ "unsafe"
+)
+
+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))
+ return int(n), e
+}
diff --git a/pkg/tcpip/link/rawfile/blockingpoll_unsafe_amd64.go b/pkg/tcpip/link/rawfile/blockingpoll_unsafe_amd64.go
new file mode 100644
index 000000000..0d89ddc1d
--- /dev/null
+++ b/pkg/tcpip/link/rawfile/blockingpoll_unsafe_amd64.go
@@ -0,0 +1,14 @@
+// Copyright 2018 The Netstack Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build linux,amd64
+
+package rawfile
+
+import (
+ "syscall"
+)
+
+//go:noescape
+func blockingPoll(fds *pollEvent, nfds int, timeout int64) (int, syscall.Errno)
diff --git a/pkg/tcpip/link/rawfile/errors.go b/pkg/tcpip/link/rawfile/errors.go
index ce58ee975..8eae9252c 100644
--- a/pkg/tcpip/link/rawfile/errors.go
+++ b/pkg/tcpip/link/rawfile/errors.go
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
+// +build linux
+
package rawfile
import (
diff --git a/pkg/tcpip/link/rawfile/rawfile_unsafe.go b/pkg/tcpip/link/rawfile/rawfile_unsafe.go
index d3660e1b4..6e8d7f556 100644
--- a/pkg/tcpip/link/rawfile/rawfile_unsafe.go
+++ b/pkg/tcpip/link/rawfile/rawfile_unsafe.go
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
+// +build linux
+
// Package rawfile contains utilities for using the netstack with raw host
// files on Linux hosts.
package rawfile
@@ -13,9 +15,6 @@ import (
"gvisor.googlesource.com/gvisor/pkg/tcpip"
)
-//go:noescape
-func blockingPoll(fds unsafe.Pointer, nfds int, timeout int64) (n int, err syscall.Errno)
-
// GetMTU determines the MTU of a network interface device.
func GetMTU(name string) (uint32, error) {
fd, err := syscall.Socket(syscall.AF_UNIX, syscall.SOCK_DGRAM, 0)
@@ -108,6 +107,12 @@ func NonBlockingWriteN(fd int, bs ...[]byte) *tcpip.Error {
return nil
}
+type pollEvent struct {
+ fd int32
+ events int16
+ revents int16
+}
+
// BlockingRead reads from a file descriptor that is set up as non-blocking. If
// no data is available, it will block in a poll() syscall until the file
// descirptor becomes readable.
@@ -118,16 +123,12 @@ func BlockingRead(fd int, b []byte) (int, *tcpip.Error) {
return int(n), nil
}
- event := struct {
- fd int32
- events int16
- revents int16
- }{
+ event := pollEvent{
fd: int32(fd),
events: 1, // POLLIN
}
- _, e = blockingPoll(unsafe.Pointer(&event), 1, -1)
+ _, e = blockingPoll(&event, 1, -1)
if e != 0 && e != syscall.EINTR {
return 0, TranslateErrno(e)
}
@@ -144,16 +145,12 @@ func BlockingReadv(fd int, iovecs []syscall.Iovec) (int, *tcpip.Error) {
return int(n), nil
}
- event := struct {
- fd int32
- events int16
- revents int16
- }{
+ event := pollEvent{
fd: int32(fd),
events: 1, // POLLIN
}
- _, e = blockingPoll(unsafe.Pointer(&event), 1, -1)
+ _, e = blockingPoll(&event, 1, -1)
if e != 0 && e != syscall.EINTR {
return 0, TranslateErrno(e)
}