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
Prev Previous commit
Next Next commit
run wasm tests
  • Loading branch information
JonasKruckenberg committed Jan 18, 2025
commit b1ede09baa29ca1d33d074d040ac40b14b294176
2 changes: 1 addition & 1 deletion kernel/fib_cpp.wat
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
local.get 21
return)
(table (;0;) 1 1 funcref)
(memory (;0;) 2)
(memory (;0;) 1)
(global (;0;) (mut i32) (i32.const 66560))
(export "memory" (memory 0))
(export "fib" (func 0))
Expand Down
4 changes: 2 additions & 2 deletions kernel/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub const TRAP_STACK_SIZE_PAGES: usize = 64; // TODO find a lower more appropria
/// doesn't cause startup slowdown & inefficient mapping, but large enough so we can bootstrap
/// our own virtual memory subsystem. At that point we are no longer reliant on this initial heap
/// size and can dynamically grow the heap as needed.
pub const INITIAL_HEAP_SIZE_PAGES: usize = 4096; // 32 MiB
pub const INITIAL_HEAP_SIZE_PAGES: usize = 4096 * 2; // 32 MiB

pub type Result<T> = core::result::Result<T, Error>;

Expand Down Expand Up @@ -132,7 +132,7 @@ fn main(hartid: usize, boot_info: &'static BootInfo) -> ! {
Instant::now().duration_since(Instant::ZERO),
Instant::from_ticks(boot_info.boot_ticks).elapsed()
);
// wasm::test();
wasm::test();

// - [all][global] parse cmdline
// - [all][global] `vm::init()` init virtual memory management
Expand Down
4 changes: 2 additions & 2 deletions kernel/src/vm/address_space.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ pub enum AddressSpaceKind {
/// Represents the address space of a process (or the kernel).
pub struct AddressSpace {
/// A binary search tree of regions that make up this address space.
pub(super) regions: wavltree::WAVLTree<AddressSpaceRegion>,
pub(crate) regions: wavltree::WAVLTree<AddressSpaceRegion>,
/// The hardware address space backing this "logical" address space that changes need to be
/// materialized into in order to take effect.
pub(super) arch: arch::AddressSpace,
pub arch: arch::AddressSpace,
/// The maximum range this address space can encompass.
///
/// This is used to check new mappings against and speed up page fault handling.
Expand Down
16 changes: 4 additions & 12 deletions kernel/src/vm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ use sync::{LazyLock, Mutex, OnceLock};
pub use trap_handler::trap_handler;
pub use user_mmap::UserMmap;
use xmas_elf::program::Type;
pub use vmo::Vmo;
pub use frame_list::FrameList;
pub use address_space::Batch;

pub static KERNEL_ASPACE: OnceLock<Mutex<AddressSpace>> = OnceLock::new();
static THE_ZERO_FRAME: LazyLock<Frame> = LazyLock::new(|| {
Expand Down Expand Up @@ -71,18 +74,7 @@ pub fn init(boot_info: &BootInfo, minfo: &MachineInfo) -> crate::Result<()> {

Ok(Mutex::new(aspace))
})?;

// let mut aspace = vm::AddressSpace::new_user(2, Some(ChaCha20Rng::from_seed(
// minfo.rng_seed.unwrap()[0..32].try_into().unwrap(),
// ))).unwrap();
// unsafe { aspace.arch.activate(); }
// log::trace!("everything is fine?!");
//
// let layout = Layout::from_size_align(5 * arch::PAGE_SIZE, arch::PAGE_SIZE).unwrap();
// let vmo = Vmo::new_paged(iter::repeat_n(THE_ZERO_FRAME.clone(), 5));
// let range = aspace.map(layout, vmo, 0, Permissions::READ | Permissions::WRITE, None).unwrap().range;
// log::trace!("{region:?}");


Ok(())
}

Expand Down