summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorgVisor bot <gvisor-bot@google.com>2021-06-23 20:22:55 +0000
committergVisor bot <gvisor-bot@google.com>2021-06-23 20:22:55 +0000
commitf5e7282890c4a0bc42f6b48b0afa2c2cd9513491 (patch)
treef99d78cd1c1e5efc52817730eb075cfb9d47d4ca
parenta4301bae281c2eed0ac91d396e789c00597e6502 (diff)
parentdfa4b3b90861a61653d0bef8f144bb4e82d21d78 (diff)
Merge release-20210614.0-19-gdfa4b3b90 (automated)
-rw-r--r--pkg/flipcall/flipcall.go7
-rw-r--r--pkg/flipcall/flipcall_arm64_state_autogen.go5
-rw-r--r--pkg/flipcall/packet_window.go (renamed from pkg/flipcall/packet_window_allocator.go)0
-rw-r--r--pkg/memutil/memfd_linux_unsafe.go (renamed from pkg/memutil/memutil_unsafe.go)1
-rw-r--r--pkg/memutil/memutil.go (renamed from pkg/flipcall/packet_window_mmap_arm64.go)15
-rw-r--r--pkg/memutil/memutil_linux_unsafe_state_autogen.go (renamed from pkg/memutil/memutil_unsafe_state_autogen.go)0
-rw-r--r--pkg/memutil/memutil_state_autogen.go (renamed from pkg/flipcall/flipcall_amd64_state_autogen.go)2
-rw-r--r--pkg/memutil/mmap.go (renamed from pkg/flipcall/packet_window_mmap_amd64.go)18
8 files changed, 20 insertions, 28 deletions
diff --git a/pkg/flipcall/flipcall.go b/pkg/flipcall/flipcall.go
index 8d8309a73..f0e4ff487 100644
--- a/pkg/flipcall/flipcall.go
+++ b/pkg/flipcall/flipcall.go
@@ -22,6 +22,7 @@ import (
"sync/atomic"
"golang.org/x/sys/unix"
+ "gvisor.dev/gvisor/pkg/memutil"
)
// An Endpoint provides the ability to synchronously transfer data and control
@@ -96,9 +97,9 @@ func (ep *Endpoint) Init(side EndpointSide, pwd PacketWindowDescriptor, opts ...
if pwd.Length > math.MaxUint32 {
return fmt.Errorf("packet window size (%d) exceeds maximum (%d)", pwd.Length, math.MaxUint32)
}
- m, e := packetWindowMmap(pwd)
- if e != 0 {
- return fmt.Errorf("failed to mmap packet window: %v", e)
+ m, err := memutil.MapFile(0, uintptr(pwd.Length), unix.PROT_READ|unix.PROT_WRITE, unix.MAP_SHARED, uintptr(pwd.FD), uintptr(pwd.Offset))
+ if err != nil {
+ return fmt.Errorf("failed to mmap packet window: %v", err)
}
ep.packet = m
ep.dataCap = uint32(pwd.Length) - uint32(PacketHeaderBytes)
diff --git a/pkg/flipcall/flipcall_arm64_state_autogen.go b/pkg/flipcall/flipcall_arm64_state_autogen.go
deleted file mode 100644
index e0d1275c8..000000000
--- a/pkg/flipcall/flipcall_arm64_state_autogen.go
+++ /dev/null
@@ -1,5 +0,0 @@
-// automatically generated by stateify.
-
-// +build arm64
-
-package flipcall
diff --git a/pkg/flipcall/packet_window_allocator.go b/pkg/flipcall/packet_window.go
index 9122c97b7..9122c97b7 100644
--- a/pkg/flipcall/packet_window_allocator.go
+++ b/pkg/flipcall/packet_window.go
diff --git a/pkg/memutil/memutil_unsafe.go b/pkg/memutil/memfd_linux_unsafe.go
index 6676d1ce3..504382213 100644
--- a/pkg/memutil/memutil_unsafe.go
+++ b/pkg/memutil/memfd_linux_unsafe.go
@@ -14,7 +14,6 @@
// +build linux
-// Package memutil provides a wrapper for the memfd_create() system call.
package memutil
import (
diff --git a/pkg/flipcall/packet_window_mmap_arm64.go b/pkg/memutil/memutil.go
index 87ad1a4a1..3185882fd 100644
--- a/pkg/flipcall/packet_window_mmap_arm64.go
+++ b/pkg/memutil/memutil.go
@@ -1,4 +1,4 @@
-// Copyright 2020 The gVisor Authors.
+// Copyright 2018 The gVisor Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -12,14 +12,5 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-// +build arm64
-
-package flipcall
-
-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, 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
-}
+// Package memutil provides utilities for working with shared memory files.
+package memutil
diff --git a/pkg/memutil/memutil_unsafe_state_autogen.go b/pkg/memutil/memutil_linux_unsafe_state_autogen.go
index 173297149..173297149 100644
--- a/pkg/memutil/memutil_unsafe_state_autogen.go
+++ b/pkg/memutil/memutil_linux_unsafe_state_autogen.go
diff --git a/pkg/flipcall/flipcall_amd64_state_autogen.go b/pkg/memutil/memutil_state_autogen.go
index 0e03c2a65..89848555d 100644
--- a/pkg/flipcall/flipcall_amd64_state_autogen.go
+++ b/pkg/memutil/memutil_state_autogen.go
@@ -1,3 +1,3 @@
// automatically generated by stateify.
-package flipcall
+package memutil
diff --git a/pkg/flipcall/packet_window_mmap_amd64.go b/pkg/memutil/mmap.go
index ced587a2a..7c939293f 100644
--- a/pkg/flipcall/packet_window_mmap_amd64.go
+++ b/pkg/memutil/mmap.go
@@ -12,12 +12,18 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package flipcall
+package memutil
-import "golang.org/x/sys/unix"
+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, 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
+// MapFile returns a memory mapping configured by the given options as per
+// mmap(2).
+func MapFile(addr, len, prot, flags, fd, offset uintptr) (uintptr, error) {
+ m, _, e := unix.RawSyscall6(unix.SYS_MMAP, addr, len, prot, flags, fd, offset)
+ if e != 0 {
+ return 0, e
+ }
+ return m, nil
}