Commit cff5f248 authored by Nifou's avatar Nifou

Add a constant PAGE_SIZE

parent 5e95eaa3
......@@ -28,7 +28,7 @@ use goblin::elf::{
use x86_64::structures::paging::page_table::PageTableFlags as Flags;
use crate::memory;
use crate::memory::{self, PAGE_SIZE};
use crate::tasking::{
process::ProcessBuilder,
info::{
......@@ -108,7 +108,7 @@ impl<'a> ElfLoader<'a> {
}
auxv.insert(AuxVecItem::PHENT as u8, self.binary.header.e_phentsize as usize);
auxv.insert(AuxVecItem::PHNUM as u8, self.binary.header.e_phnum as usize);
auxv.insert(AuxVecItem::PAGESZ as u8, 4096); // TODO: Constant?
auxv.insert(AuxVecItem::PAGESZ as u8, PAGE_SIZE);
auxv.insert(AuxVecItem::ENTRY as u8, self.binary.header.e_entry as usize);
ProcessInfo { args, envs, auxv, first_arg_addr: 0 }
......@@ -168,7 +168,7 @@ impl<'a> ElfLoader<'a> {
let mut area = MemoryArea::new(
mappings.first().unwrap().1.start_address().as_u64(),
mappings.last().unwrap().1.start_address().as_u64() + 4096, // TODO: Constant?
mappings.last().unwrap().1.start_address().as_u64() + PAGE_SIZE as u64,
flags
);
area.mappings(mappings.clone());
......
......@@ -45,7 +45,7 @@ use crate::{
},
},
memory::{
TMP_PAGE_ADDR,
TMP_PAGE_ADDR, PAGE_SIZE,
table::TemporaryPage,
},
};
......@@ -301,10 +301,10 @@ pub extern "x86-interrupt" fn page_fault_handler(stack_frame: &mut InterruptStac
// ---
{
let src = (addr.as_u64() - (addr.as_u64() % 4096)) as *const u8;
let src = (addr.as_u64() - (addr.as_u64() % PAGE_SIZE as u64)) as *const u8;
let dest = tmp.map(frame.clone(), Flags::PRESENT | Flags::WRITABLE | Flags::NO_EXECUTE) as *mut u8;
unsafe { copy_nonoverlapping(src, dest, 4096 /* TODO: Constant? */) };
unsafe { copy_nonoverlapping(src, dest, PAGE_SIZE) };
}
tmp.unmap();
......@@ -326,7 +326,7 @@ pub extern "x86-interrupt" fn page_fault_handler(stack_frame: &mut InterruptStac
// FIXME: Map with ProcessPageTable::map and change the frame in the areas
let mut area = MemoryArea::new(
page.start_address().as_u64(),
page.start_address().as_u64() + 4096,
page.start_address().as_u64() + PAGE_SIZE as u64,
flags
);
area.mappings(vec![(frame, page)]);
......
......@@ -64,6 +64,9 @@ pub const MULTIBOOT_START_PHYS: u64 = KERNEL_START_PHYS + KERNEL_SIZE;
/// The size of the multiboot information structure
pub const MULTIBOOT_SIZE: u64 = 0xa000;
/// The size of a page of virtual memory
pub const PAGE_SIZE: usize = 4096;
lazy_static! {
/// A global kernel memory mapper
pub static ref KERNEL_MAPPER: Once<Mutex<RecursivePageTable<'static>>> = Once::new();
......@@ -128,7 +131,7 @@ fn remap_kernel(frame: PhysFrame) -> RecursivePageTable<'static> {
Page::containing_address(VirtAddr::new(KERNEL_START_VIRT)),
Page::containing_address(VirtAddr::new(KERNEL_START_VIRT + KERNEL_SIZE))
).enumerate() {
let frame = PhysFrame::containing_address(PhysAddr::new(KERNEL_START_PHYS + i as u64 * 4096));
let frame = PhysFrame::containing_address(PhysAddr::new(KERNEL_START_PHYS + i as u64 * PAGE_SIZE as u64));
unsafe { mapper.map_to(page, frame, Flags::PRESENT | Flags::WRITABLE, &mut *FRAME_ALLOCATOR.r#try().unwrap().lock()).unwrap().ignore(); }
}
......@@ -137,7 +140,7 @@ fn remap_kernel(frame: PhysFrame) -> RecursivePageTable<'static> {
Page::containing_address(VirtAddr::new(HEAP_START_VIRT)),
Page::containing_address(VirtAddr::new(HEAP_START_VIRT + HEAP_SIZE as u64))
).enumerate() {
let frame = PhysFrame::containing_address(PhysAddr::new(HEAP_START_PHYS + i as u64 * 4096));
let frame = PhysFrame::containing_address(PhysAddr::new(HEAP_START_PHYS + i as u64 * PAGE_SIZE as u64));
unsafe { mapper.map_to(page, frame, Flags::PRESENT | Flags::WRITABLE, &mut *FRAME_ALLOCATOR.r#try().unwrap().lock()).unwrap().ignore(); }
}
......
......@@ -29,7 +29,7 @@ use x86_64::{
},
};
use crate::memory;
use crate::memory::{self, PAGE_SIZE};
use crate::memory::table::ProcessPageTable;
#[derive(PartialEq, Debug, Clone)]
......@@ -64,7 +64,7 @@ impl ProcessMemory {
Page::containing_address(VirtAddr::new(memory::KERNEL_START_VIRT)),
Page::containing_address(VirtAddr::new(memory::KERNEL_START_VIRT + memory::KERNEL_SIZE))
).enumerate() {
let frame = PhysFrame::containing_address(PhysAddr::new(memory::KERNEL_START_PHYS + i as u64 * 4096));
let frame = PhysFrame::containing_address(PhysAddr::new(memory::KERNEL_START_PHYS + i as u64 * PAGE_SIZE as u64));
unsafe { mapper.map_to(page, frame, Flags::PRESENT | Flags::WRITABLE, &mut *memory::FRAME_ALLOCATOR.r#try().unwrap().lock()).unwrap().ignore(); }
}
......@@ -73,7 +73,7 @@ impl ProcessMemory {
Page::containing_address(VirtAddr::new(memory::heap::HEAP_START_VIRT as u64)),
Page::containing_address(VirtAddr::new(memory::heap::HEAP_START_VIRT as u64 + memory::heap::HEAP_SIZE as u64))
).enumerate() {
let frame = PhysFrame::containing_address(PhysAddr::new(memory::heap::HEAP_START_PHYS + i as u64 * 4096));
let frame = PhysFrame::containing_address(PhysAddr::new(memory::heap::HEAP_START_PHYS + i as u64 * PAGE_SIZE as u64));
unsafe { mapper.map_to(page, frame, Flags::PRESENT | Flags::WRITABLE, &mut *memory::FRAME_ALLOCATOR.r#try().unwrap().lock()).unwrap().ignore(); }
}
});
......@@ -98,8 +98,8 @@ impl ProcessMemory {
}
// Round the start and end addresses of the area by 4096 (the size of a page)
area.start = area.start - (area.start % 4096);
area.end = area.end + (area.end % 4096);
area.start = area.start - (area.start % PAGE_SIZE as u64);
area.end = area.end + (area.end % PAGE_SIZE as u64);
area.flags.set(Flags::USER_ACCESSIBLE, true);
// Add the area in the list of existing areas
......
......@@ -22,7 +22,7 @@ use x86_64::structures::paging::{
page_table::PageTableFlags as Flags,
};
use crate::memory;
use crate::memory::{self, PAGE_SIZE};
use super::{
memory::{ProcessMemory, MemoryArea},
info::ProcessInfo,
......@@ -99,7 +99,7 @@ impl Process {
// Add the mappings in the process' page table
let mut area = MemoryArea::new(
mappings.first().unwrap().1.start_address().as_u64(),
mappings.last().unwrap().1.start_address().as_u64() + 4096, // TODO: Constant?
mappings.last().unwrap().1.start_address().as_u64() + PAGE_SIZE as u64,
Flags::PRESENT | Flags::WRITABLE
);
area.mappings(mappings.clone());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment