Struct axmem::MemorySet

source ·
pub struct MemorySet { /* private fields */ }
Expand description

PageTable + MemoryArea for a process (task)

Implementations§

source§

impl MemorySet

source

pub fn page_table_token(&self) -> usize

Get the root page table token.

source

pub fn new_empty() -> Self

Create a new empty MemorySet.

source

pub fn new_with_kernel_mapped() -> Self

Create a new MemorySet with kernel mapped regions.

source

pub fn page_table_root_ppn(&self) -> PhysAddr

The root page table physical address.

source

pub fn max_va(&self) -> VirtAddr

The max virtual address of the areas in this memory set.

source

pub fn new_region( &mut self, vaddr: VirtAddr, size: usize, flags: MappingFlags, data: Option<&[u8]>, backend: Option<MemBackend> )

Allocate contiguous region. If no data, it will create a lazy load region.

source

pub fn split_for_area(&mut self, start: VirtAddr, size: usize)

Make [start, end) unmapped and dealloced. You need to flush TLB after this.

NOTE: modified map area will have the same PhysAddr.

source

pub fn find_free_area(&self, hint: VirtAddr, size: usize) -> Option<VirtAddr>

Find a free area with given start virtual address and size. Return the start address of the area.

source

pub fn mmap( &mut self, start: VirtAddr, size: usize, flags: MappingFlags, fixed: bool, backend: Option<MemBackend> ) -> isize

mmap. You need to flush tlb after this.

source

pub fn munmap(&mut self, start: VirtAddr, size: usize)

munmap. You need to flush TLB after this.

source

pub fn msync(&mut self, start: VirtAddr, size: usize)

msync

source

pub fn mprotect(&mut self, start: VirtAddr, size: usize, flags: MappingFlags)

Edit the page table to update flags in given virt address segment. You need to flush TLB after calling this function.

NOTE: It’s possible that this function will break map areas into two for different mapping flag settings.

source

pub fn handle_page_fault( &mut self, addr: VirtAddr, flags: MappingFlags ) -> AxResult<()>

It will map newly allocated page in the page table. You need to flush TLB after this.

source

pub fn unmap_user_areas(&mut self)

将用户分配的页面从页表中直接解映射,内核分配的页面依然保留

source

pub fn query( &self, vaddr: VirtAddr ) -> AxResult<(PhysAddr, MappingFlags, PageSize)>

Query the page table to get the physical address, flags and page size of the given virtual

source

pub fn map_page_without_alloc( &mut self, vaddr: VirtAddr, paddr: PhysAddr, flags: MappingFlags ) -> AxResult<()>

Map a 4K region without allocating physical memory.

source

pub fn create_shared_mem( key: i32, size: usize, pid: u64, uid: u32, gid: u32, mode: u16 ) -> AxResult<(i32, SharedMem)>

Create a new SharedMem with given key. You need to add the returned SharedMem to global SHARED_MEMS or process’s private_mem.

Panics: SharedMem with the key already exist.

source

pub fn add_shared_mem(shmid: i32, mem: SharedMem)

Panics: shmid is already taken.

source

pub fn add_private_shared_mem(&mut self, shmid: i32, mem: SharedMem)

Panics: shmid is already taken in the process.

source

pub fn get_shared_mem(shmid: i32) -> Option<Arc<SharedMem>>

Get a SharedMem by shmid.

source

pub fn get_private_shared_mem(&self, shmid: i32) -> Option<Arc<SharedMem>>

Get a private SharedMem by shmid.

source

pub fn attach_shared_mem( &mut self, mem: Arc<SharedMem>, addr: VirtAddr, flags: MappingFlags )

Attach a SharedMem to the memory set.

source

pub fn detach_shared_mem(&mut self, _shmid: i32)

Detach a SharedMem from the memory set.

TODO: implement this

source§

impl MemorySet

source

pub fn manual_alloc_for_lazy(&mut self, addr: VirtAddr) -> AxResult<()>

判断某一个虚拟地址是否在内存集中。 若当前虚拟地址在内存集中,且对应的是lazy分配,暂未分配物理页的情况下, 则为其分配物理页面。

若不在内存集中,则返回None。

若在内存集中,且已经分配了物理页面,则不做处理。

source

pub fn manual_alloc_range_for_lazy( &mut self, start: VirtAddr, end: VirtAddr ) -> AxResult<()>

暴力实现区间强制分配 传入区间左闭右闭

source

pub fn manual_alloc_type_for_lazy<T: Sized>( &mut self, obj: *const T ) -> AxResult<()>

判断某一个类型的某一个对象是否被分配

source§

impl MemorySet

source

pub fn clone_or_err(&self) -> AxResult<Self>

Clone the MemorySet. This will create a new page table and map all the regions in the old page table to the new one.

If it occurs error, the new MemorySet will be dropped and return the error.

Trait Implementations§

source§

impl Drop for MemorySet

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> AsAny for T
where T: Any,

source§

fn as_any(&self) -> &(dyn Any + 'static)

把当前对象转化为 Any 类型,供后续 downcast 使用
source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

供 downcast_mut 使用
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.