Skip to content

Commit 6f4c705

Browse files
committed
[guest/exceptions] changed the ABI of exception related logic
We used the sysv64 ABI for exception stuff. This ABI is not available for every target so having it there unconditionally makes the hyperlight_guest lib not be compilable to said targets. This commit changes the ABI to "C" (i.e., smt more commonly used) and gates it behind a x86_64 cfg as the assembly code is dependent on 64-bit architectures. Signed-off-by: danbugs <[email protected]>
1 parent d5891af commit 6f4c705

File tree

7 files changed

+22
-21
lines changed

7 files changed

+22
-21
lines changed

src/hyperlight_guest/src/entrypoint.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ use hyperlight_common::outb::OutBAction;
2222
use log::LevelFilter;
2323
use spin::Once;
2424

25-
use crate::gdt::load_gdt;
25+
#[cfg(target_arch = "x86_64")]
26+
use crate::exceptions::{gdt::load_gdt, idtr::load_idt};
2627
use crate::guest_function_call::dispatch_function;
2728
use crate::guest_logger::init_logger;
2829
use crate::host_function_call::outb;
29-
use crate::idtr::load_idt;
3030
use crate::{__security_cookie, HEAP_ALLOCATOR, MIN_STACK_ADDRESS, OS_PAGE_SIZE, P_PEB};
3131

3232
#[inline(never)]
@@ -103,9 +103,12 @@ pub extern "win64" fn entrypoint(peb_address: u64, seed: u64, ops: u64, max_log_
103103
// don't have to change the assembly code.
104104
MIN_STACK_ADDRESS = (*peb_ptr).gueststackData.minUserStackAddress;
105105

106-
// Setup GDT and IDT
107-
load_gdt();
108-
load_idt();
106+
#[cfg(target_arch = "x86_64")]
107+
{
108+
// Setup GDT and IDT
109+
load_gdt();
110+
load_idt();
111+
}
109112

110113
let heap_start = (*peb_ptr).guestheapData.guestHeapBuffer as usize;
111114
let heap_size = (*peb_ptr).guestheapData.guestHeapSize as usize;
File renamed without changes.

src/hyperlight_guest/src/interrupt_handlers.rs renamed to src/hyperlight_guest/src/exceptions/handlers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::entrypoint::abort_with_code_and_message;
2424

2525
/// Exception handler
2626
#[no_mangle]
27-
pub extern "sysv64" fn hl_exception_handler(
27+
pub extern "C" fn hl_exception_handler(
2828
stack_pointer: u64,
2929
exception_number: u64,
3030
page_fault_address: u64,

src/hyperlight_guest/src/idt.rs renamed to src/hyperlight_guest/src/exceptions/idt.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ limitations under the License.
1616

1717
use hyperlight_common::outb::Exception;
1818

19-
use crate::interrupt_entry::{
19+
use crate::exceptions::interrupt_entry::{
2020
_do_excp0, _do_excp1, _do_excp10, _do_excp11, _do_excp12, _do_excp13, _do_excp14, _do_excp15,
2121
_do_excp16, _do_excp17, _do_excp18, _do_excp19, _do_excp2, _do_excp20, _do_excp3, _do_excp30,
2222
_do_excp4, _do_excp5, _do_excp6, _do_excp7, _do_excp8, _do_excp9,
@@ -96,7 +96,7 @@ pub(crate) fn init_idt() {
9696
set_idt_entry(Exception::SecurityException as usize, _do_excp30); // Security Exception
9797
}
9898

99-
fn set_idt_entry(index: usize, handler: unsafe extern "sysv64" fn()) {
99+
fn set_idt_entry(index: usize, handler: unsafe extern "C" fn()) {
100100
let handler_addr = handler as *const () as u64;
101101
unsafe {
102102
IDT[index] = IdtEntry::new(handler_addr);

src/hyperlight_guest/src/idtr.rs renamed to src/hyperlight_guest/src/exceptions/idtr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use core::ptr::addr_of;
22

3-
use crate::idt::{init_idt, IdtEntry, IDT};
3+
use crate::exceptions::idt::{init_idt, IdtEntry, IDT};
44

55
#[repr(C, packed)]
66
pub struct Idtr {

src/hyperlight_guest/src/interrupt_entry.rs renamed to src/hyperlight_guest/src/exceptions/interrupt_entry.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ limitations under the License.
1919

2020
use core::arch::global_asm;
2121

22-
use crate::interrupt_handlers::hl_exception_handler;
22+
use crate::exceptions::handlers::hl_exception_handler;
2323

24-
extern "sysv64" {
24+
extern "C" {
2525
// Exception handlers
2626
pub(crate) fn _do_excp0();
2727
pub(crate) fn _do_excp1();
@@ -119,7 +119,6 @@ macro_rules! generate_exceptions {
119119
// Common exception handler
120120
".global _do_excp_common\n",
121121
"_do_excp_common:\n",
122-
// In SysV ABI, the first argument is passed in rdi
123122
// rdi is the stack pointer.
124123
" mov rdi, rsp\n",
125124
" call {hl_exception_handler}\n",
@@ -173,12 +172,10 @@ macro_rules! generate_excp {
173172
stringify!($num),
174173
":\n",
175174
context_save!(),
176-
// In SysV ABI, the second argument is passed in rsi
177175
// rsi is the exception number.
178176
" mov rsi, ",
179177
stringify!($num),
180178
"\n",
181-
// In SysV ABI, the third argument is passed in rdx
182179
// rdx is only used for pagefault exception and
183180
// contains the address that caused the pagefault.
184181
" mov rdx, 0\n",
@@ -198,12 +195,10 @@ macro_rules! generate_excp {
198195
// stack aligned.
199196
" push 0\n",
200197
context_save!(),
201-
// In SysV ABI, the second argument is passed in rsi
202198
// rsi is the exception number.
203199
" mov rsi, ",
204200
stringify!($num),
205201
"\n",
206-
// In SysV ABI, the third argument is passed in rdx
207202
// rdx is only used for pagefault exception and
208203
// contains the address that caused the pagefault.
209204
" mov rdx, 0\n",

src/hyperlight_guest/src/lib.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,14 @@ pub mod print;
4444
pub(crate) mod security_check;
4545

4646
pub mod error;
47-
pub mod gdt;
48-
pub mod idt;
49-
pub mod idtr;
50-
pub mod interrupt_entry;
51-
pub mod interrupt_handlers;
47+
#[cfg(target_arch = "x86_64")]
48+
pub mod exceptions {
49+
pub mod gdt;
50+
pub mod handlers;
51+
pub mod idt;
52+
pub mod idtr;
53+
pub mod interrupt_entry;
54+
}
5255
pub mod logging;
5356

5457
// Unresolved symbols

0 commit comments

Comments
 (0)