diff --git a/src/interrupts.rs b/src/interrupts.rs index 912eefc..f487974 100644 --- a/src/interrupts.rs +++ b/src/interrupts.rs @@ -465,22 +465,12 @@ extern "C" fn syscall_handler() { } } 8 => { - let args = unsafe { - let argc = usize(regs.rsi); - let argv: &[&[u8]] = - slice::from_raw_parts(ptr::with_exposed_provenance(usize(regs.rdi)), argc); - argv.iter().map(|arg| CStr::from_bytes_with_nul_unchecked(arg)).collect::>() - }; #[warn( clippy::arithmetic_side_effects, reason = "FIXME: The current address space should be usize::MAX as that is an invalid index, instead of 0." )] let space = TASKING.address_spaces_mut(|x| x.remove(usize(regs.rdx - 1))); - let res = TASKING.new_process( - ptr::with_exposed_provenance(usize(regs.rcx)), - space, - args.as_slice(), - ); + let res = TASKING.new_process(ptr::with_exposed_provenance(usize(regs.rcx)), space); if let Ok(pid) = res { retval = 0; retval2 = u64(pid); @@ -681,11 +671,7 @@ extern "C" fn syscall_handler() { TASKING.sleep(SleepReason::WaitingForIPC); } } - 19 => { - let args = TASKING.arguments(); - retval = u64(args.0.expose_provenance()); - retval2 = u64(args.1); - } + 19 => (), 20 => { retval = if regs.rcx == 0 { unsafe { diff --git a/src/main.rs b/src/main.rs index 3d060ec..0e5ff49 100644 --- a/src/main.rs +++ b/src/main.rs @@ -291,11 +291,7 @@ pub fn main() { reason = "Argument does not contain a null byte, thus this cannot panic" )] let init_pid = TASKING - .new_process( - ptr::with_exposed_provenance(usize(init.ehdr.e_entry)), - init_addr_space, - &[&CString::new(b"init").unwrap()], - ) + .new_process(ptr::with_exposed_provenance(usize(init.ehdr.e_entry)), init_addr_space) .expect("Failed to create init process"); TASKING.wake(init_pid, SleepReason::NewProcess).unwrap(); } diff --git a/src/tasking.rs b/src/tasking.rs index 18ba881..8c37002 100644 --- a/src/tasking.rs +++ b/src/tasking.rs @@ -4,12 +4,9 @@ use crate::{ println, qemu_exit, virtual_memory::{ASpaceMutex, AddressSpace, PagingError, ACTIVE_SPACE, KERNEL_SPACE}, }; -use alloc::{ - borrow::ToOwned, boxed::Box, collections::VecDeque, ffi::CString, string::ToString, vec::Vec, -}; +use alloc::{boxed::Box, collections::VecDeque, string::ToString, vec::Vec}; use cast::{u64, usize}; use core::{ - alloc::Layout, arch::naked_asm, ffi::CStr, ptr::{addr_of, addr_of_mut}, @@ -95,7 +92,6 @@ struct Process { kernel_stack: Box<[usize], &'static ASpaceMutex>, kernel_esp: *mut usize, kernel_esp_top: VirtAddr, - arguments: (*const *const u8, usize), address_spaces: Mutex>, data_buffers: Mutex>, message_queue: Mutex>, @@ -132,7 +128,6 @@ impl Tasking { &self, entry_point: *const extern "C" fn() -> !, mut address_space: AddressSpace, - arguments: &[&CStr], ) -> Result { let mut kernel_stack = Vec::with_capacity_in(KSTACK_SIZE, &*KERNEL_SPACE); kernel_stack.resize(KSTACK_SIZE - 0x3, 0); @@ -150,43 +145,6 @@ impl Tasking { 16, PageTableFlags::USER_ACCESSIBLE, )?; - let arguments = arguments.iter().map(|arg| (*arg).to_owned()).collect::>(); - #[expect( - clippy::unwrap_used, - reason = "This fails if the byte size of the array exceeds isize::MAX, which with 48-bit virtual addresses cannot happen" - )] - let mut args_layout = Layout::array::<*const u8>(arguments.len()).unwrap(); - let mut arg_offsets = Vec::new(); - for argument in &arguments { - #[expect( - clippy::unwrap_used, - reason = "This fails if the total size of the layout exceeds isize::MAX, which with 48-bit virtual addresses cannot happen" - )] - let (new_layout, offset) = - args_layout.extend(Layout::for_value(argument.to_bytes_with_nul())).unwrap(); - args_layout = new_layout; - arg_offsets.push(offset); - } - args_layout = { - #[expect( - clippy::unwrap_used, - reason = "This fails if the aligned size of the layout exceeds isize::MAX, which with 48-bit virtual addresses cannot happen" - )] - args_layout.align_to(4096).unwrap().pad_to_align() - }; - let user_arg_mem = KERNEL_SPACE - .lock() - .map_free(args_layout.size() / 4096, PageTableFlags::USER_ACCESSIBLE)?; - address_space.run(|| unsafe { - let mut ptr_ptr: *mut *const u8 = user_arg_mem.cast(); - for (&offset, argument) in arg_offsets.iter().zip(arguments.iter()) { - let arg_ptr = user_arg_mem.add(offset); - #[expect(clippy::arithmetic_side_effects, reason = "This can never overflow as count_bytes is always one less than the bytes used for the string, which can be at most 2^64-1.")] - arg_ptr.copy_from(argument.as_ptr().cast(), argument.count_bytes() + 1); - ptr_ptr.write(arg_ptr); - ptr_ptr = ptr_ptr.add(1); - } - }); let pid = self.processes.write().insert(Process { #[expect( clippy::indexing_slicing, @@ -206,7 +164,6 @@ impl Tasking { data_buffers: Mutex::new(Slab::new()), message_queue: Mutex::new(SegQueue::new()), sleeping: RwLock::new(Some(SleepReason::NewProcess)), - arguments: (user_arg_mem.cast(), arguments.len()), }); if let Some(&proc_man_pid) = REGISTERD_PIDS.read().get(&3) { let mut len: usize; @@ -349,7 +306,10 @@ impl Tasking { len += 1; send_ipc_to(usize(proc_man_pid), buffer, len); } else { - println!("[TASKING] No process manager when PID {} exited with code {code}", current_pid); + println!( + "[TASKING] No process manager when PID {} exited with code {code}", + current_pid + ); } } loop { @@ -483,12 +443,6 @@ impl Tasking { Ok(()) } - pub fn arguments(&self) -> (*const *const u8, usize) { - #[warn(clippy::unwrap_used, reason = "FIXME")] - #[warn(clippy::indexing_slicing, reason = "FIXME(?)")] - self.processes.read()[self.current_pid.read().unwrap()].arguments - } - pub fn print_stats(&self) { let mut total = KERNEL_SPACE.lock().get_bytes_allocated(); println!( @@ -501,19 +455,7 @@ impl Tasking { |space| space.get_bytes_allocated(), ); total += bytes_used; - let name = if process.arguments.1 > 0 { - unsafe { CStr::from_ptr(process.arguments.0.read().cast()) } - .to_string_lossy() - .into_owned() - } else { - "UNKNOWN".to_string() - }; - println!( - "[TASKING] PID {} ({}) used {}", - i, - name, - SizeFormatter::new(bytes_used, BINARY), - ); + println!("[TASKING] PID {} used {}", i, SizeFormatter::new(bytes_used, BINARY),); } println!("[TASKING] Total used {} ({})", SizeFormatter::new(total, BINARY), total / 4096); }