Skip to content

Commit 6395c96

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 91277a7 commit 6395c96

File tree

5 files changed

+14
-10
lines changed

5 files changed

+14
-10
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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,10 +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();
231+
let exe_info = simple_guest_exe_info().unwrap();
232232
let mut mgr = SandboxMemoryManager::load_guest_binary_into_memory(
233233
sandbox_cfg,
234-
&mut exe_info,
234+
exe_info,
235235
false,
236236
)
237237
.unwrap();
@@ -348,10 +348,10 @@ mod tests {
348348
let sandbox_cfg = SandboxConfiguration::default();
349349
tracing::subscriber::with_default(subscriber.clone(), || {
350350
let new_mgr = || {
351-
let mut exe_info = simple_guest_exe_info().unwrap();
351+
let exe_info = simple_guest_exe_info().unwrap();
352352
let mut mgr = SandboxMemoryManager::load_guest_binary_into_memory(
353353
sandbox_cfg,
354-
&mut exe_info,
354+
exe_info,
355355
false,
356356
)
357357
.unwrap();

src/hyperlight_host/src/sandbox/uninitialized.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,11 @@ 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(
303+
cfg,
304+
exe_info,
305+
inprocess,
306+
)
303307
}
304308
}
305309
}

0 commit comments

Comments
 (0)