xref: /freebsd/lib/libsys/kexec_load.2 (revision a935c2a63f9270500cddab1d9868c6183c25d5a8)
1.\"
2.\" SPDX-License-Identifier: BSD-3-Clause
3.\"
4.\" Copyright (c) 2025	Juniper Networks, Inc.
5.\"
6.Dd October 29, 2025
7.Dt KEXEC_LOAD 2
8.Os
9.Sh NAME
10.Nm kexec_load
11.Nd prepare new kernel to reboot into
12.Sh SYNOPSIS
13.Lb libc
14.In sys/kexec.h
15.Ft int
16.Fn kexec_load "uint64_t entry" "unsigned long count" \
17 "struct kexec_segment *segments" "unsigned long flags"
18.Sh DESCRIPTION
19The
20.Fn kexec_load
21system call loads a new kernel that can be executed later by
22.Xr reboot 2 .
23Subsequent calls will replace previously loaded images.
24.Pp
25The
26.Fa flags
27argument is a bitmask of flags that control the operation of the call.
28This argument is present for compatibility with Linux, although it is currently
29unused and must be 0.
30.Pp
31The
32.Fa entry
33argument is the physical address of the entry point of the new kernel image.
34.Pp
35The
36.Fa count
37argument is the number of segments in the image, currently limited to 16.
38A value of 0 will unload the currently staged image, if one exists, without
39staging a new image.
40.Pp
41The
42.Fa segments
43argument is an array of
44.Fa count
45members of the following structure:
46.Bd -literal -offset indent
47struct  kexec_segment {
48    void *buf;
49    size_t bufsz;
50    vm_paddr_t mem;
51    vm_size_t memsz;
52};
53.Ed
54.Pp
55The
56.Va buf
57and
58.Va bufsz
59members specify a memory region in the caller's address space containing the
60source of the segment.
61The
62.Va mem
63and
64.Va memsz
65members specify the target physical region of the segment.
66.Va bufsz
67must be less than or equal to
68.Va memsz ,
69and
70.Va mem
71and
72.Va memsz
73must be page aligned.
74The region covered by
75.Va mem
76must be in the list covered by the
77.Va vm.phys_segs
78sysctl.
79.Pp
80The
81.Fn kexec_load
82system call stages the kernel image in safe memory along with all
83machine-dependent image data until
84.Xr reboot 2
85is called with the
86.Va RB_KEXEC
87flag to load the image and execute the new kernel.
88.Sh RETURN VALUES
89The
90.Fn kexec_load
91system call returns 0 on success.
92On failure, -1 is returned, and
93.Va errno
94is set to indicate the error.
95On success any previously loaded image is unloaded and replaced with the new
96image.
97On failure, the previously loaded image is unchanged.
98.Sh ERRORS
99The following errors may be returned:
100.Bl -tag -width Er
101.It Bq Er EINVAL
102Too many segments in image.
103.It Bq Er EINVAL
104The value of
105.Va bufsz
106is larger than
107.Va memsz
108in one or more segments.
109.It Bq Er EINVAL
110Machine-dependent load error.
111.It Bq Er EBUSY
112Another
113.Fn kexec_load
114call is in progress.
115.Sh HISTORY
116The
117.Nm
118system call appeared in
119.Fx 16.0 .
120