Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions src/hyperlight_host/src/mem/exe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@ pub enum ExeInfo {
Elf(ElfInfo),
}

// There isn't a commonly-used standard convention for heap and stack
// limits to be included in ELF files as they are in
// PEs. Consequently, we use these static defaults as the default
// limits, unless overwritten when setting up the sandbox.
const DEFAULT_ELF_STACK_RESERVE: u64 = 65536;
const DEFAULT_ELF_HEAP_RESERVE: u64 = 131072;

#[cfg(feature = "mem_profile")]
pub(crate) trait UnwindInfo: Send + Sync {
fn as_module(&self) -> framehop::Module<Vec<u8>>;
Expand Down Expand Up @@ -84,16 +77,6 @@ impl ExeInfo {
pub fn from_buf(buf: &[u8]) -> Result<Self> {
ElfInfo::new(buf).map(ExeInfo::Elf)
}
pub fn stack_reserve(&self) -> u64 {
match self {
ExeInfo::Elf(_) => DEFAULT_ELF_STACK_RESERVE,
}
}
pub fn heap_reserve(&self) -> u64 {
match self {
ExeInfo::Elf(_) => DEFAULT_ELF_HEAP_RESERVE,
}
}
pub fn entrypoint(&self) -> Offset {
match self {
ExeInfo::Elf(elf) => Offset::from(elf.entrypoint_va()),
Expand Down
4 changes: 2 additions & 2 deletions src/hyperlight_host/src/mem/mgr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,8 @@ impl SandboxMemoryManager<ExclusiveSharedMemory> {
let layout = SandboxMemoryLayout::new(
cfg,
exe_info.loaded_size(),
usize::try_from(cfg.get_stack_size(&exe_info))?,
usize::try_from(cfg.get_heap_size(&exe_info))?,
usize::try_from(cfg.get_stack_size())?,
usize::try_from(cfg.get_heap_size())?,
guest_blob_size,
guest_blob_mem_flags,
)?;
Expand Down
20 changes: 10 additions & 10 deletions src/hyperlight_host/src/sandbox/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ use std::time::Duration;
use libc::c_int;
use tracing::{Span, instrument};

use crate::mem::exe::ExeInfo;

/// Used for passing debug configuration to a sandbox
#[cfg(gdb)]
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
Expand Down Expand Up @@ -105,6 +103,10 @@ impl SandboxConfiguration {
pub const DEFAULT_INTERRUPT_RETRY_DELAY: Duration = Duration::from_micros(500);
/// The default signal offset from `SIGRTMIN` used to determine the signal number for interrupting
pub const INTERRUPT_VCPU_SIGRTMIN_OFFSET: u8 = 0;
/// The default heap size of a hyperlight sandbox
pub const DEFAULT_HEAP_SIZE: u64 = 131072;
/// The default stack size of a hyperlight sandbox
pub const DEFAULT_STACK_SIZE: u64 = 65536;

#[allow(clippy::too_many_arguments)]
/// Create a new configuration for a sandbox with the given sizes.
Expand Down Expand Up @@ -267,17 +269,17 @@ impl SandboxConfiguration {
/// If self.stack_size is non-zero, return it. Otherwise,
/// return exe_info.stack_reserve()
#[instrument(skip_all, parent = Span::current(), level= "Trace")]
pub(crate) fn get_stack_size(&self, exe_info: &ExeInfo) -> u64 {
pub(crate) fn get_stack_size(&self) -> u64 {
self.stack_size_override_opt()
.unwrap_or_else(|| exe_info.stack_reserve())
.unwrap_or(Self::DEFAULT_STACK_SIZE)
}

/// If self.heap_size_override is non-zero, return it. Otherwise,
/// return exe_info.heap_reserve()
#[instrument(skip_all, parent = Span::current(), level= "Trace")]
pub(crate) fn get_heap_size(&self, exe_info: &ExeInfo) -> u64 {
pub(crate) fn get_heap_size(&self) -> u64 {
self.heap_size_override_opt()
.unwrap_or_else(|| exe_info.heap_reserve())
.unwrap_or(Self::DEFAULT_HEAP_SIZE)
}
}

Expand All @@ -303,7 +305,6 @@ impl Default for SandboxConfiguration {
#[cfg(test)]
mod tests {
use super::SandboxConfiguration;
use crate::testing::simple_guest_exe_info;

#[test]
fn overrides() {
Expand All @@ -325,10 +326,9 @@ mod tests {
#[cfg(crashdump)]
true,
);
let exe_info = simple_guest_exe_info().unwrap();

let stack_size = cfg.get_stack_size(&exe_info);
let heap_size = cfg.get_heap_size(&exe_info);
let stack_size = cfg.get_stack_size();
let heap_size = cfg.get_heap_size();
assert_eq!(STACK_SIZE_OVERRIDE, stack_size);
assert_eq!(HEAP_SIZE_OVERRIDE, heap_size);

Expand Down
Loading