mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Move flipcall.packetWindowMmap to memutil.
PiperOrigin-RevId: 381100861
This commit is contained in:
+1
-3
@@ -10,9 +10,7 @@ go_library(
|
||||
"flipcall_unsafe.go",
|
||||
"futex_linux.go",
|
||||
"io.go",
|
||||
"packet_window_allocator.go",
|
||||
"packet_window_mmap_amd64.go",
|
||||
"packet_window_mmap_arm64.go",
|
||||
"packet_window.go",
|
||||
],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
// Copyright 2020 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.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
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
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
// Copyright 2020 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.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// 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
|
||||
}
|
||||
Reference in New Issue
Block a user