rust-kernel
Rustbelt: a hobby x86_64 kernel written in Rust
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | //! Processes = a thread + its own address space + a file descriptor table.
//!
//! Starting one (`spawn`):
//! 1. new level-4 page table sharing the kernel mappings (memory.rs)
//! 2. load the ELF program's segments into its user part (elf.rs)
//! 3. map a user stack just below `USER_END`
//! 4. fd table: 0, 1, 2 = the console (tty.rs)
//! 5. spawn a thread with that CR3. The thread starts in the kernel
//! (`user_thread_entry`) and "returns" into ring 3 with `iretq`.
//!
//! From then on the process only comes back into the kernel through
//! interrupts (timer -> maybe another thread runs), exceptions (page fault in
//! user mode -> the process is killed, see interrupts.rs) and syscalls.
//!
//! Not done yet (exercises): freeing a dead process's frames and page tables,
//! fork/exec/wait syscalls, passing arguments, more than one thread per process.
use crate;
use crateErrno;
use crateFile;
use crate;
use crate::;
use ;
use ;
use Mutex;
use VirtAddr;
use ;
/// The user stack: 16 KiB, ending one (unmapped) page below USER_END.
pub const USER_STACK_TOP: u64 = USER_END - 0x1000;
pub const USER_STACK_SIZE: u64 = 16 * 1024;
/// Max open files per process.
const MAX_FDS: usize = 16;
static NEXT_PID: AtomicU64 = new;
/// Load ELF program `elf` into a new address space and start it.
/// First code of every process thread (still ring 0, but already running
/// with the process's CR3 and kernel stack).
/// Jump to ring 3. `iretq` pops RIP, CS, RFLAGS, RSP, SS -- we push a fake
/// interrupt frame with user selectors (RPL 3), so "returning" from it drops
/// the privilege level. RFLAGS = 0x202: interrupts enabled (+ the always-1 bit).
unsafe !
/// End the current process (exit syscall, or killed by an exception).
!
/// Block (the calling kernel thread) until `process` has ended.
|