Compare commits
2 Commits
4548d9540e
...
fb58d2c7c4
Author | SHA1 | Date | |
---|---|---|---|
fb58d2c7c4 | |||
50e7b7236e |
@ -9,7 +9,12 @@ use crate::{
|
||||
use alloc::{boxed::Box, vec::Vec};
|
||||
use az::WrappingCast;
|
||||
use cast::{u64, usize};
|
||||
use core::{arch::{asm, naked_asm}, ffi::CStr, fmt::Write, ptr, slice};
|
||||
use core::{
|
||||
arch::{asm, naked_asm},
|
||||
ffi::CStr,
|
||||
fmt::Write,
|
||||
ptr, slice,
|
||||
};
|
||||
use hashbrown::HashMap;
|
||||
use pic8259::ChainedPics;
|
||||
use saturating_cast::SaturatingCast;
|
||||
@ -181,18 +186,14 @@ pub fn send_ipc_to(pid: usize, buffer: Box<[u8], &'static ASpaceMutex>, len: usi
|
||||
.lock()
|
||||
.move_mappings_free(buf_start_page, buf_num_pages, aspace)
|
||||
.unwrap();
|
||||
ptr::slice_from_raw_parts_mut::<u8>(
|
||||
page.start_address().as_mut_ptr(),
|
||||
buffer.len(),
|
||||
)
|
||||
ptr::slice_from_raw_parts_mut::<u8>(page.start_address().as_mut_ptr(), buffer.len())
|
||||
})
|
||||
.unwrap();
|
||||
#[expect(
|
||||
clippy::unwrap_used,
|
||||
reason = "The PID is known valid due to using it in message_queue_mut in the if-let condition"
|
||||
)]
|
||||
let new_buffer_key =
|
||||
TASKING.proc_data_buffers_mut(pid, |x| x.insert(dest_buffer)).unwrap();
|
||||
let new_buffer_key = TASKING.proc_data_buffers_mut(pid, |x| x.insert(dest_buffer)).unwrap();
|
||||
#[expect(
|
||||
clippy::unwrap_used,
|
||||
reason = "The option was already checked at the start of the if-let"
|
||||
@ -206,10 +207,8 @@ pub fn send_ipc_to(pid: usize, buffer: Box<[u8], &'static ASpaceMutex>, len: usi
|
||||
} else {
|
||||
println!("irq 1 msg: Bad PID ({})", pid);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
#[expect(clippy::needless_pass_by_value, reason = "Signature dictated by external crate")]
|
||||
fn irq_handler(_stack_frame: InterruptStackFrame, index: u8, _error_code: Option<u64>) {
|
||||
#[expect(
|
||||
@ -310,7 +309,8 @@ fn get_buffer(id: u64) -> Option<Box<[u8], &'static ASpaceMutex>> {
|
||||
})
|
||||
}
|
||||
|
||||
pub static REGISTERD_PIDS: Lazy<RwLock<HashMap<u64, u64>>> = Lazy::new(|| RwLock::new(HashMap::new()));
|
||||
pub static REGISTERD_PIDS: Lazy<RwLock<HashMap<u64, u64>>> =
|
||||
Lazy::new(|| RwLock::new(HashMap::new()));
|
||||
|
||||
static INITRD_BUF: Lazy<&'static [u8]> = Lazy::new(|| {
|
||||
#[warn(clippy::expect_used, reason = "FIXME")]
|
||||
|
@ -1,9 +1,13 @@
|
||||
use crate::{
|
||||
gdt, interrupts::{send_ipc_to, REGISTERD_PIDS}, println, qemu_exit, virtual_memory::{ASpaceMutex, AddressSpace, PagingError, ACTIVE_SPACE, KERNEL_SPACE}
|
||||
gdt,
|
||||
interrupts::{send_ipc_to, REGISTERD_PIDS},
|
||||
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 cast::{u64, usize};
|
||||
use core::{
|
||||
alloc::Layout,
|
||||
arch::naked_asm,
|
||||
@ -19,7 +23,6 @@ use x86_64::{
|
||||
structures::paging::{Page, PageTableFlags},
|
||||
VirtAddr,
|
||||
};
|
||||
use cast::{u64, usize};
|
||||
|
||||
#[naked]
|
||||
extern "C" fn switch_to_asm(current_stack: *mut *mut usize, next_stack: *mut usize) {
|
||||
@ -218,14 +221,22 @@ impl Tasking {
|
||||
buffer[19..21].copy_from_slice(&8u16.to_le_bytes());
|
||||
buffer[21..23].copy_from_slice(&6u16.to_le_bytes());
|
||||
len = 23;
|
||||
len += unsigned_varint::encode::u64(u64(pid), (&mut buffer[len..len+10]).try_into().unwrap()).len();
|
||||
len += unsigned_varint::encode::u64(
|
||||
u64(pid),
|
||||
(&mut buffer[len..len + 10]).try_into().unwrap(),
|
||||
)
|
||||
.len();
|
||||
if let Some(current_pid) = *(self.current_pid.read()) {
|
||||
buffer[len] = 1;
|
||||
len+=1;
|
||||
len += unsigned_varint::encode::u64(u64(current_pid), (&mut buffer[len..len+10]).try_into().unwrap()).len();
|
||||
len += 1;
|
||||
len += unsigned_varint::encode::u64(
|
||||
u64(current_pid),
|
||||
(&mut buffer[len..len + 10]).try_into().unwrap(),
|
||||
)
|
||||
.len();
|
||||
} else {
|
||||
buffer[len] = 0;
|
||||
len+=1;
|
||||
len += 1;
|
||||
}
|
||||
send_ipc_to(usize(proc_man_pid), buffer, len);
|
||||
} else {
|
||||
@ -352,12 +363,14 @@ impl Tasking {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn clear_exited_pid(&self, pid: usize) -> Result<(), ()> {
|
||||
if self.current_pid() == Some(pid) {
|
||||
return Err(());
|
||||
}
|
||||
let mut processes = self.processes.write();
|
||||
let process = processes.get(pid).ok_or(())?;
|
||||
if *process.sleeping.read() != Some(SleepReason::Exited) {
|
||||
return Err(());
|
||||
if process.sleeping.read().is_none() {
|
||||
self.ready_to_run.lock().retain(|e| *e != pid);
|
||||
}
|
||||
self.freeable_kstacks.lock().push(processes.remove(pid).kernel_stack);
|
||||
Ok(())
|
||||
|
Loading…
Reference in New Issue
Block a user