Skip to content

Commit 2bf2fa6

Browse files
committed
Remove host function definition regions
Former users of this region will replace it with a higher-level protocol. Hopefully, we can entirely get rid of string names for host/guest function calls in the near future. Signed-off-by: Lucy Menon <168595099+syntactically@users.noreply.github.com>
1 parent 1c13e23 commit 2bf2fa6

8 files changed

Lines changed: 9 additions & 206 deletions

File tree

src/hyperlight_common/src/mem.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,4 @@ pub struct HyperlightPEB {
4848
pub init_data: GuestMemoryRegion,
4949
pub guest_heap: GuestMemoryRegion,
5050
pub guest_stack: GuestStack,
51-
pub host_function_definitions: GuestMemoryRegion,
5251
}

src/hyperlight_guest/src/guest_handle/host_comm.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ limitations under the License.
1717
use alloc::format;
1818
use alloc::string::ToString;
1919
use alloc::vec::Vec;
20-
use core::slice::from_raw_parts;
2120

2221
use flatbuffers::FlatBufferBuilder;
2322
use hyperlight_common::flatbuffer_wrappers::function_call::{FunctionCall, FunctionCallType};
@@ -27,7 +26,6 @@ use hyperlight_common::flatbuffer_wrappers::function_types::{
2726
use hyperlight_common::flatbuffer_wrappers::guest_error::ErrorCode;
2827
use hyperlight_common::flatbuffer_wrappers::guest_log_data::GuestLogData;
2928
use hyperlight_common::flatbuffer_wrappers::guest_log_level::LogLevel;
30-
use hyperlight_common::flatbuffer_wrappers::host_function_details::HostFunctionDetails;
3129
use hyperlight_common::flatbuffer_wrappers::util::estimate_flatbuffer_capacity;
3230
use hyperlight_common::outb::OutBAction;
3331
use tracing::instrument;
@@ -152,22 +150,6 @@ impl GuestHandle {
152150
self.get_host_return_value::<T>()
153151
}
154152

155-
#[instrument(skip_all, level = "Trace")]
156-
pub fn get_host_function_details(&self) -> HostFunctionDetails {
157-
let peb_ptr = self.peb().unwrap();
158-
let host_function_details_buffer =
159-
unsafe { (*peb_ptr).host_function_definitions.ptr as *const u8 };
160-
let host_function_details_size =
161-
unsafe { (*peb_ptr).host_function_definitions.size as usize };
162-
163-
let host_function_details_slice: &[u8] =
164-
unsafe { from_raw_parts(host_function_details_buffer, host_function_details_size) };
165-
166-
host_function_details_slice
167-
.try_into()
168-
.expect("Failed to convert buffer to HostFunctionDetails")
169-
}
170-
171153
/// Log a message with the specified log level, source, caller, source file, and line number.
172154
pub fn log_message(
173155
&self,

src/hyperlight_guest_bin/src/host_comm.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ use hyperlight_common::flatbuffer_wrappers::function_types::{
2424
ParameterValue, ReturnType, ReturnValue,
2525
};
2626
use hyperlight_common::flatbuffer_wrappers::guest_error::ErrorCode;
27-
use hyperlight_common::flatbuffer_wrappers::host_function_details::HostFunctionDetails;
2827
use hyperlight_common::flatbuffer_wrappers::util::get_flatbuffer_result;
2928
use hyperlight_common::func::{ParameterTuple, SupportedReturnType};
3029
use hyperlight_guest::error::{HyperlightGuestError, Result};
@@ -72,12 +71,6 @@ pub fn get_host_return_value<T: TryFrom<ReturnValue>>() -> Result<T> {
7271
handle.get_host_return_value::<T>()
7372
}
7473

75-
pub fn get_host_function_details() -> HostFunctionDetails {
76-
let handle = unsafe { GUEST_HANDLE };
77-
78-
handle.get_host_function_details()
79-
}
80-
8174
pub fn read_n_bytes_from_user_memory(num: u64) -> Result<Vec<u8>> {
8275
let handle = unsafe { GUEST_HANDLE };
8376
handle.read_n_bytes_from_user_memory(num)

src/hyperlight_host/src/func/host_functions.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl Registerable for UninitializedSandbox {
5252
return_type: Output::TYPE,
5353
};
5454

55-
(*hfs).register_host_function(name.to_string(), entry, &mut self.mgr)
55+
(*hfs).register_host_function(name.to_string(), entry)
5656
}
5757
}
5858

@@ -196,7 +196,7 @@ pub(crate) fn register_host_function<Args: ParameterTuple, Output: SupportedRetu
196196
.host_funcs
197197
.try_lock()
198198
.map_err(|e| new_error!("Error locking at {}:{}: {}", file!(), line!(), e))?
199-
.register_host_function(name.to_string(), entry, &mut sandbox.mgr)?;
199+
.register_host_function(name.to_string(), entry)?;
200200

201201
Ok(())
202202
}

