Skip to content

Commit 16e8e7c

Browse files
committed
These changes to hyperlight-guest were created by running cargo fix --edition
Signed-off-by: Simon Davies <[email protected]>
1 parent 69c4636 commit 16e8e7c

File tree

10 files changed

+31
-31
lines changed

10 files changed

+31
-31
lines changed

src/hyperlight_guest/src/entrypoint.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub fn halt() {
3434
unsafe { asm!("hlt", options(nostack)) }
3535
}
3636

37-
#[no_mangle]
37+
#[unsafe(no_mangle)]
3838
pub extern "C" fn abort() -> ! {
3939
abort_with_code(&[0, 0xFF])
4040
}
@@ -49,7 +49,7 @@ pub fn abort_with_code(code: &[u8]) -> ! {
4949
///
5050
/// # Safety
5151
/// This function is unsafe because it dereferences a raw pointer.
52-
pub unsafe fn abort_with_code_and_message(code: &[u8], message_ptr: *const c_char) -> ! {
52+
pub unsafe fn abort_with_code_and_message(code: &[u8], message_ptr: *const c_char) -> ! { unsafe {
5353
// Step 1: Send abort code (typically 1 byte, but `code` allows flexibility)
5454
outb(OutBAction::Abort as u16, code);
5555

@@ -64,16 +64,16 @@ pub unsafe fn abort_with_code_and_message(code: &[u8], message_ptr: *const c_cha
6464

6565
// This function never returns
6666
unreachable!()
67-
}
67+
}}
6868

69-
extern "C" {
69+
unsafe extern "C" {
7070
fn hyperlight_main();
7171
fn srand(seed: u32);
7272
}
7373

7474
static INIT: Once = Once::new();
7575

76-
#[no_mangle]
76+
#[unsafe(no_mangle)]
7777
pub extern "C" fn entrypoint(peb_address: u64, seed: u64, ops: u64, max_log_level: u64) {
7878
if peb_address == 0 {
7979
panic!("PEB address is null");

src/hyperlight_guest/src/exceptions/gdt.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ struct GdtPointer {
7272
}
7373

7474
/// Load the GDT
75-
pub unsafe fn load_gdt() {
75+
pub unsafe fn load_gdt() { unsafe {
7676
let gdt_ptr = GdtPointer {
7777
size: (core::mem::size_of::<[GdtEntry; 3]>() - 1) as u16,
7878
base: addr_of!(GDT) as *const _ as u64,
@@ -94,4 +94,4 @@ pub unsafe fn load_gdt() {
9494
in(reg) &gdt_ptr,
9595
options(nostack, preserves_flags)
9696
);
97-
}
97+
}}

src/hyperlight_guest/src/exceptions/handlers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use hyperlight_common::outb::Exception;
2323
use crate::entrypoint::abort_with_code_and_message;
2424

2525
/// Exception handler
26-
#[no_mangle]
26+
#[unsafe(no_mangle)]
2727
pub extern "C" fn hl_exception_handler(
2828
stack_pointer: u64,
2929
exception_number: u64,

src/hyperlight_guest/src/exceptions/idtr.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ impl Idtr {
1616
self.base = base;
1717
}
1818

19-
pub unsafe fn load(&self) {
19+
pub unsafe fn load(&self) { unsafe {
2020
core::arch::asm!("lidt [{}]", in(reg) self, options(readonly, nostack, preserves_flags));
21-
}
21+
}}
2222
}
2323

24-
pub(crate) unsafe fn load_idt() {
24+
pub(crate) unsafe fn load_idt() { unsafe {
2525
init_idt();
2626

2727
let idt_size = 256 * size_of::<IdtEntry>();
2828
let expected_base = addr_of!(IDT) as *const _ as u64;
2929

3030
IDTR.init(expected_base, idt_size as u16);
3131
IDTR.load();
32-
}
32+
}}

src/hyperlight_guest/src/exceptions/interrupt_entry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use core::arch::global_asm;
2121

2222
use crate::exceptions::handlers::hl_exception_handler;
2323

24-
extern "C" {
24+
unsafe extern "C" {
2525
// Exception handlers
2626
pub(crate) fn _do_excp0();
2727
pub(crate) fn _do_excp1();

src/hyperlight_guest/src/guest_error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub(crate) fn set_error(error_code: ErrorCode, message: &str) {
4545
/// # Safety
4646
/// TODO
4747
/// cbindgen:ignore
48-
#[no_mangle]
48+
#[unsafe(no_mangle)]
4949
#[allow(non_camel_case_types)]
5050
pub unsafe extern "C" fn setError(code: u64, message: *const c_char) {
5151
let error_code = ErrorCode::from(code);

src/hyperlight_guest/src/guest_function_call.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pub(crate) fn call_guest_function(function_call: FunctionCall) -> Result<Vec<u8>
6868
// TODO: ideally we would define a default implementation of this with weak linkage so the guest is not required
6969
// to implement the function but its seems that weak linkage is an unstable feature so for now its probably better
7070
// to not do that.
71-
extern "Rust" {
71+
unsafe extern "Rust" {
7272
fn guest_dispatch_function(function_call: FunctionCall) -> Result<Vec<u8>>;
7373
}
7474

@@ -78,7 +78,7 @@ pub(crate) fn call_guest_function(function_call: FunctionCall) -> Result<Vec<u8>
7878

7979
// This function is marked as no_mangle/inline to prevent the compiler from inlining it , if its inlined the epilogue will not be called
8080
// and we will leak memory as the epilogue will not be called as halt() is not going to return.
81-
#[no_mangle]
81+
#[unsafe(no_mangle)]
8282
#[inline(never)]
8383
fn internal_dispatch_function() -> Result<()> {
8484
#[cfg(debug_assertions)]

src/hyperlight_guest/src/host_function_call.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ pub fn outb(port: u16, data: &[u8]) {
107107
}
108108
}
109109

110-
pub(crate) unsafe fn out32(port: u16, val: u32) {
110+
pub(crate) unsafe fn out32(port: u16, val: u32) { unsafe {
111111
arch::asm!("out dx, eax", in("dx") port, in("eax") val, options(preserves_flags, nomem, nostack));
112-
}
112+
}}
113113

114114
/// Prints a message using `OutBAction::DebugPrint`. It transmits bytes of a message
115115
/// through several VMExists and, with such, it is slower than

src/hyperlight_guest/src/memory.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,30 +81,30 @@ unsafe fn alloc_helper(size: usize, zero: bool) -> *mut c_void {
8181
///
8282
/// # Safety
8383
/// The returned pointer must be freed with `memory::free` when it is no longer needed, otherwise memory will leak.
84-
#[no_mangle]
85-
pub unsafe extern "C" fn malloc(size: usize) -> *mut c_void {
84+
#[unsafe(no_mangle)]
85+
pub unsafe extern "C" fn malloc(size: usize) -> *mut c_void { unsafe {
8686
alloc_helper(size, false)
87-
}
87+
}}
8888

8989
/// Allocates a block of memory for an array of `nmemb` elements, each of `size` bytes.
9090
/// The memory is initialized to 0s.
9191
///
9292
/// # Safety
9393
/// The returned pointer must be freed with `memory::free` when it is no longer needed, otherwise memory will leak.
94-
#[no_mangle]
95-
pub unsafe extern "C" fn calloc(nmemb: usize, size: usize) -> *mut c_void {
94+
#[unsafe(no_mangle)]
95+
pub unsafe extern "C" fn calloc(nmemb: usize, size: usize) -> *mut c_void { unsafe {
9696
let total_size = nmemb
9797
.checked_mul(size)
9898
.expect("nmemb * size should not overflow in calloc");
9999

100100
alloc_helper(total_size, true)
101-
}
101+
}}
102102

103103
/// Frees the memory block pointed to by `ptr`.
104104
///
105105
/// # Safety
106106
/// `ptr` must be a pointer to a memory block previously allocated by `memory::malloc`, `memory::calloc`, or `memory::realloc`.
107-
#[no_mangle]
107+
#[unsafe(no_mangle)]
108108
pub unsafe extern "C" fn free(ptr: *mut c_void) {
109109
if !ptr.is_null() {
110110
unsafe {
@@ -120,8 +120,8 @@ pub unsafe extern "C" fn free(ptr: *mut c_void) {
120120
///
121121
/// # Safety
122122
/// `ptr` must be a pointer to a memory block previously allocated by `memory::malloc`, `memory::calloc`, or `memory::realloc`.
123-
#[no_mangle]
124-
pub unsafe extern "C" fn realloc(ptr: *mut c_void, size: usize) -> *mut c_void {
123+
#[unsafe(no_mangle)]
124+
pub unsafe extern "C" fn realloc(ptr: *mut c_void, size: usize) -> *mut c_void { unsafe {
125125
if ptr.is_null() {
126126
// If the pointer is null, treat as a malloc
127127
return malloc(size);
@@ -155,4 +155,4 @@ pub unsafe extern "C" fn realloc(ptr: *mut c_void, size: usize) -> *mut c_void {
155155
new_block_start.add(1) as *mut c_void
156156
}
157157
}
158-
}
158+
}}

src/hyperlight_guest/src/print.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ static mut MESSAGE_BUFFER: Vec<u8> = Vec::new();
3131
///
3232
/// # Safety
3333
/// This function is not thread safe
34-
#[no_mangle]
34+
#[unsafe(no_mangle)]
3535
#[allow(static_mut_refs)]
36-
pub unsafe extern "C" fn _putchar(c: c_char) {
36+
pub unsafe extern "C" fn _putchar(c: c_char) { unsafe {
3737
let char = c as u8;
3838

3939
// Extend buffer capacity if it's empty (like `with_capacity` in lazy_static).
@@ -66,4 +66,4 @@ pub unsafe extern "C" fn _putchar(c: c_char) {
6666
// Clear the buffer after sending
6767
MESSAGE_BUFFER.clear();
6868
}
69-
}
69+
}}

0 commit comments

Comments
 (0)