Skip to content

Commit dec31c8

Browse files
syntacticallysimongdavies
authored andcommitted
Make mem::exe::LoadInfo a struct, instead of an alias
This has the major advantage that it makes it easy to impl Clone on the struct, which will be useful shortly when snapshots start to keep copies of the load info around. Signed-off-by: Simon Davies <[email protected]>
1 parent 90003be commit dec31c8

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

src/hyperlight_host/src/mem/elf.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use goblin::elf32::program_header::PT_LOAD;
2727
#[cfg(feature = "init-paging")]
2828
use goblin::elf64::program_header::PT_LOAD;
2929

30+
use super::exe::LoadInfo;
3031
use crate::{Result, log_then_return, new_error};
3132

3233
#[cfg(feature = "mem_profile")]
@@ -161,11 +162,7 @@ impl ElfInfo {
161162
.unwrap();
162163
(max_phdr.p_vaddr + max_phdr.p_memsz - self.get_base_va()) as usize
163164
}
164-
pub(crate) fn load_at(
165-
self,
166-
load_addr: usize,
167-
target: &mut [u8],
168-
) -> Result<super::exe::LoadInfo> {
165+
pub(crate) fn load_at(self, load_addr: usize, target: &mut [u8]) -> Result<LoadInfo> {
169166
let base_va = self.get_base_va();
170167
for phdr in self.phdrs.iter().filter(|phdr| phdr.p_type == PT_LOAD) {
171168
let start_va = (phdr.p_vaddr - base_va) as usize;
@@ -209,15 +206,17 @@ impl ElfInfo {
209206
if #[cfg(feature = "mem_profile")] {
210207
let va_size = self.get_va_size() as u64;
211208
let base_svma = self.get_base_va();
212-
Ok(Arc::new(UnwindInfo {
213-
payload: self.payload,
214-
load_addr: load_addr as u64,
215-
va_size,
216-
base_svma,
217-
shdrs: self.shdrs,
218-
}))
209+
Ok(LoadInfo {
210+
info: Arc::new(UnwindInfo {
211+
payload: self.payload,
212+
load_addr: load_addr as u64,
213+
va_size,
214+
base_svma,
215+
shdrs: self.shdrs,
216+
})
217+
})
219218
} else {
220-
Ok(())
219+
Ok(LoadInfo {})
221220
}
222221
}
223222
}

src/hyperlight_host/src/mem/exe.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,11 @@ impl<A> framehop::ModuleSectionInfo<A> for &DummyUnwindInfo {
5858
}
5959
}
6060

61-
#[cfg(feature = "mem_profile")]
62-
pub(crate) type LoadInfo = Arc<dyn UnwindInfo>;
63-
#[cfg(not(feature = "mem_profile"))]
64-
pub(crate) type LoadInfo = ();
61+
#[derive(Clone)]
62+
pub(crate) struct LoadInfo {
63+
#[cfg(feature = "mem_profile")]
64+
pub(crate) info: Arc<dyn UnwindInfo>,
65+
}
6566

6667
impl ExeInfo {
6768
pub fn from_file(path: &str) -> Result<Self> {

src/hyperlight_host/src/sandbox/uninitialized_evolve.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ pub(crate) fn set_up_hypervisor_partition(
163163
};
164164

165165
#[cfg(feature = "mem_profile")]
166-
let trace_info = MemTraceInfo::new(_load_info)?;
166+
let trace_info = MemTraceInfo::new(_load_info.info)?;
167167

168168
HyperlightVm::new(
169169
regions,

0 commit comments

Comments
 (0)