src/hyperlight_host/src/mem/layout.rs

Lines changed: 5 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ limitations under the License.
3535
//! +-------------------------------------------+
3636
//! | Input Data |
3737
//! +-------------------------------------------+
38-
//! | Host Function Definitions |
39-
//! +-------------------------------------------+
4038
//! | PEB Struct | (HyperlightPEB size)
4139
//! +-------------------------------------------+
4240
//! | Guest Code |
@@ -73,14 +71,14 @@ limitations under the License.
7371
use std::fmt::Debug;
7472
use std::mem::{offset_of, size_of};
7573

76-
use hyperlight_common::mem::{GuestMemoryRegion, HyperlightPEB, PAGE_SIZE_USIZE};
74+
use hyperlight_common::mem::{GuestStack, HyperlightPEB, PAGE_SIZE_USIZE};
7775
use rand::{RngCore, rng};
7876
use tracing::{Span, instrument};
7977

8078
#[cfg(feature = "init-paging")]
8179
use super::memory_region::MemoryRegionType::PageTables;
8280
use super::memory_region::MemoryRegionType::{
83-
Code, GuardPage, Heap, HostFunctionDefinitions, InitData, InputData, OutputData, Peb, Stack,
81+
Code, GuardPage, Heap, InitData, InputData, OutputData, Peb, Stack,
8482
};
8583
use super::memory_region::{
8684
DEFAULT_GUEST_BLOB_MEM_FLAGS, MemoryRegion, MemoryRegion_, MemoryRegionFlags, MemoryRegionKind,
@@ -105,7 +103,6 @@ pub(crate) struct SandboxMemoryLayout {
105103
peb_offset: usize,
106104
peb_security_cookie_seed_offset: usize,
107105
peb_guest_dispatch_function_ptr_offset: usize, // set by guest in guest entrypoint
108-
pub(super) peb_host_function_definitions_offset: usize,
109106
peb_input_data_offset: usize,
110107
peb_output_data_offset: usize,
111108
peb_init_data_offset: usize,
@@ -114,7 +111,6 @@ pub(crate) struct SandboxMemoryLayout {
114111

115112
// The following are the actual values
116113
// that are written to the PEB struct
117-
pub(crate) host_function_definitions_buffer_offset: usize,
118114
pub(super) input_data_buffer_offset: usize,
119115
pub(super) output_data_buffer_offset: usize,
120116
guest_heap_buffer_offset: usize,
@@ -156,10 +152,6 @@ impl Debug for SandboxMemoryLayout {
156152
"Guest Dispatch Function Pointer Offset",
157153
&format_args!("{:#x}", self.peb_guest_dispatch_function_ptr_offset),
158154
)
159-
.field(
160-
"Host Function Definitions Offset",
161-
&format_args!("{:#x}", self.peb_host_function_definitions_offset),
162-
)
163155
.field(
164156
"Input Data Offset",
165157
&format_args!("{:#x}", self.peb_input_data_offset),
@@ -180,10 +172,6 @@ impl Debug for SandboxMemoryLayout {
180172
"Guest Stack Offset",
181173
&format_args!("{:#x}", self.peb_guest_stack_data_offset),
182174
)
183-
.field(
184-
"Host Function Definitions Buffer Offset",
185-
&format_args!("{:#x}", self.host_function_definitions_buffer_offset),
186-
)
187175
.field(
188176
"Input Data Buffer Offset",
189177
&format_args!("{:#x}", self.input_data_buffer_offset),
@@ -256,19 +244,13 @@ impl SandboxMemoryLayout {
256244
let peb_init_data_offset = peb_offset + offset_of!(HyperlightPEB, init_data);
257245
let peb_heap_data_offset = peb_offset + offset_of!(HyperlightPEB, guest_heap);
258246
let peb_guest_stack_data_offset = peb_offset + offset_of!(HyperlightPEB, guest_stack);
259-
let peb_host_function_definitions_offset =
260-
peb_offset + offset_of!(HyperlightPEB, host_function_definitions);
261247

262248
// The following offsets are the actual values that relate to memory layout,
263249
// which are written to PEB struct
264250
let peb_address = Self::BASE_ADDRESS + peb_offset;
265-
// make sure host function definitions buffer starts at 4K boundary
266-
let host_function_definitions_buffer_offset = round_up_to(
267-
peb_host_function_definitions_offset + size_of::<GuestMemoryRegion>(),
268-
PAGE_SIZE_USIZE,
269-
);
251+
// make sure input data buffer starts at 4K boundary
270252
let input_data_buffer_offset = round_up_to(
271-
host_function_definitions_buffer_offset + cfg.get_host_function_definition_size(),
253+
peb_guest_stack_data_offset + size_of::<GuestStack>(),
272254
PAGE_SIZE_USIZE,
273255
);
274256
let output_data_buffer_offset = round_up_to(
@@ -294,15 +276,13 @@ impl SandboxMemoryLayout {
294276
heap_size,
295277
peb_security_cookie_seed_offset,
296278
peb_guest_dispatch_function_ptr_offset,
297-
peb_host_function_definitions_offset,
298279
peb_input_data_offset,
299280
peb_output_data_offset,
300281
peb_init_data_offset,
301282
peb_heap_data_offset,
302283
peb_guest_stack_data_offset,
303284
sandbox_memory_config: cfg,
304285
code_size,
305-
host_function_definitions_buffer_offset,
306286
input_data_buffer_offset,
307287
output_data_buffer_offset,
308288
guest_heap_buffer_offset,
@@ -325,22 +305,6 @@ impl SandboxMemoryLayout {
325305
self.peb_output_data_offset
326306
}
327307

328-
/// Get the offset in guest memory to the host function definitions
329-
/// size
330-
#[instrument(skip_all, parent = Span::current(), level= "Trace")]
331-
pub(super) fn get_host_function_definitions_size_offset(&self) -> usize {
332-
// The size field is the first field in the `HostFunctions` struct
333-
self.peb_host_function_definitions_offset
334-
}
335-
336-
/// Get the offset in guest memory to the host function definitions
337-
/// pointer.
338-
#[instrument(skip_all, parent = Span::current(), level= "Trace")]
339-
fn get_host_function_definitions_pointer_offset(&self) -> usize {
340-
// The size field is the field after the size field in the `HostFunctions` struct which is a u64
341-
self.peb_host_function_definitions_offset + size_of::<u64>()
342-
}
343-
344308
/// Get the offset in guest memory to the init data size
345309
#[instrument(skip_all, parent = Span::current(), level= "Trace")]
346310
pub(super) fn get_init_data_size_offset(&self) -> usize {
@@ -526,31 +490,12 @@ impl SandboxMemoryLayout {
526490
}
527491

528492
// PEB
529-
let host_functions_definitions_offset = builder.push_page_aligned(
493+
let input_data_offset = builder.push_page_aligned(
530494
size_of::<HyperlightPEB>(),
531495
MemoryRegionFlags::READ | MemoryRegionFlags::WRITE,
532496
Peb,
533497
);
534498

535-
let expected_host_functions_definitions_offset =
536-
TryInto::<usize>::try_into(self.host_function_definitions_buffer_offset)?;
537-
538-
if host_functions_definitions_offset != expected_host_functions_definitions_offset {
539-
return Err(new_error!(
540-
"Host Function Definitions offset does not match expected Host Function Definitions offset expected: {}, actual: {}",
541-
expected_host_functions_definitions_offset,
542-
host_functions_definitions_offset
543-
));
544-
}
545-
546-
// host function definitions
547-
let input_data_offset = builder.push_page_aligned(
548-
self.sandbox_memory_config
549-
.get_host_function_definition_size(),
550-
MemoryRegionFlags::READ,
551-
HostFunctionDefinitions,
552-
);
553-
554499
let expected_input_data_offset = TryInto::<usize>::try_into(self.input_data_buffer_offset)?;
555500

556501
if input_data_offset != expected_input_data_offset {
@@ -744,16 +689,6 @@ impl SandboxMemoryLayout {
744689

745690
// Skip guest_dispatch_function_ptr_offset because it is set by the guest
746691

747-
// Set up Host Function Definition
748-
shared_mem.write_u64(
749-
self.get_host_function_definitions_size_offset(),
750-
self.sandbox_memory_config
751-
.get_host_function_definition_size()
752-
.try_into()?,
753-
)?;
754-
let addr = get_address!(host_function_definitions_buffer_offset);
755-
shared_mem.write_u64(self.get_host_function_definitions_pointer_offset(), addr)?;
756-
757692
// Skip code, is set when loading binary
758693
// skip outb and outb context, is set when running in_proc
759694

@@ -861,8 +796,6 @@ mod tests {
861796

862797
expected_size += round_up_to(size_of::<HyperlightPEB>(), PAGE_SIZE_USIZE);
863798

864-
expected_size += round_up_to(cfg.get_host_function_definition_size(), PAGE_SIZE_USIZE);
865-
866799
expected_size += round_up_to(cfg.get_input_data_size(), PAGE_SIZE_USIZE);
867800

868801
expected_size += round_up_to(cfg.get_output_data_size(), PAGE_SIZE_USIZE);

src/hyperlight_host/src/mem/mgr.rs

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use hyperlight_common::flatbuffer_wrappers::function_call::{
2222
};
2323
use hyperlight_common::flatbuffer_wrappers::function_types::FunctionCallResult;
2424
use hyperlight_common::flatbuffer_wrappers::guest_log_data::GuestLogData;
25-
use hyperlight_common::flatbuffer_wrappers::host_function_details::HostFunctionDetails;
2625
#[cfg(feature = "init-paging")]
2726
use hyperlight_common::vmem;
2827
#[cfg(feature = "init-paging")]
@@ -35,7 +34,7 @@ use super::ptr::{GuestPtr, RawPtr};
3534
use super::ptr_offset::Offset;
3635
use super::shared_mem::{ExclusiveSharedMemory, GuestSharedMemory, HostSharedMemory, SharedMemory};
3736
use crate::sandbox::snapshot::Snapshot;
38-
use crate::{Result, log_then_return, new_error};
37+
use crate::{Result, new_error};
3938

4039
/// The size of stack guard cookies
4140
pub(crate) const STACK_COOKIE_LEN: usize = 16;
@@ -218,42 +217,6 @@ impl SandboxMemoryManager<ExclusiveSharedMemory> {
218217
))
219218
}
220219

221-
/// Writes host function details to memory
222-
#[instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace")]
223-
pub(crate) fn write_buffer_host_function_details(&mut self, buffer: &[u8]) -> Result<()> {
224-
let host_function_details = HostFunctionDetails::try_from(buffer).map_err(|e| {
225-
new_error!(
226-
"write_buffer_host_function_details: failed to convert buffer to HostFunctionDetails: {}",
227-
e
228-
)
229-
})?;
230-
231-
let host_function_call_buffer: Vec<u8> = (&host_function_details).try_into().map_err(|_| {
232-
new_error!(
233-
"write_buffer_host_function_details: failed to convert HostFunctionDetails to Vec<u8>"
234-
)
235-
})?;
236-
237-
let buffer_size = {
238-
let size_u64 = self
239-
.shared_mem
240-
.read_u64(self.layout.get_host_function_definitions_size_offset())?;
241-
usize::try_from(size_u64)
242-
}?;
243-
244-
if host_function_call_buffer.len() > buffer_size {
245-
log_then_return!(
246-
"Host Function Details buffer is too big for the host_function_definitions buffer"
247-
);
248-
}
249-
250-
self.shared_mem.copy_from_slice(
251-
host_function_call_buffer.as_slice(),
252-
self.layout.host_function_definitions_buffer_offset,
253-
)?;
254-
Ok(())
255-
}
256-
257220
/// Write memory layout
258221
#[instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace")]
259222
pub(crate) fn write_memory_layout(&mut self) -> Result<()> {

0 commit comments

Comments
 (0)