Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: user address space functionality #246

Merged
merged 22 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
7ce84c3
feat: implement `USER` permission
JonasKruckenberg Jan 17, 2025
740a25e
rename `MmapSlice` to `UserMmap`
JonasKruckenberg Jan 17, 2025
ec71fd8
typo
JonasKruckenberg Jan 17, 2025
ada9d7b
remove `UnwindSafe` bound on `catch_traps`
JonasKruckenberg Jan 18, 2025
43ed56c
remove `copy_from_user` & `copy_to_user` in favor of the more univers…
JonasKruckenberg Jan 18, 2025
1940e74
fix: clear sum when entering trap handler
JonasKruckenberg Jan 18, 2025
2c54feb
fixes
JonasKruckenberg Jan 18, 2025
2e8f064
fix riscv register field setting and clearing
JonasKruckenberg Jan 18, 2025
281f389
Update mod.rs
JonasKruckenberg Jan 18, 2025
965f005
fix: `with_user_memory_access` passthrough return value
JonasKruckenberg Jan 18, 2025
e4fbc92
refactor: use `VirtualAddress` in error type
JonasKruckenberg Jan 18, 2025
62842e4
fix: kernel counter creation
JonasKruckenberg Jan 18, 2025
c251643
more helpful assert messages
JonasKruckenberg Jan 18, 2025
b679b0d
feat: implement `core::iter::Step` for address types
JonasKruckenberg Jan 18, 2025
175749e
fix: respect `VMContext` field alignments
JonasKruckenberg Jan 18, 2025
673eeb8
feat: exit `array_to_wasm_trampoline` with trap instead of return
JonasKruckenberg Jan 18, 2025
28d4cdb
refactor: move allocator and addressspace into store
JonasKruckenberg Jan 18, 2025
e58874c
fix `UserMmap`
JonasKruckenberg Jan 18, 2025
b1ede09
run wasm tests
JonasKruckenberg Jan 18, 2025
cff2de3
correct jumpt to userspace
JonasKruckenberg Jan 18, 2025
04ae00b
fmt & clippy
JonasKruckenberg Jan 18, 2025
e1dc9fa
Update main.rs
JonasKruckenberg Jan 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: implement USER permission
  • Loading branch information
JonasKruckenberg committed Jan 17, 2025
commit 7ce84c3d5eaaa2ba00a93b7cacb3da2f799cd8a4
22 changes: 21 additions & 1 deletion kernel/src/arch/riscv64/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -587,13 +587,31 @@ impl PageTableEntry {
bitflags! {
#[derive(Debug, Copy, Clone, Eq, PartialEq, Default)]
pub struct PTEFlags: usize {
/// Indicates the page table entry is initialized
const VALID = 1 << 0;
/// Whether the page is readable
const READ = 1 << 1;
/// Whether the page is writable
const WRITE = 1 << 2;
/// Whether the page is executable
const EXECUTE = 1 << 3;
/// Whether the page is accessible to user mode.
///
/// By default, pages are only accessible in supervisor mode but marking a page as user-accessible
/// allows user mode code to access the page too.
const USER = 1 << 4;
/// Designates a global mapping.
///
/// Global mappings exist in all address space.
///
/// Note that as stated in the RISCV privileged spec, forgetting to mark a global mapping as gobal
/// is *fine* since it just results in slower performance. However, marking a non-global mapping as
/// global by accident will result in undefined behaviour (the CPU might use any of the competing
/// mappings for the address).
const GLOBAL = 1 << 5;
/// Indicated the page has been read, written, or executed from.
const ACCESSED = 1 << 6;
/// Indicates the page has been written to.
const DIRTY = 1 << 7;
}
}
Expand All @@ -602,13 +620,15 @@ impl From<crate::vm::Permissions> for PTEFlags {
fn from(flags: crate::vm::Permissions) -> Self {
use crate::vm::Permissions;

let mut out = Self::VALID | Self::DIRTY | Self::ACCESSED;
// we currently don't use the accessed & dirty bits and, it's recommended to set them if unused
let mut out = Self::VALID | Self::ACCESSED | Self::DIRTY;

for flag in flags {
match flag {
Permissions::READ => out.insert(Self::READ),
Permissions::WRITE => out.insert(Self::WRITE),
Permissions::EXECUTE => out.insert(Self::EXECUTE),
Permissions::USER => out.insert(Self::USER),
_ => unreachable!(),
}
}
Expand Down
9 changes: 7 additions & 2 deletions kernel/src/vm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ mod error;
pub mod flush;
pub mod frame_alloc;
mod frame_list;
mod mmap;
mod trap_handler;
mod user_mmap;
mod vmo;

use crate::arch;
Expand All @@ -30,11 +30,11 @@ use core::range::Range;
use core::{fmt, slice};
pub use error::Error;
use loader_api::BootInfo;
pub use mmap::MmapSlice;
use rand::SeedableRng;
use rand_chacha::ChaCha20Rng;
use sync::{LazyLock, Mutex, OnceLock};
pub use trap_handler::trap_handler;
pub use user_mmap::UserMmap;
use xmas_elf::program::Type;

pub static KERNEL_ASPACE: OnceLock<Mutex<AddressSpace>> = OnceLock::new();
Expand Down Expand Up @@ -201,9 +201,14 @@ impl PageFaultFlags {
bitflags::bitflags! {
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct Permissions: u8 {
/// Allow reads from the memory region
const READ = 1 << 0;
/// Allow writes to the memory region
const WRITE = 1 << 1;
/// Allow code execution from the memory region
const EXECUTE = 1 << 2;
/// Allow userspace to access the memory region
const USER = 1 << 3;
}
}

Expand Down