Skip to content

Commit e3c22ae

Browse files
committed
Clippy guests
Signed-off-by: Ludvig Liljenberg <[email protected]>
1 parent 6a5cef4 commit e3c22ae

File tree

7 files changed

+94
-86
lines changed

7 files changed

+94
-86
lines changed

.github/workflows/dep_rust.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ jobs:
5858
run: just fmt-check
5959

6060
- name: clippy
61-
run: just clippy ${{ matrix.config }}
61+
run: |
62+
just clippy ${{ matrix.config }}
63+
just clippy-guests
6264
6365
# 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
6466
- name: Ensure up-to-date Cargo.lock

Justfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ fmt-apply:
138138
clippy target=default-target:
139139
cargo clippy --all-targets --all-features --profile={{ if target == "debug" { "dev" } else { target } }} -- -D warnings
140140

141+
clippy-guests target=default-target:
142+
cd src/tests/rust_guests/simpleguest && cargo clippy --profile={{ if target == "debug" { "dev" } else { target } }} -- -D warnings
143+
cd src/tests/rust_guests/callbackguest && cargo clippy --profile={{ if target == "debug" { "dev" } else { target } }} -- -D warnings
144+
141145
clippy-apply-fix-unix:
142146
cargo clippy --fix --all
143147

src/hyperlight_guest/src/guest_function_call.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub(crate) fn call_guest_function(function_call: FunctionCall) -> Result<Vec<u8>
5858

5959
let p_function = unsafe {
6060
let function_pointer = registered_function_definition.function_pointer;
61-
core::mem::transmute::<i64, GuestFunc>(function_pointer)
61+
core::mem::transmute::<usize, GuestFunc>(function_pointer)
6262
};
6363

6464
p_function(&function_call)

src/hyperlight_guest/src/guest_function_definition.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub struct GuestFunctionDefinition {
3333
/// The type of the return value from the host function call
3434
pub return_type: ReturnType,
3535
/// The function pointer to the guest function
36-
pub function_pointer: i64,
36+
pub function_pointer: usize,
3737
}
3838

