@@ -31,6 +31,7 @@ use vm_memory::{Address, Bytes, GuestAddress, GuestMemory, GuestUsize};
3131#[ allow( non_camel_case_types) ]
3232#[ allow( non_snake_case) ]
3333#[ allow( non_upper_case_globals) ]
34+ #[ allow( missing_docs) ]
3435#[ cfg_attr( feature = "cargo-clippy" , allow( clippy:: all) ) ]
3536pub mod bootparam;
3637#[ allow( dead_code) ]
@@ -43,33 +44,55 @@ mod elf;
4344mod struct_util;
4445
4546#[ derive( Debug , PartialEq ) ]
47+ /// Kernel loader errors.
4648pub enum Error {
49+ /// Loaded big endian binary on a little endian platform.
4750 BigEndianElfOnLittle ,
51+ /// Failed writing command line to guest memory.
4852 CommandLineCopy ,
53+ /// Command line overflowed guest memory.
4954 CommandLineOverflow ,
55+ /// Invalid ELF magic number
5056 InvalidElfMagicNumber ,
57+ /// Invalid program header size.
5158 InvalidProgramHeaderSize ,
59+ /// Invalid program header offset.
5260 InvalidProgramHeaderOffset ,
61+ /// Invalid program header address.
5362 InvalidProgramHeaderAddress ,
63+ /// Invalid entry address.
5464 InvalidEntryAddress ,
65+ /// Invalid bzImage binary.
5566 InvalidBzImage ,
67+ /// Invalid kernel start address.
5668 InvalidKernelStartAddress ,
57- InitrdImageSizeTooLarge ,
69+ /// Memory to load kernel image is too small.
5870 MemoryOverflow ,
71+ /// Unable to read ELF header.
5972 ReadElfHeader ,
73+ /// Unable to read kernel image.
6074 ReadKernelImage ,
75+ /// Unable to read program header.
6176 ReadProgramHeader ,
77+ /// Unable to read bzImage header.
6278 ReadBzImageHeader ,
79+ /// Unable to read bzImage compressed image.
6380 ReadBzImageCompressedKernel ,
64- ReadInitrdImage ,
81+ /// Unable to seek to kernel start.
6582 SeekKernelStart ,
83+ /// Unable to seek to ELF start.
6684 SeekElfStart ,
85+ /// Unable to seek to program header.
6786 SeekProgramHeader ,
87+ /// Unable to seek to bzImage end.
6888 SeekBzImageEnd ,
89+ /// Unable to seek to bzImage header.
6990 SeekBzImageHeader ,
91+ /// Unable to seek to bzImage compressed kernel.
7092 SeekBzImageCompressedKernel ,
71- SeekInitrdImage ,
7293}
94+
95+ /// A specialized `Result` type for the kernel loader.
7396pub type Result < T > = std:: result:: Result < T , Error > ;
7497
7598impl error:: Error for Error {
@@ -87,21 +110,18 @@ impl error::Error for Error {
87110 Error :: InvalidEntryAddress => "Invalid entry address" ,
88111 Error :: InvalidBzImage => "Invalid bzImage" ,
89112 Error :: InvalidKernelStartAddress => "Invalid kernel start address" ,
90- Error :: InitrdImageSizeTooLarge => "Initrd image size too large" ,
91113 Error :: MemoryOverflow => "Memory to load kernel image is not enough" ,
92114 Error :: ReadElfHeader => "Unable to read elf header" ,
93115 Error :: ReadKernelImage => "Unable to read kernel image" ,
94116 Error :: ReadProgramHeader => "Unable to read program header" ,
95117 Error :: ReadBzImageHeader => "Unable to read bzImage header" ,
96118 Error :: ReadBzImageCompressedKernel => "Unable to read bzImage compressed kernel" ,
97- Error :: ReadInitrdImage => "Unable to read initrd image" ,
98119 Error :: SeekKernelStart => "Unable to seek to kernel start" ,
99120 Error :: SeekElfStart => "Unable to seek to elf start" ,
100121 Error :: SeekProgramHeader => "Unable to seek to program header" ,
101122 Error :: SeekBzImageEnd => "Unable to seek bzImage end" ,
102123 Error :: SeekBzImageHeader => "Unable to seek bzImage header" ,
103124 Error :: SeekBzImageCompressedKernel => "Unable to seek bzImage compressed kernel" ,
104- Error :: SeekInitrdImage => "Unable to seek initrd image" ,
105125 }
106126 }
107127}
@@ -113,18 +133,26 @@ impl Display for Error {
113133}
114134
115135#[ 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.
116141pub 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
118143 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.
121146 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.
124149 pub setup_header : Option < bootparam:: setup_header > ,
125150}
126151
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.
127154pub trait KernelLoader {
155+ /// How to load a specific kernel image format into the guest memory.
128156 fn load < F , M : GuestMemory > (
129157 guest_mem : & M ,
130158 kernel_start : Option < GuestAddress > ,
@@ -136,6 +164,7 @@ pub trait KernelLoader {
136164}
137165
138166#[ cfg( feature = "elf" ) ]
167+ /// Raw ELF (a.k.a. vmlinux) kernel image support.
139168pub struct Elf ;
140169
141170#[ cfg( feature = "elf" ) ]
@@ -247,6 +276,7 @@ impl KernelLoader for Elf {
247276}
248277
249278#[ cfg( feature = "bzimage" ) ]
279+ /// Big zImage (bzImage) kernel image support.
250280pub struct BzImage ;
251281
252282#[ cfg( feature = "bzimage" ) ]
0 commit comments