Skip to content

Commit

Permalink
Fix clippy errors
Browse files Browse the repository at this point in the history
Signed-off-by: Sangwan Kwon <[email protected]>
  • Loading branch information
bitboom committed Dec 18, 2024
1 parent 0eb1f00 commit abd9718
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 28 deletions.
24 changes: 12 additions & 12 deletions lib/safe-abstraction/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@
//! ## Features
//!
//! - **Encapsulation of Unsafe Code**: Offers a way to safely abstract `unsafe` operations,
//! allowing for lower-level operations like memory access to be performed more safely.
//! allowing for lower-level operations like memory access to be performed more safely.
//!
//! - **Runtime Safety Checks**: Provides methods to perform crucial safety checks at runtime,
//! such as verifying if a pointer is null and checking whether a pointer is properly aligned.
//! These checks happen when the methods are called during the execution of a program.
//! such as verifying if a pointer is null and checking whether a pointer is properly aligned.
//! These checks happen when the methods are called during the execution of a program.
//!
//! - **Compile-Time Type Safety Checks**: Enforces certain safety guarantees at compile time.
//! For example, the use of Rust's type system can ensure that only pointers
//! to types with known sizes are used, leveraging the `Sized` trait bound.
//! For example, the use of Rust's type system can ensure that only pointers
//! to types with known sizes are used, leveraging the `Sized` trait bound.
//!
//! - **Developer-Driven Safety Verification**: Introduces traits that allow developers
//! to explicitly mark parts of `unsafe` code that still require manual safety guarantees,
//! making it clear which parts of the code need careful review.
//! to explicitly mark parts of `unsafe` code that still require manual safety guarantees,
//! making it clear which parts of the code need careful review.
pub mod raw_ptr {
//! # Raw Pointer Safety Abstraction Module
Expand All @@ -48,15 +48,15 @@ pub mod raw_ptr {
//!
//! ## Traits Overview
//! - `RawPtr`: Ensures that the size of the structure
//! pointed to by the raw pointer is determined at compile time,
//! enabling safe memory operations.
//! pointed to by the raw pointer is determined at compile time,
//! enabling safe memory operations.
//!
//! - `SafetyChecked`: Implements checks to ensure that the raw pointer
//! is not null and properly aligned.
//! is not null and properly aligned.
//!
//! - `SafetyAssured`: Provides guarantees that the instance
//! pointed to by the raw pointer is properly initialized,
//! adheres to Rust's ownership rules.
//! pointed to by the raw pointer is properly initialized,
//! adheres to Rust's ownership rules.
pub trait RawPtr: Sized {
/// # Safety
Expand Down
6 changes: 3 additions & 3 deletions rmm/src/mm/translation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ struct Inner<'a> {
dirty: bool,
}

impl<'a> Inner<'a> {
impl Inner<'_> {
pub fn new() -> Self {
let root_pgtbl =
RootPageTable::<VirtAddr, L1Table, Entry, { <L1Table as Level>::NUM_ENTRIES }>::new_in(
Expand Down Expand Up @@ -187,13 +187,13 @@ impl<'a> Inner<'a> {
}
}

impl<'a> fmt::Debug for Inner<'a> {
impl fmt::Debug for Inner<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct(stringify!(Self)).finish()
}
}

impl<'a> Drop for Inner<'a> {
impl Drop for Inner<'_> {
fn drop(&mut self) {
info!("drop PageTable");
self.root_pgtbl.drop();
Expand Down
6 changes: 3 additions & 3 deletions rmm/src/realm/mm/stage2_translation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub struct Stage2Translation<'a> {
dirty: bool,
}

impl<'a> Stage2Translation<'a> {
impl Stage2Translation<'_> {
pub fn new(rtt_base: usize, root_level: usize, root_pages: usize) -> Self {
// Concatenated translation tables
// For stage 2 address translations, for the initial lookup,
Expand Down Expand Up @@ -295,7 +295,7 @@ macro_rules! set_pte {
};
}

impl<'a> IPATranslation for Stage2Translation<'a> {
impl IPATranslation for Stage2Translation<'_> {
fn get_base_address(&self) -> *const c_void {
match &self.root_pgtbl {
Root::L2N8(c) => *c as *const _ as *const c_void, // most likely first, for linux-realm
Expand Down Expand Up @@ -456,7 +456,7 @@ impl<'a> IPATranslation for Stage2Translation<'a> {
}
}

impl<'a> fmt::Debug for Stage2Translation<'a> {
impl fmt::Debug for Stage2Translation<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct(stringify!(Self)).finish()
}
Expand Down
6 changes: 2 additions & 4 deletions rmm/src/rmi/gpt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,10 @@ pub fn set_event_handler(rmi: &mut RmiHandle) {

#[cfg(any(miri, test))]
let mut granule = get_granule_if!(addr, GranuleState::Undelegated)?;
set_granule(&mut granule, GranuleState::Delegated).map_err(|e| {
set_granule(&mut granule, GranuleState::Delegated).inspect_err(|_| {
#[cfg(not(kani))]
// `page_table` is currently not reachable in model checking harnesses
rmm.page_table.unmap(addr);
e
})?;
#[cfg(not(kani))]
// `page_table` is currently not reachable in model checking harnesses
Expand Down Expand Up @@ -79,11 +78,10 @@ pub fn set_event_handler(rmi: &mut RmiHandle) {
#[cfg(not(kani))]
// `page_table` is currently not reachable in model checking harnesses
rmm.page_table.map(addr, false);
set_granule(&mut granule, GranuleState::Undelegated).map_err(|e| {
set_granule(&mut granule, GranuleState::Undelegated).inspect_err(|_| {
#[cfg(not(kani))]
// `page_table` is currently not reachable in model checking harnesses
rmm.page_table.unmap(addr);
e
})?;
#[cfg(not(kani))]
// `page_table` is currently not reachable in model checking harnesses
Expand Down
3 changes: 1 addition & 2 deletions rmm/src/rmi/realm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,11 @@ pub fn set_event_handler(rmi: &mut RmiHandle) {
set_granule(&mut rd_granule, GranuleState::RD)
};

epilogue().map_err(|e| {
epilogue().inspect_err(|_| {
#[cfg(not(kani))]
// `page_table` is currently not reachable in model checking harnesses
rmm.page_table.unmap(rd);
remove(params.vmid as usize).expect("Realm should be created before.");
e
})
});

Expand Down
3 changes: 1 addition & 2 deletions rmm/src/rmi/rec/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,10 @@ pub fn set_event_handler(rmi: &mut RmiHandle) {
rd_granule.dec_count();
}

set_granule(&mut rec_granule, GranuleState::Delegated).map_err(|e| {
set_granule(&mut rec_granule, GranuleState::Delegated).inspect_err(|_| {
#[cfg(not(kani))]
// `page_table` is currently not reachable in model checking harnesses
rmm.page_table.unmap(arg[0]);
e
})?;
#[cfg(not(kani))]
// `page_table` is currently not reachable in model checking harnesses
Expand Down
4 changes: 2 additions & 2 deletions scripts/clippy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

set -e

# TODO: Enable missing_safety_doc
cargo clippy --lib -p islet_rmm -- \
cargo clippy --lib -p islet_rmm --no-deps -- \
-A clippy::comparison_chain \
-A clippy::crate_in_macro_def \
-A clippy::empty_loop \
Expand All @@ -18,4 +17,5 @@ cargo clippy --lib -p islet_rmm -- \
-A clippy::redundant_pattern_matching \
-A clippy::type_complexity \
-A clippy::upper-case-acronyms \
-A static-mut-refs \
--deny "warnings"

0 comments on commit abd9718

Please sign in to comment.