Skip to content

Add deny lints to hyperlight-host crate #352

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions src/hyperlight_host/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#![deny(dead_code, missing_docs, unused_mut)]
//! This crate contains an SDK that is used to execute specially-
// compiled binaries within a very lightweight hypervisor environment.

use std::sync::Once;

/// This crate contains an SDK that is used to execute specially-
/// compiled binaries within a very lightweight hypervisor environment.
use log::info;
/// The `built` crate is used to generate a `built.rs` file that contains
/// information about the build environment. This information is used to
Expand All @@ -26,13 +27,10 @@ pub(crate) mod built_info {
include!(concat!(env!("OUT_DIR"), "/built.rs"));
}
/// Dealing with errors, including errors across VM boundaries
#[deny(dead_code, missing_docs, unused_mut)]
pub mod error;
/// Wrappers for host and guest functions.
#[deny(dead_code, missing_docs, unused_mut)]
pub mod func;
/// Wrappers for hypervisor implementations
#[deny(dead_code, missing_docs, unused_mut)]
pub mod hypervisor;
/// Functionality to establish and manage an individual sandbox's
/// memory.
Expand Down Expand Up @@ -62,15 +60,12 @@ pub mod hypervisor;
///
/// The pointer passed to the Entrypoint in the Guest application is the 0x200000 + size of page table + size of code,
/// at this address structs below are laid out in this order
#[deny(dead_code, missing_docs, unused_mut)]
pub mod mem;
/// Metric definitions and helpers
#[deny(dead_code, missing_docs, unused_mut)]
pub mod metrics;
/// The main sandbox implementations. Do not use this module directly in code
/// outside this file. Types from this module needed for public consumption are
/// re-exported below.
#[deny(dead_code, missing_docs, unused_mut)]
pub mod sandbox;
/// `trait`s and other functionality for dealing with defining sandbox
/// states and moving between them
Expand All @@ -82,7 +77,6 @@ pub(crate) mod seccomp;
pub(crate) mod signal_handlers;
/// Utilities for testing including interacting with `simpleguest.exe`
/// and `callbackguest.exe`, our two most basic guest binaries for testing
#[deny(missing_docs, unused_mut)]
#[cfg(test)]
pub(crate) mod testing;

Expand Down Expand Up @@ -110,8 +104,8 @@ pub use crate::func::call_ctx::MultiUseGuestCallContext;
/// The universal `Result` type used throughout the Hyperlight codebase.
pub type Result<T> = core::result::Result<T, error::HyperlightError>;

// Logs an error then returns with it , more or less equivalent to the bail! macro in anyhow
// but for HyperlightError instead of anyhow::Error
/// Logs an error then returns with it, more or less equivalent to the bail! macro in anyhow
/// but for HyperlightError instead of anyhow::Error
#[macro_export]
macro_rules! log_then_return {
($msg:literal $(,)?) => {{
Expand Down Expand Up @@ -140,7 +134,7 @@ macro_rules! log_then_return {
};
}

// same as log::debug!, but will additionally print to stdout if the print_debug feature is enabled
/// Same as log::debug!, but will additionally print to stdout if the print_debug feature is enabled
#[macro_export]
macro_rules! debug {
($($arg:tt)+) =>
Expand Down
5 changes: 5 additions & 0 deletions src/hyperlight_host/src/sandbox_state/sandbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,13 @@ pub trait Sandbox: Sized + Debug {
/// A utility trait to recognize a Sandbox that has not yet been initialized.
/// It allows retrieval of a strongly typed UninitializedSandbox.
pub trait UninitializedSandbox: Sandbox {
/// Retrieves reference to strongly typed `UninitializedSandbox`
fn get_uninitialized_sandbox(&self) -> &crate::sandbox::UninitializedSandbox;

/// Retrieves mutable reference to strongly typed `UninitializedSandbox`
fn get_uninitialized_sandbox_mut(&mut self) -> &mut crate::sandbox::UninitializedSandbox;

/// Returns `true` if the Sandbox is configured to run in process otherwise `false`
#[instrument(skip_all, parent = Span::current(), level= "Trace")]
fn is_running_in_process(&self) -> bool {
self.get_uninitialized_sandbox().run_inprocess
Expand All @@ -69,12 +72,14 @@ pub trait UninitializedSandbox: Sandbox {
pub trait EvolvableSandbox<Cur: Sandbox, Next: Sandbox, T: TransitionMetadata<Cur, Next>>:
Sandbox
{
/// Evolve `Self` to `Next` providing Metadata.
fn evolve(self, tsn: T) -> Result<Next>;
}

/// A `Sandbox` that knows how to roll back to a "previous" `Sandbox`
pub trait DevolvableSandbox<Cur: Sandbox, Prev: Sandbox, T: TransitionMetadata<Cur, Prev>>:
Sandbox
{
/// Devolve `Self` to `Prev` providing Metadata.
fn devolve(self, tsn: T) -> Result<Prev>;
}
1 change: 1 addition & 0 deletions src/hyperlight_host/src/sandbox_state/transition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ impl<'a, Cur: Sandbox, F> MultiUseContextCallback<'a, Cur, F>
where
F: FnOnce(&mut MultiUseGuestCallContext) -> Result<()>,
{
/// Invokes the callback on the provided guest context
#[instrument(skip_all, parent = Span::current(), level= "Trace")]
pub fn call(self, cur: &mut MultiUseGuestCallContext) -> Result<()> {
(self.cb)(cur)
Expand Down
Loading