kexec

package
Version: v0.0.0-...-c97c800 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2019 License: BSD-3-Clause Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RangeRAM     RangeType = "System RAM"
	RangeDefault           = "Default"
	RangeNVACPI            = "ACPI Non-volatile Storage"
	RangeACPI              = "ACPI Tables"
	RangeNVS               = "Reserved"
)

Variables

View Source
var ErrNotEnoughSpace = errors.New("not enough space")

Functions

func FileLoad

func FileLoad(kernel, ramfs *os.File, cmdline string) error

FileLoad loads the given kernel as the new kernel with the given ramfs and cmdline.

The kexec_file_load(2) syscall is x86-64 bit only.

func Load

func Load(entry uintptr, segments []Segment, flags uint64) error

Load loads the given segments into memory to be executed on a kexec-reboot.

It is assumed that segments is made up of the next kernel's code and text segments, and that `entry` is the entry point, either kernel entry point or trampoline.

func Reboot

func Reboot() error

Reboot executes a kernel previously loaded with FileInit.

Types

type ErrKexec

type ErrKexec struct {
	Entry    uintptr
	Segments []Segment
	Flags    uint64
	Errno    syscall.Errno
}

ErrKexec is the error type returned kexec. It describes entry point, flags, errno and kernel layout.

func (ErrKexec) Error

func (e ErrKexec) Error() string

type Memory

type Memory struct {
	Phys []TypedAddressRange

	Segments []Segment
}

Memory provides routines to work with physical memory ranges.

func (*Memory) AddKexecSegment

func (m *Memory) AddKexecSegment(d []byte) (addr uintptr, err error)

AddKexecSegment adds d to a new kexec segment

func (Memory) FindSpace

func (m Memory) FindSpace(sz uint) (start uintptr, err error)

FindSpace returns pointer to the physical memory, where array of size sz can be stored during next AddKexecSegment call.

func (*Memory) LoadElfSegments

func (m *Memory) LoadElfSegments(r io.ReaderAt) error

LoadElfSegments loads loadable ELF segments.

func (*Memory) ParseMemoryMap

func (m *Memory) ParseMemoryMap() error

ParseMemoryMap reads firmware provided memory map from /sys/firmware/memmap.

type Range

type Range struct {
	// Start is the inclusive start of the range.
	Start uintptr
	// Size is the size of the range.
	// Start+Size is the exclusive end of the range.
	Size uint
}

Range represents a contiguous uintptr interval [Start, Start+Size).

func (Range) Disjunct

func (r Range) Disjunct(r2 Range) bool

Disjunct returns true if r and r2 do not overlap.

func (Range) IsSupersetOf

func (r Range) IsSupersetOf(r2 Range) bool

IsSupersetOf returns true if r2 in r.

func (Range) Overlaps

func (r Range) Overlaps(r2 Range) bool

Overlaps returns true if r and r2 overlap.

type RangeType

type RangeType string

RangeType defines type of a TypedAddressRange based on the Linux kernel string provided by firmware memory map.

type Segment

type Segment struct {
	// Buf is a buffer in user space.
	Buf Range
	// Phys is a physical address of kernel.
	Phys Range
}

Segment defines kernel memory layout.

func AlignPhys

func AlignPhys(s Segment) Segment

AlignPhys fixes s to the kexec_load preconditions.

s's physical addresses must be multiples of the page size.

E.g. if page size is 0x1000: Segment {

Buf:  {Start: 0x1011, Size: 0x1022}
Phys: {Start: 0x2011, Size: 0x1022}

} has to become Segment {

Buf:  {Start: 0x1000, Size: 0x1033}
Phys: {Start: 0x2000, Size: 0x2000}

}

func Dedup

func Dedup(segs []Segment) []Segment

Dedup merges segments in segs as much as possible.

func NewSegment

func NewSegment(buf []byte, phys Range) Segment

NewSegment creates new Segment. Segments should be created using NewSegment method to prevent data pointed by Segment.Buf to be collected by garbage collector.

func (Segment) String

func (s Segment) String() string

type TypedAddressRange

type TypedAddressRange struct {
	Range
	Type RangeType
}

TypedAddressRange represents range of physical memory.

Jump to

Keyboard shortcuts

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