Fix phys offset, lock grants correctly.

This commit is contained in:
4lDO2
2022-06-10 11:43:50 +02:00
parent 15b029de36
commit 23f49414bd
3 changed files with 11 additions and 10 deletions

View File

@@ -30,7 +30,7 @@ mod rsdp;
pub fn get_sdt(sdt_address: usize, active_table: &mut ActivePageTable) -> &'static Sdt {
{
let page = Page::containing_address(VirtualAddress::new(sdt_address + crate::KERNEL_OFFSET));
let page = Page::containing_address(VirtualAddress::new(sdt_address + crate::PHYS_OFFSET));
if active_table.translate_page(page).is_none() {
let frame = Frame::containing_address(PhysicalAddress::new(sdt_address));
let result = active_table.map_to(page, frame, PageFlags::new());
@@ -38,15 +38,15 @@ pub fn get_sdt(sdt_address: usize, active_table: &mut ActivePageTable) -> &'stat
}
}
let sdt = unsafe { &*((sdt_address + crate::KERNEL_OFFSET) as *const Sdt) };
let sdt = unsafe { &*((sdt_address + crate::PHYS_OFFSET) as *const Sdt) };
// Map extra SDT frames if required
{
let start_page = Page::containing_address(VirtualAddress::new(sdt_address + 4096 + crate::KERNEL_OFFSET));
let end_page = Page::containing_address(VirtualAddress::new(sdt_address + sdt.length as usize + crate::KERNEL_OFFSET));
let start_page = Page::containing_address(VirtualAddress::new(sdt_address + 4096 + crate::PHYS_OFFSET));
let end_page = Page::containing_address(VirtualAddress::new(sdt_address + sdt.length as usize + crate::PHYS_OFFSET));
for page in Page::range_inclusive(start_page, end_page) {
if active_table.translate_page(page).is_none() {
let frame = Frame::containing_address(PhysicalAddress::new(page.start_address().data() - crate::KERNEL_OFFSET));
let frame = Frame::containing_address(PhysicalAddress::new(page.start_address().data() - crate::PHYS_OFFSET));
let result = active_table.map_to(page, frame, PageFlags::new());
result.flush();
}
@@ -125,7 +125,7 @@ pub unsafe fn init(active_table: &mut ActivePageTable, already_supplied_rsdps: O
rxsdt.map_all(active_table);
for sdt_address in rxsdt.iter() {
let sdt = &*((sdt_address + crate::KERNEL_OFFSET) as *const Sdt);
let sdt = &*((sdt_address + crate::PHYS_OFFSET) as *const Sdt);
let signature = get_sdt_signature(sdt);
if let Some(ref mut ptrs) = *(SDT_POINTERS.write()) {

View File

@@ -94,9 +94,10 @@ impl UserGrants {
// TODO: Alignment (x86_64: 4 KiB, 2 MiB, or 1 GiB).
pub fn find_free(&self, size: usize) -> Option<Region> {
// Get first available hole, but do reserve the page starting from zero as most compiled
// language cannot handle null pointers safely even if they do point to valid memory. If an
// languages cannot handle null pointers safely even if they point to valid memory. If an
// application absolutely needs to map the 0th page, they will have to do so explicitly via
// MAP_FIXED/MAP_FIXED_NOREPLACE.
// TODO: Allow explicitly allocating guard pages?
let (hole_start, hole_size) = self.holes.iter().find(|(hole_offset, hole_size)| size <= if hole_offset.data() == 0 { hole_size.saturating_sub(PAGE_SIZE) } else { **hole_size })?;
// Create new region

View File

@@ -191,8 +191,8 @@ pub fn clone(flags: CloneFlags, stack_base: usize, info: Option<&CloneInfo>) ->
// If not cloning virtual memory, use fmap to re-obtain every grant where possible
if !flags.contains(CLONE_VM) {
let grants = Arc::get_mut(&mut grants).ok_or(Error::new(EBUSY))?.get_mut();
let old_grants = mem::take(grants);
let mut grants = grants.write();
let old_grants = mem::take(&mut *grants);
// TODO: Find some way to do this without having to allocate.
@@ -1018,7 +1018,7 @@ pub fn usermode_bootstrap(mut data: Box<[u8]>) -> ! {
for (index, page) in grant.pages().enumerate() {
let len = if data.len() - index * PAGE_SIZE < PAGE_SIZE { data.len() % PAGE_SIZE } else { PAGE_SIZE };
let frame = active_table.translate_page(page).expect("expected mapped init memory to have a corresponding frame");
unsafe { ((frame.start_address().data() + crate::KERNEL_OFFSET) as *mut u8).copy_from_nonoverlapping(data.as_ptr().add(index * PAGE_SIZE), len); }
unsafe { ((frame.start_address().data() + crate::PHYS_OFFSET) as *mut u8).copy_from_nonoverlapping(data.as_ptr().add(index * PAGE_SIZE), len); }
}
context::contexts().current().expect("expected a context to exist when executing init").read().grants.write().insert(grant);