Documentation
¶
Index ¶
- Constants
- Variables
- func ArchToSnapshotArch(arch CpuArchitecture) uint32
- type AddressSpace
- func (a *AddressSpace) Allocate(req MMIOAllocationRequest) (MMIOAllocation, error)
- func (a *AddressSpace) Allocations() []MMIOAllocation
- func (a *AddressSpace) Architecture() CpuArchitecture
- func (a *AddressSpace) FixedRegions() []MMIOAllocation
- func (a *AddressSpace) RAMBase() uint64
- func (a *AddressSpace) RAMEnd() uint64
- func (a *AddressSpace) RAMSize() uint64
- func (a *AddressSpace) RegisterFixed(name string, base, size uint64) error
- type Arm64GICInfo
- type Arm64GICProvider
- type Arm64GICVersion
- type Arm64Interrupt
- type CpuArchitecture
- type Device
- type DeviceConfig
- type DeviceSnapshot
- type DeviceSnapshotter
- type DeviceTemplate
- type ExitContext
- type Hypervisor
- type MMIOAllocation
- type MMIOAllocationRequest
- type MMIORegion
- type MemoryMappedIODevice
- type MemoryRegion
- type Register
- type Register64
- type RegisterValue
- type RunConfig
- type SimpleMMIODevice
- type SimpleVMConfig
- func (c SimpleVMConfig) CPUCount() int
- func (c SimpleVMConfig) Callbacks() VMCallbacks
- func (c SimpleVMConfig) Loader() VMLoader
- func (c SimpleVMConfig) MemoryBase() uint64
- func (c SimpleVMConfig) MemorySize() uint64
- func (c SimpleVMConfig) NeedsInterruptSupport() bool
- func (c SimpleVMConfig) OnCreateVCPU(vCpu VirtualCPU) error
- func (c SimpleVMConfig) OnCreateVM(vm VirtualMachine) error
- func (c SimpleVMConfig) OnCreateVMWithMemory(vm VirtualMachine) error
- type SimpleX86IOPortDevice
- type Snapshot
- type VMCallbacks
- type VMConfig
- type VMConfigHash
- type VMLoader
- type VirtualCPU
- type VirtualCPUAmd64
- type VirtualCPUDebug
- type VirtualMachine
- type VirtualMachineAmd64
- type X86IOPortDevice
Constants ¶
const ( SnapshotMagic uint32 = 0x534e4150 // "SNAP" SnapshotVersion uint32 = 2 // v2 adds ICC register support )
Snapshot file format constants
const ( SnapshotArchInvalid uint32 = 0 SnapshotArchX86_64 uint32 = 1 SnapshotArchARM64 uint32 = 2 SnapshotArchRISCV64 uint32 = 3 )
Architecture encoding for snapshot files
Variables ¶
var ( ErrInterrupted = errors.New("operation interrupted") ErrVMHalted = errors.New("virtual machine halted") ErrHypervisorUnsupported = errors.New("hypervisor unsupported on this platform") ErrGuestRequestedReboot = errors.New("guest requested reboot") ErrYield = errors.New("yield to host") ErrUserYield = errors.New("user yield to host") )
Functions ¶
func ArchToSnapshotArch ¶
func ArchToSnapshotArch(arch CpuArchitecture) uint32
ArchToSnapshotArch converts a CpuArchitecture to its snapshot file encoding.
Types ¶
type AddressSpace ¶ added in v0.0.2
type AddressSpace struct {
// contains filtered or unexported fields
}
AddressSpace manages physical address allocation for a VM. It tracks RAM regions and allocates MMIO regions above RAM to avoid conflicts.
func NewAddressSpace ¶ added in v0.0.2
func NewAddressSpace(arch CpuArchitecture, ramBase, ramSize uint64) *AddressSpace
NewAddressSpace creates a new physical address allocator for a VM. MMIO allocations will start above ramBase+ramSize.
func NewAddressSpaceSplit ¶ added in v0.0.2
func NewAddressSpaceSplit(arch CpuArchitecture, lowBase, lowSize, highBase, highSize uint64) *AddressSpace
NewAddressSpaceSplit creates a physical address allocator for split memory layouts. This is used on x86_64 when RAM exceeds the PCI hole (3GB-4GB). Low memory: [lowBase, lowBase+lowSize) High memory: [highBase, highBase+highSize) MMIO allocations start above the high memory region.
func (*AddressSpace) Allocate ¶ added in v0.0.2
func (a *AddressSpace) Allocate(req MMIOAllocationRequest) (MMIOAllocation, error)
Allocate allocates an MMIO region with the specified requirements. The region is placed above RAM and aligned to the requested alignment.
func (*AddressSpace) Allocations ¶ added in v0.0.2
func (a *AddressSpace) Allocations() []MMIOAllocation
Allocations returns a copy of all dynamically allocated MMIO regions.
func (*AddressSpace) Architecture ¶ added in v0.0.2
func (a *AddressSpace) Architecture() CpuArchitecture
Architecture returns the CPU architecture.
func (*AddressSpace) FixedRegions ¶ added in v0.0.2
func (a *AddressSpace) FixedRegions() []MMIOAllocation
FixedRegions returns a copy of all fixed MMIO regions.
func (*AddressSpace) RAMBase ¶ added in v0.0.2
func (a *AddressSpace) RAMBase() uint64
RAMBase returns the RAM base address.
func (*AddressSpace) RAMEnd ¶ added in v0.0.2
func (a *AddressSpace) RAMEnd() uint64
RAMEnd returns the first address after RAM.
func (*AddressSpace) RAMSize ¶ added in v0.0.2
func (a *AddressSpace) RAMSize() uint64
RAMSize returns the RAM size.
func (*AddressSpace) RegisterFixed ¶ added in v0.0.2
func (a *AddressSpace) RegisterFixed(name string, base, size uint64) error
RegisterFixed registers a pre-determined MMIO region. Returns error if the region overlaps with RAM.
type Arm64GICInfo ¶
type Arm64GICInfo struct {
Version Arm64GICVersion
DistributorBase uint64
DistributorSize uint64
RedistributorBase uint64
RedistributorSize uint64
CpuInterfaceBase uint64
CpuInterfaceSize uint64
ItsBase uint64
ItsSize uint64
MaintenanceInterrupt Arm64Interrupt
}
type Arm64GICProvider ¶
type Arm64GICProvider interface {
Arm64GICInfo() (Arm64GICInfo, bool)
}
type Arm64GICVersion ¶
type Arm64GICVersion int
const ( Arm64GICVersionUnknown Arm64GICVersion = iota Arm64GICVersion2 Arm64GICVersion3 )
type Arm64Interrupt ¶
type CpuArchitecture ¶
type CpuArchitecture string
const ( ArchitectureInvalid CpuArchitecture = "invalid" ArchitectureX86_64 CpuArchitecture = "x86_64" ArchitectureARM64 CpuArchitecture = "arm64" ArchitectureRISCV64 CpuArchitecture = "riscv64" )
var ArchitectureNative CpuArchitecture
func SnapshotArchToArch ¶
func SnapshotArchToArch(arch uint32) CpuArchitecture
SnapshotArchToArch converts a snapshot file architecture encoding to CpuArchitecture.
type Device ¶
type Device interface {
Init(vm VirtualMachine) error
}
type DeviceConfig ¶
DeviceConfig captures device configuration for hashing.
type DeviceSnapshot ¶
type DeviceSnapshot interface {
}
type DeviceSnapshotter ¶
type DeviceSnapshotter interface {
Device
DeviceId() string
CaptureSnapshot() (DeviceSnapshot, error)
RestoreSnapshot(snap DeviceSnapshot) error
}
type DeviceTemplate ¶
type DeviceTemplate interface {
Create(vm VirtualMachine) (Device, error)
}
type ExitContext ¶
type ExitContext interface {
SetExitTimeslice(id timeslice.TimesliceID)
}
type Hypervisor ¶
type Hypervisor interface {
io.Closer
Architecture() CpuArchitecture
NewVirtualMachine(config VMConfig) (VirtualMachine, error)
}
type MMIOAllocation ¶ added in v0.0.2
type MMIOAllocation struct {
Name string // Device name
Base uint64 // Allocated base address
Size uint64 // Allocated size (may be larger than requested due to alignment)
}
MMIOAllocation is the result of an MMIO allocation.
type MMIOAllocationRequest ¶ added in v0.0.2
type MMIOAllocationRequest struct {
Name string // Device name for debugging/logging
Size uint64 // Required size in bytes
Alignment uint64 // Required alignment (power of 2, e.g., 0x1000 for 4KB)
}
MMIOAllocationRequest describes requirements for an MMIO region allocation.
type MMIORegion ¶
type MemoryMappedIODevice ¶
type MemoryMappedIODevice interface {
Device
MMIORegions() []MMIORegion
ReadMMIO(ctx ExitContext, addr uint64, data []byte) error
WriteMMIO(ctx ExitContext, addr uint64, data []byte) error
}
type Register ¶
type Register uint64
const ( RegisterInvalid Register = iota // AMD64 Regular Registers RegisterAMD64Rax RegisterAMD64Rbx RegisterAMD64Rcx RegisterAMD64Rdx RegisterAMD64Rsi RegisterAMD64Rdi RegisterAMD64Rsp RegisterAMD64Rbp RegisterAMD64R8 RegisterAMD64R9 RegisterAMD64R10 RegisterAMD64R11 RegisterAMD64R12 RegisterAMD64R13 RegisterAMD64R14 RegisterAMD64R15 RegisterAMD64Rip RegisterAMD64Rflags // AMD64 Special Registers RegisterAMD64Cr3 // ARM64 General-Purpose Registers RegisterARM64X0 RegisterARM64X1 RegisterARM64X2 RegisterARM64X3 RegisterARM64X4 RegisterARM64X5 RegisterARM64X6 RegisterARM64X7 RegisterARM64X8 RegisterARM64X9 RegisterARM64X10 RegisterARM64X11 RegisterARM64X12 RegisterARM64X13 RegisterARM64X14 RegisterARM64X15 RegisterARM64X16 RegisterARM64X17 RegisterARM64X18 RegisterARM64X19 RegisterARM64X20 RegisterARM64X21 RegisterARM64X22 RegisterARM64X23 RegisterARM64X24 RegisterARM64X25 RegisterARM64X26 RegisterARM64X27 RegisterARM64X28 RegisterARM64X29 RegisterARM64X30 RegisterARM64Xzr // Zero register (reads as 0, writes are discarded) RegisterARM64Sp RegisterARM64Pc RegisterARM64Pstate RegisterARM64Vbar RegisterARM64GicrBase // ARM64 System Registers for snapshots RegisterARM64SctlrEl1 RegisterARM64TcrEl1 RegisterARM64Ttbr0El1 RegisterARM64Ttbr1El1 RegisterARM64MairEl1 RegisterARM64ElrEl1 RegisterARM64SpsrEl1 RegisterARM64EsrEl1 RegisterARM64FarEl1 RegisterARM64SpEl0 RegisterARM64SpEl1 RegisterARM64CntkctlEl1 RegisterARM64CntvCtlEl0 RegisterARM64CntvCvalEl0 RegisterARM64CpacrEl1 RegisterARM64ContextidrEl1 RegisterARM64TpidrEl0 RegisterARM64TpidrEl1 RegisterARM64TpidrroEl0 RegisterARM64ParEl1 RegisterARM64Afsr0El1 RegisterARM64Afsr1El1 RegisterARM64AmairEl1 // RISC-V General-Purpose Registers RegisterRISCVX0 RegisterRISCVX1 RegisterRISCVX2 RegisterRISCVX3 RegisterRISCVX4 RegisterRISCVX5 RegisterRISCVX6 RegisterRISCVX7 RegisterRISCVX8 RegisterRISCVX9 RegisterRISCVX10 RegisterRISCVX11 RegisterRISCVX12 RegisterRISCVX13 RegisterRISCVX14 RegisterRISCVX15 RegisterRISCVX16 RegisterRISCVX17 RegisterRISCVX18 RegisterRISCVX19 RegisterRISCVX20 RegisterRISCVX21 RegisterRISCVX22 RegisterRISCVX23 RegisterRISCVX24 RegisterRISCVX25 RegisterRISCVX26 RegisterRISCVX27 RegisterRISCVX28 RegisterRISCVX29 RegisterRISCVX30 RegisterRISCVX31 RegisterRISCVPc )
type Register64 ¶
type Register64 uint64
type RegisterValue ¶
type RegisterValue interface {
// contains filtered or unexported methods
}
type SimpleMMIODevice ¶
type SimpleMMIODevice struct {
Regions []MMIORegion
ReadFunc func(ctx ExitContext, addr uint64, data []byte) error
WriteFunc func(ctx ExitContext, addr uint64, data []byte) error
}
func (SimpleMMIODevice) Init ¶
func (d SimpleMMIODevice) Init(vm VirtualMachine) error
func (SimpleMMIODevice) MMIORegions ¶
func (d SimpleMMIODevice) MMIORegions() []MMIORegion
func (SimpleMMIODevice) ReadMMIO ¶
func (d SimpleMMIODevice) ReadMMIO(ctx ExitContext, addr uint64, data []byte) error
func (SimpleMMIODevice) WriteMMIO ¶
func (d SimpleMMIODevice) WriteMMIO(ctx ExitContext, addr uint64, data []byte) error
type SimpleVMConfig ¶
type SimpleVMConfig struct {
NumCPUs int
MemSize uint64
MemBase uint64
InterruptSupport bool
VMLoader VMLoader
CreateVM func(vm VirtualMachine) error
CreateVMWithMemory func(vm VirtualMachine) error
CreateVCPU func(vCpu VirtualCPU) error
}
func (SimpleVMConfig) CPUCount ¶
func (c SimpleVMConfig) CPUCount() int
func (SimpleVMConfig) Callbacks ¶
func (c SimpleVMConfig) Callbacks() VMCallbacks
func (SimpleVMConfig) Loader ¶
func (c SimpleVMConfig) Loader() VMLoader
func (SimpleVMConfig) MemoryBase ¶
func (c SimpleVMConfig) MemoryBase() uint64
func (SimpleVMConfig) MemorySize ¶
func (c SimpleVMConfig) MemorySize() uint64
func (SimpleVMConfig) NeedsInterruptSupport ¶
func (c SimpleVMConfig) NeedsInterruptSupport() bool
func (SimpleVMConfig) OnCreateVCPU ¶
func (c SimpleVMConfig) OnCreateVCPU(vCpu VirtualCPU) error
OnCreateVCPU implements VMCallbacks.
func (SimpleVMConfig) OnCreateVM ¶
func (c SimpleVMConfig) OnCreateVM(vm VirtualMachine) error
OnCreateVM implements VMCallbacks.
func (SimpleVMConfig) OnCreateVMWithMemory ¶
func (c SimpleVMConfig) OnCreateVMWithMemory(vm VirtualMachine) error
OnCreateVMWithMemory implements VMCallbacks.
type SimpleX86IOPortDevice ¶
type SimpleX86IOPortDevice struct {
Ports []uint16
ReadFunc func(ctx ExitContext, port uint16, data []byte) error
WriteFunc func(ctx ExitContext, port uint16, data []byte) error
}
func (SimpleX86IOPortDevice) IOPorts ¶
func (d SimpleX86IOPortDevice) IOPorts() []uint16
func (SimpleX86IOPortDevice) Init ¶
func (d SimpleX86IOPortDevice) Init(vm VirtualMachine) error
func (SimpleX86IOPortDevice) ReadIOPort ¶
func (d SimpleX86IOPortDevice) ReadIOPort(ctx ExitContext, port uint16, data []byte) error
func (SimpleX86IOPortDevice) WriteIOPort ¶
func (d SimpleX86IOPortDevice) WriteIOPort(ctx ExitContext, port uint16, data []byte) error
type VMCallbacks ¶
type VMCallbacks interface {
OnCreateVM(vm VirtualMachine) error
OnCreateVMWithMemory(vm VirtualMachine) error
OnCreateVCPU(vCpu VirtualCPU) error
}
type VMConfigHash ¶
type VMConfigHash [32]byte
VMConfigHash represents a hash of VM configuration for cache validation. Two snapshots can only be restored if they have the same config hash.
func ComputeConfigHash ¶
func ComputeConfigHash(arch CpuArchitecture, memSize, memBase uint64, cpuCount int, deviceConfigs []DeviceConfig) VMConfigHash
ComputeConfigHash computes a deterministic hash of VM configuration parameters. This is used to validate that a cached snapshot matches the current VM configuration.
func (VMConfigHash) String ¶
func (h VMConfigHash) String() string
String returns a hex string representation of the hash.
type VMLoader ¶
type VMLoader interface {
Load(vm VirtualMachine) error
}
type VirtualCPU ¶
type VirtualCPU interface {
VirtualMachine() VirtualMachine
ID() int
SetRegisters(regs map[Register]RegisterValue) error
GetRegisters(regs map[Register]RegisterValue) error
Run(ctx context.Context) error
}
type VirtualCPUAmd64 ¶
type VirtualCPUDebug ¶
type VirtualCPUDebug interface {
VirtualCPU
EnableTrace(maxEntries int) error
GetTraceBuffer() ([]string, error)
}
type VirtualMachine ¶
type VirtualMachine interface {
io.ReaderAt
io.WriterAt
io.Closer
Hypervisor() Hypervisor
MemorySize() uint64
MemoryBase() uint64
Run(ctx context.Context, cfg RunConfig) error
SetIRQ(irqLine uint32, level bool) error
VirtualCPUCall(id int, f func(vcpu VirtualCPU) error) error
AddDevice(dev Device) error
AddDeviceFromTemplate(template DeviceTemplate) (Device, error)
AllocateMemory(physAddr, size uint64) (MemoryRegion, error)
// AllocateMMIO requests an MMIO region from the VM's physical address allocator.
// The region is allocated above RAM to avoid conflicts. Returns the allocated
// base address and size.
AllocateMMIO(req MMIOAllocationRequest) (MMIOAllocation, error)
// RegisterFixedMMIO registers a pre-determined MMIO region (for legacy devices
// like GIC, UART, HPET, IO-APIC). Returns error if the region conflicts with
// RAM or other allocations.
RegisterFixedMMIO(name string, base, size uint64) error
// GetAllocatedMMIORegions returns all dynamically allocated MMIO regions.
// Used for E820 map and device tree generation.
GetAllocatedMMIORegions() []MMIOAllocation
CaptureSnapshot() (Snapshot, error)
RestoreSnapshot(snap Snapshot) error
}
type VirtualMachineAmd64 ¶
type VirtualMachineAmd64 interface {
VirtualMachine
SetIRQ(irqLine uint32, level bool) error
}
type X86IOPortDevice ¶
type X86IOPortDevice interface {
Device
IOPorts() []uint16
ReadIOPort(ctx ExitContext, port uint16, data []byte) error
WriteIOPort(ctx ExitContext, port uint16, data []byte) error
}