kexec

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2019 License: BSD-3-Clause Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RangeRAM      RangeType = "System RAM"
	RangeDefault            = "Default"
	RangeACPI               = "ACPI Tables"
	RangeNVS                = "ACPI Non-volatile Storage"
	RangeReserved           = "Reserved"
)
View Source
const M1 = 1 << 20

M1 is 1 Megabyte in bits.

View Source
const MaxAddr = ^uintptr(0)

Variables

This section is empty.

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 added in v0.4.0

func Load(entry uintptr, segments Segments, 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.

Load will align segments to page boundaries and deduplicate overlapping ranges.

func Reboot

func Reboot() error

Reboot executes a kernel previously loaded with FileInit.

Types

type ErrKexec added in v0.4.0

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

ErrKexec is returned by Load if the kexec failed. It describes entry point, flags, errno and kernel layout.

func (ErrKexec) Error added in v0.4.0

func (e ErrKexec) Error() string

Error implements error.

type ErrNotEnoughSpace added in v0.4.0

type ErrNotEnoughSpace struct {
	Size uint
}

ErrNotEnoughSpace is returned by the FindSpace family of functions if no range is large enough to accommodate the request.

func (ErrNotEnoughSpace) Error added in v0.5.0

func (e ErrNotEnoughSpace) Error() string

type Memory added in v0.4.0

type Memory struct {
	// Phys defines the layout of physical memory.
	//
	// Phys is used to tell loaded operating systems what memory is usable
	// as RAM, and what memory is reserved (for ACPI or other reasons).
	Phys MemoryMap

	// Segments are the segments used to load a new operating system.
	//
	// Each segment also contains a physical memory region it maps to.
	Segments Segments
}

Memory provides routines to work with physical memory ranges.

func (*Memory) AddKexecSegment added in v0.4.0

func (m *Memory) AddKexecSegment(d []byte) (Range, error)

AddKexecSegment adds d to a new kexec segment

func (*Memory) AddPhysSegment added in v0.5.0

func (m *Memory) AddPhysSegment(d []byte, limit Range) (Range, error)

AddPhysSegment reserves len(d) bytes in the physical memmap within limit and adds a kexec segment with d in that range.

func (Memory) AvailableRAM added in v0.5.0

func (m Memory) AvailableRAM() Ranges

AvailableRAM returns page-aligned unused regions of RAM.

AvailableRAM takes all RAM-marked pages in the memory map and subtracts the kexec segments already allocated. RAM segments begin at a page boundary.

E.g if page size is 4K and RAM segments are

[{start:0 size:8192} {start:8192 size:8000}]

and kexec segments are

[{start:40 size:50} {start:8000 size:2000}]

result should be

[{start:0 size:40} {start:4096 end:8000 - 4096}]

func (Memory) FindSpace added in v0.4.0

func (m Memory) FindSpace(sz uint) (Range, error)

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

func (*Memory) LoadElfSegments added in v0.4.0

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

LoadElfSegments loads loadable ELF segments.

func (*Memory) ParseMemoryMap added in v0.4.0

func (m *Memory) ParseMemoryMap() error

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

func (*Memory) ReservePhys added in v0.5.0

func (m *Memory) ReservePhys(sz uint, limit Range) (Range, error)

ReservePhys reserves page-aligned sz bytes in the physical memmap within the given limit address range.

type MemoryMap added in v0.5.0

type MemoryMap []TypedRange

MemoryMap defines the layout of physical memory.

MemoryMap defines which ranges in memory are usable RAM and which are reserved for various reasons.

func ParseMemoryMap added in v0.5.0

func ParseMemoryMap() (MemoryMap, error)

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

func (MemoryMap) FilterByType added in v0.5.0

func (m MemoryMap) FilterByType(typ RangeType) Ranges

Filter only returns ranges of the given typ.

func (*MemoryMap) Insert added in v0.5.0

func (m *MemoryMap) Insert(r TypedRange)

Insert a new TypedRange into the memory map, removing chunks of other ranges as necessary.

Assumes that TypedRange is a valid range -- no checking.

type Range added in v0.4.0

type Range struct {
	// Start is the inclusive start of the range.
	Start uintptr

	// Size is the number of elements in the range.
	//
	// Start+Size is the exclusive end of the range.
	Size uint
}

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

func RangeFromInterval added in v0.5.0

func RangeFromInterval(start, end uintptr) Range

RangeFromInterval returns a Range representing [start, end).

func (Range) Adjacent added in v0.5.0

func (r Range) Adjacent(r2 Range) bool

Adjacent returns true if r and r2 do not overlap, but are immediately next to each other.

func (Range) Contains added in v0.5.0

func (r Range) Contains(p uintptr) bool

Contains returns true iff p is in the interval described by r.

func (Range) Disjunct added in v0.4.0

func (r Range) Disjunct(r2 Range) bool

Disjunct returns true if r and r2 do not overlap.

func (Range) End added in v0.5.0

func (r Range) End() uintptr

End returns the uintptr *after* the end of the interval.

func (Range) Intersect added in v0.5.0

func (r Range) Intersect(r2 Range) *Range

Intersect returns the continuous range of points common to r and r2 if there is one.

func (Range) IsSupersetOf added in v0.4.0

func (r Range) IsSupersetOf(r2 Range) bool

IsSupersetOf returns true if r2 in r.

func (Range) Minus added in v0.5.0

func (r Range) Minus(r2 Range) []Range

Minus removes all points in r2 from r.

func (Range) Overlaps added in v0.4.0

func (r Range) Overlaps(r2 Range) bool

Overlaps returns true if r and r2 overlap.

func (Range) String added in v0.5.0

func (r Range) String() string

String returns [Start, Start+Size) as a string.

type RangeType added in v0.4.0

type RangeType string

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

func (RangeType) String added in v0.5.0

func (r RangeType) String() string

String implements fmt.Stringer.

type Ranges added in v0.5.0

type Ranges []Range

Ranges is a list of non-overlapping ranges.

func (Ranges) FindSpace added in v0.5.0

func (rs Ranges) FindSpace(sz uint) (space Range, err error)

FindSpace finds a continguous piece of sz points within Ranges and returns the Range pointing to it.

func (Ranges) FindSpaceAbove added in v0.5.0

func (rs Ranges) FindSpaceAbove(sz uint, minAddr uintptr) (space Range, err error)

FindSpaceAbove finds a continguous piece of sz points within Ranges and returns a space.Start >= minAddr.

func (Ranges) FindSpaceIn added in v0.5.0

func (rs Ranges) FindSpaceIn(sz uint, limit Range) (space Range, err error)

FindSpaceIn finds a continguous piece of sz points within Ranges and returns a Range where space.Start >= limit.Start, with space.End() < limit.End().

func (Ranges) Minus added in v0.5.0

func (rs Ranges) Minus(r Range) Ranges

Minus removes all points in r from all ranges in rs.

func (Ranges) Sort added in v0.5.0

func (rs Ranges) Sort()

Sort sorts ranges by their start point.

type Segment added in v0.4.0

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 added in v0.4.0

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 NewSegment added in v0.4.0

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 added in v0.4.0

func (s Segment) String() string

type Segments added in v0.5.0

type Segments []Segment

Segments is a collection of segments.

func Dedup added in v0.4.0

func Dedup(segs Segments) Segments

Dedup deduplicates overlapping and merges adjacent segments in segs.

func (*Segments) Insert added in v0.5.0

func (segs *Segments) Insert(s Segment)

Insert inserts s assuming it does not overlap with an existing segment.

func (Segments) PhysContains added in v0.5.0

func (segs Segments) PhysContains(p uintptr) bool

PhysContains returns whether p exists in any of segs' physical memory ranges.

type TypedRange added in v0.5.0

type TypedRange struct {
	Range
	Type RangeType
}

TypedRange represents range of physical memory.

func (TypedRange) String added in v0.5.0

func (tr TypedRange) String() string

Jump to

Keyboard shortcuts

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