Compare commits
No commits in common. "fb58d2c7c4de8f1ba32eb8e7c09523639109d5b2" and "4548d9540ea16e76110b8c8b564fad5cf9bfa8e2" have entirely different histories.
fb58d2c7c4
...
4548d9540e
@ -9,12 +9,7 @@ use crate::{
|
|||||||
use alloc::{boxed::Box, vec::Vec};
|
use alloc::{boxed::Box, vec::Vec};
|
||||||
use az::WrappingCast;
|
use az::WrappingCast;
|
||||||
use cast::{u64, usize};
|
use cast::{u64, usize};
|
||||||
use core::{
|
use core::{arch::{asm, naked_asm}, ffi::CStr, fmt::Write, ptr, slice};
|
||||||
arch::{asm, naked_asm},
|
|
||||||
ffi::CStr,
|
|
||||||
fmt::Write,
|
|
||||||
ptr, slice,
|
|
||||||
};
|
|
||||||
use hashbrown::HashMap;
|
use hashbrown::HashMap;
|
||||||
use pic8259::ChainedPics;
|
use pic8259::ChainedPics;
|
||||||
use saturating_cast::SaturatingCast;
|
use saturating_cast::SaturatingCast;
|
||||||
@ -132,83 +127,89 @@ impl Drop for EoiGuard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn send_ipc_to(pid: usize, buffer: Box<[u8], &'static ASpaceMutex>, len: usize) {
|
pub fn send_ipc_to(pid: usize, buffer: Box<[u8], &'static ASpaceMutex>, len: usize) {
|
||||||
//#[expect(
|
//#[expect(
|
||||||
// clippy::unwrap_used,
|
// clippy::unwrap_used,
|
||||||
// reason = "The min call guarantees that the value is in the range of a u32 before the cast"
|
// reason = "The min call guarantees that the value is in the range of a u32 before the cast"
|
||||||
//)]
|
//)]
|
||||||
//let trunc_len: u32 = usize::min(len, 4096).try_into().unwrap();
|
//let trunc_len: u32 = usize::min(len, 4096).try_into().unwrap();
|
||||||
//#[expect(
|
//#[expect(
|
||||||
// clippy::arithmetic_side_effects,
|
// clippy::arithmetic_side_effects,
|
||||||
// reason = "Can't underflow, as x % 4 < 4 no matter the x"
|
// reason = "Can't underflow, as x % 4 < 4 no matter the x"
|
||||||
//)]
|
//)]
|
||||||
//let padding = if (trunc_len % 4) != 0 { 4 - (trunc_len % 4) } else { 0 };
|
//let padding = if (trunc_len % 4) != 0 { 4 - (trunc_len % 4) } else { 0 };
|
||||||
//#[expect(
|
//#[expect(
|
||||||
// clippy::arithmetic_side_effects,
|
// clippy::arithmetic_side_effects,
|
||||||
// reason = "Can't overflow, as padding is no more than 4 and trunc_len is no more than 4096."
|
// reason = "Can't overflow, as padding is no more than 4 and trunc_len is no more than 4096."
|
||||||
//)]
|
//)]
|
||||||
//let padded_len = trunc_len + padding;
|
//let padded_len = trunc_len + padding;
|
||||||
//#[expect(
|
//#[expect(
|
||||||
// clippy::arithmetic_side_effects,
|
// clippy::arithmetic_side_effects,
|
||||||
// reason = "Can't overflow, as padded_len is no more than 4096 and 4096+24 < u32::MAX"
|
// reason = "Can't overflow, as padded_len is no more than 4096 and 4096+24 < u32::MAX"
|
||||||
//)]
|
//)]
|
||||||
//let total_len = padded_len + 8 + (4 * 4);
|
//let total_len = padded_len + 8 + (4 * 4);
|
||||||
//SECOND_PORT.write_u32s(&[
|
//SECOND_PORT.write_u32s(&[
|
||||||
// 0x3, // SPB type
|
// 0x3, // SPB type
|
||||||
// total_len, // Total block length
|
// total_len, // Total block length
|
||||||
// len.saturating_cast::<u32>().saturating_add(8), // Packet length
|
// len.saturating_cast::<u32>().saturating_add(8), // Packet length
|
||||||
//]);
|
//]);
|
||||||
//SECOND_PORT.write_bytes(&pid.to_ne_bytes());
|
//SECOND_PORT.write_bytes(&pid.to_ne_bytes());
|
||||||
//#[expect(
|
//#[expect(
|
||||||
// clippy::indexing_slicing,
|
// clippy::indexing_slicing,
|
||||||
// reason = "The truncated length is always <= the buffer's length"
|
// reason = "The truncated length is always <= the buffer's length"
|
||||||
//)]
|
//)]
|
||||||
//SECOND_PORT.write_bytes(&buffer[0..usize(trunc_len)]);
|
//SECOND_PORT.write_bytes(&buffer[0..usize(trunc_len)]);
|
||||||
//for _ in 0..padding {
|
//for _ in 0..padding {
|
||||||
// SECOND_PORT.write_bytes(&[0]);
|
// SECOND_PORT.write_bytes(&[0]);
|
||||||
//}
|
//}
|
||||||
//SECOND_PORT.write_u32s(&[
|
//SECOND_PORT.write_u32s(&[
|
||||||
// total_len, // Total block length
|
// total_len, // Total block length
|
||||||
//]);
|
//]);
|
||||||
//assert!(len <= buffer.len());
|
//assert!(len <= buffer.len());
|
||||||
if TASKING.message_queue_mut(pid, |_| ()).is_ok() {
|
if TASKING.message_queue_mut(pid, |_| ()).is_ok() {
|
||||||
let buf_num_pages = buffer.len() / 4096;
|
let buf_num_pages = buffer.len() / 4096;
|
||||||
let buffer = Box::into_raw(buffer);
|
let buffer = Box::into_raw(buffer);
|
||||||
let buf_start_page =
|
let buf_start_page =
|
||||||
Page::from_start_address(VirtAddr::new(u64(buffer.expose_provenance()))).unwrap();
|
Page::from_start_address(VirtAddr::new(u64(buffer.expose_provenance()))).unwrap();
|
||||||
let dest_buffer = TASKING
|
let dest_buffer = TASKING
|
||||||
.address_space_mut(pid, |aspace| {
|
.address_space_mut(pid, |aspace| {
|
||||||
// This is None only if the destiniation is the current process. If so,
|
// This is None only if the destiniation is the current process. If so,
|
||||||
// no remapping is necessary so just return the old buffer.
|
// no remapping is necessary so just return the old buffer.
|
||||||
let Some(aspace) = aspace else {
|
let Some(aspace) = aspace else {
|
||||||
return buffer;
|
return buffer;
|
||||||
};
|
};
|
||||||
let page = ACTIVE_SPACE
|
let page = ACTIVE_SPACE
|
||||||
.lock()
|
.lock()
|
||||||
.move_mappings_free(buf_start_page, buf_num_pages, aspace)
|
.move_mappings_free(buf_start_page, buf_num_pages, aspace)
|
||||||
.unwrap();
|
.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(),
|
||||||
.unwrap();
|
buffer.len(),
|
||||||
#[expect(
|
)
|
||||||
clippy::unwrap_used,
|
})
|
||||||
reason = "The PID is known valid due to using it in message_queue_mut in the if-let condition"
|
.unwrap();
|
||||||
)]
|
#[expect(
|
||||||
let new_buffer_key = TASKING.proc_data_buffers_mut(pid, |x| x.insert(dest_buffer)).unwrap();
|
clippy::unwrap_used,
|
||||||
#[expect(
|
reason = "The PID is known valid due to using it in message_queue_mut in the if-let condition"
|
||||||
clippy::unwrap_used,
|
)]
|
||||||
reason = "The option was already checked at the start of the if-let"
|
let new_buffer_key =
|
||||||
)]
|
TASKING.proc_data_buffers_mut(pid, |x| x.insert(dest_buffer)).unwrap();
|
||||||
TASKING.message_queue_mut(pid, |x| x.push((new_buffer_key, len))).unwrap();
|
#[expect(
|
||||||
#[expect(
|
clippy::unwrap_used,
|
||||||
clippy::unwrap_used,
|
reason = "The option was already checked at the start of the if-let"
|
||||||
reason = "The PID is known valid due to using it in message_queue_mut in the if-let condition"
|
)]
|
||||||
)]
|
TASKING.message_queue_mut(pid, |x| x.push((new_buffer_key, len))).unwrap();
|
||||||
TASKING.wake(pid, SleepReason::WaitingForIPC).unwrap();
|
#[expect(
|
||||||
} else {
|
clippy::unwrap_used,
|
||||||
println!("irq 1 msg: Bad PID ({})", pid);
|
reason = "The PID is known valid due to using it in message_queue_mut in the if-let condition"
|
||||||
}
|
)]
|
||||||
|
TASKING.wake(pid, SleepReason::WaitingForIPC).unwrap();
|
||||||
|
} else {
|
||||||
|
println!("irq 1 msg: Bad PID ({})", pid);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[expect(clippy::needless_pass_by_value, reason = "Signature dictated by external crate")]
|
#[expect(clippy::needless_pass_by_value, reason = "Signature dictated by external crate")]
|
||||||
fn irq_handler(_stack_frame: InterruptStackFrame, index: u8, _error_code: Option<u64>) {
|
fn irq_handler(_stack_frame: InterruptStackFrame, index: u8, _error_code: Option<u64>) {
|
||||||
#[expect(
|
#[expect(
|
||||||
@ -309,8 +310,7 @@ fn get_buffer(id: u64) -> Option<Box<[u8], &'static ASpaceMutex>> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub static REGISTERD_PIDS: Lazy<RwLock<HashMap<u64, u64>>> =
|
pub static REGISTERD_PIDS: Lazy<RwLock<HashMap<u64, u64>>> = Lazy::new(|| RwLock::new(HashMap::new()));
|
||||||
Lazy::new(|| RwLock::new(HashMap::new()));
|
|
||||||
|
|
||||||
static INITRD_BUF: Lazy<&'static [u8]> = Lazy::new(|| {
|
static INITRD_BUF: Lazy<&'static [u8]> = Lazy::new(|| {
|
||||||
#[warn(clippy::expect_used, reason = "FIXME")]
|
#[warn(clippy::expect_used, reason = "FIXME")]
|
||||||
|
@ -1,13 +1,9 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
gdt,
|
gdt, interrupts::{send_ipc_to, REGISTERD_PIDS}, println, qemu_exit, virtual_memory::{ASpaceMutex, AddressSpace, PagingError, ACTIVE_SPACE, KERNEL_SPACE}
|
||||||
interrupts::{send_ipc_to, REGISTERD_PIDS},
|
|
||||||
println, qemu_exit,
|
|
||||||
virtual_memory::{ASpaceMutex, AddressSpace, PagingError, ACTIVE_SPACE, KERNEL_SPACE},
|
|
||||||
};
|
};
|
||||||
use alloc::{
|
use alloc::{
|
||||||
borrow::ToOwned, boxed::Box, collections::VecDeque, ffi::CString, string::ToString, vec::Vec,
|
borrow::ToOwned, boxed::Box, collections::VecDeque, ffi::CString, string::ToString, vec::Vec,
|
||||||
};
|
};
|
||||||
use cast::{u64, usize};
|
|
||||||
use core::{
|
use core::{
|
||||||
alloc::Layout,
|
alloc::Layout,
|
||||||
arch::naked_asm,
|
arch::naked_asm,
|
||||||
@ -23,6 +19,7 @@ use x86_64::{
|
|||||||
structures::paging::{Page, PageTableFlags},
|
structures::paging::{Page, PageTableFlags},
|
||||||
VirtAddr,
|
VirtAddr,
|
||||||
};
|
};
|
||||||
|
use cast::{u64, usize};
|
||||||
|
|
||||||
#[naked]
|
#[naked]
|
||||||
extern "C" fn switch_to_asm(current_stack: *mut *mut usize, next_stack: *mut usize) {
|
extern "C" fn switch_to_asm(current_stack: *mut *mut usize, next_stack: *mut usize) {
|
||||||
@ -221,22 +218,14 @@ impl Tasking {
|
|||||||
buffer[19..21].copy_from_slice(&8u16.to_le_bytes());
|
buffer[19..21].copy_from_slice(&8u16.to_le_bytes());
|
||||||
buffer[21..23].copy_from_slice(&6u16.to_le_bytes());
|
buffer[21..23].copy_from_slice(&6u16.to_le_bytes());
|
||||||
len = 23;
|
len = 23;
|
||||||
len += unsigned_varint::encode::u64(
|
len += unsigned_varint::encode::u64(u64(pid), (&mut buffer[len..len+10]).try_into().unwrap()).len();
|
||||||
u64(pid),
|
|
||||||
(&mut buffer[len..len + 10]).try_into().unwrap(),
|
|
||||||
)
|
|
||||||
.len();
|
|
||||||
if let Some(current_pid) = *(self.current_pid.read()) {
|
if let Some(current_pid) = *(self.current_pid.read()) {
|
||||||
buffer[len] = 1;
|
buffer[len] = 1;
|
||||||
len += 1;
|
len+=1;
|
||||||
len += unsigned_varint::encode::u64(
|
len += unsigned_varint::encode::u64(u64(current_pid), (&mut buffer[len..len+10]).try_into().unwrap()).len();
|
||||||
u64(current_pid),
|
|
||||||
(&mut buffer[len..len + 10]).try_into().unwrap(),
|
|
||||||
)
|
|
||||||
.len();
|
|
||||||
} else {
|
} else {
|
||||||
buffer[len] = 0;
|
buffer[len] = 0;
|
||||||
len += 1;
|
len+=1;
|
||||||
}
|
}
|
||||||
send_ipc_to(usize(proc_man_pid), buffer, len);
|
send_ipc_to(usize(proc_man_pid), buffer, len);
|
||||||
} else {
|
} else {
|
||||||
@ -363,14 +352,12 @@ impl Tasking {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn clear_exited_pid(&self, pid: usize) -> Result<(), ()> {
|
pub fn clear_exited_pid(&self, pid: usize) -> Result<(), ()> {
|
||||||
if self.current_pid() == Some(pid) {
|
|
||||||
return Err(());
|
|
||||||
}
|
|
||||||
let mut processes = self.processes.write();
|
let mut processes = self.processes.write();
|
||||||
let process = processes.get(pid).ok_or(())?;
|
let process = processes.get(pid).ok_or(())?;
|
||||||
if process.sleeping.read().is_none() {
|
if *process.sleeping.read() != Some(SleepReason::Exited) {
|
||||||
self.ready_to_run.lock().retain(|e| *e != pid);
|
return Err(());
|
||||||
}
|
}
|
||||||
self.freeable_kstacks.lock().push(processes.remove(pid).kernel_stack);
|
self.freeable_kstacks.lock().push(processes.remove(pid).kernel_stack);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
Loading…
Reference in New Issue
Block a user