Reference

kexec_load(2)

prepare new kernel to reboot into

NAME

kexec_load – prepare new kernel to reboot into

SYNOPSIS

Standard C Library (libc, -lc)

#include <sys/kexec.h>

int

kexec_load(uint64_t entry, unsigned long count, struct kexec_segment *segments, unsigned long flags);

DESCRIPTION

The kexec_load() system call loads a new kernel that can be executed later by reboot(2). Subsequent calls will replace previously loaded images.

The flags argument is a bitmask of flags that control the operation of the call. This argument is present for compatibility with Linux, although it is currently unused and must be 0.

The entry argument is the physical address of the entry point of the new kernel image.

The count argument is the number of segments in the image, currently limited to 16. A value of 0 will unload the currently staged image, if one exists, without staging a new image.

The segments argument is an array of count members of the following structure:

struct  kexec_segment {
    void *buf;
    size_t bufsz;
    vm_paddr_t mem;
    vm_size_t memsz;
};

The buf and bufsz members specify a memory region in the caller's address space containing the source of the segment. The mem and memsz members specify the target physical region of the segment. bufsz must be less than or equal to memsz, and mem and memsz must be page aligned. The region covered by mem must be in the list covered by the vm.phys_segs sysctl.

The kexec_load() system call stages the kernel image in safe memory along with all machine-dependent image data until reboot(2) is called with the RB_KEXEC flag to load the image and execute the new kernel.

RETURN VALUES

The kexec_load() system call returns 0 on success. On failure, -1 is returned, and errno is set to indicate the error. On success any previously loaded image is unloaded and replaced with the new image. On failure, the previously loaded image is unchanged.

ERRORS

The following errors may be returned:

[EINVAL]

Too many segments in image.

[EINVAL]

The value of bufsz is larger than memsz in one or more segments.

[EINVAL]

Machine-dependent load error.

[EBUSY]

Another kexec_load() call is in progress.

HISTORY

The kexec_load system call appeared in FreeBSD 16.0.