mirror of
https://github.com/sgmarz/osblog.git
synced 2024-11-23 18:06:20 +04:00
Get set up to support file descriptors in user space.
This commit is contained in:
parent
7db18179a6
commit
0b83a3629a
@ -7,7 +7,7 @@
|
|||||||
// The frequency of QEMU is 10 MHz
|
// The frequency of QEMU is 10 MHz
|
||||||
pub const FREQ: u64 = 10_000_000;
|
pub const FREQ: u64 = 10_000_000;
|
||||||
// Let's do this 250 times per second for switching
|
// Let's do this 250 times per second for switching
|
||||||
pub const CONTEXT_SWITCH_TIME: u64 = FREQ / 250;
|
pub const CONTEXT_SWITCH_TIME: u64 = FREQ / 500;
|
||||||
|
|
||||||
/// In 64-bit mode, we're given three different modes for the MMU:
|
/// In 64-bit mode, we're given three different modes for the MMU:
|
||||||
/// 0 - The MMU is off -- no protection and no translation PA = VA
|
/// 0 - The MMU is off -- no protection and no translation PA = VA
|
||||||
|
@ -169,7 +169,7 @@ impl File {
|
|||||||
pid: my_pid,
|
pid: my_pid,
|
||||||
root: zalloc(1) as *mut Table,
|
root: zalloc(1) as *mut Table,
|
||||||
state: ProcessState::Running,
|
state: ProcessState::Running,
|
||||||
data: ProcessData::zero(),
|
data: ProcessData::new(),
|
||||||
sleep_until: 0,
|
sleep_until: 0,
|
||||||
program: zalloc(program_pages) };
|
program: zalloc(program_pages) };
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ use crate::{cpu::{build_satp,
|
|||||||
SatpMode,
|
SatpMode,
|
||||||
TrapFrame,
|
TrapFrame,
|
||||||
Registers},
|
Registers},
|
||||||
|
fs::Inode,
|
||||||
page::{alloc,
|
page::{alloc,
|
||||||
dealloc,
|
dealloc,
|
||||||
map,
|
map,
|
||||||
@ -249,7 +250,7 @@ pub fn add_kernel_process(func: fn()) -> u16 {
|
|||||||
pid: my_pid,
|
pid: my_pid,
|
||||||
root: zalloc(1) as *mut Table,
|
root: zalloc(1) as *mut Table,
|
||||||
state: ProcessState::Running,
|
state: ProcessState::Running,
|
||||||
data: ProcessData::zero(),
|
data: ProcessData::new(),
|
||||||
sleep_until: 0,
|
sleep_until: 0,
|
||||||
program: null_mut()
|
program: null_mut()
|
||||||
};
|
};
|
||||||
@ -334,7 +335,7 @@ pub fn add_kernel_process_args(func: fn(args_ptr: usize), args: usize) -> u16 {
|
|||||||
pid: my_pid,
|
pid: my_pid,
|
||||||
root: zalloc(1) as *mut Table,
|
root: zalloc(1) as *mut Table,
|
||||||
state: ProcessState::Running,
|
state: ProcessState::Running,
|
||||||
data: ProcessData::zero(),
|
data: ProcessData::new(),
|
||||||
sleep_until: 0,
|
sleep_until: 0,
|
||||||
program: null_mut(),
|
program: null_mut(),
|
||||||
};
|
};
|
||||||
@ -501,7 +502,7 @@ impl Process {
|
|||||||
pid: unsafe { NEXT_PID },
|
pid: unsafe { NEXT_PID },
|
||||||
root: zalloc(1) as *mut Table,
|
root: zalloc(1) as *mut Table,
|
||||||
state: ProcessState::Running,
|
state: ProcessState::Running,
|
||||||
data: ProcessData::zero(),
|
data: ProcessData::new(),
|
||||||
sleep_until: 0,
|
sleep_until: 0,
|
||||||
program: null_mut()
|
program: null_mut()
|
||||||
};
|
};
|
||||||
@ -570,7 +571,6 @@ impl Drop for Process {
|
|||||||
/// Since we're storing ownership of a Process in the linked list,
|
/// Since we're storing ownership of a Process in the linked list,
|
||||||
/// we can cause it to deallocate automatically when it is removed.
|
/// we can cause it to deallocate automatically when it is removed.
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
// println!("Dropping process {}", self.get_pid());
|
|
||||||
// We allocate the stack as a page.
|
// We allocate the stack as a page.
|
||||||
dealloc(self.stack);
|
dealloc(self.stack);
|
||||||
// This is unsafe, but it's at the drop stage, so we won't
|
// This is unsafe, but it's at the drop stage, so we won't
|
||||||
@ -589,6 +589,13 @@ impl Drop for Process {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub enum FileDescriptor {
|
||||||
|
File(Inode),
|
||||||
|
Device(usize),
|
||||||
|
Network,
|
||||||
|
Unknown,
|
||||||
|
}
|
||||||
|
|
||||||
// The private data in a process contains information
|
// The private data in a process contains information
|
||||||
// that is relevant to where we are, including the path
|
// that is relevant to where we are, including the path
|
||||||
// and open file descriptors.
|
// and open file descriptors.
|
||||||
@ -596,16 +603,18 @@ impl Drop for Process {
|
|||||||
// private process data. This is essentially our resource control block (RCB).
|
// private process data. This is essentially our resource control block (RCB).
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub struct ProcessData {
|
pub struct ProcessData {
|
||||||
environ: BTreeMap<String, String>
|
environ: BTreeMap<String, String>,
|
||||||
|
fdesc: BTreeMap<u16, FileDescriptor>,
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is private data that we can query with system calls.
|
// This is private data that we can query with system calls.
|
||||||
// If we want to implement CFQ (completely fair queuing), which
|
// If we want to implement CFQ (completely fair queuing), which
|
||||||
// is a per-process block queuing algorithm, we can put that here.
|
// is a per-process block queuing algorithm, we can put that here.
|
||||||
impl ProcessData {
|
impl ProcessData {
|
||||||
pub fn zero() -> Self {
|
pub fn new() -> Self {
|
||||||
ProcessData {
|
ProcessData {
|
||||||
environ: BTreeMap::new()
|
environ: BTreeMap::new(),
|
||||||
|
fdesc: BTreeMap::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user