exec with interpreter

This commit is contained in:
Ashwin Naren
2025-12-31 23:35:11 -08:00
parent a8200dc067
commit f0771dde4f
5 changed files with 132 additions and 49 deletions

View File

@@ -13,7 +13,7 @@ const MMAP_BASE: usize = 0x4000_0000_0000;
/// Manages mappings in a process's address space.
pub struct MemoryMap<AS: UserAddressSpace> {
vmas: BTreeMap<VA, VMArea>,
pub(super) vmas: BTreeMap<VA, VMArea>,
address_space: AS,
}

View File

@@ -48,10 +48,21 @@ impl<AS: UserAddressSpace> ProcessVM<AS> {
Ok(Self { mm, brk })
}
pub fn from_map(map: MemoryMap<AS>, brk: VA) -> Self {
pub fn from_map(map: MemoryMap<AS>) -> Self {
// Last entry will be the VMA with the highest address.
let brk = map
.vmas
.last_key_value()
.expect("No VMAs in map")
.1
.region
.end_address()
// VMAs should already be page-aligned, but just in case.
.align_up(PAGE_SIZE);
Self {
mm: map,
brk: VirtMemoryRegion::new(brk.align_up(PAGE_SIZE), 0),
brk: VirtMemoryRegion::new(brk, 0),
}
}

View File

@@ -172,7 +172,7 @@ impl VMAreaKind {
/// managing a process's memory layout.
#[derive(Clone, PartialEq)]
pub struct VMArea {
pub(super) region: VirtMemoryRegion,
pub region: VirtMemoryRegion,
pub(super) kind: VMAreaKind,
pub(super) permissions: VMAPermissions,
}
@@ -205,11 +205,15 @@ impl VMArea {
/// * `f`: A handle to the ELF file's inode.
/// * `hdr`: The ELF program header (`LOAD` segment) to create the VMA from.
/// * `endian`: The endianness of the ELF file, for correctly parsing header fields.
/// * `address_bias`: A bias added to the VAs of the segment.
pub fn from_pheader<E: Endian>(
f: Arc<dyn Inode>,
hdr: ProgramHeader64<E>,
endian: E,
address_bias: Option<usize>,
) -> VMArea {
let address_bias = address_bias.unwrap_or(0);
let mut permissions = VMAPermissions {
read: false,
write: false,
@@ -229,7 +233,7 @@ impl VMArea {
}
let mappable_region = VirtMemoryRegion::new(
VA::from_value(hdr.p_vaddr(endian) as usize),
VA::from_value(hdr.p_vaddr(endian) as usize + address_bias),
hdr.p_memsz(endian) as usize,
)
.to_mappable_region();
@@ -446,6 +450,11 @@ impl VMArea {
VMAreaKind::Anon => new_vma,
}
}
/// Return the virtual memory region managed by this VMA.
pub fn region(&self) -> VirtMemoryRegion {
self.region
}
}
#[cfg(test)]