Skip to content

Commit 6240501

Browse files
committed
[fmt/clippy] fixing ci
Signed-off-by: danbugs <[email protected]>
1 parent bb7c680 commit 6240501

File tree

9 files changed

+93
-68
lines changed

9 files changed

+93
-68
lines changed

src/hyperlight_guest/src/entrypoint.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ use hyperlight_common::mem::{HyperlightPEB, RunMode};
2222
use log::LevelFilter;
2323
use spin::Once;
2424

25+
use crate::gdt::load_gdt;
2526
use crate::guest_error::reset_error;
2627
use crate::guest_function_call::dispatch_function;
2728
use crate::guest_logger::init_logger;
2829
use crate::host_function_call::{outb, OutBAction};
30+
use crate::idtr::load_idt;
2931
use crate::{
3032
__security_cookie, HEAP_ALLOCATOR, MIN_STACK_ADDRESS, OS_PAGE_SIZE, OUTB_PTR,
3133
OUTB_PTR_WITH_CONTEXT, P_PEB, RUNNING_MODE,
3234
};
33-
use crate::gdt::load_gdt;
34-
use crate::idtr::load_idt;
3535

3636
#[inline(never)]
3737
pub fn halt() {

src/hyperlight_guest/src/gdt.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,8 @@ impl GdtEntry {
4848
static mut GDT: [GdtEntry; 3] = [
4949
// Null descriptor
5050
GdtEntry::new(0, 0, 0, 0),
51-
5251
// Kernel Code Segment (0x08)
5352
GdtEntry::new(0, 0, 0x9A, 0xA),
54-
5553
// Kernel Data Segment (0x10)
5654
GdtEntry::new(0, 0, 0x92, 0xC),
5755
];
@@ -87,4 +85,3 @@ pub unsafe fn load_gdt() {
8785
options(nostack, preserves_flags)
8886
);
8987
}
90-

src/hyperlight_guest/src/idt.rs

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,30 @@ limitations under the License.
1515
*/
1616

1717
use crate::interrupt_entry::{
18-
_do_excp0, _do_excp1, _do_excp2, _do_excp3, _do_excp4, _do_excp5, _do_excp6, _do_excp7,
19-
_do_excp8, _do_excp9, _do_excp10, _do_excp11, _do_excp12, _do_excp13, _do_excp14, _do_excp15,
20-
_do_excp16, _do_excp17, _do_excp18, _do_excp19, _do_excp20, _do_excp30};
18+
_do_excp0, _do_excp1, _do_excp10, _do_excp11, _do_excp12, _do_excp13, _do_excp14, _do_excp15,
19+
_do_excp16, _do_excp17, _do_excp18, _do_excp19, _do_excp2, _do_excp20, _do_excp3, _do_excp30,
20+
_do_excp4, _do_excp5, _do_excp6, _do_excp7, _do_excp8, _do_excp9,
21+
};
2122

2223
// An entry in the Interrupt Descriptor Table (IDT)
2324
// For reference, see: https://wiki.osdev.org/Interrupt_Descriptor_Table#Structure_on_x86-64
2425
#[repr(C, align(16))]
2526
pub(crate) struct IdtEntry {
26-
offset_low: u16, // Lower 16 bits of handler address
27-
selector: u16, // code segment selector in GDT
28-
ist: u8, // Interrupt Stack Table offset
29-
type_attr: u8, // Gate type and flags
30-
offset_mid: u16, // Middle 16 bits of handler address
31-
offset_high: u32, // High 32 bits of handler address
32-
zero: u32, // Reserved (always 0)
27+
offset_low: u16, // Lower 16 bits of handler address
28+
selector: u16, // code segment selector in GDT
29+
interrupt_stack_table_offset: u8, // Interrupt Stack Table offset
30+
type_attr: u8, // Gate type and flags
31+
offset_mid: u16, // Middle 16 bits of handler address
32+
offset_high: u32, // High 32 bits of handler address
33+
zero: u32, // Reserved (always 0)
3334
}
3435

