refactor: unsafe only in adapter + libkos; forbid(unsafe_code) everywhere else; libkos Window (volatile, bounds-checked MMIO/DMA/shared mem), entry!, thread::spawn; MapRegion returns pages; kernel const-built (with_cores/install_platform); newtype addrs

This commit is contained in:
2026-10-27 21:43:24 +01:00
parent 83809bbe94
commit 842d14987c
107 changed files with 771 additions and 647 deletions

View File

@@ -1,3 +1,5 @@
#![forbid(unsafe_code)]
pub fn add(left: u64, right: u64) -> u64 {
left + right
}

View File

@@ -1,3 +1,5 @@
#![forbid(unsafe_code)]
pub fn add(left: u64, right: u64) -> u64 {
left + right
}

View File

@@ -1,3 +1,5 @@
#![forbid(unsafe_code)]
pub fn add(left: u64, right: u64) -> u64 {
left + right
}

View File

@@ -1,3 +1,5 @@
#![forbid(unsafe_code)]
pub fn add(left: u64, right: u64) -> u64 {
left + right
}

View File

@@ -1,3 +1,5 @@
#![forbid(unsafe_code)]
pub fn add(left: u64, right: u64) -> u64 {
left + right
}

View File

@@ -1,3 +1,5 @@
#![forbid(unsafe_code)]
pub fn add(left: u64, right: u64) -> u64 {
left + right
}

View File

@@ -1,3 +1,5 @@
#![forbid(unsafe_code)]
pub fn add(left: u64, right: u64) -> u64 {
left + right
}

View File

@@ -1,3 +1,5 @@
#![forbid(unsafe_code)]
pub fn add(left: u64, right: u64) -> u64 {
left + right
}

View File

@@ -1,3 +1,5 @@
#![forbid(unsafe_code)]
pub fn add(left: u64, right: u64) -> u64 {
left + right
}

View File

@@ -1,4 +1,5 @@
#![no_std]
#![forbid(unsafe_code)]
pub mod focus;
pub mod font;

View File

@@ -1,3 +1,5 @@
#![forbid(unsafe_code)]
pub fn add(left: u64, right: u64) -> u64 {
left + right
}

View File

@@ -1,3 +1,5 @@
#![forbid(unsafe_code)]
pub fn add(left: u64, right: u64) -> u64 {
left + right
}

View File

@@ -8,9 +8,6 @@ name = "input-server"
test = false
bench = false
[features]
default = ["qemu-virt"]
qemu-virt = []
[dependencies]
types = { workspace = true }

View File

@@ -1,2 +1 @@
pub mod mock;
pub mod qemu_uart;

View File

@@ -1,47 +0,0 @@
use port_input_device::{InputDevice, InputEvent, Key};
const UART_BASE: usize = 0x10000000;
const UART_LSR: usize = 5;
pub struct UartInputDevice {
base: usize,
}
impl UartInputDevice {
pub fn new() -> Self {
Self { base: UART_BASE }
}
fn read_byte(&self) -> Option<u8> {
let lsr = unsafe { core::ptr::read_volatile((self.base + UART_LSR) as *const u8) };
if lsr & 1 != 0 {
Some(unsafe { core::ptr::read_volatile(self.base as *const u8) })
} else {
None
}
}
fn byte_to_key(byte: u8) -> Key {
match byte {
b'w' | b'W' => Key::Up,
b's' | b'S' => Key::Down,
b'a' | b'A' => Key::Left,
b'd' | b'D' => Key::Right,
b'\r' | b'\n' => Key::Enter,
0x1B => Key::Escape,
c => Key::Char(c),
}
}
}
impl InputDevice for UartInputDevice {
fn poll(&mut self) -> Option<InputEvent> {
let byte = self.read_byte()?;
Some(InputEvent::KeyDown(Self::byte_to_key(byte)))
}
fn has_event(&self) -> bool {
let lsr = unsafe { core::ptr::read_volatile((self.base + UART_LSR) as *const u8) };
lsr & 1 != 0
}
}

View File

