This commit is contained in:
pjht 2024-08-17 16:46:09 -05:00
parent 84e0a4d593
commit 127b95f838
Signed by: pjht
GPG Key ID: 7B5F6AFBEC7EE78E
3 changed files with 9 additions and 10 deletions

View File

@ -14,13 +14,14 @@ use hashbrown::HashMap;
use pic8259::ChainedPics; use pic8259::ChainedPics;
use saturating_cast::SaturatingCast; use saturating_cast::SaturatingCast;
use spin::{Lazy, Mutex, RwLock}; use spin::{Lazy, Mutex, RwLock};
use tap::Tap;
use x86_64::{ use x86_64::{
registers::control::Cr2, registers::control::Cr2,
set_general_handler, set_general_handler,
structures::{ structures::{
idt::{InterruptDescriptorTable, InterruptStackFrame, PageFaultErrorCode}, idt::{InterruptDescriptorTable, InterruptStackFrame, PageFaultErrorCode},
paging::{mapper::TranslateResult, Page, PageTableFlags, PageTableIndex, PhysFrame, Translate}, paging::{
mapper::TranslateResult, Page, PageTableFlags, PageTableIndex, PhysFrame, Translate,
},
}, },
PhysAddr, PrivilegeLevel, VirtAddr, PhysAddr, PrivilegeLevel, VirtAddr,
}; };
@ -331,7 +332,7 @@ extern "C" fn syscall_handler() {
retval = failed.into(); retval = failed.into();
} }
7 => { 7 => {
if let Some(mut buffer) = get_buffer(regs.rdx) { if let Some(buffer) = get_buffer(regs.rdx) {
let len = usize(regs.rdi); let len = usize(regs.rdi);
assert!(len <= buffer.len()); assert!(len <= buffer.len());
TASKING.address_spaces_mut(|x| { TASKING.address_spaces_mut(|x| {

View File

@ -8,7 +8,6 @@ use core::{
arch::asm, arch::asm,
ffi::CStr, ffi::CStr,
ptr::{addr_of, addr_of_mut}, ptr::{addr_of, addr_of_mut},
sync::atomic::{AtomicUsize, Ordering},
}; };
use crossbeam_queue::SegQueue; use crossbeam_queue::SegQueue;
use humansize::{SizeFormatter, BINARY}; use humansize::{SizeFormatter, BINARY};

View File

@ -222,17 +222,16 @@ pub static ACTIVE_SPACE: Lazy<ASpaceMutex> = Lazy::new(|| {
ASpaceMutex::new(new_space) ASpaceMutex::new(new_space)
}); });
fn alloc_pt() -> Result<(*mut PageTable, PhysAddr), PagingError> {
let frame = PHYSICAL_MEMORY.lock().allocate_frame().ok_or(MapToError::FrameAllocationFailed)?;
Ok((frame.as_virt_ptr(), frame.start_address()))
}
impl AddressSpace { impl AddressSpace {
pub fn new() -> Result<Self, PagingError> { pub fn new() -> Result<Self, PagingError> {
// SAFETY: We copy the kernel space mappings to the newly allocated table before we make a reference to it, so // SAFETY: We copy the kernel space mappings to the newly allocated table before we make a reference to it, so
// the reference cannot point to uninitialized data. // the reference cannot point to uninitialized data.
let new_table = unsafe { let new_table = unsafe {
let new_table = alloc_pt()?.0; let new_table = PHYSICAL_MEMORY
.lock()
.allocate_frame()
.ok_or(MapToError::FrameAllocationFailed)?
.as_virt_ptr::<PageTable>();
new_table.copy_from(KERNEL_SPACE.lock().mapper.level_4_table(), 1); new_table.copy_from(KERNEL_SPACE.lock().mapper.level_4_table(), 1);
&mut *new_table &mut *new_table
}; };