mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-22 00:43:24 +00:00
Inherit HasDaddr for reference type
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
a482c87696
commit
cd3faa8123
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -277,6 +277,7 @@ dependencies = [
|
||||
"aster-rights",
|
||||
"aster-rights-proc",
|
||||
"bitvec",
|
||||
"inherit-methods-macro",
|
||||
"ktest",
|
||||
"pod",
|
||||
"typeflags-util",
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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]
|
||||
|
@ -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 {
|
||||
|
Reference in New Issue
Block a user