Skip to content
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

Run clippy on guests in CI #237

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion .github/workflows/dep_rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ jobs:
run: just fmt-check

- name: clippy
run: just clippy ${{ matrix.config }}
run: |
just clippy ${{ matrix.config }}
just clippy-guests ${{ matrix.config }}

# Does not check for updated Cargo.lock files for test rust guests as this causes an issue with this checkwhen deoendabot updates dependencies in common crates
- name: Ensure up-to-date Cargo.lock
Expand Down
4 changes: 4 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ fmt-apply:
clippy target=default-target:
cargo clippy --all-targets --all-features --profile={{ if target == "debug" { "dev" } else { target } }} -- -D warnings

clippy-guests target=default-target:
cd src/tests/rust_guests/simpleguest && cargo clippy --profile={{ if target == "debug" { "dev" } else { target } }} -- -D warnings
cd src/tests/rust_guests/callbackguest && cargo clippy --profile={{ if target == "debug" { "dev" } else { target } }} -- -D warnings

clippy-apply-fix-unix:
cargo clippy --fix --all

Expand Down
2 changes: 1 addition & 1 deletion src/hyperlight_guest/src/guest_function_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub(crate) fn call_guest_function(function_call: FunctionCall) -> Result<Vec<u8>

let p_function = unsafe {
let function_pointer = registered_function_definition.function_pointer;
core::mem::transmute::<i64, GuestFunc>(function_pointer)
core::mem::transmute::<usize, GuestFunc>(function_pointer)
};

p_function(&function_call)
Expand Down
4 changes: 2 additions & 2 deletions src/hyperlight_guest/src/guest_function_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub struct GuestFunctionDefinition {
/// The type of the return value from the host function call
pub return_type: ReturnType,
/// The function pointer to the guest function
pub function_pointer: i64,
pub function_pointer: usize,
}