3536
impl IdtEntry {
3637
fn new(handler: u64) -> Self {
3738
Self {
3839
offset_low: (handler & 0xFFFF) as u16,
39-
selector: 0x08, // Kernel Code Segment
40-
ist: 0, // No IST used
40+
selector: 0x08, // Kernel Code Segment
41+
interrupt_stack_table_offset: 0, // No interrupt stack table used
4142
type_attr: 0x8E,
4243
// 0x8E = 10001110b
4344
// 1 00 0 1110
@@ -53,38 +54,38 @@ impl IdtEntry {
5354
}
5455
}
5556

56-
5757
// The IDT is an array of 256 IDT entries
5858
// (for reference, see: https://wiki.osdev.org/Interrupt_Descriptor_Table#Structure_on_x86-64)
5959
pub(crate) static mut IDT: [IdtEntry; 256] = unsafe { core::mem::zeroed() };
6060

6161
pub(crate) fn init_idt() {
62-
set_idt_entry(0, _do_excp0); // Divide by zero
63-
set_idt_entry(1, _do_excp1); // Debug
64-
set_idt_entry(2, _do_excp2); // Non-maskable interrupt
65-
set_idt_entry(3, _do_excp3); // Breakpoint
66-
set_idt_entry(4, _do_excp4); // Overflow
67-
set_idt_entry(5, _do_excp5); // Bound Range Exceeded
68-
set_idt_entry(6, _do_excp6); // Invalid Opcode
69-
set_idt_entry(7, _do_excp7); // Device Not Available
70-
set_idt_entry(8, _do_excp8); // Double Fault
71-
set_idt_entry(9, _do_excp9); // Coprocessor Segment Overrun
72-
set_idt_entry(10, _do_excp10); // Invalid TSS
73-
set_idt_entry(11, _do_excp11); // Segment Not Present
74-
set_idt_entry(12, _do_excp12); // Stack-Segment Fault
75-
set_idt_entry(13, _do_excp13); // General Protection Fault
76-
set_idt_entry(14, _do_excp14); // Page Fault
77-
set_idt_entry(15, _do_excp15); // Reserved
78-
set_idt_entry(16, _do_excp16); // x87 Floating-Point Exception
79-
set_idt_entry(17, _do_excp17); // Alignment Check
80-
set_idt_entry(18, _do_excp18); // Machine Check
81-
set_idt_entry(19, _do_excp19); // SIMD Floating-Point Exception
82-
set_idt_entry(20, _do_excp20); // Virtualization Exception
83-
set_idt_entry(30, _do_excp30); // Security Exception
62+
set_idt_entry(0, _do_excp0); // Divide by zero
63+
set_idt_entry(1, _do_excp1); // Debug
64+
set_idt_entry(2, _do_excp2); // Non-maskable interrupt
65+
set_idt_entry(3, _do_excp3); // Breakpoint
66+
set_idt_entry(4, _do_excp4); // Overflow
67+
set_idt_entry(5, _do_excp5); // Bound Range Exceeded
68+
set_idt_entry(6, _do_excp6); // Invalid Opcode
69+
set_idt_entry(7, _do_excp7); // Device Not Available
70+
set_idt_entry(8, _do_excp8); // Double Fault
71+
set_idt_entry(9, _do_excp9); // Coprocessor Segment Overrun
72+
set_idt_entry(10, _do_excp10); // Invalid TSS
73+
set_idt_entry(11, _do_excp11); // Segment Not Present
74+
set_idt_entry(12, _do_excp12); // Stack-Segment Fault
75+
set_idt_entry(13, _do_excp13); // General Protection Fault
76+
set_idt_entry(14, _do_excp14); // Page Fault
77+
set_idt_entry(15, _do_excp15); // Reserved
78+
set_idt_entry(16, _do_excp16); // x87 Floating-Point Exception
79+
set_idt_entry(17, _do_excp17); // Alignment Check
80+
set_idt_entry(18, _do_excp18); // Machine Check
81+
set_idt_entry(19, _do_excp19); // SIMD Floating-Point Exception
82+
set_idt_entry(20, _do_excp20); // Virtualization Exception
83+
set_idt_entry(30, _do_excp30); // Security Exception
8484
}
8585

8686
fn set_idt_entry(index: usize, handler: unsafe extern "sysv64" fn()) {
8787
let handler_addr = handler as *const () as u64;
88-
unsafe { IDT[index] = IdtEntry::new(handler_addr); }
88+
unsafe {
89+
IDT[index] = IdtEntry::new(handler_addr);
90+
}
8991
}
90-

src/hyperlight_guest/src/idtr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use core::ptr::addr_of;
2+
23
use crate::idt::{init_idt, IdtEntry, IDT};
34

45
#[repr(C, packed)]

src/hyperlight_guest/src/interrupt_entry.rs

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ limitations under the License.
1818
// https://github.com/nanvix/nanvix/tree/dev/src/kernel/src/hal/arch/x86
1919

2020
use core::arch::global_asm;
21+
2122
use crate::interrupt_handlers::hl_exception_handler;
2223

2324
extern "sysv64" {
@@ -66,7 +67,6 @@ macro_rules! context_save {
6667
" push r13\n",
6768
" push r14\n",
6869
" push r15\n",
69-
7070
// Save segment registers
7171
" mov rax, ds\n",
7272
" push rax\n",
@@ -92,7 +92,6 @@ macro_rules! context_restore {
9292
" mov es, rax\n",
9393
" pop rax\n",
9494
" mov ds, rax\n",
95-
9695
// Restore general-purpose registers
9796
" pop r15\n",
9897
" pop r14\n",
@@ -168,12 +167,18 @@ macro_rules! generate_exceptions {
168167
macro_rules! generate_excp {
169168
($num:expr) => {
170169
concat!(
171-
".global _do_excp", stringify!($num), "\n",
172-
"_do_excp", stringify!($num), ":\n",
170+
".global _do_excp",
171+
stringify!($num),
172+
"\n",
173+
"_do_excp",
174+
stringify!($num),
175+
":\n",
173176
context_save!(),
174177
// In SysV ABI, the second argument is passed in rsi
175178
// rsi is the exception number.
176-
" mov rsi, ", stringify!($num), "\n",
179+
" mov rsi, ",
180+
stringify!($num),
181+
"\n",
177182
// In SysV ABI, the third argument is passed in rdx
178183
// rdx is only used for pagefault exception and
179184
// contains the address that caused the pagefault.
@@ -183,16 +188,22 @@ macro_rules! generate_excp {
183188
};
184189
($num:expr, pusherrcode) => {
185190
concat!(
186-
".global _do_excp", stringify!($num), "\n",
187-
"_do_excp", stringify!($num), ":\n",
191+
".global _do_excp",
192+
stringify!($num),
193+
"\n",
194+
"_do_excp",
195+
stringify!($num),
196+
":\n",
188197
// Some exceptions push an error code onto the stack.
189198
// For the ones that don't, we push a 0 to keep the
190199
// stack aligned.
191200
" push 0\n",
192201
context_save!(),
193202
// In SysV ABI, the second argument is passed in rsi
194203
// rsi is the exception number.
195-
" mov rsi, ", stringify!($num), "\n",
204+
" mov rsi, ",
205+
stringify!($num),
206+
"\n",
196207
// In SysV ABI, the third argument is passed in rdx
197208
// rdx is only used for pagefault exception and
198209
// contains the address that caused the pagefault.
@@ -202,10 +213,16 @@ macro_rules! generate_excp {
202213
};
203214
($num:expr, pagefault) => {
204215
concat!(
205-
".global _do_excp", stringify!($num), "\n",
206-
"_do_excp", stringify!($num), ":\n",
216+
".global _do_excp",
217+
stringify!($num),
218+
"\n",
219+
"_do_excp",
220+
stringify!($num),
221+
":\n",
207222
context_save!(),
208-
" mov rsi, ", stringify!($num), "\n",
223+
" mov rsi, ",
224+
stringify!($num),
225+
"\n",
209226
// In a page fault exception, the cr2 register
210227
// contains the address that caused the page fault.
211228
" mov rdx, cr2\n",

src/hyperlight_guest/src/interrupt_handlers.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ limitations under the License.
1919

2020
/// Exception handler
2121
#[no_mangle]
22-
pub extern "sysv64" fn hl_exception_handler(stack_pointer: u64, exception_number: u64, page_fault_address: u64) {
22+
pub extern "sysv64" fn hl_exception_handler(
23+
stack_pointer: u64,
24+
exception_number: u64,
25+
page_fault_address: u64,
26+
) {
2327
panic!(
2428
"EXCEPTION: {:#x}\n\
2529
Page Fault Address: {:#x}\n\

src/hyperlight_guest/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ pub mod setjmp;
5050

5151
pub mod chkstk;
5252
pub mod error;
53-
pub mod logging;
54-
pub mod interrupt_entry;
55-
pub mod interrupt_handlers;
53+
pub mod gdt;
5654
pub mod idt;
5755
pub mod idtr;
58-
pub mod gdt;
56+
pub mod interrupt_entry;
57+
pub mod interrupt_handlers;
58+
pub mod logging;
5959

6060
// Unresolved symbols
6161
///cbindgen:ignore

src/hyperlight_host/src/func/guest_dispatch.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ mod tests {
160160
None,
161161
None,
162162
)
163-
.unwrap();
163+
.unwrap();
164164

165165
make_get_pid_syscall_func.register(&mut usbox, "MakeGetpidSyscall")?;
166166

@@ -196,7 +196,7 @@ mod tests {
196196
None,
197197
None,
198198
)
199-
.unwrap();
199+
.unwrap();
200200

201201
make_get_pid_syscall_func.register_with_extra_allowed_syscalls(
202202
&mut usbox,
@@ -228,7 +228,7 @@ mod tests {
228228
None,
229229
None,
230230
)
231-
.unwrap()
231+
.unwrap()
232232
};
233233

234234
// test_function0
@@ -345,7 +345,7 @@ mod tests {
345345
// just use the built-in host print function
346346
None,
347347
)
348-
.unwrap();
348+
.unwrap();
349349
test_call_guest_function_by_name(u_sbox);
350350
}
351351

@@ -365,7 +365,7 @@ mod tests {
365365
Some(crate::SandboxRunOptions::RunInProcess(true)),
366366
None,
367367
)
368-
.unwrap();
368+
.unwrap();
369369
test_call_guest_function_by_name(u_sbox);
370370
}
371371

@@ -378,7 +378,7 @@ mod tests {
378378
Some(crate::SandboxRunOptions::RunInProcess(false)),
379379
None,
380380
)
381-
.unwrap();
381+
.unwrap();
382382
test_call_guest_function_by_name(u_sbox);
383383
}
384384

@@ -444,7 +444,7 @@ mod tests {
444444
None,
445445
None,
446446
)
447-
.unwrap();
447+
.unwrap();
448448

449449
// Make this host call run for 5 seconds
450450

@@ -489,7 +489,7 @@ mod tests {
489489
None,
490490
None,
491491
)
492-
.unwrap();
492+
.unwrap();
493493

494494
let mut multi_use_sandbox: MultiUseSandbox = usbox.evolve(Noop::default()).unwrap();
495495

@@ -506,7 +506,10 @@ mod tests {
506506
// msg should indicate we got an invalid opcode exception
507507
assert!(msg.contains("EXCEPTION: 0x6"));
508508
}
509-
e => panic!("Expected HyperlightError::GuestExecutionError but got {:?}", e),
509+
e => panic!(
510+
"Expected HyperlightError::GuestExecutionError but got {:?}",
511+
e
512+
),
510513
}
511514
}
512515
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,9 @@ fn log_message(function_call: &FunctionCall) -> Result<Vec<u8>> {
638638
}
639639

640640
fn trigger_exception(_: &FunctionCall) -> Result<Vec<u8>> {
641-
unsafe { core::arch::asm!("ud2"); } // trigger an undefined instruction exception
641+
unsafe {
642+
core::arch::asm!("ud2");
643+
} // trigger an undefined instruction exception
642644
Ok(get_flatbuffer_result_from_void())
643645
}
644646

0 commit comments

Comments
 (0)