gvisorgvisor.dev/gvisor/pkg/eventfd Index | Files

package eventfd

import "gvisor.dev/gvisor/pkg/eventfd"

Package eventfd wraps Linux's eventfd(2) syscall.

Index

Types

type Eventfd

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

Eventfd represents a Linux eventfd object.

func Create

func Create() (Eventfd, error)

Create returns an initialized eventfd.

func Wrap

func Wrap(fd int) Eventfd

Wrap returns an initialized Eventfd using the provided fd.

func (Eventfd) Close

func (ev Eventfd) Close() error

Close closes the eventfd, after which it should not be used.

func (*Eventfd) DisableMMIO

func (ev *Eventfd) DisableMMIO()

DisableMMIO undoes the effect of a previous call to EnableMMIO. DisableMMIO cannot be called concurrently with Write, MMIOWrite, or MMIOAddr.

func (Eventfd) Dup

func (ev Eventfd) Dup() (Eventfd, error)

Dup copies the eventfd, calling dup(2) on the underlying file descriptor.

func (*Eventfd) EnableMMIO

func (ev *Eventfd) EnableMMIO(addr uintptr, ctrl MMIOController)

EnableMMIO causes future calls to ev.Write() to use memory-mapped writes to addr, subject to ctrl. EnableMMIO cannot be called concurrently with Write, MMIOWrite, or MMIOAddr.

This feature is used to support KVM ioeventfds. Since this requires that addr is mapped read-only or with no permissions in the host virtual address space (so that writes in host mode fault), it cannot reasonably be Go-managed memory, so it's safe to type as uintptr rather than a pointer.

func (Eventfd) FD

func (ev Eventfd) FD() int

FD returns the underlying file descriptor. Use with care, as this breaks the Eventfd abstraction.

func (Eventfd) MMIOAddr

func (ev Eventfd) MMIOAddr() uintptr

MMIOAddr returns the address set by the last call to EnableMMIO.

func (Eventfd) MMIOWrite

func (ev Eventfd) MMIOWrite(val uint64) error

MMIOWrite is equivalent to Write, but returns an error if the write cannot be implemented by writing to the address set by EnableMMIO. This is primarily useful for testing.

func (Eventfd) Notify

func (ev Eventfd) Notify() error

Notify alerts other users of the eventfd. Users can receive alerts by calling Wait or Read.

func (Eventfd) Read

func (ev Eventfd) Read() (uint64, error)

Read blocks until eventfd is non-zero (i.e. someone calls Notify or Write) and returns the value read.

func (Eventfd) Wait

func (ev Eventfd) Wait() error

Wait blocks until eventfd is non-zero (i.e. someone calls Notify or Write).

func (Eventfd) Write

func (ev Eventfd) Write(val uint64) error

Write writes a specific value to the eventfd.

type MMIOController

type MMIOController interface {
	// Enabled returns true if writing to the associated MMIO address can
	// succeed. This is inherently racy, so if the memory-mapped write faults,
	// the eventfd will fall back to writing using a syscall.
	Enabled() bool

	// Close is called when the associated Eventfd is closed.
	Close(ev Eventfd)
}

MMIOController controls eventfd memory-mapped I/O.

Source Files

eventfd.go eventfd_unsafe.go

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

Tools for package owners.