mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-25 18:33:24 +00:00
Replace InFramePtr with SafePtr
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
ab4b1b47dc
commit
c38e4f0800
@ -3,7 +3,7 @@ use pod::Pod;
|
||||
use spin::Once;
|
||||
|
||||
use crate::{
|
||||
vm::{Paddr, Vaddr, VmIo},
|
||||
vm::{HasPaddr, Paddr, Vaddr, VmIo},
|
||||
Error,
|
||||
};
|
||||
|
||||
@ -60,6 +60,12 @@ impl VmIo for IoMem {
|
||||
}
|
||||
}
|
||||
|
||||
impl HasPaddr for IoMem {
|
||||
fn paddr(&self) -> Paddr {
|
||||
crate::vm::vaddr_to_paddr(self.virtual_address).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl IoMem {
|
||||
pub fn new(range: Range<Paddr>) -> Option<IoMem> {
|
||||
if CHECKER.get().unwrap().check(&range) {
|
||||
@ -72,10 +78,6 @@ impl IoMem {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn paddr(&self) -> Paddr {
|
||||
crate::vm::vaddr_to_paddr(self.virtual_address).unwrap()
|
||||
}
|
||||
|
||||
fn check_range(&self, offset: usize, len: usize) -> crate::Result<()> {
|
||||
let sum = offset.checked_add(len).ok_or(Error::InvalidArgs)?;
|
||||
if sum > self.limit {
|
||||
|
@ -6,7 +6,7 @@ use core::{
|
||||
|
||||
use crate::{arch::iommu, config::PAGE_SIZE, prelude::*, Error};
|
||||
|
||||
use super::frame_allocator;
|
||||
use super::{frame_allocator, HasPaddr};
|
||||
use super::{Paddr, VmIo};
|
||||
|
||||
use pod::Pod;
|
||||
@ -304,6 +304,12 @@ impl Clone for VmFrame {
|
||||
}
|
||||
}
|
||||
|
||||
impl HasPaddr for VmFrame {
|
||||
fn paddr(&self) -> Paddr {
|
||||
self.start_paddr()
|
||||
}
|
||||
}
|
||||
|
||||
impl VmFrame {
|
||||
/// Creates a new VmFrame.
|
||||
///
|
||||
|
@ -32,9 +32,9 @@ use spin::Once;
|
||||
|
||||
use crate::boot::memory_region::{MemoryRegion, MemoryRegionType};
|
||||
|
||||
/// Convert physical address to virtual address using offset, only available inside jinux-frame
|
||||
pub(crate) fn paddr_to_vaddr(pa: usize) -> usize {
|
||||
pa + PHYS_OFFSET
|
||||
/// Get physical address trait
|
||||
pub trait HasPaddr {
|
||||
fn paddr(&self) -> Paddr;
|
||||
}
|
||||
|
||||
pub fn vaddr_to_paddr(va: Vaddr) -> Option<Paddr> {
|
||||
@ -50,6 +50,11 @@ pub const fn is_page_aligned(p: usize) -> bool {
|
||||
(p & (PAGE_SIZE - 1)) == 0
|
||||
}
|
||||
|
||||
/// Convert physical address to virtual address using offset, only available inside jinux-frame
|
||||
pub(crate) fn paddr_to_vaddr(pa: usize) -> usize {
|
||||
pa + PHYS_OFFSET
|
||||
}
|
||||
|
||||
/// Only available inside jinux-frame
|
||||
pub(crate) static MEMORY_REGIONS: Once<Vec<MemoryRegion>> = Once::new();
|
||||
|
||||
|
Reference in New Issue
Block a user