DragonOS/kernel/src/process/process.rs
LoGin e28411791f
完成中断管理模块重构 (#554)
- 支持中断共享
- 把现有驱动程序移植到新的irq模块
- 使用`ProcessorId`标识处理器id
- 尚未实现threaded_irq

性能上,edge irq flow handler里面,对于锁的使用,可能有点问题。为了获取/修改common data还有其他几个结构体的状态,进行了多次加锁和放锁,导致性能降低。这是接下来需要优化的点。
2024-03-03 16:31:08 +08:00

71 lines
1.9 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

use system_error::SystemError;
use crate::{
filesystem::vfs::{
file::{File, FileMode},
ROOT_INODE,
},
process::{Pid, ProcessManager},
};
use super::{ProcessFlags, __PROCESS_MANAGEMENT_INIT_DONE};
pub fn current_pcb_flags() -> ProcessFlags {
if unsafe { !__PROCESS_MANAGEMENT_INIT_DONE } {
return ProcessFlags::empty();
}
return ProcessManager::current_pcb().flags().clone();
}
pub fn current_pcb_preempt_count() -> usize {
if unsafe { !__PROCESS_MANAGEMENT_INIT_DONE } {
return 0;
}
return ProcessManager::current_pcb().preempt_count();
}
/// @brief 初始化pid=1的进程的stdio
pub fn stdio_init() -> Result<(), SystemError> {
if ProcessManager::current_pcb().pid() != Pid(1) {
return Err(SystemError::EPERM);
}
let tty_inode = ROOT_INODE()
.lookup("/dev/tty0")
.expect("Init stdio: can't find tty0");
let stdin =
File::new(tty_inode.clone(), FileMode::O_RDONLY).expect("Init stdio: can't create stdin");
let stdout =
File::new(tty_inode.clone(), FileMode::O_WRONLY).expect("Init stdio: can't create stdout");
let stderr = File::new(tty_inode.clone(), FileMode::O_WRONLY | FileMode::O_SYNC)
.expect("Init stdio: can't create stderr");
/*
按照规定进程的文件描述符数组的前三个位置分别是stdin, stdout, stderr
*/
assert_eq!(
ProcessManager::current_pcb()
.fd_table()
.write()
.alloc_fd(stdin, None)
.unwrap(),
0
);
assert_eq!(
ProcessManager::current_pcb()
.fd_table()
.write()
.alloc_fd(stdout, None)
.unwrap(),
1
);
assert_eq!(
ProcessManager::current_pcb()
.fd_table()
.write()
.alloc_fd(stderr, None)
.unwrap(),
2
);
return Ok(());
}