Skip to content

Commit 005f706

Browse files
roypatandreeaflorescu
authored andcommitted
Clear clippy's undocumented_unsafe_blocks warnings
Add SAFETY comments for code outside tests, and allow directives inside test modules Signed-off-by: Patrick Roy <roypat@amazon.co.uk>
1 parent e3955e4 commit 005f706

File tree

8 files changed

+28
-0
lines changed

8 files changed

+28
-0
lines changed

benches/aarch64/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ fn create_guest_memory() -> GuestMemoryMmap {
2424
#[derive(Clone, Copy, Default)]
2525
pub struct FdtPlaceholder([u8; FDT_MAX_SIZE]);
2626

27+
// SAFETY: The layout of the structure is fixed and can be initialized by
28+
// reading its content from byte array.
2729
unsafe impl ByteValued for FdtPlaceholder {}
2830

2931
fn build_fdt_boot_params() -> BootParams {

src/configurator/aarch64/fdt.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ impl BootConfigurator for FdtBootConfigurator {
9494

9595
#[cfg(test)]
9696
mod tests {
97+
#![allow(clippy::undocumented_unsafe_blocks)]
9798
use super::*;
9899
use vm_memory::{Address, ByteValued, GuestAddress, GuestMemoryMmap};
99100

src/configurator/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ impl BootParams {
424424

425425
#[cfg(test)]
426426
mod tests {
427+
#![allow(clippy::undocumented_unsafe_blocks)]
427428
use super::*;
428429

429430
#[derive(Clone, Copy, Default)]

src/configurator/x86_64/pvh.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,16 @@ impl From<Error> for BootConfiguratorError {
6969
}
7070
}
7171

72+
// SAFETY: The layout of the structure is fixed and can be initialized by
73+
// reading its content from byte array.
7274
unsafe impl ByteValued for hvm_start_info {}
75+
76+
// SAFETY: The layout of the structure is fixed and can be initialized by
77+
// reading its content from byte array.
7378
unsafe impl ByteValued for hvm_memmap_table_entry {}
79+
80+
// SAFETY: The layout of the structure is fixed and can be initialized by
81+
// reading its content from byte array.
7482
unsafe impl ByteValued for hvm_modlist_entry {}
7583

7684
impl BootConfigurator for PvhBootConfigurator {

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ pub mod cmdline;
101101
pub mod configurator;
102102
pub mod loader;
103103

104+
#[allow(clippy::undocumented_unsafe_blocks)]
104105
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
105106
mod loader_gen;
106107
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]

src/loader/aarch64/pe/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ use super::super::{Error as KernelLoaderError, KernelLoader, KernelLoaderResult,
2323
/// ARM64 Image (PE) format support
2424
pub struct PE;
2525

26+
// SAFETY: The layout of the structure is fixed and can be initialized by
27+
// reading its content from byte array.
2628
unsafe impl ByteValued for arm64_image_header {}
2729

2830
#[derive(Debug, PartialEq, Eq)]

src/loader/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,13 @@ pub trait KernelLoader {
180180
}
181181

182182
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
183+
// SAFETY: The layout of the structure is fixed and can be initialized by
184+
// reading its content from byte array.
183185
unsafe impl ByteValued for bootparam::setup_header {}
186+
184187
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
188+
// SAFETY: The layout of the structure is fixed and can be initialized by
189+
// reading its content from byte array.
185190
unsafe impl ByteValued for bootparam::boot_params {}
186191

187192
/// Writes the command line string to the given guest memory slice.

src/loader/x86_64/elf/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,16 @@ use crate::loader::{Error as KernelLoaderError, KernelLoader, KernelLoaderResult
2323
use crate::loader_gen::elf;
2424
pub use crate::loader_gen::start_info;
2525

26+
// SAFETY: The layout of the structure is fixed and can be initialized by
27+
// reading its content from byte array.
2628
unsafe impl ByteValued for elf::Elf64_Ehdr {}
29+
30+
// SAFETY: The layout of the structure is fixed and can be initialized by
31+
// reading its content from byte array.
2732
unsafe impl ByteValued for elf::Elf64_Nhdr {}
33+
34+
// SAFETY: The layout of the structure is fixed and can be initialized by
35+
// reading its content from byte array.
2836
unsafe impl ByteValued for elf::Elf64_Phdr {}
2937

3038
#[derive(Debug, PartialEq, Eq)]

0 commit comments

Comments
 (0)