Documentation ¶
Overview ¶
Package kexec implements kexec load and file load syscall API.
Index ¶
- Constants
- func FileLoad(kernel, ramfs *os.File, cmdline string) error
- func Load(entry uintptr, segments Segments, flags uint64) error
- func Reboot() error
- type ErrKexec
- type ErrNotEnoughSpace
- type Memory
- func (m *Memory) AddKexecSegment(d []byte) (Range, error)
- func (m *Memory) AddKexecSegmentExplicit(d []byte, sz, offset, alignSizeBytes uint) (Range, error)
- func (m *Memory) AddPhysSegment(d []byte, limit Range) (Range, error)
- func (m Memory) AvailableRAM() Ranges
- func (m Memory) FindSpace(sz, alignSizeBytes uint) (Range, error)
- func (m *Memory) LoadElfSegments(r io.ReaderAt) (Object, error)
- func (m *Memory) ParseMemoryMap() error
- func (m *Memory) ParseMemoryMapFromFDT(fdt *dt.FDT) error
- func (m *Memory) ReservePhys(sz uint, limit Range) (Range, error)
- type MemoryMap
- type Object
- type PayloadMemType
- type PayloadMemoryMapParam
- type Range
- func (r Range) Adjacent(r2 Range) bool
- func (r Range) Contains(p uintptr) bool
- func (r Range) Disjunct(r2 Range) bool
- func (r Range) End() uintptr
- func (r Range) Intersect(r2 Range) *Range
- func (r Range) IsSupersetOf(r2 Range) bool
- func (r Range) Minus(r2 Range) []Range
- func (r Range) Overlaps(r2 Range) bool
- func (r Range) String() string
- type RangeType
- type Ranges
- type Segment
- type Segments
- type TypedRange
Constants ¶
const ( PayloadTypeRAM = 1 PayloadTypeDefault = 2 PayloadTypeACPI = 3 PayloadTypeNVS = 4 PayloadTypeReserved = 5 )
Payload memory type (PayloadMemType) in UefiPayload
const M1 = 1 << 20
M1 is 1 Megabyte in bits.
const MaxAddr = ^uintptr(0)
MaxAddr is the highest address in a 64bit address space.
Variables ¶
This section is empty.
Functions ¶
func FileLoad ¶
FileLoad loads the given kernel as the new kernel with the given ramfs and cmdline.
The kexec_file_load(2) syscall is x86-64 and arm64 only.
func Load ¶
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.
Types ¶
type ErrKexec ¶
ErrKexec is returned by Load if the kexec failed. It describes entry point, flags, errno and kernel layout.
type ErrNotEnoughSpace ¶
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 ¶
func (e ErrNotEnoughSpace) Error() string
type Memory ¶
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 ¶
AddKexecSegment adds d to a new kexec segment
func (*Memory) AddKexecSegmentExplicit ¶
AddKexecSegmentExplicit adds d to a new kexec segment, but allows asking for extra space, secifying alignment size, and setting text_offset.
func (*Memory) AddPhysSegment ¶
AddPhysSegment reserves len(d) bytes in the physical memmap within limit and adds a kexec segment with d in that range.
func (Memory) AvailableRAM ¶
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 ¶
FindSpace returns pointer to the physical memory, where array of size sz can be stored during next AddKexecSegment call.
Align up to at least a page size if alignSizeBytes is smaller.
func (*Memory) LoadElfSegments ¶
LoadElfSegments loads loadable ELF segments.
func (*Memory) ParseMemoryMap ¶
ParseMemoryMap reads firmware provided memory map from /sys/firmware/memmap.
func (*Memory) ParseMemoryMapFromFDT ¶
ParseMemoryMapFromFDT reads firmware provided memory map from an FDT.
type MemoryMap ¶
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 ¶
ParseMemoryMap reads firmware provided memory map from /sys/firmware/memmap.
func (*MemoryMap) AsPayloadParam ¶
func (m *MemoryMap) AsPayloadParam() PayloadMemoryMapParam
AsPayloadParam converts MemoryMap to a PayloadMemoryMapParam
func (MemoryMap) FilterByType ¶
FilterByType only returns ranges of the given typ.
func (*MemoryMap) Insert ¶
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 Object ¶
Object is an object file, specific to kexec uses. It is used to get Progs and Entry from an object. elf.Prog is generic enough that we can use it to define loadable segments for non-ELF objects, such as Plan 9 a.out
type PayloadMemoryMapParam ¶
type PayloadMemoryMapParam []payloadMemoryMapEntry
PayloadMemoryMapParam is payload's MemoryMap parameter
type Range ¶
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 ¶
RangeFromInterval returns a Range representing [start, end).
func (Range) Adjacent ¶
Adjacent returns true if r and r2 do not overlap, but are immediately next to each other.
func (Range) Intersect ¶
Intersect returns the continuous range of points common to r and r2 if there is one.
func (Range) IsSupersetOf ¶
IsSupersetOf returns true if r2 in r.
type RangeType ¶
type RangeType string
RangeType defines type of a TypedRange based on the Linux kernel string provided by firmware memory map.
type Ranges ¶
type Ranges []Range
Ranges is a list of non-overlapping ranges.
func (Ranges) FindSpace ¶
FindSpace finds a continguous piece of sz points within Ranges and returns the Range pointing to it.
If alignSizeBytes is zero, align up by page size.
func (Ranges) FindSpaceAbove ¶
FindSpaceAbove finds a continguous piece of sz points within Ranges and returns a space.Start >= minAddr.
func (Ranges) FindSpaceIn ¶
FindSpaceIn finds a continguous piece of sz points within Ranges and returns a Range where space.Start >= limit.Start, with space.End() < limit.End().
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 AlignPhysStart ¶
AlignPhysStart aligns s.Phys.Start to the page size. AlignPhysStart does not align the size of the segment.
func NewSegment ¶
NewSegment creates new Segment. Segments should be created using NewSegment method to prevent data pointed by Segment.Buf to be collected by garbage collector.
type Segments ¶
type Segments []Segment
Segments is a collection of segments.
func AlignAndMerge ¶
AlignAndMerge adjusts segs to the preconditions of kexec_load.
Pre-conditions: segs physical ranges are disjoint. Post-conditions: segs physical start addresses & size aligned to page size.
func (Segments) IsSupersetOf ¶
IsSupersetOf checks whether all segments in o are present in s and contain the same buffer content.
func (Segments) PhysContains ¶
PhysContains returns whether p exists in any of segs' physical memory ranges.
type TypedRange ¶
TypedRange represents range of physical memory.
func (TypedRange) String ¶
func (tr TypedRange) String() string