Skip to content

Commit 41483d5

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 ba778d1 commit 41483d5

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
@@ -336,7 +336,7 @@ impl SandboxMemoryManager<ExclusiveSharedMemory> {
336336
#[instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace")]
337337
pub(crate) fn load_guest_binary_into_memory(
338338
cfg: SandboxConfiguration,
339-
exe_info: &mut ExeInfo,
339+
exe_info: ExeInfo,
340340
guest_blob: Option<&GuestBlob>,
341341
) -> Result<Self> {
342342
let guest_blob_size = guest_blob.map(|b| b.data.len()).unwrap_or(0);
@@ -345,8 +345,8 @@ impl SandboxMemoryManager<ExclusiveSharedMemory> {
345345
let layout = SandboxMemoryLayout::new(
346346
cfg,
347347
exe_info.loaded_size(),
348-
usize::try_from(cfg.get_stack_size(exe_info))?,
349-
usize::try_from(cfg.get_heap_size(exe_info))?,
348+
usize::try_from(cfg.get_stack_size(&exe_info))?,
349+
usize::try_from(cfg.get_heap_size(&exe_info))?,
350350
guest_blob_size,
351351
guest_blob_mem_flags,
352352
)?;

src/hyperlight_host/src/sandbox/outb.rs

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

257257
let new_mgr = || {
258-
let mut exe_info = simple_guest_exe_info().unwrap();
259-
let mut mgr = SandboxMemoryManager::load_guest_binary_into_memory(
260-
sandbox_cfg,
261-
&mut exe_info,
262-
None,
263-
)
264-
.unwrap();
258+
let exe_info = simple_guest_exe_info().unwrap();
259+
let mut mgr =
260+
SandboxMemoryManager::load_guest_binary_into_memory(sandbox_cfg, exe_info, None)
261+
.unwrap();
265262
let mem_size = mgr.get_shared_mem_mut().mem_size();
266263
let layout = mgr.layout;
267264
let shared_mem = mgr.get_shared_mem_mut();
@@ -370,10 +367,10 @@ mod tests {
370367
let sandbox_cfg = SandboxConfiguration::default();
371368
tracing::subscriber::with_default(subscriber.clone(), || {
372369
let new_mgr = || {
373-
let mut exe_info = simple_guest_exe_info().unwrap();
370+
let exe_info = simple_guest_exe_info().unwrap();
374371
let mut mgr = SandboxMemoryManager::load_guest_binary_into_memory(
375372
sandbox_cfg,
376-
&mut exe_info,
373+
exe_info,
377374
None,
378375
)
379376
.unwrap();

src/hyperlight_host/src/sandbox/uninitialized.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,12 +309,12 @@ impl UninitializedSandbox {
309309
guest_binary: &GuestBinary,
310310
guest_blob: Option<&GuestBlob>,
311311
) -> Result<SandboxMemoryManager<ExclusiveSharedMemory>> {
312-
let mut exe_info = match guest_binary {
312+
let exe_info = match guest_binary {
313313
GuestBinary::FilePath(bin_path_str) => ExeInfo::from_file(bin_path_str)?,
314314
GuestBinary::Buffer(buffer) => ExeInfo::from_buf(buffer)?,
315315
};
316316

317-
SandboxMemoryManager::load_guest_binary_into_memory(cfg, &mut exe_info, guest_blob)
317+
SandboxMemoryManager::load_guest_binary_into_memory(cfg, exe_info, guest_blob)
318318
}
319319

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

0 commit comments

Comments
 (0)