Skip to content

Commit bb7c680

Browse files
committed
[interrupt-handlers] addressing @ludfjig 's pr feedback
- consolidating init_idt and load_idt - added push 0 for exceptions that dont push their error code to the stack Signed-off-by: danbugs <[email protected]>
1 parent d7f2d52 commit bb7c680

File tree

5 files changed

+44
-25
lines changed

5 files changed

+44
-25
lines changed

src/hyperlight_guest/src/entrypoint.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ use crate::{
3131
OUTB_PTR_WITH_CONTEXT, P_PEB, RUNNING_MODE,
3232
};
3333
use crate::gdt::load_gdt;
34-
use crate::idt::init_idt;
3534
use crate::idtr::load_idt;
3635

3736
#[inline(never)]
@@ -91,7 +90,6 @@ pub extern "win64" fn entrypoint(peb_address: u64, seed: u64, ops: u64, max_log_
9190

9291
// Set up GDT/IDT
9392
load_gdt();
94-
init_idt();
9593
load_idt();
9694

9795
// Enable interrupts

src/hyperlight_guest/src/idtr.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use core::ptr::addr_of;
2-
use crate::idt::{IdtEntry, IDT};
2+
use crate::idt::{init_idt, IdtEntry, IDT};
33

44
#[repr(C, packed)]
55
pub struct Idtr {
@@ -21,6 +21,8 @@ impl Idtr {
2121
}
2222

2323
pub(crate) unsafe fn load_idt() {
24+
init_idt();
25+
2426
let idt_size = 256 * size_of::<IdtEntry>();
2527
let expected_base = addr_of!(IDT) as *const _ as u64;
2628

src/hyperlight_guest/src/interrupt_entry.rs

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -127,27 +127,27 @@ macro_rules! generate_exceptions {
127127
context_restore!(),
128128
" mov r14, 495\n",
129129
" iretq\n", // iretq is used to return from exception in x86_64
130-
generate_excp!(0),
131-
generate_excp!(1),
132-
generate_excp!(2),
133-
generate_excp!(3),
134-
generate_excp!(4),
135-
generate_excp!(5),
136-
generate_excp!(6),
137-
generate_excp!(7),
130+
generate_excp!(0, pusherrcode),
131+
generate_excp!(1, pusherrcode),
132+
generate_excp!(2, pusherrcode),
133+
generate_excp!(3, pusherrcode),
134+
generate_excp!(4, pusherrcode),
135+
generate_excp!(5, pusherrcode),
136+
generate_excp!(6, pusherrcode),
137+
generate_excp!(7, pusherrcode),
138138
generate_excp!(8),
139-
generate_excp!(9),
139+
generate_excp!(9, pusherrcode),
140140
generate_excp!(10),
141141
generate_excp!(11),
142142
generate_excp!(12),
143143
generate_excp!(13),
144144
generate_excp!(14, pagefault),
145-
generate_excp!(15),
146-
generate_excp!(16),
145+
generate_excp!(15, pusherrcode),
146+
generate_excp!(16, pusherrcode),
147147
generate_excp!(17),
148-
generate_excp!(18),
149-
generate_excp!(19),
150-
generate_excp!(20),
148+
generate_excp!(18, pusherrcode),
149+
generate_excp!(19, pusherrcode),
150+
generate_excp!(20, pusherrcode),
151151
generate_excp!(30),
152152
)
153153
};
@@ -181,6 +181,25 @@ macro_rules! generate_excp {
181181
" jmp _do_excp_common\n"
182182
)
183183
};
184+
($num:expr, pusherrcode) => {
185+
concat!(
186+
".global _do_excp", stringify!($num), "\n",
187+
"_do_excp", stringify!($num), ":\n",
188+
// Some exceptions push an error code onto the stack.
189+
// For the ones that don't, we push a 0 to keep the
190+
// stack aligned.
191+
" push 0\n",
192+
context_save!(),
193+
// In SysV ABI, the second argument is passed in rsi
194+
// rsi is the exception number.
195+
" mov rsi, ", stringify!($num), "\n",
196+
// In SysV ABI, the third argument is passed in rdx
197+
// rdx is only used for pagefault exception and
198+
// contains the address that caused the pagefault.
199+
" mov rdx, 0\n",
200+
" jmp _do_excp_common\n"
201+
)
202+
};
184203
($num:expr, pagefault) => {
185204
concat!(
186205
".global _do_excp", stringify!($num), "\n",

src/tests/rust_guests/callbackguest/Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/tests/rust_guests/simpleguest/Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)