diff options
author | Ayush Ranjan <ayushranjan@google.com> | 2021-03-03 10:23:55 -0800 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2021-03-03 10:25:58 -0800 |
commit | a9441aea2780da8c93da1c73da860219f98438de (patch) | |
tree | 8b12915756f5bfb926218214cd7bc0b3281605fd /pkg/flipcall | |
parent | b8a5420f49a2afd622ec08b5019e1bf537f7da82 (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/flipcall')
-rw-r--r-- | pkg/flipcall/BUILD | 1 | ||||
-rw-r--r-- | pkg/flipcall/flipcall.go | 5 | ||||
-rw-r--r-- | pkg/flipcall/futex_linux.go | 10 | ||||
-rw-r--r-- | pkg/flipcall/packet_window_allocator.go | 10 | ||||
-rw-r--r-- | pkg/flipcall/packet_window_mmap_amd64.go | 8 | ||||
-rw-r--r-- | pkg/flipcall/packet_window_mmap_arm64.go | 8 |
6 files changed, 20 insertions, 22 deletions
diff --git a/pkg/flipcall/BUILD b/pkg/flipcall/BUILD index cc31d0175..9730b88c1 100644 --- a/pkg/flipcall/BUILD +++ b/pkg/flipcall/BUILD @@ -20,6 +20,7 @@ go_library( "//pkg/log", "//pkg/memutil", "//pkg/sync", + "@org_golang_x_sys//unix:go_default_library", ], ) diff --git a/pkg/flipcall/flipcall.go b/pkg/flipcall/flipcall.go index c4a3366ce..8d8309a73 100644 --- a/pkg/flipcall/flipcall.go +++ b/pkg/flipcall/flipcall.go @@ -20,7 +20,8 @@ import ( "fmt" "math" "sync/atomic" - "syscall" + + "golang.org/x/sys/unix" ) // An Endpoint provides the ability to synchronously transfer data and control @@ -130,7 +131,7 @@ func (ep *Endpoint) Destroy() { } func (ep *Endpoint) unmapPacket() { - syscall.RawSyscall(syscall.SYS_MUNMAP, ep.packet, uintptr(ep.dataCap)+PacketHeaderBytes, 0) + unix.RawSyscall(unix.SYS_MUNMAP, ep.packet, uintptr(ep.dataCap)+PacketHeaderBytes, 0) ep.packet = 0 } diff --git a/pkg/flipcall/futex_linux.go b/pkg/flipcall/futex_linux.go index 0e559ee16..c212f05f1 100644 --- a/pkg/flipcall/futex_linux.go +++ b/pkg/flipcall/futex_linux.go @@ -20,8 +20,8 @@ import ( "fmt" "runtime" "sync/atomic" - "syscall" + "golang.org/x/sys/unix" "gvisor.dev/gvisor/pkg/abi/linux" ) @@ -66,22 +66,22 @@ func (ep *Endpoint) futexWaitUntilActive() error { } func (ep *Endpoint) futexWakeConnState(numThreads int32) error { - if _, _, e := syscall.RawSyscall(syscall.SYS_FUTEX, ep.packet, linux.FUTEX_WAKE, uintptr(numThreads)); e != 0 { + if _, _, e := unix.RawSyscall(unix.SYS_FUTEX, ep.packet, linux.FUTEX_WAKE, uintptr(numThreads)); e != 0 { return e } return nil } func (ep *Endpoint) futexWaitConnState(curState uint32) error { - _, _, e := syscall.Syscall6(syscall.SYS_FUTEX, ep.packet, linux.FUTEX_WAIT, uintptr(curState), 0, 0, 0) - if e != 0 && e != syscall.EAGAIN && e != syscall.EINTR { + _, _, e := unix.Syscall6(unix.SYS_FUTEX, ep.packet, linux.FUTEX_WAIT, uintptr(curState), 0, 0, 0) + if e != 0 && e != unix.EAGAIN && e != unix.EINTR { return e } return nil } func yieldThread() { - syscall.Syscall(syscall.SYS_SCHED_YIELD, 0, 0, 0) + unix.Syscall(unix.SYS_SCHED_YIELD, 0, 0, 0) // The thread we're trying to yield to may be waiting for a Go runtime P. // runtime.Gosched() will hand off ours if necessary. runtime.Gosched() diff --git a/pkg/flipcall/packet_window_allocator.go b/pkg/flipcall/packet_window_allocator.go index af9cc3d21..9122c97b7 100644 --- a/pkg/flipcall/packet_window_allocator.go +++ b/pkg/flipcall/packet_window_allocator.go @@ -18,8 +18,8 @@ import ( "fmt" "math/bits" "os" - "syscall" + "golang.org/x/sys/unix" "gvisor.dev/gvisor/pkg/abi/linux" "gvisor.dev/gvisor/pkg/memutil" ) @@ -85,8 +85,8 @@ func (pwa *PacketWindowAllocator) Init() error { // Apply F_SEAL_SHRINK to prevent either party from causing SIGBUS in the // other by truncating the file, and F_SEAL_SEAL to prevent either party // from applying F_SEAL_GROW or F_SEAL_WRITE. - if _, _, e := syscall.RawSyscall(syscall.SYS_FCNTL, uintptr(fd), linux.F_ADD_SEALS, linux.F_SEAL_SHRINK|linux.F_SEAL_SEAL); e != 0 { - syscall.Close(fd) + if _, _, e := unix.RawSyscall(unix.SYS_FCNTL, uintptr(fd), linux.F_ADD_SEALS, linux.F_SEAL_SHRINK|linux.F_SEAL_SEAL); e != 0 { + unix.Close(fd) return fmt.Errorf("failed to apply memfd seals: %v", e) } pwa.fd = fd @@ -106,7 +106,7 @@ func NewPacketWindowAllocator() (*PacketWindowAllocator, error) { // Destroy releases resources owned by pwa. This invalidates file descriptors // previously returned by pwa.FD() and pwd.Allocate(). func (pwa *PacketWindowAllocator) Destroy() { - syscall.Close(pwa.fd) + unix.Close(pwa.fd) } // FD represents the file descriptor of the shared memory file backing pwa. @@ -158,7 +158,7 @@ func (pwa *PacketWindowAllocator) ensureFileSize(min int64) error { } newSize = newNewSize } - if err := syscall.Ftruncate(pwa.FD(), newSize); err != nil { + if err := unix.Ftruncate(pwa.FD(), newSize); err != nil { return fmt.Errorf("ftruncate failed: %v", err) } pwa.fileSize = newSize diff --git a/pkg/flipcall/packet_window_mmap_amd64.go b/pkg/flipcall/packet_window_mmap_amd64.go index 869183b11..ced587a2a 100644 --- a/pkg/flipcall/packet_window_mmap_amd64.go +++ b/pkg/flipcall/packet_window_mmap_amd64.go @@ -14,12 +14,10 @@ package flipcall -import ( - "syscall" -) +import "golang.org/x/sys/unix" // Return a memory mapping of the pwd in memory that can be shared outside the sandbox. -func packetWindowMmap(pwd PacketWindowDescriptor) (uintptr, syscall.Errno) { - m, _, err := syscall.RawSyscall6(syscall.SYS_MMAP, 0, uintptr(pwd.Length), syscall.PROT_READ|syscall.PROT_WRITE, syscall.MAP_SHARED, uintptr(pwd.FD), uintptr(pwd.Offset)) +func packetWindowMmap(pwd PacketWindowDescriptor) (uintptr, unix.Errno) { + m, _, err := unix.RawSyscall6(unix.SYS_MMAP, 0, uintptr(pwd.Length), unix.PROT_READ|unix.PROT_WRITE, unix.MAP_SHARED, uintptr(pwd.FD), uintptr(pwd.Offset)) return m, err } diff --git a/pkg/flipcall/packet_window_mmap_arm64.go b/pkg/flipcall/packet_window_mmap_arm64.go index b9c9c44f6..87ad1a4a1 100644 --- a/pkg/flipcall/packet_window_mmap_arm64.go +++ b/pkg/flipcall/packet_window_mmap_arm64.go @@ -16,12 +16,10 @@ package flipcall -import ( - "syscall" -) +import "golang.org/x/sys/unix" // Return a memory mapping of the pwd in memory that can be shared outside the sandbox. -func packetWindowMmap(pwd PacketWindowDescriptor) (uintptr, syscall.Errno) { - m, _, err := syscall.RawSyscall6(syscall.SYS_MMAP, 0, uintptr(pwd.Length), syscall.PROT_READ|syscall.PROT_WRITE, syscall.MAP_SHARED, uintptr(pwd.FD), uintptr(pwd.Offset)) +func packetWindowMmap(pwd PacketWindowDescriptor) (uintptr, unix.Errno) { + m, _, err := unix.RawSyscall6(unix.SYS_MMAP, 0, uintptr(pwd.Length), unix.PROT_READ|unix.PROT_WRITE, unix.MAP_SHARED, uintptr(pwd.FD), uintptr(pwd.Offset)) return m, err } |