Skip to content

Commit

Permalink
feat(user_ptr): implement user_ptr
Browse files Browse the repository at this point in the history
  • Loading branch information
ChenRuiwei committed Apr 7, 2024
1 parent 892aa05 commit 7f1e368
Show file tree
Hide file tree
Showing 21 changed files with 1,012 additions and 516 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

174 changes: 0 additions & 174 deletions Makefile

This file was deleted.

5 changes: 5 additions & 0 deletions arch/src/riscv64/interrupts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ pub fn set_trap_handler(handler_addr: usize) {
}
}

#[inline]
pub fn set_trap_handler_vector(handler_addr: usize) {
unsafe { stvec::write(handler_addr, TrapMode::Vectored) }
}

/// Disable interrupt and resume to the interrupt state before when it gets
/// dropped
pub struct InterruptGuard {
Expand Down
1 change: 1 addition & 0 deletions config/src/mm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub const HART_START_ADDR: usize = 0x80200000;
pub const USER_STACK_SIZE: usize = 1024 * 1024 * 8; // 8M

pub const PAGE_SIZE: usize = 1 << PAGE_SIZE_BITS;
pub const PAGE_MASK: usize = PAGE_SIZE - 1;
pub const PAGE_SIZE_BITS: usize = 12;
pub const PTE_NUM_ONE_PAGE: usize = 512;

Expand Down
3 changes: 3 additions & 0 deletions docs/roadmap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Roadmap

- Userptr
1 change: 1 addition & 0 deletions kernel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ async_utils = { path = "../modules/async_utils/" }
irq_count = { path = "../modules/irq_count/" }
recycle_allocator = { path = "../modules/recycle_allocator/" }

cfg-if = "1.0"
buddy_system_allocator = "0.9"
bitflags = "2.5"
bit_field = "0.10"
Expand Down
3 changes: 3 additions & 0 deletions kernel/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ extern crate alloc;
#[macro_use]
extern crate bitflags;

#[macro_use]
extern crate cfg_if;

#[macro_use]
extern crate driver;

Expand Down
10 changes: 10 additions & 0 deletions kernel/src/mm/memory_space/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ use log::info;
use memory::{PageTable, VirtAddr, VirtPageNum};
use spin::Lazy;
use sync::mutex::SpinNoIrqLock;
use systype::SysResult;
use xmas_elf::ElfFile;

use self::vm_area::VmArea;
use super::user_ptr::PageFaultAccessType;
use crate::{
mm::{
memory_space::vm_area::{MapPermission, VmAreaType},
Expand Down Expand Up @@ -331,6 +333,14 @@ impl MemorySpace {
(memory_space, user_stack_top, entry_point, auxv)
}

pub fn handle_pagefault(
&mut self,
vaddr: VirtAddr,
access_type: PageFaultAccessType,
) -> SysResult<()> {
todo!();
}

pub fn activate(&self) {
self.page_table.activate();
}
Expand Down
4 changes: 2 additions & 2 deletions kernel/src/mm/memory_space/vm_area.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use alloc::vec::Vec;
use alloc::{borrow::ToOwned, vec::Vec};

use config::mm::PAGE_SIZE;
use memory::{pte::PTEFlags, StepByOne, VPNRange, VirtAddr, VirtPageNum};
Expand Down Expand Up @@ -117,7 +117,7 @@ impl VmArea {
for vpn in self.vpn_range {
page_table.map(
vpn,
VirtAddr::from(vpn).to_pa().into(),
VirtAddr::from(vpn).to_offset().to_pa().into(),
self.map_perm.into(),
)
}
Expand Down
5 changes: 3 additions & 2 deletions kernel/src/mm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
///
pub mod memory_space;
mod page;
mod user_ptr;

use config::board::MEMORY_END;
use log::info;
Expand All @@ -27,8 +28,8 @@ pub fn init() {
}
heap::init_heap_allocator();
frame::init_frame_allocator(
VirtAddr::from(_ekernel as usize).to_pa().into(),
VirtAddr::from(MEMORY_END).to_pa().into(),
VirtAddr::from(_ekernel as usize).to_offset().to_pa().into(),
VirtAddr::from(MEMORY_END).to_offset().to_pa().into(),
);
info!("KERNEL SPACE init finished");
mm::activate_kernel_space();
Expand Down
Loading

0 comments on commit 7f1e368

Please sign in to comment.