Make new processes start sleeping
This commit is contained in:
parent
0abfd39522
commit
0e6ce349fa
@ -188,14 +188,11 @@ fn irq_handler(_stack_frame: InterruptStackFrame, index: u8, _error_code: Option
|
|||||||
clippy::unwrap_used,
|
clippy::unwrap_used,
|
||||||
reason = "The PID is known valid due to using it in message_queue_mut in the if-let condition"
|
reason = "The PID is known valid due to using it in message_queue_mut in the if-let condition"
|
||||||
)]
|
)]
|
||||||
let sleep_status = TASKING.proc_sleeping(pid).unwrap();
|
|
||||||
if sleep_status == Some(SleepReason::WaitingForIPC) {
|
|
||||||
#[expect(
|
#[expect(
|
||||||
clippy::unwrap_used,
|
clippy::unwrap_used,
|
||||||
reason = "The PID is known valid due to using it in message_queue_mut in the if-let condition"
|
reason = "The PID is known valid due to using it in message_queue_mut in the if-let condition"
|
||||||
)]
|
)]
|
||||||
TASKING.wake(pid).unwrap();
|
TASKING.wake(pid, SleepReason::WaitingForIPC).unwrap();
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
println!("irq 1 msg: Bad PID ({})", pid);
|
println!("irq 1 msg: Bad PID ({})", pid);
|
||||||
}
|
}
|
||||||
@ -549,14 +546,11 @@ extern "C" fn syscall_handler() {
|
|||||||
clippy::unwrap_used,
|
clippy::unwrap_used,
|
||||||
reason = "The PID is known valid due to using it in message_queue_mut in the if-let condition"
|
reason = "The PID is known valid due to using it in message_queue_mut in the if-let condition"
|
||||||
)]
|
)]
|
||||||
let sleep_status = TASKING.proc_sleeping(pid).unwrap();
|
|
||||||
if sleep_status == Some(SleepReason::WaitingForIPC) {
|
|
||||||
#[expect(
|
#[expect(
|
||||||
clippy::unwrap_used,
|
clippy::unwrap_used,
|
||||||
reason = "The PID is known valid due to using it in message_queue_mut in the if-let condition"
|
reason = "The PID is known valid due to using it in message_queue_mut in the if-let condition"
|
||||||
)]
|
)]
|
||||||
TASKING.wake(pid).unwrap();
|
TASKING.wake(pid, SleepReason::WaitingForIPC).unwrap();
|
||||||
}
|
|
||||||
retval = 0;
|
retval = 0;
|
||||||
} else {
|
} else {
|
||||||
println!("ipc_send: Bad PID ({})", pid);
|
println!("ipc_send: Bad PID ({})", pid);
|
||||||
@ -752,6 +746,14 @@ extern "C" fn syscall_handler() {
|
|||||||
retval = 1;
|
retval = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
24 => {
|
||||||
|
let pid = usize(regs.rcx);
|
||||||
|
if TASKING.wake(pid, SleepReason::NewProcess).is_err() {
|
||||||
|
retval = 1;
|
||||||
|
} else {
|
||||||
|
retval = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
};
|
};
|
||||||
unsafe { SYSCALL_REGS = regs };
|
unsafe { SYSCALL_REGS = regs };
|
||||||
|
@ -102,7 +102,7 @@ use physical_memory::PHYSICAL_MEMORY;
|
|||||||
use serial::SECOND_PORT;
|
use serial::SECOND_PORT;
|
||||||
use spin::lazy::Lazy;
|
use spin::lazy::Lazy;
|
||||||
use tar_no_std::TarArchiveRef;
|
use tar_no_std::TarArchiveRef;
|
||||||
use tasking::TASKING;
|
use tasking::{SleepReason, TASKING};
|
||||||
use virtual_memory::{ACTIVE_SPACE, KERNEL_SPACE};
|
use virtual_memory::{ACTIVE_SPACE, KERNEL_SPACE};
|
||||||
use x86_64::{
|
use x86_64::{
|
||||||
registers::rflags::{self, RFlags},
|
registers::rflags::{self, RFlags},
|
||||||
@ -290,11 +290,12 @@ pub fn main() {
|
|||||||
clippy::unwrap_used,
|
clippy::unwrap_used,
|
||||||
reason = "Argument does not contain a null byte, thus this cannot panic"
|
reason = "Argument does not contain a null byte, thus this cannot panic"
|
||||||
)]
|
)]
|
||||||
TASKING
|
let init_pid = TASKING
|
||||||
.new_process(
|
.new_process(
|
||||||
ptr::with_exposed_provenance(usize(init.ehdr.e_entry)),
|
ptr::with_exposed_provenance(usize(init.ehdr.e_entry)),
|
||||||
init_addr_space,
|
init_addr_space,
|
||||||
&[&CString::new(b"init").unwrap()],
|
&[&CString::new(b"init").unwrap()],
|
||||||
)
|
)
|
||||||
.expect("Failed to create init process");
|
.expect("Failed to create init process");
|
||||||
|
TASKING.wake(init_pid, SleepReason::NewProcess).unwrap();
|
||||||
}
|
}
|
||||||
|
@ -85,6 +85,7 @@ extern "C" fn task_init() {
|
|||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||||
pub enum SleepReason {
|
pub enum SleepReason {
|
||||||
WaitingForIPC,
|
WaitingForIPC,
|
||||||
|
NewProcess,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -203,10 +204,10 @@ impl Tasking {
|
|||||||
address_spaces: Mutex::new(Slab::new()),
|
address_spaces: Mutex::new(Slab::new()),
|
||||||
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(None),
|
sleeping: RwLock::new(Some(SleepReason::NewProcess)),
|
||||||
arguments: (user_arg_mem.cast(), arguments.len()),
|
arguments: (user_arg_mem.cast(), arguments.len()),
|
||||||
});
|
});
|
||||||
self.ready_to_run.lock().push_back(pid);
|
//self.ready_to_run.lock().push_back(pid);
|
||||||
Ok(pid)
|
Ok(pid)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -394,11 +395,16 @@ impl Tasking {
|
|||||||
self.task_yield();
|
self.task_yield();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn wake(&self, pid: usize) -> Result<(), InvalidPid> {
|
pub fn wake(&self, pid: usize, reason: SleepReason) -> Result<(), InvalidPid> {
|
||||||
*self.processes.read().get(pid).ok_or(InvalidPid)?.sleeping.write() = None;
|
let processes = self.processes.read();
|
||||||
|
let process = processes.get(pid).ok_or(InvalidPid)?;
|
||||||
|
let mut sleeping = process.sleeping.write();
|
||||||
|
if *sleeping == Some(reason) {
|
||||||
if Some(pid) != self.current_pid() {
|
if Some(pid) != self.current_pid() {
|
||||||
self.ready_to_run.lock().push_back(pid);
|
self.ready_to_run.lock().push_back(pid);
|
||||||
}
|
}
|
||||||
|
*sleeping = None;
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user