mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Remove usermem dependency from marshal
Both marshal and usermem are depended on by many packages and a dependency on marshal can often create circular dependencies. marshal should consider adding internal dependencies carefully moving forward. Fixes #6160 PiperOrigin-RevId: 379199882
This commit is contained in:
@@ -293,8 +293,6 @@ type Sigevent struct {
|
||||
UnRemainder [44]byte
|
||||
}
|
||||
|
||||
// LINT.IfChange
|
||||
|
||||
// SigAction represents struct sigaction.
|
||||
//
|
||||
// +marshal
|
||||
@@ -306,8 +304,6 @@ type SigAction struct {
|
||||
Mask SignalSet
|
||||
}
|
||||
|
||||
// LINT.ThenChange(../../safecopy/safecopy_unsafe.go)
|
||||
|
||||
// SignalStack represents information about a user stack, and is equivalent to
|
||||
// stack_t.
|
||||
//
|
||||
|
||||
@@ -12,9 +12,7 @@ go_library(
|
||||
"//:sandbox",
|
||||
],
|
||||
deps = [
|
||||
"//pkg/context",
|
||||
"//pkg/hostarch",
|
||||
"//pkg/marshal",
|
||||
"//pkg/usermem",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -19,10 +19,8 @@ package primitive
|
||||
import (
|
||||
"io"
|
||||
|
||||
"gvisor.dev/gvisor/pkg/context"
|
||||
"gvisor.dev/gvisor/pkg/hostarch"
|
||||
"gvisor.dev/gvisor/pkg/marshal"
|
||||
"gvisor.dev/gvisor/pkg/usermem"
|
||||
)
|
||||
|
||||
// Int8 is a marshal.Marshallable implementation for int8.
|
||||
@@ -400,26 +398,3 @@ func CopyStringOut(cc marshal.CopyContext, addr hostarch.Addr, src string) (int,
|
||||
srcP := ByteSlice(src)
|
||||
return srcP.CopyOut(cc, addr)
|
||||
}
|
||||
|
||||
// IOCopyContext wraps an object implementing hostarch.IO to implement
|
||||
// marshal.CopyContext.
|
||||
type IOCopyContext struct {
|
||||
Ctx context.Context
|
||||
IO usermem.IO
|
||||
Opts usermem.IOOpts
|
||||
}
|
||||
|
||||
// CopyScratchBuffer implements marshal.CopyContext.CopyScratchBuffer.
|
||||
func (i *IOCopyContext) CopyScratchBuffer(size int) []byte {
|
||||
return make([]byte, size)
|
||||
}
|
||||
|
||||
// CopyOutBytes implements marshal.CopyContext.CopyOutBytes.
|
||||
func (i *IOCopyContext) CopyOutBytes(addr hostarch.Addr, b []byte) (int, error) {
|
||||
return i.IO.CopyOut(i.Ctx, addr, b, i.Opts)
|
||||
}
|
||||
|
||||
// CopyInBytes implements marshal.CopyContext.CopyInBytes.
|
||||
func (i *IOCopyContext) CopyInBytes(addr hostarch.Addr, b []byte) (int, error) {
|
||||
return i.IO.CopyIn(i.Ctx, addr, b, i.Opts)
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ go_library(
|
||||
],
|
||||
visibility = ["//:sandbox"],
|
||||
deps = [
|
||||
"//pkg/abi/linux",
|
||||
"//pkg/syserror",
|
||||
"@org_golang_x_sys//unix:go_default_library",
|
||||
],
|
||||
|
||||
@@ -20,6 +20,7 @@ import (
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
"gvisor.dev/gvisor/pkg/abi/linux"
|
||||
)
|
||||
|
||||
// maxRegisterSize is the maximum register size used in memcpy and memclr. It
|
||||
@@ -342,15 +343,7 @@ func errorFromFaultSignal(addr uintptr, sig int32) error {
|
||||
// handler however, and if this is function is being used externally then the
|
||||
// same courtesy is expected.
|
||||
func ReplaceSignalHandler(sig unix.Signal, handler uintptr, previous *uintptr) error {
|
||||
// TODO(gvisor.dev/issue/6160): This struct is the same as linux.SigAction.
|
||||
// Once the usermem dependency is removed from primitive, delete this replica
|
||||
// and remove IFTTT comments in abi/linux/signal.go.
|
||||
var sa struct {
|
||||
handler uintptr
|
||||
flags uint64
|
||||
restorer uintptr
|
||||
mask uint64
|
||||
}
|
||||
var sa linux.SigAction
|
||||
const maskLen = 8
|
||||
|
||||
// Get the existing signal handler information, and save the current
|
||||
@@ -361,14 +354,14 @@ func ReplaceSignalHandler(sig unix.Signal, handler uintptr, previous *uintptr) e
|
||||
}
|
||||
|
||||
// Fail if there isn't a previous handler.
|
||||
if sa.handler == 0 {
|
||||
if sa.Handler == 0 {
|
||||
return fmt.Errorf("previous handler for signal %x isn't set", sig)
|
||||
}
|
||||
|
||||
*previous = sa.handler
|
||||
*previous = uintptr(sa.Handler)
|
||||
|
||||
// Install our own handler.
|
||||
sa.handler = handler
|
||||
sa.Handler = uint64(handler)
|
||||
if _, _, e := unix.RawSyscall6(unix.SYS_RT_SIGACTION, uintptr(sig), uintptr(unsafe.Pointer(&sa)), 0, maskLen, 0, 0); e != 0 {
|
||||
return e
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ func (p *Pipe) Ioctl(ctx context.Context, io usermem.IO, args arch.SyscallArgume
|
||||
v = math.MaxInt32 // Silently truncate.
|
||||
}
|
||||
// Copy result to userspace.
|
||||
iocc := primitive.IOCopyContext{
|
||||
iocc := usermem.IOCopyContext{
|
||||
IO: io,
|
||||
Ctx: ctx,
|
||||
Opts: usermem.IOOpts{
|
||||
|
||||
@@ -7,6 +7,7 @@ go_library(
|
||||
srcs = [
|
||||
"bytes_io.go",
|
||||
"bytes_io_unsafe.go",
|
||||
"marshal.go",
|
||||
"usermem.go",
|
||||
],
|
||||
visibility = ["//:sandbox"],
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
// Copyright 2021 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 usermem
|
||||
|
||||
import (
|
||||
"gvisor.dev/gvisor/pkg/context"
|
||||
"gvisor.dev/gvisor/pkg/hostarch"
|
||||
)
|
||||
|
||||
// IOCopyContext wraps an object implementing hostarch.IO to implement
|
||||
// marshal.CopyContext.
|
||||
type IOCopyContext struct {
|
||||
Ctx context.Context
|
||||
IO IO
|
||||
Opts IOOpts
|
||||
}
|
||||
|
||||
// CopyScratchBuffer implements marshal.CopyContext.CopyScratchBuffer.
|
||||
func (i *IOCopyContext) CopyScratchBuffer(size int) []byte {
|
||||
return make([]byte, size)
|
||||
}
|
||||
|
||||
// CopyOutBytes implements marshal.CopyContext.CopyOutBytes.
|
||||
func (i *IOCopyContext) CopyOutBytes(addr hostarch.Addr, b []byte) (int, error) {
|
||||
return i.IO.CopyOut(i.Ctx, addr, b, i.Opts)
|
||||
}
|
||||
|
||||
// CopyInBytes implements marshal.CopyContext.CopyInBytes.
|
||||
func (i *IOCopyContext) CopyInBytes(addr hostarch.Addr, b []byte) (int, error) {
|
||||
return i.IO.CopyIn(i.Ctx, addr, b, i.Opts)
|
||||
}
|
||||
Reference in New Issue
Block a user