Documentation
¶
Index ¶
- func ClearSymbolCache()
- type BootOptions
- type BootPlan
- type E820Entry
- type KernelImage
- func (k *KernelImage) BuildZeroPage(vm hv.VirtualMachine, zeroPageGPA, loadAddr uint64, cmdline string, ...) error
- func (k *KernelImage) DefaultLoadAddress() uint64
- func (k *KernelImage) EntryPoint(loadAddr uint64) uint64
- func (k *KernelImage) LoadIntoMemory(vm hv.VirtualMachine, loadAddr uint64) error
- func (k *KernelImage) Payload() []byte
- func (k *KernelImage) Prepare(vm hv.VirtualMachine, opts BootOptions) (*BootPlan, error)
- type SetupHeader
- type StackFrame
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 ¶
E820Entry describes a single BIOS e820 memory map entry.
func DefaultE820Map ¶
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:
- setup_header.pref_address if non-zero
- 1 MiB if LOAD_HIGH flag set
- 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 ¶
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).