Skip to content

Commit 1d938f2

Browse files
committed
[host/{mem,func},guest/host_functions,common/peb] Removed HostFunctionDefinitions memory region
We only used the HostFunctionDefinitions region to validate that a host function exists before calling it. But, if the host function doesn't exist, we'll just exit anyway, so that utility is questionable. Signed-off-by: danbugs <[email protected]>
1 parent 617b158 commit 1d938f2

File tree

9 files changed

+8
-255
lines changed

9 files changed

+8
-255
lines changed

src/hyperlight_common/src/mem/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ pub struct GuestPanicContextData {
8989
pub struct HyperlightPEB {
9090
pub security_cookie_seed: u64,
9191
pub guest_function_dispatch_ptr: u64,
92-
pub hostFunctionDefinitions: HostFunctionDefinitions,
9392
pub hostException: HostException,
9493
pub guestErrorData: GuestErrorData,
9594
pub pCode: *mut c_char,

src/hyperlight_guest/src/host_function_call.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ use hyperlight_common::mem::RunMode;
2929

3030
use crate::error::{HyperlightGuestError, Result};
3131
use crate::host_error::check_for_host_error;
32-
use crate::host_functions::validate_host_function_call;
3332
use crate::shared_input_data::try_pop_shared_input_data_into;
3433
use crate::shared_output_data::push_shared_output_data;
3534
use crate::{OUTB_PTR, OUTB_PTR_WITH_CONTEXT, P_PEB, RUNNING_MODE};
@@ -71,8 +70,6 @@ pub fn call_host_function(
7170
return_type,
7271
);
7372

74-
validate_host_function_call(&host_function_call)?;
75-
7673
let host_function_call_buffer: Vec<u8> = host_function_call
7774
.try_into()
7875
.expect("Unable to serialize host function call");

src/hyperlight_guest/src/host_functions.rs

Lines changed: 0 additions & 112 deletions
This file was deleted.

src/hyperlight_guest/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ pub mod guest_function_register;
4040

4141
pub mod host_error;
4242
pub mod host_function_call;
43-
pub mod host_functions;
4443

4544
pub(crate) mod guest_logger;
4645
pub mod memory;

src/hyperlight_host/src/func/host_functions.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ macro_rules! host_function {
109109
.try_lock()
110110
.map_err(|e| new_error!("Error locking at {}:{}: {}", file!(), line!(), e))?
111111
.register_host_function_with_syscalls(
112-
sandbox.mgr.as_mut(),
113112
&HostFunctionDefinition::new(name.to_string(), None, R::get_hyperlight_type()),
114113
HyperlightFunction::new(func),
115114
_eas,
@@ -126,7 +125,6 @@ macro_rules! host_function {
126125
.try_lock()
127126
.map_err(|e| new_error!("Error locking at {}:{}: {}", file!(), line!(), e))?
128127
.register_host_function(
129-
sandbox.mgr.as_mut(),
130128
&HostFunctionDefinition::new(name.to_string(), None, R::get_hyperlight_type()),
131129
HyperlightFunction::new(func),
132130
)?;
@@ -236,7 +234,6 @@ macro_rules! host_function {
236234
.try_lock()
237235
.map_err(|e| new_error!("Error locking at {}:{}: {}", file!(), line!(), e))?
238236
.register_host_function_with_syscalls(
239-
sandbox.mgr.as_mut(),
240237
&HostFunctionDefinition::new(
241238
name.to_string(),
242239
parameter_types,
@@ -257,7 +254,6 @@ macro_rules! host_function {
257254
.try_lock()
258255
.map_err(|e| new_error!("Error locking at {}:{}: {}", file!(), line!(), e))?
259256
.register_host_function(
260-
sandbox.mgr.as_mut(),
261257
&HostFunctionDefinition::new(
262258
name.to_string(),
263259
parameter_types,

src/hyperlight_host/src/mem/layout.rs

Lines changed: 5 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ use rand::{rng, RngCore};
2222
use tracing::{instrument, Span};
2323

2424
use super::memory_region::MemoryRegionType::{
25-
Code, GuardPage, GuestErrorData, Heap, HostExceptionData, HostFunctionDefinitions, InputData,
26-
OutputData, PageTables, PanicContext, Peb, Stack,
25+
Code, GuardPage, GuestErrorData, Heap, HostExceptionData, InputData, OutputData, PageTables,
26+
PanicContext, Peb, Stack,
2727
};
2828
use super::memory_region::{MemoryRegion, MemoryRegionFlags, MemoryRegionVecBuilder};
2929
use super::mgr::AMOUNT_OF_MEMORY_PER_PT;
@@ -49,9 +49,7 @@ use crate::{log_then_return, new_error, Result};
4949
// +-------------------------------------------+
5050
// | Host Exception Handlers |
5151
// +-------------------------------------------+
52-
// | Host Function Definitions |
53-
// +-------------------------------------------+
54-
// | PEB Struct (0x98) |
52+
// | PEB Struct | (HyperlightPEB size)
5553
// +-------------------------------------------+
5654
// | Guest Code |
5755
// +-------------------------------------------+
@@ -64,9 +62,6 @@ use crate::{log_then_return, new_error, Result};
6462
// | PML4 |
6563
// +-------------------------------------------+ 0x0_000
6664

67-
///
68-
/// - `HostDefinitions` - the length of this is the `HostFunctionDefinitionSize`
69-
/// field from `SandboxConfiguration`
7065
///
7166
/// - `HostExceptionData` - memory that contains details of any Host Exception that
7267
/// occurred in outb function. it contains a 32 bit length following by a json
@@ -108,7 +103,6 @@ pub(crate) struct SandboxMemoryLayout {
108103
peb_offset: usize,
109104
peb_security_cookie_seed_offset: usize,
110105
peb_guest_dispatch_function_ptr_offset: usize, // set by guest in guest entrypoint
111-
pub(super) peb_host_function_definitions_offset: usize,
112106
pub(crate) peb_host_exception_offset: usize,
113107
peb_guest_error_offset: usize,
114108
peb_code_and_outb_pointer_offset: usize,
@@ -121,7 +115,6 @@ pub(crate) struct SandboxMemoryLayout {
121115

122116
// The following are the actual values
123117
// that are written to the PEB struct
124-
pub(crate) host_function_definitions_buffer_offset: usize,
125118
pub(crate) host_exception_buffer_offset: usize,
126119
pub(super) guest_error_buffer_offset: usize,
127120
pub(super) input_data_buffer_offset: usize,
@@ -160,10 +153,6 @@ impl Debug for SandboxMemoryLayout {
160153
"Guest Dispatch Function Pointer Offset",
161154
&format_args!("{:#x}", self.peb_guest_dispatch_function_ptr_offset),
162155
)
163-
.field(
164-
"Host Function Definitions Offset",
165-
&format_args!("{:#x}", self.peb_host_function_definitions_offset),
166-
)
167156
.field(
168157
"Host Exception Offset",
169158
&format_args!("{:#x}", self.peb_host_exception_offset),
@@ -196,10 +185,6 @@ impl Debug for SandboxMemoryLayout {
196185
"Guest Stack Offset",
197186
&format_args!("{:#x}", self.peb_guest_stack_data_offset),
198187
)
199-
.field(
200-
"Host Function Definitions Buffer Offset",
201-
&format_args!("{:#x}", self.host_function_definitions_buffer_offset),
202-
)
203188
.field(
204189
"Host Exception Buffer Offset",
205190
&format_args!("{:#x}", self.host_exception_buffer_offset),
@@ -292,8 +277,6 @@ impl SandboxMemoryLayout {
292277
peb_offset + offset_of!(HyperlightPEB, security_cookie_seed);
293278
let peb_guest_dispatch_function_ptr_offset =
294279
peb_offset + offset_of!(HyperlightPEB, guest_function_dispatch_ptr);
295-
let peb_host_function_definitions_offset =
296-
peb_offset + offset_of!(HyperlightPEB, hostFunctionDefinitions);
297280
let peb_host_exception_offset = peb_offset + offset_of!(HyperlightPEB, hostException);
298281
let peb_guest_error_offset = peb_offset + offset_of!(HyperlightPEB, guestErrorData);
299282
let peb_code_and_outb_pointer_offset = peb_offset + offset_of!(HyperlightPEB, pCode);
@@ -308,14 +291,9 @@ impl SandboxMemoryLayout {
308291
// The following offsets are the actual values that relate to memory layout,
309292
// which are written to PEB struct
310293
let peb_address = Self::BASE_ADDRESS + peb_offset;
311-
// make sure host function definitions buffer starts at 4K boundary
312-
let host_function_definitions_buffer_offset = round_up_to(
313-
peb_guest_stack_data_offset + size_of::<GuestStackData>(),
314-
PAGE_SIZE_USIZE,
315-
);
316294
// make sure host exception buffer starts at 4K boundary
317295
let host_exception_buffer_offset = round_up_to(
318-
host_function_definitions_buffer_offset + cfg.get_host_function_definition_size(),
296+
peb_guest_stack_data_offset + size_of::<GuestStackData>(),
319297
PAGE_SIZE_USIZE,
320298
);
321299
let guest_error_buffer_offset = round_up_to(
@@ -351,7 +329,6 @@ impl SandboxMemoryLayout {
351329
heap_size,
352330
peb_security_cookie_seed_offset,
353331
peb_guest_dispatch_function_ptr_offset,
354-
peb_host_function_definitions_offset,
355332
peb_host_exception_offset,
356333
peb_guest_error_offset,
357334
peb_code_and_outb_pointer_offset,
@@ -364,7 +341,6 @@ impl SandboxMemoryLayout {
364341
guest_error_buffer_offset,
365342
sandbox_memory_config: cfg,
366343
code_size,
367-
host_function_definitions_buffer_offset,
368344
host_exception_buffer_offset,
369345
input_data_buffer_offset,
370346
output_data_buffer_offset,
@@ -410,22 +386,6 @@ impl SandboxMemoryLayout {
410386
self.peb_output_data_offset
411387
}
412388

413-
/// Get the offset in guest memory to the host function definitions
414-
/// size
415-
#[instrument(skip_all, parent = Span::current(), level= "Trace")]
416-
pub(super) fn get_host_function_definitions_size_offset(&self) -> usize {
417-
// The size field is the first field in the `HostFunctions` struct
418-
self.peb_host_function_definitions_offset
419-
}
420-
421-
/// Get the offset in guest memory to the host function definitions
422-
/// pointer.
423-
#[instrument(skip_all, parent = Span::current(), level= "Trace")]
424-
fn get_host_function_definitions_pointer_offset(&self) -> usize {
425-
// The size field is the field after the size field in the `HostFunctions` struct which is a u64
426-
self.peb_host_function_definitions_offset + size_of::<u64>()
427-
}
428-
429389
/// Get the offset in guest memory to the minimum guest stack address.
430390
#[instrument(skip_all, parent = Span::current(), level= "Trace")]
431391
fn get_min_guest_stack_address_offset(&self) -> usize {
@@ -623,8 +583,6 @@ impl SandboxMemoryLayout {
623583
total_mapped_memory_size += round_up_to(stack_size, PAGE_SIZE_USIZE);
624584
total_mapped_memory_size += round_up_to(heap_size, PAGE_SIZE_USIZE);
625585
total_mapped_memory_size += round_up_to(cfg.get_host_exception_size(), PAGE_SIZE_USIZE);
626-
total_mapped_memory_size +=
627-
round_up_to(cfg.get_host_function_definition_size(), PAGE_SIZE_USIZE);
628586
total_mapped_memory_size += round_up_to(cfg.get_guest_error_buffer_size(), PAGE_SIZE_USIZE);
629587
total_mapped_memory_size += round_up_to(cfg.get_input_data_size(), PAGE_SIZE_USIZE);
630588
total_mapped_memory_size += round_up_to(cfg.get_output_data_size(), PAGE_SIZE_USIZE);
@@ -709,31 +667,12 @@ impl SandboxMemoryLayout {
709667
}
710668

711669
// PEB
712-
let host_functions_definitions_offset = builder.push_page_aligned(
670+
let host_exception_offset = builder.push_page_aligned(
713671
size_of::<HyperlightPEB>(),
714672
MemoryRegionFlags::READ | MemoryRegionFlags::WRITE,
715673
Peb,
716674
);
717675

718-
let expected_host_functions_definitions_offset =
719-
TryInto::<usize>::try_into(self.host_function_definitions_buffer_offset)?;
720-
721-
if host_functions_definitions_offset != expected_host_functions_definitions_offset {
722-
return Err(new_error!(
723-
"Host Function Definitions offset does not match expected Host Function Definitions offset expected: {}, actual: {}",
724-
expected_host_functions_definitions_offset,
725-
host_functions_definitions_offset
726-
));
727-
}
728-
729-
// host function definitions
730-
let host_exception_offset = builder.push_page_aligned(
731-
self.sandbox_memory_config
732-
.get_host_function_definition_size(),
733-
MemoryRegionFlags::READ,
734-
HostFunctionDefinitions,
735-
);
736-
737676
let expected_host_exception_offset =
738677
TryInto::<usize>::try_into(self.host_exception_buffer_offset)?;
739678

@@ -938,16 +877,6 @@ impl SandboxMemoryLayout {
938877

939878
// Skip guest_dispatch_function_ptr_offset because it is set by the guest
940879

941-
// Set up Host Function Definition
942-
shared_mem.write_u64(
943-
self.get_host_function_definitions_size_offset(),
944-
self.sandbox_memory_config
945-
.get_host_function_definition_size()
946-
.try_into()?,
947-
)?;
948-
let addr = get_address!(host_function_definitions_buffer);
949-
shared_mem.write_u64(self.get_host_function_definitions_pointer_offset(), addr)?;
950-
951880
// Set up Host Exception Header
952881
// The peb only needs to include the size, not the actual buffer
953882
// since the the guest wouldn't want to read the buffer anyway
@@ -1098,8 +1027,6 @@ mod tests {
10981027

10991028
expected_size += round_up_to(size_of::<HyperlightPEB>(), PAGE_SIZE_USIZE);
11001029

1101-
expected_size += round_up_to(cfg.get_host_function_definition_size(), PAGE_SIZE_USIZE);
1102-
11031030
expected_size += round_up_to(cfg.get_host_exception_size(), PAGE_SIZE_USIZE);
11041031

11051032
expected_size += round_up_to(cfg.get_guest_error_buffer_size(), PAGE_SIZE_USIZE);

src/hyperlight_host/src/mem/memory_region.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,6 @@ pub enum MemoryRegionType {
131131
Code,
132132
/// The region contains the PEB
133133
Peb,
134-
/// The region contains the Host Function Definitions
135-
HostFunctionDefinitions,
136134
/// The region contains the Host Exception Data
137135
HostExceptionData,
138136
/// The region contains the Guest Error Data

0 commit comments

Comments
 (0)