@@ -31,6 +31,7 @@ use vm_memory::{Address, Bytes, GuestAddress, GuestMemory, GuestUsize};
31
31
#[ allow( non_camel_case_types) ]
32
32
#[ allow( non_snake_case) ]
33
33
#[ allow( non_upper_case_globals) ]
34
+ #[ allow( missing_docs) ]
34
35
#[ cfg_attr( feature = "cargo-clippy" , allow( clippy:: all) ) ]
35
36
pub mod bootparam;
36
37
#[ allow( dead_code) ]
@@ -43,33 +44,55 @@ mod elf;
43
44
mod struct_util;
44
45
45
46
#[ derive( Debug , PartialEq ) ]
47
+ /// Kernel loader errors.
46
48
pub enum Error {
49
+ /// Loaded big endian binary on a little endian platform.
47
50
BigEndianElfOnLittle ,
51
+ /// Failed writing command line to guest memory.
48
52
CommandLineCopy ,
53
+ /// Command line overflowed guest memory.
49
54
CommandLineOverflow ,
55
+ /// Invalid ELF magic number
50
56
InvalidElfMagicNumber ,
57
+ /// Invalid program header size.
51
58
InvalidProgramHeaderSize ,
59
+ /// Invalid program header offset.
52
60
InvalidProgramHeaderOffset ,
61
+ /// Invalid program header address.
53
62
InvalidProgramHeaderAddress ,
63
+ /// Invalid entry address.
54
64
InvalidEntryAddress ,
65
+ /// Invalid bzImage binary.
55
66
InvalidBzImage ,
67
+ /// Invalid kernel start address.
56
68
InvalidKernelStartAddress ,
57
- InitrdImageSizeTooLarge ,
69
+ /// Memory to load kernel image is too small.
58
70
MemoryOverflow ,
71
+ /// Unable to read ELF header.
59
72
ReadElfHeader ,
73
+ /// Unable to read kernel image.
60
74
ReadKernelImage ,
75
+ /// Unable to read program header.
61
76
ReadProgramHeader ,
77
+ /// Unable to read bzImage header.
62
78
ReadBzImageHeader ,
79
+ /// Unable to read bzImage compressed image.
63
80
ReadBzImageCompressedKernel ,
64
- ReadInitrdImage ,
81
+ /// Unable to seek to kernel start.
65
82
SeekKernelStart ,
83
+ /// Unable to seek to ELF start.
66
84
SeekElfStart ,
85
+ /// Unable to seek to program header.
67
86
SeekProgramHeader ,
87
+ /// Unable to seek to bzImage end.
68
88
SeekBzImageEnd ,
89
+ /// Unable to seek to bzImage header.
69
90
SeekBzImageHeader ,
91
+ /// Unable to seek to bzImage compressed kernel.
70
92
SeekBzImageCompressedKernel ,
71
- SeekInitrdImage ,
72
93
}
94
+
95
+ /// A specialized `Result` type for the kernel loader.
73
96
pub type Result < T > = std:: result:: Result < T , Error > ;
74
97
75
98
impl error:: Error for Error {
@@ -87,21 +110,18 @@ impl error::Error for Error {
87
110
Error :: InvalidEntryAddress => "Invalid entry address" ,
88
111
Error :: InvalidBzImage => "Invalid bzImage" ,
89
112
Error :: InvalidKernelStartAddress => "Invalid kernel start address" ,
90
- Error :: InitrdImageSizeTooLarge => "Initrd image size too large" ,
91
113
Error :: MemoryOverflow => "Memory to load kernel image is not enough" ,
92
114
Error :: ReadElfHeader => "Unable to read elf header" ,
93
115
Error :: ReadKernelImage => "Unable to read kernel image" ,
94
116
Error :: ReadProgramHeader => "Unable to read program header" ,
95
117
Error :: ReadBzImageHeader => "Unable to read bzImage header" ,
96
118
Error :: ReadBzImageCompressedKernel => "Unable to read bzImage compressed kernel" ,
97
- Error :: ReadInitrdImage => "Unable to read initrd image" ,
98
119
Error :: SeekKernelStart => "Unable to seek to kernel start" ,
99
120
Error :: SeekElfStart => "Unable to seek to elf start" ,
100
121
Error :: SeekProgramHeader => "Unable to seek to program header" ,
101
122
Error :: SeekBzImageEnd => "Unable to seek bzImage end" ,
102
123
Error :: SeekBzImageHeader => "Unable to seek bzImage header" ,
103
124
Error :: SeekBzImageCompressedKernel => "Unable to seek bzImage compressed kernel" ,
104
- Error :: SeekInitrdImage => "Unable to seek initrd image" ,
105
125
}
106
126
}
107
127
}
@@ -113,18 +133,26 @@ impl Display for Error {
113
133
}
114
134
115
135
#[ derive( Debug , Default , Copy , Clone , PartialEq ) ]
136
+ /// Result of the KernelLoader load() call.
137
+ ///
138
+ /// This specifies where the kernel is loading and passes additional
139
+ /// information for the rest of the boot process to be completed by
140
+ /// the VMM.
116
141
pub struct KernelLoaderResult {
117
- // Address in the guest memory where the kernel image starts to be loaded
142
+ /// Address in the guest memory where the kernel image starts to be loaded
118
143
pub kernel_load : GuestAddress ,
119
- // Offset in guest memory corresponding to the end of kernel image, in case that
120
- // device tree blob and initrd will be loaded adjacent to kernel image.
144
+ /// Offset in guest memory corresponding to the end of kernel image, in case that
145
+ /// device tree blob and initrd will be loaded adjacent to kernel image.
121
146
pub kernel_end : GuestUsize ,
122
- // This field is only for bzImage following https://www.kernel.org/doc/Documentation/x86/boot.txt
123
- // VMM should make use of it to fill zero page for bzImage direct boot.
147
+ /// This field is only for bzImage following https://www.kernel.org/doc/Documentation/x86/boot.txt
148
+ /// VMM should make use of it to fill zero page for bzImage direct boot.
124
149
pub setup_header : Option < bootparam:: setup_header > ,
125
150
}
126
151
152
+ /// A kernel image loading support must implement the KernelLoader trait.
153
+ /// The only method to be implemented is the load one, returning a KernelLoaderResult structure.
127
154
pub trait KernelLoader {
155
+ /// How to load a specific kernel image format into the guest memory.
128
156
fn load < F , M : GuestMemory > (
129
157
guest_mem : & M ,
130
158
kernel_start : Option < GuestAddress > ,
@@ -136,6 +164,7 @@ pub trait KernelLoader {
136
164
}
137
165
138
166
#[ cfg( feature = "elf" ) ]
167
+ /// Raw ELF (a.k.a. vmlinux) kernel image support.
139
168
pub struct Elf ;
140
169
141
170
#[ cfg( feature = "elf" ) ]
@@ -247,6 +276,7 @@ impl KernelLoader for Elf {
247
276
}
248
277
249
278
#[ cfg( feature = "bzimage" ) ]
279
+ /// Big zImage (bzImage) kernel image support.
250
280
pub struct BzImage ;
251
281
252
282
#[ cfg( feature = "bzimage" ) ]
0 commit comments