Skip to content

Commit 7d7e03d

Browse files
Samuel Ortizrbradford
authored andcommitted
lib: Force public interfaces documentation
...and actually document them. Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
1 parent d67f657 commit 7d7e03d

File tree

2 files changed

+60
-11
lines changed

2 files changed

+60
-11
lines changed

src/lib.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,25 @@
77
//
88
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause
99

10+
#![deny(missing_docs)]
11+
12+
//! A Linux kernel image loading crate.
13+
//!
14+
//! This crate offers support for loading raw ELF (vmlinux) and compressed
15+
//! big zImage (bzImage) kernel images.
16+
//! Support for any other kernel image format can be added by implementing
17+
//! the KernelLoader.
18+
//!
19+
//! # Platform support
20+
//!
21+
//! - x86_64
22+
//!
23+
//! This crates only supports x86_64 platforms because it implements support
24+
//! for kernel image formats (vmlinux and bzImage) that are x86 specific.
25+
//!
26+
//! Extending it to support other kernel image formats (e.g. ARM's Image)
27+
//! will make it consumable by other platforms.
28+
1029
pub mod cmdline;
1130
pub mod loader;
1231

src/loader/mod.rs

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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))]
3536
pub mod bootparam;
3637
#[allow(dead_code)]
@@ -43,33 +44,55 @@ mod elf;
4344
mod struct_util;
4445

4546
#[derive(Debug, PartialEq)]
47+
/// Kernel loader errors.
4648
pub 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.
7396
pub type Result<T> = std::result::Result<T, Error>;
7497

7598
impl 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.
116141
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
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.
127154
pub 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.
139168
pub 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.
250280
pub struct BzImage;
251281

252282
#[cfg(feature = "bzimage")]

0 commit comments

Comments
 (0)