Inherit HasDaddr for reference type

This commit is contained in:
Jianfeng Jiang
2024-04-29 03:07:02 +00:00
committed by Tate, Hongliang Tian
parent a482c87696
commit cd3faa8123
5 changed files with 17 additions and 3 deletions

1
Cargo.lock generated
View File

@ -277,6 +277,7 @@ dependencies = [
"aster-rights",
"aster-rights-proc",
"bitvec",
"inherit-methods-macro",
"ktest",
"pod",
"typeflags-util",

View File

@ -7,6 +7,7 @@ use alloc::collections::BTreeSet;
pub use dma_coherent::DmaCoherent;
pub use dma_stream::{DmaDirection, DmaStream, DmaStreamSlice};
use inherit_methods_macro::inherit_methods;
use spin::Once;
use super::Paddr;
@ -36,6 +37,11 @@ pub trait HasDaddr {
fn daddr(&self) -> Daddr;
}
#[inherit_methods(from = "(**self)")]
impl<T: HasDaddr> HasDaddr for &T {
fn daddr(&self) -> Daddr;
}
/// Set of all physical addresses with dma mapping.
static DMA_MAPPING_SET: Once<SpinLock<BTreeSet<Paddr>>> = Once::new();

View File

@ -250,11 +250,11 @@ impl EventTable {
Self { stream, num_events }
}
fn get(&self, idx: usize) -> EventBuf {
fn get(&self, idx: usize) -> EventBuf<'_> {
assert!(idx < self.num_events);
let offset = idx * EVENT_SIZE;
SafePtr::new(self.stream.clone(), offset)
SafePtr::new(&self.stream, offset)
}
const fn num_events(&self) -> usize {
@ -263,7 +263,7 @@ impl EventTable {
}
const EVENT_SIZE: usize = core::mem::size_of::<VirtioInputEvent>();
type EventBuf = SafePtr<VirtioInputEvent, DmaStream>;
type EventBuf<'a> = SafePtr<VirtioInputEvent, &'a DmaStream>;
impl<T, M: HasDaddr> DmaBuf for SafePtr<T, M> {
fn len(&self) -> usize {

View File

@ -12,5 +12,6 @@ typeflags-util = { path = "../typeflags-util" }
aster-rights-proc = { path = "../aster-rights-proc" }
aster-rights = { path = "../aster-rights" }
bitvec = { version = "1.0", default-features = false, features = ["alloc"] }
inherit-methods-macro = { git = "https://github.com/asterinas/inherit-methods-macro", rev = "98f7e3e" }
ktest = { path = "../../../framework/libs/ktest" }
[features]

View File

@ -8,6 +8,7 @@ use aster_frame::{
};
use aster_rights::{Dup, Exec, Full, Read, Signal, TRightSet, TRights, Write};
use aster_rights_proc::require;
use inherit_methods_macro::inherit_methods;
pub use pod::Pod;
pub use typeflags_util::SetContain;
@ -337,6 +338,11 @@ impl<T, R> SafePtr<T, DmaStream, R> {
}
}
#[inherit_methods(from = "(*self)")]
impl<'a, T, R> SafePtr<T, &'a DmaStream, R> {
pub fn sync(&self) -> Result<()>;
}
#[require(R > Dup)]
impl<T, M: Clone, R: TRights> Clone for SafePtr<T, M, TRightSet<R>> {
fn clone(&self) -> Self {