Skip to content

Commit 855b3cb

Browse files
committed
fix hyperlight-guest to avoid clippy warnings about using shared reference to mutable static
Signed-off-by: Simon Davies <[email protected]>
1 parent 9813f32 commit 855b3cb

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

src/hyperlight_guest/src/exceptions/idtr.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ pub(crate) unsafe fn load_idt() { unsafe {
2626

2727
let idt_size = 256 * size_of::<IdtEntry>();
2828
let expected_base = addr_of!(IDT) as *const _ as u64;
29-
30-
IDTR.init(expected_base, idt_size as u16);
31-
IDTR.load();
29+
30+
// Use &raw mut to get a mutable raw pointer, then dereference it
31+
// this is to avoid the clippy warning "shared reference to mutable static"
32+
let idtr = &mut *(&raw mut IDTR);
33+
idtr.init(expected_base, idt_size as u16);
34+
idtr.load();
3235
}}

src/hyperlight_guest/src/guest_function_call.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ pub(crate) fn call_guest_function(function_call: FunctionCall) -> Result<Vec<u8>
4343
}
4444

4545
// Find the function definition for the function call.
46-
if let Some(registered_function_definition) =
47-
unsafe { REGISTERED_GUEST_FUNCTIONS.get(&function_call.function_name) }
46+
// Use &raw const to get an immutable reference to the static HashMap
47+
// this is to avoid the clippy warning "shared reference to mutable static"
48+
if let Some(registered_function_definition) = unsafe { (*(&raw const REGISTERED_GUEST_FUNCTIONS)).get(&function_call.function_name) }
4849
{
4950
let function_call_parameter_types: Vec<ParameterType> = function_call
5051
.parameters

src/tests/rust_guests/simpleguest/src/main.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,15 @@ static mut BIGARRAY: [i32; 1024 * 1024] = [0; 1024 * 1024];
5656

5757
fn set_static(_: &FunctionCall) -> Result<Vec<u8>> {
5858
unsafe {
59-
for val in BIGARRAY.iter_mut() {
59+
// Use &raw mut to get a mutable raw pointer, then dereference it
60+
// this is to avoid the clippy warning "shared reference to mutable static"
61+
let bigarray = &mut *(&raw mut BIGARRAY);
62+
for val in bigarray.iter_mut() {
6063
*val = 1;
6164
}
62-
Ok(get_flatbuffer_result(BIGARRAY.len() as i32))
65+
// Use &raw const to get a raw pointer, then dereference it
66+
// this is to avoid the clippy warning "shared reference to mutable static"
67+
Ok(get_flatbuffer_result((*(&raw const BIGARRAY)).len() as i32))
6368
}
6469
}
6570

0 commit comments

Comments
 (0)