impl GuestFunctionDefinition {
Expand All @@ -42,7 +42,7 @@ impl GuestFunctionDefinition {
function_name: String,
parameter_types: Vec<ParameterType>,
return_type: ReturnType,
function_pointer: i64,
function_pointer: usize,
) -> Self {
Self {
function_name,
Expand Down
10 changes: 3 additions & 7 deletions src/hyperlight_guest_capi/src/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub fn guest_dispatch_function(function_call: FunctionCall) -> Result<Vec<u8>> {
let ffi_func_call = FfiFunctionCall::from_function_call(function_call)?;

let guest_func =
unsafe { mem::transmute::<i64, CGuestFunc>(registered_func.function_pointer) };
unsafe { mem::transmute::<usize, CGuestFunc>(registered_func.function_pointer) };
let function_result = guest_func(&ffi_func_call);

unsafe { Ok(FfiVec::into_vec(*function_result)) }
Expand Down Expand Up @@ -76,12 +76,8 @@ pub extern "C" fn hl_register_function_definition(

let func_params = unsafe { slice::from_raw_parts(params_type, param_no).to_vec() };

let func_def = GuestFunctionDefinition::new(
func_name,
func_params,
return_type,
func_ptr as usize as i64,
);
let func_def =
GuestFunctionDefinition::new(func_name, func_params, return_type, func_ptr as usize);

#[allow(static_mut_refs)]
unsafe { &mut REGISTERED_C_GUEST_FUNCTIONS }.register(func_def);
Expand Down
48 changes: 24 additions & 24 deletions src/tests/rust_guests/callbackguest/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,47 +62,47 @@ fn guest_function(function_call: &FunctionCall) -> Result<Vec<u8>> {
if let ParameterValue::String(message) = &function_call.parameters.as_ref().unwrap()[0] {
send_message_to_host_method("HostMethod", "Hello from GuestFunction, ", message)
} else {
return Err(HyperlightGuestError::new(
Err(HyperlightGuestError::new(
ErrorCode::GuestFunctionParameterTypeMismatch,
"Invalid parameters passed to guest_function".to_string(),
));
))
}
}

fn guest_function1(function_call: &FunctionCall) -> Result<Vec<u8>> {
if let ParameterValue::String(message) = &function_call.parameters.as_ref().unwrap()[0] {
send_message_to_host_method("HostMethod1", "Hello from GuestFunction1, ", message)
} else {
return Err(HyperlightGuestError::new(
Err(HyperlightGuestError::new(
ErrorCode::GuestFunctionParameterTypeMismatch,
"Invalid parameters passed to guest_function1".to_string(),
));
))
}
}

fn guest_function2(function_call: &FunctionCall) -> Result<Vec<u8>> {
if let ParameterValue::String(message) = &function_call.parameters.as_ref().unwrap()[0] {
send_message_to_host_method("HostMethod1", "Hello from GuestFunction2, ", message)
} else {
return Err(HyperlightGuestError::new(
Err(HyperlightGuestError::new(
ErrorCode::GuestFunctionParameterTypeMismatch,
"Invalid parameters passed to guest_function2".to_string(),
));
))
}
}

fn guest_function3(function_call: &FunctionCall) -> Result<Vec<u8>> {
if let ParameterValue::String(message) = &function_call.parameters.as_ref().unwrap()[0] {
send_message_to_host_method("HostMethod1", "Hello from GuestFunction3, ", message)
} else {
return Err(HyperlightGuestError::new(
Err(HyperlightGuestError::new(
ErrorCode::GuestFunctionParameterTypeMismatch,
"Invalid parameters passed to guest_function3".to_string(),
));
))
}
}

fn guest_function4() -> Result<Vec<u8>> {
fn guest_function4(_: &FunctionCall) -> Result<Vec<u8>> {
call_host_function(
"HostMethod4",
Some(Vec::from(&[ParameterValue::String(
Expand All @@ -125,7 +125,7 @@ fn guest_log_message(function_call: &FunctionCall) -> Result<Vec<u8>> {
&function_call.parameters.as_ref().unwrap()[2],
) {
let mut log_level = *level;
if log_level < 0 || log_level > 6 {
if !(0..=6).contains(&log_level) {
log_level = 0;
}

Expand All @@ -140,25 +140,25 @@ fn guest_log_message(function_call: &FunctionCall) -> Result<Vec<u8>> {

Ok(get_flatbuffer_result_from_int(message.len() as i32))
} else {
return Err(HyperlightGuestError::new(
Err(HyperlightGuestError::new(
ErrorCode::GuestFunctionParameterTypeMismatch,
"Invalid parameters passed to guest_log_message".to_string(),
));
))
}
}

fn call_error_method(function_call: &FunctionCall) -> Result<Vec<u8>> {
if let ParameterValue::String(message) = &function_call.parameters.as_ref().unwrap()[0] {
send_message_to_host_method("ErrorMethod", "Error From Host: ", message)
} else {
return Err(HyperlightGuestError::new(
Err(HyperlightGuestError::new(
ErrorCode::GuestFunctionParameterTypeMismatch,
"Invalid parameters passed to call_error_method".to_string(),
));
))
}
}

fn call_host_spin() -> Result<Vec<u8>> {
fn call_host_spin(_: &FunctionCall) -> Result<Vec<u8>> {
call_host_function("Spin", None, ReturnType::Void)?;
Ok(get_flatbuffer_result_from_void())
}
Expand All @@ -169,47 +169,47 @@ pub extern "C" fn hyperlight_main() {
"PrintOutput".to_string(),
Vec::from(&[ParameterType::String]),
ReturnType::Int,
print_output_as_guest_function as i64,
print_output_as_guest_function as usize,
);
register_function(print_output_def);

let guest_function_def = GuestFunctionDefinition::new(
"GuestMethod".to_string(),
Vec::from(&[ParameterType::String]),
ReturnType::Int,
guest_function as i64,
guest_function as usize,
);
register_function(guest_function_def);

let guest_function1_def = GuestFunctionDefinition::new(
"GuestMethod1".to_string(),
Vec::from(&[ParameterType::String]),
ReturnType::Int,
guest_function1 as i64,
guest_function1 as usize,
);
register_function(guest_function1_def);

let guest_function2_def = GuestFunctionDefinition::new(
"GuestMethod2".to_string(),
Vec::from(&[ParameterType::String]),
ReturnType::Int,
guest_function2 as i64,
guest_function2 as usize,
);
register_function(guest_function2_def);

let guest_function3_def = GuestFunctionDefinition::new(
"GuestMethod3".to_string(),
Vec::from(&[ParameterType::String]),
ReturnType::Int,
guest_function3 as i64,
guest_function3 as usize,
);
register_function(guest_function3_def);

let guest_function4_def = GuestFunctionDefinition::new(
"GuestMethod4".to_string(),
Vec::new(),
ReturnType::Int,
guest_function4 as i64,
guest_function4 as usize,
);
register_function(guest_function4_def);

Expand All @@ -221,23 +221,23 @@ pub extern "C" fn hyperlight_main() {
ParameterType::Int,
]),
ReturnType::Int,
guest_log_message as i64,
guest_log_message as usize,
);
register_function(guest_log_message_def);

let call_error_method_def = GuestFunctionDefinition::new(
"CallErrorMethod".to_string(),
Vec::from(&[ParameterType::String]),
ReturnType::Int,
call_error_method as i64,
call_error_method as usize,
);
register_function(call_error_method_def);

let call_host_spin_def = GuestFunctionDefinition::new(
"CallHostSpin".to_string(),
Vec::new(),
ReturnType::Int,
call_host_spin as i64,
call_host_spin as usize,
);
register_function(call_host_spin_def);
}
Expand Down
Loading
Loading