gvisorgvisor.dev/gvisor/pkg/sentry/hostfd Index | Files

package hostfd

import "gvisor.dev/gvisor/pkg/sentry/hostfd"

Package hostfd provides efficient I/O with host file descriptors.

Index

Constants

const MaxReadWriteIov = 1024 // UIO_MAXIOV

MaxReadWriteIov is the maximum permitted size of a struct iovec array in a readv, writev, preadv, or pwritev host syscall.

const MaxSendRecvMsgIov = 1024 // UIO_MAXIOV

MaxSendRecvMsgIov is the maximum permitted size of a struct iovec array in a sendmsg or recvmsg host syscall.

Functions

func Preadv2

func Preadv2(fd int32, dsts safemem.BlockSeq, offset int64, flags uint32) (uint64, error)

Preadv2 reads up to dsts.NumBytes() bytes from host file descriptor fd into dsts. offset and flags are interpreted as for preadv2(2).

Preconditions: !dsts.IsEmpty().

func PutReadWriterAt

func PutReadWriterAt(rw *ReadWriterAt)

PutReadWriterAt releases a ReadWriterAt returned by a previous call to GetReadWriterAt that is no longer in use.

func Pwritev2

func Pwritev2(fd int32, srcs safemem.BlockSeq, offset int64, flags uint32) (uint64, error)

Pwritev2 writes up to srcs.NumBytes() from srcs into host file descriptor fd. offset and flags are interpreted as for pwritev2(2).

Preconditions: !srcs.IsEmpty().

Types

type ReadWriterAt

type ReadWriterAt struct {
	// contains filtered or unexported fields
}

ReadWriterAt implements safemem.Reader and safemem.Writer by reading from and writing to a host file descriptor respectively. ReadWriterAts should be obtained by calling GetReadWriterAt.

Clients should usually prefer to use Preadv2 and Pwritev2 directly.

func GetReadWriterAt

func GetReadWriterAt(fd int32, offset int64, flags uint32) *ReadWriterAt

GetReadWriterAt returns a ReadWriterAt that reads from / writes to the given host file descriptor, starting at the given offset and using the given preadv2(2)/pwritev2(2) flags. If offset is -1, the host file descriptor's offset is used instead. Users are responsible for ensuring that fd remains valid for the lifetime of the returned ReadWriterAt, and must call PutReadWriterAt when it is no longer needed.

func (*ReadWriterAt) ReadToBlocks

func (rw *ReadWriterAt) ReadToBlocks(dsts safemem.BlockSeq) (uint64, error)

ReadToBlocks implements safemem.Reader.ReadToBlocks.

func (*ReadWriterAt) WriteFromBlocks

func (rw *ReadWriterAt) WriteFromBlocks(srcs safemem.BlockSeq) (uint64, error)

WriteFromBlocks implements safemem.Writer.WriteFromBlocks.

Source Files

hostfd.go hostfd_linux.go hostfd_unsafe.go

Version
v0.0.0-20250605235530-a6711d1e1dc6 (latest)
Published
Jun 5, 2025
Platform
linux/amd64
Imports
5 packages
Last checked
4 hours ago

Tools for package owners.