Skip to content

Commit 6ad8ac6

Browse files
committed
[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 ca67134 commit 6ad8ac6

File tree

5 files changed

+12
-15
lines changed

5 files changed

+12
-15
lines changed

src/hyperlight_host/src/mem/elf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl ElfInfo {
6868
.unwrap(); // guaranteed not to panic because of the check in new()
6969
(max_phdr.p_vaddr + max_phdr.p_memsz - self.get_base_va()) as usize
7070
}
71-
pub(crate) fn load_at(&self, load_addr: usize, target: &mut [u8]) -> Result<()> {
71+
pub(crate) fn load_at(self, load_addr: usize, target: &mut [u8]) -> Result<()> {
7272
let base_va = self.get_base_va();
7373
for phdr in self.phdrs.iter().filter(|phdr| phdr.p_type == PT_LOAD) {
7474
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
@@ -80,9 +80,9 @@ impl ExeInfo {
8080
// copying into target, but the PE loader chooses to apply
8181
// relocations in its owned representation of the PE contents,
8282
// which requires it to be &mut.
83-
pub fn load(&mut self, load_addr: usize, target: &mut [u8]) -> Result<()> {
83+
pub fn load(self, load_addr: usize, target: &mut [u8]) -> Result<()> {
8484
match self {
85-
ExeInfo::PE(pe) => {
85+
ExeInfo::PE(mut pe) => {
8686
let patches = pe.get_exe_relocation_patches(load_addr)?;
8787
pe.apply_relocation_patches(patches)?;
8888
target[0..pe.payload.len()].copy_from_slice(&pe.payload);

src/hyperlight_host/src/mem/mgr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,12 +391,12 @@ impl SandboxMemoryManager<ExclusiveSharedMemory> {
391391
#[instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace")]
392392
pub(crate) fn load_guest_binary_into_memory(
393393
cfg: SandboxConfiguration,
394-
exe_info: &mut ExeInfo,
394+
mut exe_info: ExeInfo,
395395
inprocess: bool,
396396
) -> Result<Self> {
397397
let (layout, mut shared_mem, load_addr, entrypoint_offset) = load_guest_binary_common(
398398
cfg,
399-
exe_info,
399+
&mut exe_info,
400400
|shared_mem: &ExclusiveSharedMemory, layout: &SandboxMemoryLayout| {
401401
let addr_usize = if inprocess {
402402
// if we're running in-process, load_addr is the absolute

src/hyperlight_host/src/sandbox/outb.rs

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

230230
let new_mgr = || {
231-
let mut exe_info = simple_guest_exe_info().unwrap();
232-
let mut mgr = SandboxMemoryManager::load_guest_binary_into_memory(
233-
sandbox_cfg,
234-
&mut exe_info,
235-
false,
236-
)
237-
.unwrap();
231+
let exe_info = simple_guest_exe_info().unwrap();
232+
let mut mgr =
233+
SandboxMemoryManager::load_guest_binary_into_memory(sandbox_cfg, exe_info, false)
234+
.unwrap();
238235
let mem_size = mgr.get_shared_mem_mut().mem_size();
239236
let layout = mgr.layout;
240237
let shared_mem = mgr.get_shared_mem_mut();
@@ -348,10 +345,10 @@ mod tests {
348345
let sandbox_cfg = SandboxConfiguration::default();
349346
tracing::subscriber::with_default(subscriber.clone(), || {
350347
let new_mgr = || {
351-
let mut exe_info = simple_guest_exe_info().unwrap();
348+
let exe_info = simple_guest_exe_info().unwrap();
352349
let mut mgr = SandboxMemoryManager::load_guest_binary_into_memory(
353350
sandbox_cfg,
354-
&mut exe_info,
351+
exe_info,
355352
false,
356353
)
357354
.unwrap();

src/hyperlight_host/src/sandbox/uninitialized.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ impl UninitializedSandbox {
299299
};
300300
SandboxMemoryManager::load_guest_binary_using_load_library(cfg, path, &mut exe_info)
301301
} else {
302-
SandboxMemoryManager::load_guest_binary_into_memory(cfg, &mut exe_info, inprocess)
302+
SandboxMemoryManager::load_guest_binary_into_memory(cfg, exe_info, inprocess)
303303
}
304304
}
305305
}

0 commit comments

Comments
 (0)