Struct kcore::vm::VmSpace[][src]

pub struct VmSpace<P: PageTable> { /* fields omitted */ }
Expand description

Virtual memory address space.

Implementations

impl<P: PageTable> VmSpace<P>[src]

pub fn new() -> Result<Self>[src]

Create a new address space.

pub fn check_overlap(&self, va: Range<usize>) -> Result<()>[src]

pub async fn mmap(
    &mut self,
    addr: usize,
    len: usize,
    chan: &Arc<Chan>,
    offset: usize,
    anonymous: bool
) -> Result<()>
[src]

Create a memory segment mapping.

Accessing virtual address [addr, addr + len) is equivalent to accessing ontents starting at offset of given chan. offset, addr and len must be a multiple of page size.

An anonymous mapping won’t carry any modification to the underlying chan. It’s unspecified when the underlying chan is then modified by others after creating the anonymous mapping, since we may or may not view the modified value in the mapping.

pub async fn munmap(&mut self, addr: usize, len: usize) -> Result<bool>[src]

Unmap a continugous chunk of memory.

All pages containing a part of the indicated range [addr, addr + len) are unmapped.

Note that when the chunk of memory to unmap is included by exactly one segment, we need to split it and add a new segment. In other cases, we can just reuse the old segments by modifying their keys and anon.

This is atomic. Return error if unmap failed. Otherwise, all mappings are guaranteed to be unmapped and the return value indicates whether there are any error when flushing to the backing objects. See also [VmSegment::unmap].

pub async fn fork(&mut self) -> Result<VmSpace<P>>[src]

Fork an address space.

For example, it may be called when forking a process.

pub async fn fault(&mut self, va: usize) -> Result<()>[src]

Page fault handler at virtual address va.

Faults can be divided into following cases:

  1. Fault at a shared page in chan. It may happen when the page is newly mapped shared but not yet referred.
  2. Fault at a copy-on-write private page. When the private page is forked, corresponding page table entries will be marked as read-only. Thus, for example, this kind of fault will happend when the child process is trying to modify this page.
  3. Fault at a unfetched private page. It may happen when the page is newly mapped private but not yet referred.

If it returns ok, the address space will have read/write permission to the page containing virtual address va. That means the kernel can safely read or write to the page (after switching to it) without page fault.

pub async fn free(self)[src]

Unmap all segments and drop this address space.

Note that this dosen’t gurantee all dirty pages are successfully flushed to their backing object.

pub async fn read(&mut self, buf: &mut [u8], offset: usize) -> Result<()>[src]

Read data in memory area [offset, offset + buf.len) from this address space.

pub async fn write(&mut self, buf: &[u8], offset: usize) -> Result<()>[src]

Write data from buffer to memory area [offset, offset + buf.len) of this address space.

Auto Trait Implementations

impl<P> !RefUnwindSafe for VmSpace<P>

impl<P> Send for VmSpace<P> where
    P: Send

impl<P> Sync for VmSpace<P> where
    P: Sync

impl<P> Unpin for VmSpace<P> where
    P: Unpin

impl<P> !UnwindSafe for VmSpace<P>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> Same<T> for T[src]

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.