Documentation
¶
Overview ¶
Package uffd provides Linux userfaultfd helpers without cgo at runtime.
Index ¶
- Constants
- Variables
- func CheckSupport() error
- func CheckSupportWithFlags(flags uintptr) error
- func GetCopyBytes(copy *UffdioCopy) int64
- func GetMoveBytes(move *UffdioMove) int64
- func GetMsgArg(msg *UffdMsg) [24]byte
- func GetMsgEvent(msg *UffdMsg) uint8
- func GetPagefaultAddress(pagefault *UffdPagefault) uint64
- func Handle(uffd UFFD, start uintptr, src io.ReaderAt) error
- func HandleContext(ctx context.Context, uffd UFFD, start uintptr, src io.ReaderAt) error
- func ReceiveFDs(conn *net.UnixConn, num int) ([]uintptr, error)
- func SendFDs(conn *net.UnixConn, fds []uintptr) error
- func SendUFFD(conn *net.UnixConn, uffd UFFD, start uintptr) error
- type Fault
- type Handler
- type HandlerOptions
- type MoveBuffer
- type Registration
- type Resolver
- type UFFD
- type UffdMsg
- type UffdPagefault
- type UffdioAPI
- type UffdioCopy
- type UffdioMove
- type UffdioRange
- type UffdioRegister
Constants ¶
const ( // NR_userfaultfd is the Linux syscall number for creating a userfaultfd // descriptor directly. NR_userfaultfd = uintptr(0) // UFFD_O_CLOEXEC requests that Open mark the returned descriptor // close-on-exec. UFFD_O_CLOEXEC = uintptr(0x80000) // UFFD_O_NONBLOCK requests that Open return a non-blocking descriptor. UFFD_O_NONBLOCK = uintptr(0x800) // UFFD_OPEN_DEFAULT keeps the returned fd close-on-exec and non-blocking. // // Callers that specifically want a userspace-fault-only descriptor can add // UFFD_USER_MODE_ONLY explicitly. UFFD_OPEN_DEFAULT = uffdSharedOpenFlags // UFFD_API is the userfaultfd API version passed to UFFDIO_API during // descriptor initialisation. UFFD_API = uint64(0xAA) // UFFD_EVENT_PAGEFAULT identifies a missing-page event in UffdMsg.Event. UFFD_EVENT_PAGEFAULT = uint8(0x12) // UFFDIO_REGISTER_MODE_MISSING requests missing-page tracking when // registering a virtual address range. UFFDIO_REGISTER_MODE_MISSING = uint64(1 << 0) // UFFDIO_API is the ioctl number used to negotiate the userfaultfd API // version and feature bits. UFFDIO_API = uintptr(0) // UFFDIO_REGISTER is the ioctl number used to register a virtual address // range for userfaultfd tracking. UFFDIO_REGISTER = uintptr(0) // UFFDIO_COPY is the ioctl number used to resolve a fault by copying bytes // into the registered range. UFFDIO_COPY = uintptr(0) // UFFDIO_MOVE is the ioctl number used to resolve a fault by moving page // contents into the registered range. UFFDIO_MOVE = uintptr(0) )
const ( // UFFD_FEATURE_MOVE is the feature bit negotiated through UFFDIO_API that // enables UFFDIO_MOVE support for a descriptor. UFFD_FEATURE_MOVE = uint64(1 << 16) // UFFD_USER_MODE_ONLY requests a descriptor that handles faults originating // in user mode and skips kernel-mode faults. UFFD_USER_MODE_ONLY = uintptr(1) )
Variables ¶
var ( // ErrUnexpectedEventType indicates that a userfaultfd event other than a // missing-page fault was received by Handle. ErrUnexpectedEventType = errors.New("unexpected event type") // ErrInvalidFDsLength indicates that a Unix rights message contained an // unexpected number of file descriptors. ErrInvalidFDsLength = errors.New("invalid file descriptors length") // ErrUnsupportedPlatform indicates that the current GOOS/GOARCH does not // support the low-level userfaultfd implementation in this package. ErrUnsupportedPlatform = errors.New("userfaultfd is unsupported on this platform") // ErrInvalidPopulateRange indicates that Populate was asked to operate on a // destination or buffer length that is not page aligned. ErrInvalidPopulateRange = errors.New("populate range must be page aligned") )
Functions ¶
func CheckSupport ¶
func CheckSupport() error
CheckSupport always returns ErrUnsupportedPlatform on non-Linux builds.
func CheckSupportWithFlags ¶
CheckSupportWithFlags always returns ErrUnsupportedPlatform on non-Linux builds.
func GetCopyBytes ¶
func GetCopyBytes(copy *UffdioCopy) int64
GetCopyBytes returns the completion count from a placeholder UFFDIO_COPY request.
func GetMoveBytes ¶
func GetMoveBytes(move *UffdioMove) int64
GetMoveBytes returns the completion count from a placeholder UFFDIO_MOVE request.
func GetMsgEvent ¶
GetMsgEvent returns the event discriminator from a placeholder uffd_msg.
func GetPagefaultAddress ¶
func GetPagefaultAddress(pagefault *UffdPagefault) uint64
GetPagefaultAddress returns the fault address from a placeholder pagefault payload.
func HandleContext ¶
HandleContext always returns ErrUnsupportedPlatform on non-Linux builds.
func ReceiveFDs ¶
ReceiveFDs always returns ErrUnsupportedPlatform on non-Linux builds.
Types ¶
type Fault ¶
type Fault struct {
Address uintptr
}
Fault describes a missing-page event delivered by userfaultfd on Linux.
On non-Linux builds it exists only so the public API remains type-compatible.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler serves missing-page events and delegates page population to a callback.
On non-Linux builds it exists for API compatibility and always reports ErrUnsupportedPlatform when used.
func NewHandler ¶
func NewHandler(uffd UFFD, opts *HandlerOptions) *Handler
NewHandler creates a placeholder handler that reports ErrUnsupportedPlatform when used on non-Linux builds.
type HandlerOptions ¶
HandlerOptions configures a generic fault handler.
On non-Linux builds it is retained for API compatibility only.
type MoveBuffer ¶
type MoveBuffer []byte
MoveBuffer is a placeholder mmap-backed buffer type on non-Linux builds.
func AllocateMoveBuffer ¶
func AllocateMoveBuffer(length int) (MoveBuffer, error)
AllocateMoveBuffer always returns ErrUnsupportedPlatform on non-Linux builds.
func (MoveBuffer) Bytes ¶
func (b MoveBuffer) Bytes() []byte
Bytes always returns nil on non-Linux builds.
type Registration ¶
type Registration struct {
// contains filtered or unexported fields
}
Registration owns an mmap-backed region registered with a userfaultfd and the descriptor that tracks it. Call Close when the registration is no longer needed.
func Register ¶
func Register(length int) (*Registration, error)
Register always returns ErrUnsupportedPlatform on non-Linux builds.
func RegisterWithFlags ¶
func RegisterWithFlags(length int, flags uintptr) (*Registration, error)
RegisterWithFlags always returns ErrUnsupportedPlatform on non-Linux builds.
func (*Registration) Bytes ¶
func (r *Registration) Bytes() []byte
Bytes returns the registered region clipped to the originally requested length.
func (*Registration) Close ¶
func (r *Registration) Close() error
Close is a no-op on non-Linux builds.
func (*Registration) Start ¶
func (r *Registration) Start() uintptr
Start returns the base address used to translate fault offsets back into reader offsets.
func (*Registration) UFFD ¶
func (r *Registration) UFFD() UFFD
UFFD returns the userfaultfd associated with the registration.
type Resolver ¶
type Resolver struct {
// contains filtered or unexported fields
}
Resolver resolves faults by populating pages in the registered region.
On non-Linux builds its methods always return ErrUnsupportedPlatform.
type UFFD ¶
type UFFD uintptr
UFFD is a placeholder userfaultfd descriptor type on non-Linux builds.
func ReceiveUFFD ¶
ReceiveUFFD always returns ErrUnsupportedPlatform on non-Linux builds.
type UffdMsg ¶
UffdMsg mirrors Linux struct uffd_msg and carries events read from a userfaultfd descriptor.
type UffdPagefault ¶
UffdPagefault mirrors the pagefault payload stored in UffdMsg.Arg for UFFD_EVENT_PAGEFAULT events.
type UffdioAPI ¶
UffdioAPI mirrors Linux struct uffdio_api, used with UFFDIO_API to negotiate feature bits and discover supported ioctls.
func NewUffdioAPI ¶
NewUffdioAPI builds a placeholder UFFDIO_API request struct on non-Linux builds so tests and callers can still construct values.
type UffdioCopy ¶
UffdioCopy mirrors Linux struct uffdio_copy, used with UFFDIO_COPY to resolve missing pages from a source buffer.
func NewUffdioCopy ¶
NewUffdioCopy builds a placeholder UFFDIO_COPY request struct on non-Linux builds.
type UffdioMove ¶
UffdioMove mirrors Linux struct uffdio_move, used with UFFDIO_MOVE to move page contents into a registered range.
func NewUffdioMove ¶
NewUffdioMove builds a placeholder UFFDIO_MOVE request struct on non-Linux builds.
type UffdioRange ¶
UffdioRange mirrors Linux struct uffdio_range and identifies a virtual address range in a process.
type UffdioRegister ¶
type UffdioRegister struct {
Range UffdioRange
Mode uint64
Ioctls uint64
}
UffdioRegister mirrors Linux struct uffdio_register, used with UFFDIO_REGISTER to register ranges for fault tracking.
func NewUffdioRegister ¶
func NewUffdioRegister(start, length, mode uint64) UffdioRegister
NewUffdioRegister builds a placeholder UFFDIO_REGISTER request struct on non-Linux builds.