Clean up code and fix 0 being a valid addr space index

This commit is contained in:
pjht 2022-11-08 10:43:13 -06:00
parent 1995cf9337
commit bf09798825
7 changed files with 9 additions and 15 deletions

2
Cargo.lock generated
View File

@ -273,7 +273,7 @@ dependencies = [
[[package]] [[package]]
name = "unwinding" name = "unwinding"
version = "0.1.4" version = "0.1.5"
dependencies = [ dependencies = [
"gimli", "gimli",
] ]

Binary file not shown.

View File

@ -232,7 +232,7 @@ extern "C" fn syscall_handler() {
.map_free(regs.rdx as usize, PageTableFlags::from_bits_truncate(regs.rsi)) .map_free(regs.rdx as usize, PageTableFlags::from_bits_truncate(regs.rsi))
.map_or(0, |x| x as u64) .map_or(0, |x| x as u64)
} else if let Some(space) = } else if let Some(space) =
TASKING.lock().address_spaces_mut().get_mut(regs.rcx as usize) TASKING.lock().address_spaces_mut().get_mut((regs.rcx - 1) as usize)
{ {
space space
.map_free(regs.rdx as usize, PageTableFlags::from_bits_truncate(regs.rsi)) .map_free(regs.rdx as usize, PageTableFlags::from_bits_truncate(regs.rsi))
@ -251,11 +251,11 @@ extern "C" fn syscall_handler() {
retval2 = initrd.len() as u64; retval2 = initrd.len() as u64;
} }
4 => { 4 => {
retval = retval = (TASKING.lock().address_spaces_mut().insert(AddressSpace::new().unwrap()) + 1)
TASKING.lock().address_spaces_mut().insert(AddressSpace::new().unwrap()) as u64; as u64;
} }
5 => { 5 => {
TASKING.lock().address_spaces_mut().remove(regs.rcx as usize); TASKING.lock().address_spaces_mut().remove((regs.rcx - 1) as usize);
} }
6 => { 6 => {
let page = Page::from_start_address(VirtAddr::new(regs.rdx)).unwrap(); let page = Page::from_start_address(VirtAddr::new(regs.rdx)).unwrap();
@ -267,7 +267,7 @@ extern "C" fn syscall_handler() {
TASKING TASKING
.lock() .lock()
.address_spaces_mut() .address_spaces_mut()
.get_mut(regs.rcx as usize) .get_mut((regs.rcx - 1) as usize)
.unwrap() .unwrap()
.map_assert_unused(page, num_pages, flags) .map_assert_unused(page, num_pages, flags)
} }
@ -280,7 +280,7 @@ extern "C" fn syscall_handler() {
// let aligned_address = regs.rsi & !0xFFF; // let aligned_address = regs.rsi & !0xFFF;
// let aligned_len = len as u64 + (regs.rsi - aligned_address); // let aligned_len = len as u64 + (regs.rsi - aligned_address);
let mut tasking = TASKING.lock(); let mut tasking = TASKING.lock();
let space = tasking.address_spaces_mut().get_mut(regs.rcx as usize).unwrap(); let space = tasking.address_spaces_mut().get_mut((regs.rcx - 1) as usize).unwrap();
// space // space
// .map_assert_unused( // .map_assert_unused(
// Page::from_start_address(VirtAddr::new(aligned_address)).unwrap(), // Page::from_start_address(VirtAddr::new(aligned_address)).unwrap(),
@ -295,7 +295,7 @@ extern "C" fn syscall_handler() {
} }
} }
8 => { 8 => {
let space = TASKING.lock().address_spaces_mut().remove(regs.rdx as usize); let space = TASKING.lock().address_spaces_mut().remove((regs.rdx - 1) as usize);
let res = TASKING.lock().new_process(regs.rcx as *const _, space); let res = TASKING.lock().new_process(regs.rcx as *const _, space);
if let Ok(pid) = res { if let Ok(pid) = res {
retval = 0; retval = 0;

View File

@ -78,7 +78,6 @@ extern "C" fn task_force_unlock() {
} }
#[derive(Debug)] #[derive(Debug)]
#[repr(C)]
struct Process { struct Process {
kernel_stack: Box<[usize], &'static ASpaceMutex>, kernel_stack: Box<[usize], &'static ASpaceMutex>,
kernel_esp: *mut usize, kernel_esp: *mut usize,

View File

@ -225,15 +225,10 @@ impl AddressSpace {
/// Runs a provided closure in an address space. /// Runs a provided closure in an address space.
/// ///
/// This function takes ownership of the address space and passes it back after running the
/// closure. This is necessary to prevent the closure fron having access to the address space by
/// both the local variable it was in, and the `ACTIVE_SPACE` static, which would alias mutable
/// references.
///
/// ## Examples /// ## Examples
/// ``` /// ```
/// let address_space = AddressSpace::new(); /// let address_space = AddressSpace::new();
/// let address_space = address_space.run(|| {/* your closure here */}); /// address_space.run(|| {/* your closure here */});
/// ``` /// ```
#[allow(unused)] #[allow(unused)]
pub fn run<F: FnOnce()>(&mut self, func: F) { pub fn run<F: FnOnce()>(&mut self, func: F) {

Binary file not shown.

Binary file not shown.