kvm

package
v0.0.0-...-e83addd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 12, 2021 License: GPL-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package kvm provides an interface to the kvm system call.

Package kvm provides an interface to the kvm system call.

Index

Constants

View Source
const (
	/* CR0 bits */
	CR0_PE = 1
	CR0_MP = (1 << 1)
	CR0_EM = (1 << 2)
	CR0_TS = (1 << 3)
	CR0_ET = (1 << 4)
	CR0_NE = (1 << 5)
	CR0_WP = (1 << 16)
	CR0_AM = (1 << 18)
	CR0_NW = (1 << 29)
	CR0_CD = (1 << 30)
	CR0_PG = (1 << 31)

	/* CR4= bits */
	CR4_VME        = 1
	CR4_PVI        = (1 << 1)
	CR4_TSD        = (1 << 2)
	CR4_DE         = (1 << 3)
	CR4_PSE        = (1 << 4)
	CR4_PAE        = (1 << 5)
	CR4_MCE        = (1 << 6)
	CR4_PGE        = (1 << 7)
	CR4_PCE        = (1 << 8)
	CR4_OSFXSR     = (1 << 8)
	CR4_OSXMMEXCPT = (1 << 10)
	CR4_UMIP       = (1 << 11)
	CR4_VMXE       = (1 << 13)
	CR4_SMXE       = (1 << 14)
	CR4_FSGSBASE   = (1 << 16)
	CR4_PCIDE      = (1 << 17)
	CR4_OSXSAVE    = (1 << 18)
	CR4_SMEP       = (1 << 20)
	CR4_SMAP       = (1 << 21)

	EFER_SCE = 1
	EFER_LME = (1 << 8)
	EFER_LMA = (1 << 10)
	EFER_NXE = (1 << 11)

	/* 64-bit page * entry bits */
	PDE64_PRESENT  = 1
	PDE64_RW       = (1 << 1)
	PDE64_USER     = (1 << 2)
	PDE64_ACCESSED = (1 << 5)
	PDE64_DIRTY    = (1 << 6)
	PDE64_PS       = (1 << 7)
	PDE64_G        = (1 << 8)
)
View Source
const (
	// Enable enables debug options in the guest
	Enable = 1
	// SingleStep enables single step.
	SingleStep = 2
)
View Source
const (
	ExitUnknown       = 0
	ExitException     = 1
	ExitIo            = 2
	ExitHypercall     = 3
	ExitDebug         = 4
	ExitHlt           = 5
	ExitMmio          = 6
	ExitIrqWindowOpen = 7
	ExitShutdown      = 8
	ExitFailEntry     = 9
	ExitIntr          = 10
	ExitSetTPR        = 11
	ExitTPRAccess     = 12
	ExitNmi           = 16
	ExitInternalError = 17
	ExitOsi           = 18
	// 	ExitPapr_hcall      = 19
	ExitWatchdog    = 21
	ExitEpr         = 23
	ExitSystemEvent = 24
	ExitIoapicEOI   = 26
)

KVM exit values.

View Source
const APIVersion = 12

APIVersion is the KVM API version. The only API version we support. The only API version anyway. This was a mistake remedied by the capability stuff.

View Source
const KVMIO = 0xAE

KVMIO is for the KVMIO ioctl.

View Source
const PageTableBase = 0xffff0000

PageTableBase is where our initial page tables go. EFI apps should not go near this.

Variables

View Source
var (
	// ErrTraceeExited is returned when a command is executed on a tracee
	// that has already exited.
	ErrTraceeExited = errors.New("tracee exited")
	// Debug can be set externally to trace activity.
	Debug = func(string, ...interface{}) {}
)

Functions

This section is empty.

Types

type CPUIDEntry

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

CPUIDEntry is one cpuid entry returned by KVM.

func (*CPUIDEntry) String

func (e *CPUIDEntry) String() string

