amd64

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2026 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearSymbolCache

func ClearSymbolCache()

ClearSymbolCache clears the memoised symbol tables. Intended for tests.

Types

type BootOptions

type BootOptions struct {
	// Cmdline is the kernel command line (without trailing NUL).
	Cmdline string
	// LoadAddr explicitly sets the payload load GPA. If zero, a default is
	// chosen using the kernel's preferred address and alignment.
	LoadAddr uint64
	// Initrd holds the initramfs image to copy into guest RAM.
	Initrd []byte
	// InitrdGPA overrides where the initramfs is copied in guest RAM. If zero,
	// a location is chosen automatically.
	InitrdGPA uint64
	// ZeroPageGPA is where the 4 KiB boot_params ("zero page") will be written.
	// Default: 0x00090000.
	ZeroPageGPA uint64
	// CmdlineGPA is where the NUL-terminated command line will be placed.
	// Default: ZeroPageGPA + 0x1000.
	CmdlineGPA uint64
	// StackTopGPA sets the initial RSP. If zero, it defaults near the top of
	// guest RAM (RAM end - 4 KiB) aligned down to 16 bytes.
	StackTopGPA uint64
	// PagingBase is the GPA used as scratch for the identity-mapped paging
	// structures. Default: 0x00020000.
	PagingBase uint64
	// AddressSpaceGiB controls how much memory (in GiB) is identity mapped by
	// SetupLongMode. Default: 4 GiB.
	AddressSpaceGiB int
	// E820 overrides the BIOS memory map. If empty, a single RAM entry covering
	// the entire allocated memory region is used.
	E820 []E820Entry
}

BootOptions parameterise how the kernel is placed into guest RAM.

type BootPlan

type BootPlan struct {
	LoadAddr        uint64
	EntryGPA        uint64
	ZeroPageGPA     uint64
	CmdlineGPA      uint64
	StackTopGPA     uint64
	PagingBase      uint64
	AddressSpaceGiB int
}

BootPlan captures the derived addresses required to hand control to the kernel. After Prepare completes successfully, ConfigureVCPU can be used to program the first vCPU.

func (*BootPlan) ConfigureVCPU

func (p *BootPlan) ConfigureVCPU(vcpu hv.VirtualCPU) error

ConfigureVCPU programs the supplied vCPU for a 64-bit Linux handoff using the prepared memory layout.

type E820Entry

type E820Entry struct {
	Addr uint64
	Size uint64
	Type uint32
}

E820Entry describes a single BIOS e820 memory map entry.

func DefaultE820Map

func DefaultE820Map(memStart, memEnd uint64) []E820Entry

DefaultE820Map exposes the standard memory layout used by the loader.

type KernelImage

type KernelImage struct {

	// bzImage-specific fields.
	Data          []byte
	Header        SetupHeader
	HeaderBytes   []byte
	PayloadOffset int
	// contains filtered or unexported fields
}

KernelImage represents a loaded Linux kernel image on the host side.

func LoadBzImage

func LoadBzImage(kernel io.ReaderAt, kernelSize int64) (*KernelImage, error)

LoadBzImage reads kernelPath and validates the Linux/x86 boot header. It returns a KernelImage containing the raw image bytes, parsed setup header and a copy of the packed setup_header structure suitable for placing into the boot_params zero page.

func LoadKernel

func LoadKernel(kernel io.ReaderAt, kernelSize int64) (*KernelImage, error)

LoadKernel detects the format of kernelPath and returns a parsed KernelImage.

func (*KernelImage) BuildZeroPage

func (k *KernelImage) BuildZeroPage(vm hv.VirtualMachine, zeroPageGPA, loadAddr uint64, cmdline string, cmdlineGPA uint64, initrdGPA uint64, initrdSize uint32, e820 []E820Entry) error

BuildZeroPage populates the boot_params and supporting command line in guest memory according to the Linux x86_64 boot protocol.

func (*KernelImage) DefaultLoadAddress

func (k *KernelImage) DefaultLoadAddress() uint64

DefaultLoadAddress returns a reasonable load address for the kernel payload. Preference order:

  1. setup_header.pref_address if non-zero
  2. 1 MiB if LOAD_HIGH flag set
  3. 64 KiB otherwise

func (*KernelImage) EntryPoint

func (k *KernelImage) EntryPoint(loadAddr uint64) uint64

EntryPoint returns the 64-bit entry point GPA when the payload is loaded at loadAddr. The Linux boot protocol places the 64-bit entry at load+0x200.

func (*KernelImage) LoadIntoMemory

func (k *KernelImage) LoadIntoMemory(vm hv.VirtualMachine, loadAddr uint64) error

LoadIntoMemory copies the kernel payload into guest RAM at loadAddr. The range [loadAddr, loadAddr+max(init_size, len(payload))) is cleared before the payload is copied to satisfy the kernel's expectation of zeroed memory.

func (*KernelImage) Payload

func (k *KernelImage) Payload() []byte

Payload returns the compressed protected-mode payload of the kernel image.

func (*KernelImage) Prepare

func (k *KernelImage) Prepare(vm hv.VirtualMachine, opts BootOptions) (*BootPlan, error)

Prepare loads the kernel payload, builds the zero page and returns the derived boot parameters. Call ConfigureVCPU to apply the plan to a vCPU.

type SetupHeader

type SetupHeader struct {
	ProtocolVersion     uint16
	SetupSectors        uint8
	LoadFlags           uint8
	Code32Start         uint32
	RamdiskImage        uint32
	RamdiskSize         uint32
	HeapEndPtr          uint16
	CmdLinePtr          uint32
	InitrdAddrMax       uint32
	KernelAlignment     uint32
	RelocatableKernel   uint8
	MinAlignment        uint8
	XLoadFlags          uint16
	CmdlineSize         uint32
	HardwareSubarch     uint32
	HardwareSubarchData uint64
	PayloadOffset       uint32
	PayloadLength       uint32
	SetupData           uint64
	PrefAddress         uint64
	InitSize            uint32
	HandoverOffset      uint32
	KernelInfoOffset    uint32
}

type StackFrame

type StackFrame struct {
	Index    int
	PhysAddr uint64
	PC       uint64
	Symbol   string
	Offset   uint64
}

StackFrame captures a single unwound frame from the guest kernel.

func CaptureStackTrace

func CaptureStackTrace(vcpu hv.VirtualCPU, vmlinux io.ReaderAt, systemMapLoader func() (io.ReaderAt, error), maxFrames int) ([]StackFrame, error)

CaptureStackTrace walks the current guest stack and symbolises the frames using symbols from either vmlinux or (optionally) a System.map. The return slice always contains at least the current RIP when no fatal error occurs. maxFrames bounds the number of frames collected; if zero or negative a default of 16 is used. Symbol resolution assumes KASLR is disabled (for example by building without CONFIG_RANDOMIZE_BASE or booting with nokaslr).

Jump to

Keyboard shortcuts

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