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

View File

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

View File

@ -222,17 +222,16 @@ pub static ACTIVE_SPACE: Lazy<ASpaceMutex> = Lazy::new(|| {
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 {
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
// the reference cannot point to uninitialized data.
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);
&mut *new_table
};