Use RMM TableKind and fix x86_64 compilation

This commit is contained in:
Jeremy Soller
2021-05-03 21:15:46 -06:00
parent 2aa4d8caf5
commit 8d61c79b23
16 changed files with 61 additions and 179 deletions

View File

@@ -3,7 +3,7 @@ use core::ptr::{self, NonNull};
use linked_list_allocator::Heap;
use spin::Mutex;
use crate::paging::{ActivePageTable, PageTableType};
use crate::paging::{ActivePageTable, TableKind};
static HEAP: Mutex<Option<Heap>> = Mutex::new(None);
@@ -32,7 +32,7 @@ unsafe impl GlobalAlloc for Allocator {
panic!("__rust_allocate: heap not initialized");
};
super::map_heap(&mut ActivePageTable::new(PageTableType::Kernel), crate::KERNEL_HEAP_OFFSET + size, crate::KERNEL_HEAP_SIZE);
super::map_heap(&mut ActivePageTable::new(TableKind::Kernel), crate::KERNEL_HEAP_OFFSET + size, crate::KERNEL_HEAP_SIZE);
if let Some(ref mut heap) = *HEAP.lock() {
heap.extend(crate::KERNEL_HEAP_SIZE);

View File

@@ -1,7 +1,7 @@
use core::mem;
use goblin::elf::sym;
use crate::paging::{ActivePageTable, PageTableType, VirtualAddress};
use crate::paging::{ActivePageTable, TableKind, VirtualAddress};
/// Get a stack trace
//TODO: Check for stack being mapped before dereferencing
@@ -12,8 +12,8 @@ pub unsafe fn stack_trace() {
println!("TRACE: {:>016x}", fp);
//Maximum 64 frames
let active_ktable = ActivePageTable::new(PageTableType::Kernel);
let active_utable = ActivePageTable::new(PageTableType::User);
let active_ktable = ActivePageTable::new(TableKind::Kernel);
let active_utable = ActivePageTable::new(TableKind::User);
let in_kernel_or_user_table = |ptr| {
active_ktable.translate(VirtualAddress::new(ptr)).is_some() ||
active_utable.translate(VirtualAddress::new(ptr)).is_some()

View File

@@ -111,11 +111,11 @@ impl Mapper {
let mut translated_flags: PageDescriptorFlags = PageDescriptorFlags::VALID | PageDescriptorFlags::PAGE | PageDescriptorFlags::AF;
if flags.contains(EntryFlags::NO_EXECUTE) {
match page.start_address().get_type() {
VirtualAddressType::User => {
match page.start_address().kind() {
TableKind::User => {
translated_flags.insert(PageDescriptorFlags::UXN);
},
VirtualAddressType::Kernel => {
TableKind::Kernel => {
translated_flags.insert(PageDescriptorFlags::PXN);
},
}

View File

@@ -9,10 +9,10 @@ use crate::device::cpu::registers::{control_regs, tlb};
use crate::memory::{allocate_frames, Frame};
use self::entry::{EntryFlags, TableDescriptorFlags};
use self::mapper::{Mapper, MapperFlushAll, MapperType};
use self::mapper::{Mapper, MapperFlushAll};
use self::temporary_page::TemporaryPage;
pub use rmm::PhysicalAddress;
pub use rmm::{PhysicalAddress, TableKind, VirtualAddress};
pub mod entry;
pub mod mapper;
@@ -211,11 +211,6 @@ pub struct ActivePageTable {
locked: bool,
}
pub enum PageTableType {
User,
Kernel
}
impl Deref for ActivePageTable {
type Target = Mapper;
@@ -232,24 +227,18 @@ impl DerefMut for ActivePageTable {
impl ActivePageTable {
//TODO: table_type argument
pub unsafe fn new(table_type: PageTableType) -> ActivePageTable {
pub unsafe fn new(table_kind: TableKind) -> ActivePageTable {
page_table_lock();
ActivePageTable {
mapper: Mapper::new(match table_type {
PageTableType::User => MapperType::User,
PageTableType::Kernel => MapperType::Kernel,
}),
mapper: Mapper::new(table_kind),
locked: true,
}
}
//TODO: table_type argument
pub unsafe fn new_unlocked(table_type: PageTableType) -> ActivePageTable {
pub unsafe fn new_unlocked(table_kind: TableKind) -> ActivePageTable {
ActivePageTable {
mapper: Mapper::new(match table_type {
PageTableType::User => MapperType::User,
PageTableType::Kernel => MapperType::Kernel,
}),
mapper: Mapper::new(table_kind),
locked: false,
}
}
@@ -376,34 +365,6 @@ impl InactivePageTable {
}
}
/// A virtual address.
#[derive(Copy, Clone, Debug, Eq, Ord, PartialEq, PartialOrd)]
pub struct VirtualAddress(usize);
#[derive(Debug, PartialEq)]
pub enum VirtualAddressType {
User,
Kernel
}
impl VirtualAddress {
pub fn new(address: usize) -> Self {
VirtualAddress(address)
}
pub fn data(&self) -> usize {
self.0
}
pub fn get_type(&self) -> VirtualAddressType {
if ((self.0 >> 48) & 0xffff) == 0xffff {
VirtualAddressType::Kernel
} else {
VirtualAddressType::User
}
}
}
/// Page
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub struct Page {

View File

@@ -177,8 +177,8 @@ pub unsafe fn init_generic(is_bsp: bool, idt: &mut Idt) {
use crate::memory::{Frame, PhysicalAddress};
use crate::paging::{ActivePageTable, Page, VirtualAddress};
let mut active_table = ActivePageTable::new();
let base_virtual_address = VirtualAddress::new(frames.start_address().data() + crate::PHYS_OFFSET);
let mut active_table = ActivePageTable::new(base_virtual_address.kind());
for i in 0..page_count {
let virtual_address = VirtualAddress::new(base_virtual_address.data() + i * crate::memory::PAGE_SIZE);

View File

@@ -2,7 +2,7 @@ use core::{mem, str};
use goblin::elf::sym;
use rustc_demangle::demangle;
use crate::paging::{ActivePageTable, PageTableType, VirtualAddress};
use crate::paging::{ActivePageTable, TableKind, VirtualAddress};
/// Get a stack trace
//TODO: Check for stack being mapped before dereferencing
@@ -13,7 +13,7 @@ pub unsafe fn stack_trace() {
println!("TRACE: {:>016X}", rbp);
//Maximum 64 frames
let active_table = ActivePageTable::new(PageTableType::User);
let active_table = ActivePageTable::new(TableKind::User);
for _frame in 0..64 {
if let Some(rip_rbp) = rbp.checked_add(mem::size_of::<usize>()) {
if active_table.translate(VirtualAddress::new(rbp)).is_some() && active_table.translate(VirtualAddress::new(rip_rbp)).is_some() {

View File

@@ -15,6 +15,8 @@ pub use rmm::{
Arch as RmmArch,
PageFlags,
PhysicalAddress,
TableKind,
VirtualAddress,
X8664Arch as RmmA,
};
@@ -184,7 +186,7 @@ pub unsafe fn init(
init_pat();
let mut active_table = ActivePageTable::new_unlocked(PageTableType::User);
let mut active_table = ActivePageTable::new_unlocked(TableKind::User);
let flush_all = map_tss(cpu_id, &mut active_table);
flush_all.flush();
@@ -198,7 +200,7 @@ pub unsafe fn init_ap(
) -> usize {
init_pat();
let mut active_table = ActivePageTable::new_unlocked(PageTableType::User);
let mut active_table = ActivePageTable::new_unlocked(TableKind::User);
let mut new_table = InactivePageTable::from_address(bsp_table);
@@ -225,11 +227,6 @@ pub struct ActivePageTable {
locked: bool,
}
pub enum PageTableType {
User,
Kernel
}
impl Deref for ActivePageTable {
type Target = Mapper;
@@ -245,7 +242,7 @@ impl DerefMut for ActivePageTable {
}
impl ActivePageTable {
pub unsafe fn new(_table_type: PageTableType) -> ActivePageTable {
pub unsafe fn new(_table_kind: TableKind) -> ActivePageTable {
page_table_lock();
ActivePageTable {
mapper: Mapper::new(),
@@ -253,7 +250,7 @@ impl ActivePageTable {
}
}
pub unsafe fn new_unlocked(_table_type: PageTableType) -> ActivePageTable {
pub unsafe fn new_unlocked(_table_kind: TableKind) -> ActivePageTable {
ActivePageTable {
mapper: Mapper::new(),
locked: false,
@@ -379,34 +376,6 @@ impl InactivePageTable {
}
}
/// A virtual address.
#[derive(Copy, Clone, Debug, Eq, Ord, PartialEq, PartialOrd)]
pub struct VirtualAddress(usize);
#[derive(Debug, PartialEq)]
pub enum VirtualAddressType {
User,
Kernel
}
impl VirtualAddress {
pub fn new(address: usize) -> Self {
VirtualAddress(address)
}
pub fn data(&self) -> usize {
self.0
}
pub fn get_type(&self) -> VirtualAddressType {
if ((self.0 >> 48) & 0xffff) == 0xffff {
VirtualAddressType::Kernel
} else {
VirtualAddressType::User
}
}
}
/// Page
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub struct Page {

View File

@@ -4,7 +4,7 @@ use alloc::collections::BTreeMap;
use core::alloc::{GlobalAlloc, Layout};
use core::{iter, mem};
use core::sync::atomic::Ordering;
use crate::paging::{ActivePageTable, PageTableType};
use crate::paging::{ActivePageTable, TableKind};
use spin::RwLock;
use crate::syscall::error::{Result, Error, EAGAIN};
@@ -100,9 +100,9 @@ impl ContextList {
context.arch.set_context_handle();
}
context.arch.set_page_utable(unsafe { ActivePageTable::new(PageTableType::User).address() });
context.arch.set_page_utable(unsafe { ActivePageTable::new(TableKind::User).address() });
#[cfg(target_arch = "aarch64")]
context.arch.set_page_ktable(unsafe { ActivePageTable::new(PageTableType::Kernel).address() });
context.arch.set_page_ktable(unsafe { ActivePageTable::new(TableKind::Kernel).address() });
context.arch.set_fx(fx.as_ptr() as usize);
context.arch.set_stack(stack.as_ptr() as usize + offset);
context.kfx = Some(fx);

View File

@@ -15,7 +15,7 @@ use crate::arch::paging::PAGE_SIZE;
use crate::context::file::FileDescriptor;
use crate::ipi::{ipi, IpiKind, IpiTarget};
use crate::memory::Frame;
use crate::paging::{ActivePageTable, InactivePageTable, Page, PageFlags, PageTableType, PageIter, PhysicalAddress, RmmA, VirtualAddress};
use crate::paging::{ActivePageTable, InactivePageTable, Page, PageFlags, PageIter, PhysicalAddress, RmmA, VirtualAddress};
use crate::paging::mapper::PageFlushAll;
use crate::paging::temporary_page::TemporaryPage;
@@ -303,10 +303,7 @@ impl Grant {
}
pub fn physmap(from: PhysicalAddress, to: VirtualAddress, size: usize, flags: PageFlags<RmmA>) -> Grant {
let mut active_table = match to.get_type() {
VirtualAddressType::User => unsafe { ActivePageTable::new(PageTableType::User) },
VirtualAddressType::Kernel => unsafe { ActivePageTable::new(PageTableType::Kernel) }
};
let mut active_table = unsafe { ActivePageTable::new(to.kind()) };
let flush_all = PageFlushAll::new();
@@ -333,10 +330,7 @@ impl Grant {
}
pub fn map(to: VirtualAddress, size: usize, flags: PageFlags<RmmA>) -> Grant {
let mut active_table = match to.get_type() {
VirtualAddressType::User => unsafe { ActivePageTable::new(PageTableType::User) },
VirtualAddressType::Kernel => unsafe { ActivePageTable::new(PageTableType::Kernel) }
};
let mut active_table = unsafe { ActivePageTable::new(to.kind()) };
let flush_all = PageFlushAll::new();
@@ -362,10 +356,7 @@ impl Grant {
}
pub fn map_inactive(from: VirtualAddress, to: VirtualAddress, size: usize, flags: PageFlags<RmmA>, desc_opt: Option<FileDescriptor>, new_table: &mut InactivePageTable, temporary_page: &mut TemporaryPage) -> Grant {
let mut active_table = match from.get_type() {
VirtualAddressType::User => unsafe { ActivePageTable::new(PageTableType::User) },
VirtualAddressType::Kernel => unsafe { ActivePageTable::new(PageTableType::Kernel) }
};
let active_table = unsafe { ActivePageTable::new(from.kind()) };
//TODO: Do not allocate
let mut frames = VecDeque::with_capacity(size/PAGE_SIZE);
@@ -377,10 +368,7 @@ impl Grant {
frames.push_back(frame);
}
let mut active_table = match to.get_type() {
VirtualAddressType::User => unsafe { ActivePageTable::new(PageTableType::User) },
VirtualAddressType::Kernel => unsafe { ActivePageTable::new(PageTableType::Kernel) }
};
let mut active_table = unsafe { ActivePageTable::new(to.kind()) };
active_table.with(new_table, temporary_page, |mapper| {
let start_page = Page::containing_address(to);
@@ -411,10 +399,7 @@ impl Grant {
pub fn secret_clone(&self, new_start: VirtualAddress) -> Grant {
assert!(self.mapped);
let mut active_table = match new_start.get_type() {
VirtualAddressType::User => unsafe { ActivePageTable::new(PageTableType::User) },
VirtualAddressType::Kernel => unsafe { ActivePageTable::new(PageTableType::Kernel) }
};
let mut active_table = unsafe { ActivePageTable::new(new_start.kind()) };
let flush_all = PageFlushAll::new();
@@ -471,10 +456,7 @@ impl Grant {
pub fn move_to(&mut self, new_start: VirtualAddress, new_table: &mut InactivePageTable, temporary_page: &mut TemporaryPage) {
assert!(self.mapped);
let mut active_table = match new_start.get_type() {
VirtualAddressType::User => unsafe { ActivePageTable::new(PageTableType::User) },
VirtualAddressType::Kernel => unsafe { ActivePageTable::new(PageTableType::Kernel) }
};
let mut active_table = unsafe { ActivePageTable::new(new_start.kind()) };
let flush_all = PageFlushAll::new();
@@ -510,10 +492,7 @@ impl Grant {
pub fn unmap(mut self) {
assert!(self.mapped);
let mut active_table = match self.start_address().get_type() {
VirtualAddressType::User => unsafe { ActivePageTable::new(PageTableType::User) },
VirtualAddressType::Kernel => unsafe { ActivePageTable::new(PageTableType::Kernel) }
};
let mut active_table = unsafe { ActivePageTable::new(self.start_address().kind()) };
let flush_all = PageFlushAll::new();
@@ -543,10 +522,7 @@ impl Grant {
pub fn unmap_inactive(mut self, new_table: &mut InactivePageTable, temporary_page: &mut TemporaryPage) {
assert!(self.mapped);
let mut active_table = match self.start_address().get_type() {
VirtualAddressType::User => unsafe { ActivePageTable::new(PageTableType::User) },
VirtualAddressType::Kernel => unsafe { ActivePageTable::new(PageTableType::Kernel) }
};
let mut active_table = unsafe { ActivePageTable::new(self.start_address().kind()) };
active_table.with(new_table, temporary_page, |mapper| {
let start_page = Page::containing_address(self.start_address());
@@ -721,10 +697,7 @@ impl Memory {
}
fn map(&mut self, clear: bool) {
let mut active_table = match self.start.get_type() {
VirtualAddressType::User => unsafe { ActivePageTable::new(PageTableType::User) },
VirtualAddressType::Kernel => unsafe { ActivePageTable::new(PageTableType::Kernel) }
};
let mut active_table = unsafe { ActivePageTable::new(self.start.kind()) };
let flush_all = PageFlushAll::new();
@@ -744,10 +717,7 @@ impl Memory {
}
fn unmap(&mut self) {
let mut active_table = match self.start.get_type() {
VirtualAddressType::User => unsafe { ActivePageTable::new(PageTableType::User) },
VirtualAddressType::Kernel => unsafe { ActivePageTable::new(PageTableType::Kernel) }
};
let mut active_table = unsafe { ActivePageTable::new(self.start.kind()) };
let flush_all = PageFlushAll::new();
@@ -762,10 +732,7 @@ impl Memory {
/// A complicated operation to move a piece of memory to a new page table
/// It also allows for changing the address at the same time
pub fn move_to(&mut self, new_start: VirtualAddress, new_table: &mut InactivePageTable, temporary_page: &mut TemporaryPage) {
let mut active_table = match new_start.get_type() {
VirtualAddressType::User => unsafe { ActivePageTable::new(PageTableType::User) },
VirtualAddressType::Kernel => unsafe { ActivePageTable::new(PageTableType::Kernel) }
};
let mut active_table = unsafe { ActivePageTable::new(new_start.kind()) };
let flush_all = PageFlushAll::new();
@@ -787,10 +754,7 @@ impl Memory {
}
pub fn remap(&mut self, new_flags: PageFlags<RmmA>) {
let mut active_table = match self.start.get_type() {
VirtualAddressType::User => unsafe { ActivePageTable::new(PageTableType::User) },
VirtualAddressType::Kernel => unsafe { ActivePageTable::new(PageTableType::Kernel) }
};
let mut active_table = unsafe { ActivePageTable::new(self.start.kind()) };
let flush_all = PageFlushAll::new();
@@ -805,10 +769,7 @@ impl Memory {
}
pub fn resize(&mut self, new_size: usize, clear: bool) {
let mut active_table = match self.start.get_type() {
VirtualAddressType::User => unsafe { ActivePageTable::new(PageTableType::User) },
VirtualAddressType::Kernel => unsafe { ActivePageTable::new(PageTableType::Kernel) }
};
let mut active_table = unsafe { ActivePageTable::new(self.start.kind()) };
//TODO: Calculate page changes to minimize operations
if new_size > self.size {

View File

@@ -8,7 +8,7 @@ use crate::{
paging::{
mapper::PageFlushAll,
temporary_page::TemporaryPage,
ActivePageTable, InactivePageTable, PageTableType, Page, PAGE_SIZE, VirtualAddress
ActivePageTable, InactivePageTable, Page, PAGE_SIZE, TableKind, VirtualAddress
}
},
common::unique::Unique,
@@ -457,7 +457,7 @@ where F: FnOnce(*mut u8) -> Result<()>
// in `proc:<pid>/mem`, or return a partial read/write.
let start = Page::containing_address(VirtualAddress::new(crate::USER_TMP_MISC_OFFSET));
let mut active_page_table = unsafe { ActivePageTable::new(PageTableType::User) };
let mut active_page_table = unsafe { ActivePageTable::new(TableKind::User) };
let mut target_page_table = unsafe {
InactivePageTable::from_address(context.arch.get_page_utable())
};

View File

@@ -17,7 +17,7 @@ use spin::{Mutex, RwLock};
use crate::acpi::sdt::Sdt;
use crate::acpi::SdtSignature;
use crate::paging::ActivePageTable;
use crate::paging::{ActivePageTable, TableKind};
#[derive(Clone, Copy)]
struct PhysSlice {
@@ -92,7 +92,7 @@ enum Handle {
impl AcpiScheme {
fn get_tables() -> Vec<(SdtSignature, PhysSlice)> {
let mut active_table = unsafe { ActivePageTable::new() };
let mut active_table = unsafe { ActivePageTable::new(TableKind::Kernel) };
let mut tables = Vec::new();
@@ -427,7 +427,7 @@ impl Scheme for AcpiScheme {
) = self.tables[index];
assert_eq!(phys_ptr, old_virt);
let new_virt =
crate::acpi::get_sdt(phys_ptr, unsafe { &mut ActivePageTable::new() })
crate::acpi::get_sdt(phys_ptr, unsafe { &mut ActivePageTable::new(TableKind::Kernel) })
as *const Sdt as usize;
let table_contents =

View File

@@ -1,7 +1,7 @@
use crate::context;
use crate::context::memory::{page_flags, Grant};
use crate::memory::{free_frames, used_frames, PAGE_SIZE};
use crate::paging::{ActivePageTable, PageTableType, VirtualAddress, VirtualAddressType};
use crate::paging::{ActivePageTable, VirtualAddress};
use crate::syscall::data::{Map, OldMap, StatVfs};
use crate::syscall::error::*;
use crate::syscall::flag::MapFlags;
@@ -48,10 +48,7 @@ impl Scheme for MemoryScheme {
// Make sure it's *absolutely* not mapped already
// TODO: Keep track of all allocated memory so this isn't necessary
let active_table = match VirtualAddress::new(map.address).get_type() {
VirtualAddressType::User => unsafe { ActivePageTable::new(PageTableType::User) },
VirtualAddressType::Kernel => unsafe { ActivePageTable::new(PageTableType::Kernel) }
};
let active_table = unsafe { ActivePageTable::new(VirtualAddress::new(map.address).kind()) };
for page in region.pages() {
if active_table.translate_page(page).is_some() {

View File

@@ -1,6 +1,6 @@
use crate::interrupt::InterruptStack;
use crate::memory::{allocate_frames_complex, deallocate_frames, Frame};
use crate::paging::{ActivePageTable, PageFlags, PageTableType, PhysicalAddress, VirtualAddress};
use crate::paging::{ActivePageTable, PageFlags, PhysicalAddress, VirtualAddress};
use crate::paging::entry::EntryFlags;
use crate::context;
use crate::context::memory::{Grant, Region};
@@ -153,10 +153,7 @@ pub fn physunmap(virtual_address: usize) -> Result<usize> {
pub fn virttophys(virtual_address: usize) -> Result<usize> {
enforce_root()?;
let active_table = match VirtualAddress::new(virtual_address).get_type() {
VirtualAddressType::User => unsafe { ActivePageTable::new(PageTableType::User) },
VirtualAddressType::Kernel => unsafe { ActivePageTable::new(PageTableType::Kernel) }
};
let active_table = unsafe { ActivePageTable::new(VirtualAddress::new(virtual_address).kind()) };
match active_table.translate(VirtualAddress::new(virtual_address)) {
Some(physical_address) => Ok(physical_address.data()),

View File

@@ -10,7 +10,7 @@ use spin::{Once, RwLock, RwLockReadGuard, RwLockWriteGuard};
use crate::context::{self, Context};
use crate::time;
use crate::memory::PhysicalAddress;
use crate::paging::{ActivePageTable, VirtualAddress};
use crate::paging::{ActivePageTable, TableKind, VirtualAddress};
use crate::syscall::data::TimeSpec;
use crate::syscall::error::{Error, Result, ESRCH, EAGAIN, EFAULT, EINVAL};
use crate::syscall::flag::{FUTEX_WAIT, FUTEX_WAKE, FUTEX_REQUEUE};
@@ -45,7 +45,7 @@ pub fn futexes_mut() -> RwLockWriteGuard<'static, FutexList> {
// pointee cannot be changed by another thread, which could make atomic ops useless.
pub fn futex(addr: &mut i32, op: usize, val: i32, val2: usize, addr2: *mut i32) -> Result<usize> {
let target_physaddr = unsafe {
let active_table = ActivePageTable::new();
let active_table = ActivePageTable::new(TableKind::User);
let virtual_address = VirtualAddress::new(addr as *mut i32 as usize);
// FIXME: Already validated in syscall/mod.rs
@@ -133,7 +133,7 @@ pub fn futex(addr: &mut i32, op: usize, val: i32, val2: usize, addr2: *mut i32)
},
FUTEX_REQUEUE => {
let addr2_physaddr = unsafe {
let active_table = ActivePageTable::new();
let active_table = ActivePageTable::new(TableKind::User);
let addr2_safe = validate_slice_mut(addr2, 1).map(|addr2_safe| &mut addr2_safe[0])?;
let addr2_virt = VirtualAddress::new(addr2_safe as *mut i32 as usize);

View File

@@ -21,7 +21,7 @@ use crate::ipi::{ipi, IpiKind, IpiTarget};
use crate::memory::allocate_frames;
use crate::paging::mapper::PageFlushAll;
use crate::paging::temporary_page::TemporaryPage;
use crate::paging::{ActivePageTable, InactivePageTable, Page, PageFlags, PageTableType, VirtualAddress, PAGE_SIZE};
use crate::paging::{ActivePageTable, InactivePageTable, Page, PageFlags, TableKind, VirtualAddress, PAGE_SIZE};
use crate::{ptrace, syscall};
use crate::scheme::FileHandle;
use crate::start::usermode;
@@ -352,8 +352,8 @@ pub fn clone(flags: CloneFlags, stack_base: usize) -> Result<ContextId> {
context.arch = arch;
let mut active_utable = unsafe { ActivePageTable::new(PageTableType::User) };
let mut active_ktable = unsafe { ActivePageTable::new(PageTableType::Kernel) };
let mut active_utable = unsafe { ActivePageTable::new(TableKind::User) };
let mut active_ktable = unsafe { ActivePageTable::new(TableKind::Kernel) };
let mut temporary_upage = TemporaryPage::new(Page::containing_address(VirtualAddress::new(crate::USER_TMP_MISC_OFFSET)));
let mut temporary_kpage = TemporaryPage::new(Page::containing_address(VirtualAddress::new(crate::KERNEL_TMP_MISC_OFFSET)));
@@ -399,9 +399,9 @@ pub fn clone(flags: CloneFlags, stack_base: usize) -> Result<ContextId> {
// Copy physmap mapping
{
let frame = active_table.p4()[crate::PHYS_PML4].pointed_frame().expect("physmap not mapped");
let flags = active_table.p4()[crate::PHYS_PML4].flags();
active_table.with(&mut new_table, &mut temporary_page, |mapper| {
let frame = active_ktable.p4()[crate::PHYS_PML4].pointed_frame().expect("physmap not mapped");
let flags = active_ktable.p4()[crate::PHYS_PML4].flags();
active_ktable.with(&mut new_ktable, &mut temporary_kpage, |mapper| {
mapper.p4_mut()[crate::PHYS_PML4].set(frame, flags);
});
}
@@ -1365,7 +1365,7 @@ pub fn mprotect(address: usize, size: usize, flags: MapFlags) -> Result<usize> {
let end_offset = size.checked_sub(1).ok_or(Error::new(EFAULT))?;
let end_address = address.checked_add(end_offset).ok_or(Error::new(EFAULT))?;
let mut active_table = unsafe { ActivePageTable::new(PageTableType::User) };
let mut active_table = unsafe { ActivePageTable::new(TableKind::User) };
let flush_all = PageFlushAll::new();

View File

@@ -1,16 +1,13 @@
use core::{mem, slice, str};
use crate::paging::{ActivePageTable, Page, PageTableType, VirtualAddress};
use crate::paging::{ActivePageTable, Page, VirtualAddress};
use crate::syscall::error::*;
fn validate(address: usize, size: usize, writable: bool) -> Result<()> {
let end_offset = size.checked_sub(1).ok_or(Error::new(EFAULT))?;
let end_address = address.checked_add(end_offset).ok_or(Error::new(EFAULT))?;
let active_table = match VirtualAddress::new(address).get_type() {
VirtualAddressType::User => unsafe { ActivePageTable::new(PageTableType::User) },
VirtualAddressType::Kernel => unsafe { ActivePageTable::new(PageTableType::Kernel) }
};
let active_table = unsafe { ActivePageTable::new(VirtualAddress::new(address).kind()) };
let start_page = Page::containing_address(VirtualAddress::new(address));
let end_page = Page::containing_address(VirtualAddress::new(end_address));