3939
impl GuestFunctionDefinition {
@@ -42,7 +42,7 @@ impl GuestFunctionDefinition {
4242
function_name: String,
4343
parameter_types: Vec<ParameterType>,
4444
return_type: ReturnType,
45-
function_pointer: i64,
45+
function_pointer: usize,
4646
) -> Self {
4747
Self {
4848
function_name,

src/hyperlight_guest_capi/src/dispatch.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub fn guest_dispatch_function(function_call: FunctionCall) -> Result<Vec<u8>> {
3939
let ffi_func_call = FfiFunctionCall::from_function_call(function_call)?;
4040

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

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

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

79-
let func_def = GuestFunctionDefinition::new(
80-
func_name,
81-
func_params,
82-
return_type,
83-
func_ptr as usize as i64,
84-
);
79+
let func_def =
80+
GuestFunctionDefinition::new(func_name, func_params, return_type, func_ptr as usize);
8581

8682
#[allow(static_mut_refs)]
8783
unsafe { &mut REGISTERED_C_GUEST_FUNCTIONS }.register(func_def);

src/tests/rust_guests/callbackguest/src/main.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -62,47 +62,47 @@ fn guest_function(function_call: &FunctionCall) -> Result<Vec<u8>> {
6262
if let ParameterValue::String(message) = &function_call.parameters.as_ref().unwrap()[0] {
6363
send_message_to_host_method("HostMethod", "Hello from GuestFunction, ", message)
6464
} else {
65-
return Err(HyperlightGuestError::new(
65+
Err(HyperlightGuestError::new(
6666
ErrorCode::GuestFunctionParameterTypeMismatch,
6767
"Invalid parameters passed to guest_function".to_string(),
68-
));
68+
))
6969
}
7070
}
7171

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

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

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

105-
fn guest_function4() -> Result<Vec<u8>> {
105+
fn guest_function4(_: &FunctionCall) -> Result<Vec<u8>> {
106106
call_host_function(
107107
"HostMethod4",
108108
Some(Vec::from(&[ParameterValue::String(
@@ -125,7 +125,7 @@ fn guest_log_message(function_call: &FunctionCall) -> Result<Vec<u8>> {
125125
&function_call.parameters.as_ref().unwrap()[2],
126126
) {
127127
let mut log_level = *level;
128-
if log_level < 0 || log_level > 6 {
128+
if !(0..=6).contains(&log_level) {
129129
log_level = 0;
130130
}
131131

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

141141
Ok(get_flatbuffer_result_from_int(message.len() as i32))
142142
} else {
143-
return Err(HyperlightGuestError::new(
143+
Err(HyperlightGuestError::new(
144144
ErrorCode::GuestFunctionParameterTypeMismatch,
145145
"Invalid parameters passed to guest_log_message".to_string(),
146-
));
146+
))
147147
}
148148
}
149149

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

161-
fn call_host_spin() -> Result<Vec<u8>> {
161+
fn call_host_spin(_: &FunctionCall) -> Result<Vec<u8>> {
162162
call_host_function("Spin", None, ReturnType::Void)?;
163163
Ok(get_flatbuffer_result_from_void())
164164
}
@@ -169,47 +169,47 @@ pub extern "C" fn hyperlight_main() {
169169
"PrintOutput".to_string(),
170170
Vec::from(&[ParameterType::String]),
171171
ReturnType::Int,
172-
print_output_as_guest_function as i64,
172+
print_output_as_guest_function as usize,
173173
);
174174
register_function(print_output_def);
175175

176176
let guest_function_def = GuestFunctionDefinition::new(
177177
"GuestMethod".to_string(),
178178
Vec::from(&[ParameterType::String]),
179179
ReturnType::Int,
180-
guest_function as i64,
180+
guest_function as usize,
181181
);
182182
register_function(guest_function_def);
183183

184184
let guest_function1_def = GuestFunctionDefinition::new(
185185
"GuestMethod1".to_string(),
186186
Vec::from(&[ParameterType::String]),
187187
ReturnType::Int,
188-
guest_function1 as i64,
188+
guest_function1 as usize,
189189
);
190190
register_function(guest_function1_def);
191191

192192
let guest_function2_def = GuestFunctionDefinition::new(
193193
"GuestMethod2".to_string(),
194194
Vec::from(&[ParameterType::String]),
195195
ReturnType::Int,
196-
guest_function2 as i64,
196+
guest_function2 as usize,
197197
);
198198
register_function(guest_function2_def);
199199

200200
let guest_function3_def = GuestFunctionDefinition::new(
201201
"GuestMethod3".to_string(),
202202
Vec::from(&[ParameterType::String]),
203203
ReturnType::Int,
204-
guest_function3 as i64,
204+
guest_function3 as usize,
205205
);
206206
register_function(guest_function3_def);
207207

208208
let guest_function4_def = GuestFunctionDefinition::new(
209209
"GuestMethod4".to_string(),
210210
Vec::new(),
211211
ReturnType::Int,
212-
guest_function4 as i64,
212+
guest_function4 as usize,
213213
);
214214
register_function(guest_function4_def);
215215

@@ -221,23 +221,23 @@ pub extern "C" fn hyperlight_main() {
221221
ParameterType::Int,
222222
]),
223223
ReturnType::Int,
224-
guest_log_message as i64,
224+
guest_log_message as usize,
225225
);
226226
register_function(guest_log_message_def);
227227

228228
let call_error_method_def = GuestFunctionDefinition::new(
229229
"CallErrorMethod".to_string(),
230230
Vec::from(&[ParameterType::String]),
231231
ReturnType::Int,
232-
call_error_method as i64,
232+
call_error_method as usize,
233233
);
234234
register_function(call_error_method_def);
235235

236236
let call_host_spin_def = GuestFunctionDefinition::new(
237237
"CallHostSpin".to_string(),
238238
Vec::new(),
239239
ReturnType::Int,
240-
call_host_spin as i64,
240+
call_host_spin as usize,
241241
);
242242
register_function(call_host_spin_def);
243243
}

0 commit comments

Comments
 (0)