|
1 | | -use crate::{map_portal, processor::ProcessorInner, Sv39Manager, PROCESSOR}; |
| 1 | +use crate::{fs::Fd, map_portal, processor::ProcessorInner, Sv39Manager, PROCESSOR}; |
2 | 2 | use alloc::{alloc::alloc_zeroed, boxed::Box, sync::Arc, vec::Vec}; |
3 | 3 | use core::{alloc::Layout, str::FromStr}; |
4 | 4 | use spin::Mutex; |
5 | | -use tg_easy_fs::FileHandle; |
6 | 5 | use tg_kernel_context::{foreign::ForeignContext, LocalContext}; |
7 | 6 | use tg_kernel_vm::{ |
8 | 7 | page_table::{MmuMeta, Sv39, VAddr, VmFlags, PPN, VPN}, |
@@ -41,7 +40,7 @@ pub struct Process { |
41 | 40 | /// 可变 |
42 | 41 | pub address_space: AddressSpace<Sv39, Sv39Manager>, |
43 | 42 | /// 文件描述符表 |
44 | | - pub fd_table: Vec<Option<Mutex<Arc<FileHandle>>>>, |
| 43 | + pub fd_table: Vec<Option<Mutex<Fd>>>, |
45 | 44 | /// 信号模块 |
46 | 45 | pub signal: Box<dyn Signal>, |
47 | 46 | /// 分配的锁以及信号量 |
@@ -84,14 +83,11 @@ impl Process { |
84 | 83 | let satp = (8 << 60) | address_space.root_ppn().val(); |
85 | 84 | let thread = Thread::new(satp, context); |
86 | 85 | // 复制父进程文件符描述表 |
87 | | - let mut new_fd_table: Vec<Option<Mutex<Arc<FileHandle>>>> = Vec::new(); |
88 | | - for fd in self.fd_table.iter_mut() { |
89 | | - if let Some(file) = fd { |
90 | | - new_fd_table.push(Some(Mutex::new(file.get_mut().clone()))); |
91 | | - } else { |
92 | | - new_fd_table.push(None); |
93 | | - } |
94 | | - } |
| 86 | + let new_fd_table: Vec<Option<Mutex<Fd>>> = self |
| 87 | + .fd_table |
| 88 | + .iter() |
| 89 | + .map(|fd| fd.as_ref().map(|f| Mutex::new(f.lock().clone()))) |
| 90 | + .collect(); |
95 | 91 | Some(( |
96 | 92 | Self { |
97 | 93 | pid, |
@@ -174,11 +170,20 @@ impl Process { |
174 | 170 | address_space, |
175 | 171 | fd_table: vec![ |
176 | 172 | // Stdin |
177 | | - Some(Mutex::new(Arc::new(FileHandle::empty(true, false)))), |
| 173 | + Some(Mutex::new(Fd::Empty { |
| 174 | + read: true, |
| 175 | + write: false, |
| 176 | + })), |
178 | 177 | // Stdout |
179 | | - Some(Mutex::new(Arc::new(FileHandle::empty(false, true)))), |
| 178 | + Some(Mutex::new(Fd::Empty { |
| 179 | + read: false, |
| 180 | + write: true, |
| 181 | + })), |
180 | 182 | // Stderr |
181 | | - Some(Mutex::new(Arc::new(FileHandle::empty(false, true)))), |
| 183 | + Some(Mutex::new(Fd::Empty { |
| 184 | + read: false, |
| 185 | + write: true, |
| 186 | + })), |
182 | 187 | ], |
183 | 188 | signal: Box::new(SignalImpl::new()), |
184 | 189 | semaphore_list: Vec::new(), |
|
0 commit comments