summaryrefslogtreecommitdiffhomepage
path: root/pkg/iovec
diff options
context:
space:
mode:
authorAyush Ranjan <ayushranjan@google.com>2021-03-03 10:23:55 -0800
committergVisor bot <gvisor-bot@google.com>2021-03-03 10:25:58 -0800
commita9441aea2780da8c93da1c73da860219f98438de (patch)
tree8b12915756f5bfb926218214cd7bc0b3281605fd /pkg/iovec
parentb8a5420f49a2afd622ec08b5019e1bf537f7da82 (diff)
[op] Replace syscall package usage with golang.org/x/sys/unix in pkg/.
The syscall package has been deprecated in favor of golang.org/x/sys. Note that syscall is still used in the following places: - pkg/sentry/socket/hostinet/stack.go: some netlink related functionalities are not yet available in golang.org/x/sys. - syscall.Stat_t is still used in some places because os.FileInfo.Sys() still returns it and not unix.Stat_t. Updates #214 PiperOrigin-RevId: 360701387
Diffstat (limited to 'pkg/iovec')
-rw-r--r--pkg/iovec/BUILD5
-rw-r--r--pkg/iovec/iovec.go15
-rw-r--r--pkg/iovec/iovec_test.go9
3 files changed, 15 insertions, 14 deletions
diff --git a/pkg/iovec/BUILD b/pkg/iovec/BUILD
index eda82cfc1..b92a58556 100644
--- a/pkg/iovec/BUILD
+++ b/pkg/iovec/BUILD
@@ -6,7 +6,10 @@ go_library(
name = "iovec",
srcs = ["iovec.go"],
visibility = ["//:sandbox"],
- deps = ["//pkg/abi/linux"],
+ deps = [
+ "//pkg/abi/linux",
+ "@org_golang_x_sys//unix:go_default_library",
+ ],
)
go_test(
diff --git a/pkg/iovec/iovec.go b/pkg/iovec/iovec.go
index dd70fe80f..0789c74bf 100644
--- a/pkg/iovec/iovec.go
+++ b/pkg/iovec/iovec.go
@@ -19,18 +19,17 @@
package iovec
import (
- "syscall"
-
+ "golang.org/x/sys/unix"
"gvisor.dev/gvisor/pkg/abi/linux"
)
// MaxIovs is the maximum number of iovecs host platform can accept.
var MaxIovs = linux.UIO_MAXIOV
-// Builder is a builder for slice of syscall.Iovec.
+// Builder is a builder for slice of unix.Iovec.
type Builder struct {
- iovec []syscall.Iovec
- storage [8]syscall.Iovec
+ iovec []unix.Iovec
+ storage [8]unix.Iovec
// overflow tracks the last buffer when iovec length is at MaxIovs.
overflow []byte
@@ -48,7 +47,7 @@ func (b *Builder) Add(buf []byte) {
b.addByAppend(buf)
return
}
- b.iovec = append(b.iovec, syscall.Iovec{
+ b.iovec = append(b.iovec, unix.Iovec{
Base: &buf[0],
Len: uint64(len(buf)),
})
@@ -62,7 +61,7 @@ func (b *Builder) Add(buf []byte) {
func (b *Builder) addByAppend(buf []byte) {
b.overflow = append(b.overflow, buf...)
- b.iovec[len(b.iovec)-1] = syscall.Iovec{
+ b.iovec[len(b.iovec)-1] = unix.Iovec{
Base: &b.overflow[0],
Len: uint64(len(b.overflow)),
}
@@ -70,6 +69,6 @@ func (b *Builder) addByAppend(buf []byte) {
// Build returns the final Iovec slice. The length of returned iovec will not
// excceed MaxIovs.
-func (b *Builder) Build() []syscall.Iovec {
+func (b *Builder) Build() []unix.Iovec {
return b.iovec
}
diff --git a/pkg/iovec/iovec_test.go b/pkg/iovec/iovec_test.go
index a3900c299..f6deb4208 100644
--- a/pkg/iovec/iovec_test.go
+++ b/pkg/iovec/iovec_test.go
@@ -19,7 +19,6 @@ package iovec
import (
"bytes"
"fmt"
- "syscall"
"testing"
"unsafe"
@@ -100,16 +99,16 @@ func TestBuilderBuildMaxIov(t *testing.T) {
if err := unix.Pipe(fds[:]); err != nil {
t.Fatalf("Pipe: %v", err)
}
- defer syscall.Close(fds[0])
- defer syscall.Close(fds[1])
+ defer unix.Close(fds[0])
+ defer unix.Close(fds[1])
- wrote, _, e := syscall.RawSyscall(syscall.SYS_WRITEV, uintptr(fds[1]), uintptr(unsafe.Pointer(&iovec[0])), uintptr(len(iovec)))
+ wrote, _, e := unix.RawSyscall(unix.SYS_WRITEV, uintptr(fds[1]), uintptr(unsafe.Pointer(&iovec[0])), uintptr(len(iovec)))
if int(wrote) != len(data) || e != 0 {
t.Fatalf("writev: %v, %v; want %v, 0", wrote, e, len(data))
}
got := make([]byte, len(data))
- if n, err := syscall.Read(fds[0], got); n != len(got) || err != nil {
+ if n, err := unix.Read(fds[0], got); n != len(got) || err != nil {
t.Fatalf("read: %v, %v; want %v, nil", n, err, len(got))
}