String implements String. It returns a string formatted as strace formats it: {nent=54, entries=[{function=0, index=0, flags=0, eax=0xd, ebx=0x68747541, ecx=0x444d4163, edx=0x69746e65},

type CPUIDInfo

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

CPUIDInfo contains information about CPUID information. We've learned the hard way that it's best for the ents array to be really large -- too large -- 256 seems appropriate. KVM does not provide partial results; it just returns an error if len(ents) is too small.

func (*CPUIDInfo) String

func (i *CPUIDInfo) String() string

String implements String. It returns a string formatted as strace would format it: {nent=54, entries=[{function=0, index=0, flags=0, eax=0xd, ebx=0x68747541, ecx=0x444d4163, edx=0x69746e65}, ... With the one difference that there is a single line per cpuid (makes finding issues way easier)

type ClearDirtyLog

type ClearDirtyLog struct {
	Slot      uint32
	NumPages  uint32
	FirstPage uint64
}

ClearDirtyLog clears the dirty page log.

type CreateRegion

type CreateRegion struct {
	Slot  uint32
	Flags uint32
	GPA   uint64
	Size  uint64
}

CreateRegion is used for KVM_CREATE_MEMORY_REGION

type DebugControl

type DebugControl struct {
	Control uint32
	// contains filtered or unexported fields
}

DebugControl controls guest debug.

type DirtyLog

type DirtyLog struct {
	Slot uint32
	// contains filtered or unexported fields
}

DirtyLog gets a log of dirty pages.

type Exit

type Exit uint32

Exit= is the VM exit value returned by KVM.

func (Exit) String

func (e Exit) String() string

type IOEventFD

type IOEventFD struct {
	Datamatch uint64
	Addr      uint64 /* legal pio/mmio address */
	Len       uint32 /* 1, 2, 4, or 8 or 0 to ignore length */
	FD        int32
	Flags     uint32
	// contains filtered or unexported fields
}

IOEventFD controls how events are managed.

type MemoryRegion

type MemoryRegion struct {
	Slot  uint32
	Flags uint32
	GPA   uint64
	Size  uint64 /* bytes */
}

MemoryRegion is used for CREATE_MEMORY_REGION

type Region

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

A Region defines a memory region. This is likely overkill; we likely don't want anything more than a single 2G region starting at 0.

type SetSignalMask

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

SetSignalMask sets the signal mask

type TPRAccessCtl

type TPRAccessCtl struct {
	Enabled uint32
	Flags   uint32
	// contains filtered or unexported fields
}

TPRAccessCtl controls how TPRAccess is reported.

type Tracee

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

A Tracee is a process that is being traced.

func Attach

func Attach(pid int) (*Tracee, error)

Attach attaches to the given process.

func New

func New() (*Tracee, error)

New returns a new Tracee. It will fail if the kvm device can not be opened. All the work done here is complex, but it all has to work or ... no kvm. But as soon as possible we shift to using the goroutine. FWIW.

func (*Tracee) Close

func (t *Tracee) Close() error

Close closes a Tracee.

func (*Tracee) Detach

func (t *Tracee) Detach() error

Detach detaches the tracee, destroying it in the process.

func (*Tracee) Event

func (t *Tracee) Event() unix.SignalfdSiginfo

func (*Tracee) GetIPtr

func (t *Tracee) GetIPtr() (uintptr, error)

GetIPtr reads the instruction pointer from the inferior and returns it.

func (*Tracee) GetRegs

func (t *Tracee) GetRegs() (*syscall.PtraceRegs, error)

GetRegs reads the registers from the inferior.

func (*Tracee) GetSigInfo

func (t *Tracee) GetSigInfo() (*unix.SignalfdSiginfo, error)

GetSigInfo gets the signal info for a pid into a *unix.SignalfdSiginfo

func (*Tracee) GetSiginfo

func (t *Tracee) GetSiginfo() (*unix.SignalfdSiginfo, error)

GetSiginfo reads the signal information for the signal that stopped the inferior. Only valid on Unix if the inferior is stopped due to a signal.

func (*Tracee) NewProc

func (t *Tracee) NewProc(id int) error

NewProc creates a CPU, given an id. TODO :we're getting sloppy about the t.do stuff, fix.

func (*Tracee) PID

func (t *Tracee) PID() int

PID returns the PID for a Tracee. we'll return the cpuid for now.

func (*Tracee) Read

func (t *Tracee) Read(address uintptr, data []byte) error

Read grabs memory starting at the given address, for len(data) bytes.

func (*Tracee) ReadWord

func (t *Tracee) ReadWord(address uintptr) (uint64, error)

ReadWord reads the given word from the inferior's address space. Only allowed to read from Region 0 for now.

func (*Tracee) Run

func (t *Tracee) Run() error

SingleStep continues the tracee for one instruction. Todo: see if we are in single step mode, if not, set, etc.

func (*Tracee) SetRegs

func (t *Tracee) SetRegs(pr *syscall.PtraceRegs) error

SetRegs sets regs for a Tracee. The ability to set sregs is limited by what can be set in ptraceregs.

func (*Tracee) SingleStep

func (t *Tracee) SingleStep(onoff bool) error

EnableSingleStep enables single stepping the guest

func (*Tracee) String

func (t *Tracee) String() string

func (*Tracee) Tab

func (t *Tracee) Tab() []byte

func (*Tracee) Write

func (t *Tracee) Write(address uintptr, data []byte) error

func (*Tracee) WriteWord

func (t *Tracee) WriteWord(address uintptr, word uint64) error

WriteWord writes the given word into the inferior's address space.

type Translate

type Translate struct {
	// LinearAddress is input.
	LinearAddress uint64

	// This is output
	PhysicalAddress uint64
	Valid           uint8
	Writeable       uint8
	Usermode        uint8
	// contains filtered or unexported fields
}

Translate translates guest linear to physical? This is for for TRANSLATE

type UserRegion

type UserRegion struct {
	Slot     uint32
	Flags    uint32
	GPA      uint64
	Size     uint64
	UserAddr uint64
}

UserRegion is used for SET_USER_MEMORY_REGION

type VAPICAddr

type VAPICAddr struct {
	Addr uint64
}

VAPICAddr sets the VAPIC address.

type VMRun

type VMRun struct {
	/* in */
	RequestInterruptWindow uint8
	ImmediateExit          uint8

	/* out */
	ExitReason                 uint32
	ReadyForInterruptInjection uint8
	IFFlag                     uint8
	Flags                      uint16
	CR8                        uint64
	APICBase                   uint64
	// contains filtered or unexported fields
}

for KVM_RUN, returned by mmap(vcpu_fd, offset=0)

func (*VMRun) String

func (r *VMRun) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL