Skip to content

Commit

Permalink
misc(vm): vm_flags -> flags
Browse files Browse the repository at this point in the history
Signed-off-by: Anhad Singh <[email protected]>
  • Loading branch information
Andy-Python-Programmer committed Jul 3, 2024
1 parent 773565f commit 08f1190
Showing 1 changed file with 25 additions and 30 deletions.
55 changes: 25 additions & 30 deletions src/aero_kernel/src/userland/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ impl MMapFile {

#[derive(Clone)]
pub struct Mapping {
vm_flags: VmFlag,
flags: VmFlag,

pub start_addr: VirtAddr,
pub end_addr: VirtAddr,
Expand All @@ -382,22 +382,21 @@ pub struct Mapping {

impl Mapping {
pub fn set_protection(&mut self, protection: MMapProt) -> aero_syscall::Result<()> {
if (protection.contains(MMapProt::PROT_READ) && !self.vm_flags.contains(VmFlag::MAY_READ))
if (protection.contains(MMapProt::PROT_READ) && !self.flags.contains(VmFlag::MAY_READ))
|| (protection.contains(MMapProt::PROT_WRITE)
&& !self.vm_flags.contains(VmFlag::MAY_WRITE))
|| (protection.contains(MMapProt::PROT_EXEC)
&& !self.vm_flags.contains(VmFlag::MAY_EXEC))
&& !self.flags.contains(VmFlag::MAY_WRITE))
|| (protection.contains(MMapProt::PROT_EXEC) && !self.flags.contains(VmFlag::MAY_EXEC))
{
return Err(aero_syscall::SyscallError::EACCES);
}

self.vm_flags = (self.vm_flags & !VM_PROT_MASK) | protection.into();
self.flags = (self.flags & !VM_PROT_MASK) | protection.into();
Ok(())
}

#[inline]
pub fn protection(&self) -> VmFlag {
self.vm_flags & VM_PROT_MASK
self.flags & VM_PROT_MASK
}

/// Handler routine for private anonymous pages. Since its an anonymous page is not
Expand All @@ -421,9 +420,7 @@ impl Mapping {
// NOTE: We dont need to remove the writeable flag from this mapping, since
// the writeable flag will be removed from the parent and child on fork so,
// the mapping gets copied on write.
PageTableFlags::USER_ACCESSIBLE
| PageTableFlags::PRESENT
| self.vm_flags.into(),
PageTableFlags::USER_ACCESSIBLE | PageTableFlags::PRESENT | self.flags.into(),
)
}
.expect("Failed to identity map userspace private mapping")
Expand All @@ -446,7 +443,7 @@ impl Mapping {
page,
PageTableFlags::USER_ACCESSIBLE
| PageTableFlags::PRESENT
| self.vm_flags.into(),
| self.flags.into(),
)
.unwrap()
.flush();
Expand Down Expand Up @@ -475,7 +472,7 @@ impl Mapping {
let addr = addr.align_down(Size4KiB::SIZE);
let size = Size4KiB::SIZE.min(file.size as u64 - (addr - self.start_addr));

return if self.vm_flags.contains(VmFlag::SHARED) {
return if self.flags.contains(VmFlag::SHARED) {
self.handle_pf_shared_file(offset_table, reason, addr, offset as _, size as _)
} else {
self.handle_pf_private_file(offset_table, reason, addr, offset as _, size as _)
Expand Down Expand Up @@ -532,7 +529,7 @@ impl Mapping {
frame,
PageTableFlags::PRESENT
| PageTableFlags::USER_ACCESSIBLE
| (self.vm_flags & !VmFlag::WRITE).into(),
| (self.flags & !VmFlag::WRITE).into(),
)
}
.expect("failed to map allocated frame for private file read")
Expand All @@ -553,9 +550,7 @@ impl Mapping {
offset_table.map_to(
Page::containing_address(addr),
frame,
PageTableFlags::PRESENT
| PageTableFlags::USER_ACCESSIBLE
| self.vm_flags.into(),
PageTableFlags::PRESENT | PageTableFlags::USER_ACCESSIBLE | self.flags.into(),
)
}
.expect("failed to map allocated frame for private file read")
Expand Down Expand Up @@ -607,7 +602,7 @@ impl Mapping {
page_cache.page(),
PageTableFlags::PRESENT
| PageTableFlags::USER_ACCESSIBLE
| self.vm_flags.into(),
| self.flags.into(),
)
}
.unwrap()
Expand All @@ -621,7 +616,7 @@ impl Mapping {
page_cache.page(),
PageTableFlags::PRESENT
| PageTableFlags::USER_ACCESSIBLE
| (self.vm_flags & !VmFlag::WRITE).into(),
| (self.flags & !VmFlag::WRITE).into(),
)
}
.unwrap()
Expand All @@ -636,7 +631,7 @@ impl Mapping {
frame,
PageTableFlags::PRESENT
| PageTableFlags::USER_ACCESSIBLE
| self.vm_flags.into(),
| self.flags.into(),
)
}
.unwrap()
Expand Down Expand Up @@ -710,15 +705,15 @@ impl Mapping {
if let Some(vm_frame) = phys_addr.as_vm_frame() {
if vm_frame.ref_count() > 1 || copy {
// This page is used by more then one process, so make it a private copy.
Self::map_copied(offset_table, page, self.vm_flags).unwrap();
Self::map_copied(offset_table, page, self.flags).unwrap();
} else {
// This page is used by only one process, so make it writable.
unsafe {
offset_table.update_flags(
page,
PageTableFlags::PRESENT
| PageTableFlags::USER_ACCESSIBLE
| self.vm_flags.into(),
| self.flags.into(),
)
}
.unwrap()
Expand Down Expand Up @@ -769,7 +764,7 @@ impl Mapping {
end_addr: end + (self.end_addr - end),
file: new_file,
refresh_flags: true,
vm_flags: self.vm_flags,
flags: self.flags,
};

self.end_addr = start;
Expand Down Expand Up @@ -857,21 +852,21 @@ impl VmProtected {
}

if reason.contains(PageFaultErrorCode::CAUSED_BY_WRITE)
&& !map.vm_flags.contains(VmFlag::WRITE)
&& !map.flags.contains(VmFlag::WRITE)
{
return false;
}

if reason.contains(PageFaultErrorCode::INSTRUCTION_FETCH)
&& !map.vm_flags.contains(VmFlag::EXEC)
&& !map.flags.contains(VmFlag::EXEC)
{
return false;
}

let mut address_space = AddressSpace::this();
let mut offset_table = address_space.offset_page_table();

match (!map.vm_flags.contains(VmFlag::SHARED), map.file.is_none()) {
match (!map.flags.contains(VmFlag::SHARED), map.file.is_none()) {
(true, true) => {
map.handle_pf_private_anon(&mut offset_table, reason, accessed_address)
}
Expand Down Expand Up @@ -1024,7 +1019,7 @@ impl VmProtected {
// Merge same mappings instead of creating a new one.
if let Some(prev) = cursor.peek_prev() {
if prev.end_addr == addr
&& prev.vm_flags == vm_flags
&& prev.flags == vm_flags
&& prev.file.is_none()
&& file.is_none()
{
Expand All @@ -1039,7 +1034,7 @@ impl VmProtected {

file: file.map(|f| MMapFile::new(f, offset, size)),
refresh_flags: true,
vm_flags,
flags: vm_flags,
});

addr
Expand Down Expand Up @@ -1071,7 +1066,7 @@ impl VmProtected {
"{:?}..{:?} => {:?} (offset={:#x}, size={:#x})",
mmap.start_addr,
mmap.end_addr,
mmap.vm_flags,
mmap.flags,
file.offset,
file.size,
);
Expand All @@ -1080,7 +1075,7 @@ impl VmProtected {
"{:?}..{:?} => {:?}",
mmap.start_addr,
mmap.end_addr,
mmap.vm_flags,
mmap.flags,
);
}
}
Expand Down Expand Up @@ -1365,7 +1360,7 @@ impl VmProtected {

for map in self.mappings.iter().filter(|map| {
// Do not copy page table entries where a page fault can map them correctly.
!map.vm_flags.contains(VmFlag::SHARED) && map.vm_flags.contains(VmFlag::MAY_WRITE)
!map.flags.contains(VmFlag::SHARED) && map.flags.contains(VmFlag::MAY_WRITE)
}) {
offset_table.copy_page_range(&mut current, map.start_addr..=map.end_addr);
}
Expand Down

0 comments on commit 08f1190

Please sign in to comment.