@@ -1,4 +1,5 @@
#![no_std]
#![forbid(unsafe_code)]
pub mod adapters;
pub mod protocol;
@@ -9,10 +10,7 @@ pub mod server;
mod tests;
pub fn run() -> ! {
#[cfg(feature = "qemu-virt")]
let device = adapters::qemu_uart::UartInputDevice::new();
#[cfg(not(feature = "qemu-virt"))]
// The real devices are driven by bins/input-qemu.
let device = adapters::mock::MockInputDevice::new();
let mut srv = server::InputServer::new(device);

View File

@@ -1,9 +1,11 @@
#![no_std]
#![forbid(unsafe_code)]
#![no_main]
extern crate libkos;
#[unsafe(no_mangle)]
extern "C" fn main() {
libkos::entry!(main);
fn main() {
input_server::run();
}

View File

@@ -1,3 +1,5 @@
#![forbid(unsafe_code)]
pub fn add(left: u64, right: u64) -> u64 {
left + right
}

View File

@@ -1,4 +1,5 @@
#![no_std]
#![forbid(unsafe_code)]
pub mod protocol;
pub mod server;

View File

@@ -1,9 +1,11 @@
#![no_std]
#![forbid(unsafe_code)]
#![no_main]
extern crate libkos;
#[unsafe(no_mangle)]
extern "C" fn main() {
libkos::entry!(main);
fn main() {
log_server::run();
}

View File

@@ -1,3 +1,5 @@
#![forbid(unsafe_code)]
pub fn add(left: u64, right: u64) -> u64 {
left + right
}

View File

@@ -1,3 +1,5 @@
#![forbid(unsafe_code)]
pub fn add(left: u64, right: u64) -> u64 {
left + right
}

View File

@@ -1,3 +1,5 @@
#![forbid(unsafe_code)]
pub fn add(left: u64, right: u64) -> u64 {
left + right
}

View File

@@ -1,3 +1,5 @@
#![forbid(unsafe_code)]
pub fn add(left: u64, right: u64) -> u64 {
left + right
}

View File

@@ -1,4 +1,5 @@
#![no_std]
#![forbid(unsafe_code)]
pub mod protocol;
pub mod server;

View File

@@ -1,9 +1,11 @@
#![no_std]
#![forbid(unsafe_code)]
#![no_main]
extern crate libkos;
#[unsafe(no_mangle)]
extern "C" fn main() {
libkos::entry!(main);
fn main() {
permission_manager::run();
}

View File

@@ -1,3 +1,5 @@
#![forbid(unsafe_code)]
pub fn add(left: u64, right: u64) -> u64 {
left + right
}

View File

@@ -1,3 +1,5 @@
#![forbid(unsafe_code)]
pub fn add(left: u64, right: u64) -> u64 {
left + right
}

View File

@@ -1,4 +1,5 @@
#![no_std]
#![forbid(unsafe_code)]
pub mod protocol;
pub mod server;

View File

@@ -1,9 +1,11 @@
#![no_std]
#![forbid(unsafe_code)]
#![no_main]
extern crate libkos;
#[unsafe(no_mangle)]
extern "C" fn main() {
libkos::entry!(main);
fn main() {
session_server::run();
}

View File

@@ -1,4 +1,5 @@
#![no_std]
#![forbid(unsafe_code)]
extern crate alloc;
@@ -18,11 +19,10 @@ use libkos::syscall;
use types::address::VirtualAddress;
use types::badge::Badge;
use types::bounded::{CapSlot, PageCount};
use types::mapping::PagePerms;
use types::permission::{Permission, PermissionSet};
/// Client buffers sit high in storage's window, clear of its heap.
const BUFFERS_VA: usize = 0x0100_0000;
const BUFFERS_VA: VirtualAddress = VirtualAddress::from_raw(0x0100_0000);
const EP: CapSlot = CapSlot::const_new(0);
@@ -33,12 +33,10 @@ struct Kernel;
impl server::Host for Kernel {
fn create(&mut self, client: usize) -> Option<(&'static mut [u8], Option<CapSlot>)> {
let va = BUFFERS_VA + client * protocol::BUFFER_SIZE;
let va = VirtualAddress::from_raw(BUFFERS_VA.raw() + client * protocol::BUFFER_SIZE);
let region = syscall::create_region(PageCount::new(protocol::BUFFER_PAGES as u16)?).ok()?;
syscall::map_region(region, VirtualAddress::from_raw(va), PagePerms::ReadWrite).ok()?;
// SAFETY: the region is mapped read-write at `va` for as long as
// the server holds `region`, which it never drops.
let buf = unsafe { core::slice::from_raw_parts_mut(va as *mut u8, protocol::BUFFER_SIZE) };
// Storage never drops `region`, so the buffer stays mapped.
let buf = libkos::window::map_buffer(region, va).ok()?;
Some((buf, Some(region)))
}

View File

@@ -1,3 +1,5 @@
#![forbid(unsafe_code)]
pub fn add(left: u64, right: u64) -> u64 {
left + right
}

View File

@@ -1,3 +1,5 @@
#![forbid(unsafe_code)]
pub fn add(left: u64, right: u64) -> u64 {
left + right
}

View File

@@ -1,4 +1,5 @@
#![no_std]
#![forbid(unsafe_code)]
extern crate alloc;

View File

@@ -1,9 +1,11 @@
#![no_std]
#![forbid(unsafe_code)]
#![no_main]
extern crate libkos;
#[unsafe(no_mangle)]
extern "C" fn main() {
libkos::entry!(main);
fn main() {
terminal_server::run();
}

View File

@@ -1,3 +1,5 @@
#![forbid(unsafe_code)]
pub fn add(left: u64, right: u64) -> u64 {
left + right
}

View File

@@ -1,3 +1,5 @@
#![forbid(unsafe_code)]
pub fn add(left: u64, right: u64) -> u64 {
left + right
}