Skip to content

Commit 748fdb7

Browse files
authored
Merge branch 'main' into call_fn
Signed-off-by: Jorge Prendes <[email protected]>
2 parents d0ac424 + d353fc7 commit 748fdb7

File tree

39 files changed

+108
-549
lines changed

39 files changed

+108
-549
lines changed

Cargo.lock

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

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ fn main() -> hyperlight_host::Result<()> {
4242
// Create an uninitialized sandbox with a guest binary
4343
let mut uninitialized_sandbox = UninitializedSandbox::new(
4444
hyperlight_host::GuestBinary::FilePath(hyperlight_testing::simple_guest_as_string().unwrap()),
45-
None, // default configuration
46-
None, // default run options
45+
None // default configuration
4746
)?;
4847

4948
// Registering a host function makes it available to be called by the guest

fuzz/fuzz_targets/guest_call.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ fuzz_target!(
3535
let u_sbox = UninitializedSandbox::new(
3636
GuestBinary::FilePath(simple_guest_for_fuzzing_as_string().expect("Guest Binary Missing")),
3737
None,
38-
None,
3938
)
4039
.unwrap();
4140

fuzz/fuzz_targets/host_call.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ fuzz_target!(
3333
init: {
3434
let u_sbox = UninitializedSandbox::new(
3535
GuestBinary::FilePath(simple_guest_for_fuzzing_as_string().expect("Guest Binary Missing")),
36-
None,
37-
None,
36+
None
3837
)
3938
.unwrap();
4039

fuzz/fuzz_targets/host_print.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ fuzz_target!(
2020
let u_sbox = UninitializedSandbox::new(
2121
GuestBinary::FilePath(simple_guest_for_fuzzing_as_string().expect("Guest Binary Missing")),
2222
None,
23-
None,
2423
)
2524
.unwrap();
2625

src/hyperlight_common/src/mem.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,6 @@ pub const PAGE_SIZE_USIZE: usize = 1 << 12;
2222

2323
use core::ffi::{c_char, c_void};
2424

25-
#[repr(u64)]
26-
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
27-
pub enum RunMode {
28-
None = 0,
29-
Hypervisor = 1,
30-
InProcessWindows = 2,
31-
InProcessLinux = 3,
32-
Invalid = 4,
33-
}
34-
3525
#[repr(C)]
3626
pub struct InputData {
3727
pub inputDataSize: u64,
@@ -67,9 +57,6 @@ pub struct HyperlightPEB {
6757
pub security_cookie_seed: u64,
6858
pub guest_function_dispatch_ptr: u64,
6959
pub pCode: *mut c_char,
70-
pub pOutb: *mut c_void,
71-
pub pOutbContext: *mut c_void,
72-
pub runMode: RunMode,
7360
pub inputdata: InputData,
7461
pub outputdata: OutputData,
7562
pub guestheapData: GuestHeapData,

src/hyperlight_guest/src/chkstk.rs

Lines changed: 3 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,9 @@ limitations under the License.
1515
*/
1616

1717
use core::arch::global_asm;
18-
use core::mem::size_of;
1918

20-
use hyperlight_common::mem::RunMode;
21-
22-
use crate::guest_error::{set_invalid_runmode_error, set_stack_allocate_error};
23-
use crate::{MIN_STACK_ADDRESS, RUNNING_MODE};
19+
use crate::guest_error::set_stack_allocate_error;
20+
use crate::MIN_STACK_ADDRESS;
2421

2522
extern "win64" {
2623
fn __chkstk();
@@ -35,21 +32,6 @@ global_asm!(
3532
push r10
3633
push r11
3734
38-
/* Load run_mode into r10 */
39-
mov r10, qword ptr [rip+{run_mode}]
40-
41-
cmp r10, 0
42-
je handle_none
43-
cmp r10, 1
44-
je handle_hypervisor
45-
cmp r10, 2
46-
je handle_inproc_windows
47-
cmp r10, 3
48-
je handle_inproc_linux
49-
/* run_mode > 3 (invalid), so treat like handle_none */
50-
jmp handle_invalid
51-
52-
handle_hypervisor:
5335
/* Load the minimum stack address from the PEB */
5436
mov r11, [rip+{min_stack_addr}]
5537
@@ -72,49 +54,11 @@ global_asm!(
7254
call {set_error}
7355
hlt
7456
75-
handle_inproc_windows:
76-
/* Get the current stack pointer */
77-
lea r10, [rsp + 0x18]
78-
79-
/* Calculate what the new stack pointer will be */
80-
sub r10, rax
81-
cmovb r10, r11
82-
mov r11, qword ptr gs:[0x0000000000000010]
83-
cmp r10, r11
84-
jae cs_ret
85-
and r10w, 0x0F000
86-
csip_stackprobe:
87-
lea r11, [r11 + 0x0FFFFFFFFFFFFF000]
88-
mov byte ptr [r11], 0
89-
cmp r10, r11
90-
jne csip_stackprobe
9157
cs_ret:
9258
/* Restore RAX, R11 */
9359
pop r11
9460
pop r10
95-
ret
96-
handle_inproc_linux:
97-
/* no-op */
98-
jmp cs_ret
99-
handle_none:
100-
/* no-op. This can entrypoint has a large stack allocation
101-
before RunMode variable is set */
102-
jmp cs_ret
103-
handle_invalid:
104-
call {invalid_runmode}",
105-
run_mode = sym RUNNING_MODE,
61+
ret",
10662
min_stack_addr = sym MIN_STACK_ADDRESS,
10763
set_error = sym set_stack_allocate_error,
108-
invalid_runmode = sym set_invalid_runmode_error
10964
);
110-
111-
// Assumptions made in implementation above. If these are no longer true, compilation will fail
112-
// and the developer will need to update the assembly code.
113-
const _: () = {
114-
assert!(size_of::<RunMode>() == size_of::<u64>());
115-
assert!(RunMode::None as u64 == 0);
116-
assert!(RunMode::Hypervisor as u64 == 1);
117-
assert!(RunMode::InProcessWindows as u64 == 2);
118-
assert!(RunMode::InProcessLinux as u64 == 3);
119-
assert!(RunMode::Invalid as u64 == 4);
120-
};

src/hyperlight_guest/src/entrypoint.rs

Lines changed: 12 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ limitations under the License.
1515
*/
1616

1717
use core::arch::asm;
18-
use core::ffi::{c_char, c_void, CStr};
18+
use core::ffi::{c_char, CStr};
1919

20-
use hyperlight_common::mem::{HyperlightPEB, RunMode};
20+
use hyperlight_common::mem::HyperlightPEB;
2121
use hyperlight_common::outb::OutBAction;
2222
use log::LevelFilter;
2323
use spin::Once;
@@ -27,18 +27,11 @@ use crate::guest_function_call::dispatch_function;
2727
use crate::guest_logger::init_logger;
2828
use crate::host_function_call::outb;
2929
use crate::idtr::load_idt;
30-
use crate::{
31-
__security_cookie, HEAP_ALLOCATOR, MIN_STACK_ADDRESS, OS_PAGE_SIZE, OUTB_PTR,
32-
OUTB_PTR_WITH_CONTEXT, P_PEB, RUNNING_MODE,
33-
};
30+
use crate::{__security_cookie, HEAP_ALLOCATOR, MIN_STACK_ADDRESS, OS_PAGE_SIZE, P_PEB};
3431

3532
#[inline(never)]
3633
pub fn halt() {
37-
unsafe {
38-
if RUNNING_MODE == RunMode::Hypervisor {
39-
asm!("hlt", options(nostack))
40-
}
41-
}
34+
unsafe { asm!("hlt", options(nostack)) }
4235
}
4336

4437
#[no_mangle]
@@ -105,45 +98,14 @@ pub extern "win64" fn entrypoint(peb_address: u64, seed: u64, ops: u64, max_log_
10598
.expect("Invalid log level");
10699
init_logger(max_log_level);
107100

108-
match (*peb_ptr).runMode {
109-
RunMode::Hypervisor => {
110-
RUNNING_MODE = RunMode::Hypervisor;
111-
// This static is to make it easier to implement the __chkstk function in assembly.
112-
// It also means that should we change the layout of the struct in the future, we
113-
// don't have to change the assembly code.
114-
MIN_STACK_ADDRESS = (*peb_ptr).gueststackData.minUserStackAddress;
115-
116-
// Setup GDT and IDT
117-
load_gdt();
118-
load_idt();
119-
}
120-
RunMode::InProcessLinux | RunMode::InProcessWindows => {
121-
RUNNING_MODE = (*peb_ptr).runMode;
122-
123-
OUTB_PTR = {
124-
let outb_ptr: extern "win64" fn(u16, *const u8, u64) =
125-
core::mem::transmute((*peb_ptr).pOutb);
126-
Some(outb_ptr)
127-
};
128-
129-
if (*peb_ptr).pOutbContext.is_null() {
130-
panic!("OutbContext is null");
131-
}
132-
133-
OUTB_PTR_WITH_CONTEXT = {
134-
let outb_ptr_with_context: extern "win64" fn(
135-
*mut c_void,
136-
u16,
137-
*const u8,
138-
u64,
139-
) = core::mem::transmute((*peb_ptr).pOutb);
140-
Some(outb_ptr_with_context)
141-
};
142-
}
143-
_ => {
144-
panic!("Invalid runmode in PEB");
145-
}
146-
}
101+
// This static is to make it easier to implement the __chkstk function in assembly.
102+
// It also means that should we change the layout of the struct in the future, we
103+
// don't have to change the assembly code.
104+
MIN_STACK_ADDRESS = (*peb_ptr).gueststackData.minUserStackAddress;
105+
106+
// Setup GDT and IDT
107+
load_gdt();
108+
load_idt();
147109

148110
let heap_start = (*peb_ptr).guestheapData.guestHeapBuffer as usize;
149111
let heap_size = (*peb_ptr).guestheapData.guestHeapSize as usize;

src/hyperlight_guest/src/guest_error.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,6 @@ pub(crate) extern "win64" fn set_stack_allocate_error() {
5252
outb(OutBAction::Abort as u16, &[ErrorCode::StackOverflow as u8]);
5353
}
5454

55-
#[no_mangle]
56-
pub(crate) extern "win64" fn set_invalid_runmode_error() {
57-
panic!("Invalid run mode in __chkstk");
58-
}
59-
6055
/// Exposes a C API to allow the guest to set an error
6156
///
6257
/// # Safety

0 commit comments

Comments
 (0)