Remove handling of CLI arguments
This commit is contained in:
parent
b3cc54fddf
commit
c4d9bb128a
@ -465,22 +465,12 @@ extern "C" fn syscall_handler() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
8 => {
|
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::<Vec<_>>()
|
|
||||||
};
|
|
||||||
#[warn(
|
#[warn(
|
||||||
clippy::arithmetic_side_effects,
|
clippy::arithmetic_side_effects,
|
||||||
reason = "FIXME: The current address space should be usize::MAX as that is an invalid index, instead of 0."
|
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 space = TASKING.address_spaces_mut(|x| x.remove(usize(regs.rdx - 1)));
|
||||||
let res = TASKING.new_process(
|
let res = TASKING.new_process(ptr::with_exposed_provenance(usize(regs.rcx)), space);
|
||||||
ptr::with_exposed_provenance(usize(regs.rcx)),
|
|
||||||
space,
|
|
||||||
args.as_slice(),
|
|
||||||
);
|
|
||||||
if let Ok(pid) = res {
|
if let Ok(pid) = res {
|
||||||
retval = 0;
|
retval = 0;
|
||||||
retval2 = u64(pid);
|
retval2 = u64(pid);
|
||||||
@ -681,11 +671,7 @@ extern "C" fn syscall_handler() {
|
|||||||
TASKING.sleep(SleepReason::WaitingForIPC);
|
TASKING.sleep(SleepReason::WaitingForIPC);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
19 => {
|
19 => (),
|
||||||
let args = TASKING.arguments();
|
|
||||||
retval = u64(args.0.expose_provenance());
|
|
||||||
retval2 = u64(args.1);
|
|
||||||
}
|
|
||||||
20 => {
|
20 => {
|
||||||
retval = if regs.rcx == 0 {
|
retval = if regs.rcx == 0 {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -291,11 +291,7 @@ pub fn main() {
|
|||||||
reason = "Argument does not contain a null byte, thus this cannot panic"
|
reason = "Argument does not contain a null byte, thus this cannot panic"
|
||||||
)]
|
)]
|
||||||
let init_pid = TASKING
|
let init_pid = TASKING
|
||||||
.new_process(
|
.new_process(ptr::with_exposed_provenance(usize(init.ehdr.e_entry)), init_addr_space)
|
||||||
ptr::with_exposed_provenance(usize(init.ehdr.e_entry)),
|
|
||||||
init_addr_space,
|
|
||||||
&[&CString::new(b"init").unwrap()],
|
|
||||||
)
|
|
||||||
.expect("Failed to create init process");
|
.expect("Failed to create init process");
|
||||||
TASKING.wake(init_pid, SleepReason::NewProcess).unwrap();
|
TASKING.wake(init_pid, SleepReason::NewProcess).unwrap();
|
||||||
}
|
}
|
||||||
|
@ -4,12 +4,9 @@ use crate::{
|
|||||||
println, qemu_exit,
|
println, qemu_exit,
|
||||||
virtual_memory::{ASpaceMutex, AddressSpace, PagingError, ACTIVE_SPACE, KERNEL_SPACE},
|
virtual_memory::{ASpaceMutex, AddressSpace, PagingError, ACTIVE_SPACE, KERNEL_SPACE},
|
||||||
};
|
};
|
||||||
use alloc::{
|
use alloc::{boxed::Box, collections::VecDeque, string::ToString, vec::Vec};
|
||||||
borrow::ToOwned, boxed::Box, collections::VecDeque, ffi::CString, string::ToString, vec::Vec,
|
|
||||||
};
|
|
||||||
use cast::{u64, usize};
|
use cast::{u64, usize};
|
||||||
use core::{
|
use core::{
|
||||||
alloc::Layout,
|
|
||||||
arch::naked_asm,
|
arch::naked_asm,
|
||||||
ffi::CStr,
|
ffi::CStr,
|
||||||
ptr::{addr_of, addr_of_mut},
|
ptr::{addr_of, addr_of_mut},
|
||||||
@ -95,7 +92,6 @@ struct Process {
|
|||||||
kernel_stack: Box<[usize], &'static ASpaceMutex>,
|
kernel_stack: Box<[usize], &'static ASpaceMutex>,
|
||||||
kernel_esp: *mut usize,
|
kernel_esp: *mut usize,
|
||||||
kernel_esp_top: VirtAddr,
|
kernel_esp_top: VirtAddr,
|
||||||
arguments: (*const *const u8, usize),
|
|
||||||
address_spaces: Mutex<Slab<AddressSpace>>,
|
address_spaces: Mutex<Slab<AddressSpace>>,
|
||||||
data_buffers: Mutex<Slab<*mut [u8]>>,
|
data_buffers: Mutex<Slab<*mut [u8]>>,
|
||||||
message_queue: Mutex<SegQueue<(usize, usize)>>,
|
message_queue: Mutex<SegQueue<(usize, usize)>>,
|
||||||
@ -132,7 +128,6 @@ impl Tasking {
|
|||||||
&self,
|
&self,
|
||||||
entry_point: *const extern "C" fn() -> !,
|
entry_point: *const extern "C" fn() -> !,
|
||||||
mut address_space: AddressSpace,
|
mut address_space: AddressSpace,
|
||||||
arguments: &[&CStr],
|
|
||||||
) -> Result<usize, PagingError> {
|
) -> Result<usize, PagingError> {
|
||||||
let mut kernel_stack = Vec::with_capacity_in(KSTACK_SIZE, &*KERNEL_SPACE);
|
let mut kernel_stack = Vec::with_capacity_in(KSTACK_SIZE, &*KERNEL_SPACE);
|
||||||
kernel_stack.resize(KSTACK_SIZE - 0x3, 0);
|
kernel_stack.resize(KSTACK_SIZE - 0x3, 0);
|
||||||
@ -150,43 +145,6 @@ impl Tasking {
|
|||||||
16,
|
16,
|
||||||
PageTableFlags::USER_ACCESSIBLE,
|
PageTableFlags::USER_ACCESSIBLE,
|
||||||
)?;
|
)?;
|
||||||
let arguments = arguments.iter().map(|arg| (*arg).to_owned()).collect::<Vec<CString>>();
|
|
||||||
#[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 {
|
let pid = self.processes.write().insert(Process {
|
||||||
#[expect(
|
#[expect(
|
||||||
clippy::indexing_slicing,
|
clippy::indexing_slicing,
|
||||||
@ -206,7 +164,6 @@ impl Tasking {
|
|||||||
data_buffers: Mutex::new(Slab::new()),
|
data_buffers: Mutex::new(Slab::new()),
|
||||||
message_queue: Mutex::new(SegQueue::new()),
|
message_queue: Mutex::new(SegQueue::new()),
|
||||||
sleeping: RwLock::new(Some(SleepReason::NewProcess)),
|
sleeping: RwLock::new(Some(SleepReason::NewProcess)),
|
||||||
arguments: (user_arg_mem.cast(), arguments.len()),
|
|
||||||
});
|
});
|
||||||
if let Some(&proc_man_pid) = REGISTERD_PIDS.read().get(&3) {
|
if let Some(&proc_man_pid) = REGISTERD_PIDS.read().get(&3) {
|
||||||
let mut len: usize;
|
let mut len: usize;
|
||||||
@ -349,7 +306,10 @@ impl Tasking {
|
|||||||
len += 1;
|
len += 1;
|
||||||
send_ipc_to(usize(proc_man_pid), buffer, len);
|
send_ipc_to(usize(proc_man_pid), buffer, len);
|
||||||
} else {
|
} 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 {
|
loop {
|
||||||
@ -483,12 +443,6 @@ impl Tasking {
|
|||||||
Ok(())
|
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) {
|
pub fn print_stats(&self) {
|
||||||
let mut total = KERNEL_SPACE.lock().get_bytes_allocated();
|
let mut total = KERNEL_SPACE.lock().get_bytes_allocated();
|
||||||
println!(
|
println!(
|
||||||
@ -501,19 +455,7 @@ impl Tasking {
|
|||||||
|space| space.get_bytes_allocated(),
|
|space| space.get_bytes_allocated(),
|
||||||
);
|
);
|
||||||
total += bytes_used;
|
total += bytes_used;
|
||||||
let name = if process.arguments.1 > 0 {
|
println!("[TASKING] PID {} used {}", i, SizeFormatter::new(bytes_used, BINARY),);
|
||||||
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] Total used {} ({})", SizeFormatter::new(total, BINARY), total / 4096);
|
println!("[TASKING] Total used {} ({})", SizeFormatter::new(total, BINARY), total / 4096);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user