Skip to content

Commit 21cf19b

Browse files
syntacticallydblnz
authored andcommitted
[hyperlight_host/exe] Allow load() to consume the exe_info
This will be useful in the near future, when it will allow transforming the exe_info into unwind information without an extra copy. Signed-off-by: Lucy Menon <[email protected]>
1 parent c3d65fc commit 21cf19b

File tree

5 files changed

+14
-17
lines changed

5 files changed

+14
-17
lines changed

src/hyperlight_host/src/mem/elf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl ElfInfo {
7373
.unwrap();
7474
(max_phdr.p_vaddr + max_phdr.p_memsz - self.get_base_va()) as usize
7575
}
76-
pub(crate) fn load_at(&self, load_addr: usize, target: &mut [u8]) -> Result<()> {
76+
pub(crate) fn load_at(&mut self, load_addr: usize, target: &mut [u8]) -> Result<()> {
7777
let base_va = self.get_base_va();
7878
for phdr in self.phdrs.iter().filter(|phdr| phdr.p_type == PT_LOAD) {
7979
let start_va = (phdr.p_vaddr - base_va) as usize;

src/hyperlight_host/src/mem/exe.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ impl ExeInfo {
7171
// copying into target, but the PE loader chooses to apply
7272
// relocations in its owned representation of the PE contents,
7373
// which requires it to be &mut.
74-
pub fn load(&mut self, load_addr: usize, target: &mut [u8]) -> Result<()> {
74+
pub fn load(self, load_addr: usize, target: &mut [u8]) -> Result<()> {
7575
match self {
76-
ExeInfo::Elf(elf) => {
76+
ExeInfo::Elf(mut elf) => {
7777
elf.load_at(load_addr, target)?;
7878
}
7979
}

src/hyperlight_host/src/mem/mgr.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ impl SandboxMemoryManager<ExclusiveSharedMemory> {
311311
#[instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace")]
312312
pub(crate) fn load_guest_binary_into_memory(
313313
cfg: SandboxConfiguration,
314-
exe_info: &mut ExeInfo,
314+
exe_info: ExeInfo,
315315
guest_blob: Option<&GuestBlob>,
316316
) -> Result<Self> {
317317
let guest_blob_size = guest_blob.map(|b| b.data.len()).unwrap_or(0);
@@ -320,8 +320,8 @@ impl SandboxMemoryManager<ExclusiveSharedMemory> {
320320
let layout = SandboxMemoryLayout::new(
321321
cfg,
322322
exe_info.loaded_size(),
323-
usize::try_from(cfg.get_stack_size(exe_info))?,
324-
usize::try_from(cfg.get_heap_size(exe_info))?,
323+
usize::try_from(cfg.get_stack_size(&exe_info))?,
324+
usize::try_from(cfg.get_heap_size(&exe_info))?,
325325
guest_blob_size,
326326
guest_blob_mem_flags,
327327
)?;

src/hyperlight_host/src/sandbox/outb.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -246,13 +246,10 @@ mod tests {
246246
let sandbox_cfg = SandboxConfiguration::default();
247247

248248
let new_mgr = || {
249-
let mut exe_info = simple_guest_exe_info().unwrap();
250-
let mut mgr = SandboxMemoryManager::load_guest_binary_into_memory(
251-
sandbox_cfg,
252-
&mut exe_info,
253-
None,
254-
)
255-
.unwrap();
249+
let exe_info = simple_guest_exe_info().unwrap();
250+
let mut mgr =
251+
SandboxMemoryManager::load_guest_binary_into_memory(sandbox_cfg, exe_info, None)
252+
.unwrap();
256253
let mem_size = mgr.get_shared_mem_mut().mem_size();
257254
let layout = mgr.layout;
258255
let shared_mem = mgr.get_shared_mem_mut();
@@ -361,10 +358,10 @@ mod tests {
361358
let sandbox_cfg = SandboxConfiguration::default();
362359
tracing::subscriber::with_default(subscriber.clone(), || {
363360
let new_mgr = || {
364-
let mut exe_info = simple_guest_exe_info().unwrap();
361+
let exe_info = simple_guest_exe_info().unwrap();
365362
let mut mgr = SandboxMemoryManager::load_guest_binary_into_memory(
366363
sandbox_cfg,
367-
&mut exe_info,
364+
exe_info,
368365
None,
369366
)
370367
.unwrap();

src/hyperlight_host/src/sandbox/uninitialized.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,12 +281,12 @@ impl UninitializedSandbox {
281281
guest_binary: &GuestBinary,
282282
guest_blob: Option<&GuestBlob>,
283283
) -> Result<SandboxMemoryManager<ExclusiveSharedMemory>> {
284-
let mut exe_info = match guest_binary {
284+
let exe_info = match guest_binary {
285285
GuestBinary::FilePath(bin_path_str) => ExeInfo::from_file(bin_path_str)?,
286286
GuestBinary::Buffer(buffer) => ExeInfo::from_buf(buffer)?,
287287
};
288288

289-
SandboxMemoryManager::load_guest_binary_into_memory(cfg, &mut exe_info, guest_blob)
289+
SandboxMemoryManager::load_guest_binary_into_memory(cfg, exe_info, guest_blob)
290290
}
291291

292292
/// Set the max log level to be used by the guest.

0 commit comments

Comments
 (0)