diff --git a/Cargo.lock b/Cargo.lock index 1fce0a6c..20e6fffb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -229,7 +229,7 @@ dependencies = [ "time", "typeflags", "typeflags-util", - "xarray 0.1.0", + "xarray", "xmas-elf 0.8.0", ] @@ -1324,7 +1324,6 @@ dependencies = [ "volatile 0.6.1", "x86", "x86_64", - "xarray 0.1.0 (git+https://github.com/asterinas/xarray)", ] [[package]] @@ -1984,14 +1983,6 @@ dependencies = [ "ostd", ] -[[package]] -name = "xarray" -version = "0.1.0" -source = "git+https://github.com/asterinas/xarray#1dad5d9b74aac30193bd242a97077b4c54933830" -dependencies = [ - "smallvec", -] - [[package]] name = "xmas-elf" version = "0.8.0" diff --git a/ostd/Cargo.toml b/ostd/Cargo.toml index aa1dfffc..264f14ff 100644 --- a/ostd/Cargo.toml +++ b/ostd/Cargo.toml @@ -37,7 +37,6 @@ spin = "0.9.4" smallvec = "1.13.2" unwinding = { version = "=0.2.5", default-features = false, features = ["fde-gnu-eh-frame-hdr", "hide-trace", "panic", "personality", "unwinder"] } volatile = "0.6.1" -xarray = { git = "https://github.com/asterinas/xarray", version = "0.1.0" } [target.x86_64-unknown-none.dependencies] x86_64 = "0.14.13" diff --git a/ostd/src/collections/mod.rs b/ostd/src/collections/mod.rs deleted file mode 100644 index 0f819462..00000000 --- a/ostd/src/collections/mod.rs +++ /dev/null @@ -1,6 +0,0 @@ -// SPDX-License-Identifier: MPL-2.0 - -//! This module provides some advanced collections. - -// TODO: Remove the old xarray module. -pub mod xarray; diff --git a/ostd/src/collections/xarray.rs b/ostd/src/collections/xarray.rs deleted file mode 100644 index 63bbe824..00000000 --- a/ostd/src/collections/xarray.rs +++ /dev/null @@ -1,6 +0,0 @@ -// SPDX-License-Identifier: MPL-2.0 - -//! This module introduces the xarray crate and provides relevant support and interfaces for `XArray`. -extern crate xarray as xarray_crate; - -pub use xarray_crate::{Cursor, CursorMut, XArray, XMark}; diff --git a/ostd/src/lib.rs b/ostd/src/lib.rs index 65df0c7d..a91c2b97 100644 --- a/ostd/src/lib.rs +++ b/ostd/src/lib.rs @@ -33,7 +33,6 @@ pub mod arch; pub mod arch; pub mod boot; pub mod bus; -pub mod collections; pub mod console; pub mod cpu; mod error; diff --git a/ostd/src/mm/frame/test.rs b/ostd/src/mm/frame/test.rs index 16fa7154..64431373 100644 --- a/ostd/src/mm/frame/test.rs +++ b/ostd/src/mm/frame/test.rs @@ -486,8 +486,8 @@ mod untyped { } #[ktest] - fn xarray_item_entry() { - use xarray::ItemEntry; + fn frame_impls_non_null_ptr() { + use crate::sync::non_null::NonNullPtr; let init_val = 42; let frame = FrameAllocOptions::new() @@ -497,13 +497,13 @@ mod untyped { let uframe: UFrame = frame.into(); // Converts and retrieves the frame from raw pointer - let raw_ptr = ItemEntry::into_raw(uframe); - let frame_from_raw: Frame = unsafe { ItemEntry::from_raw(raw_ptr) }; + let raw_ptr = NonNullPtr::into_raw(uframe); + let frame_from_raw: Frame = unsafe { NonNullPtr::from_raw(raw_ptr.cast()) }; assert_eq!(frame_from_raw.start_paddr(), ptr); assert_eq!(frame_from_raw.meta().value, init_val); // References the frame from raw pointer - let frame_ref: FrameRef = unsafe { Frame::raw_as_ref(raw_ptr) }; + let frame_ref: FrameRef = unsafe { Frame::raw_as_ref(raw_ptr.cast()) }; assert_eq!(frame_ref.start_paddr(), ptr); } } diff --git a/ostd/src/mm/frame/untyped.rs b/ostd/src/mm/frame/untyped.rs index 335177da..ec16477f 100644 --- a/ostd/src/mm/frame/untyped.rs +++ b/ostd/src/mm/frame/untyped.rs @@ -7,12 +7,16 @@ //! the declaration of untyped frames and segments, and the implementation of //! extra functionalities (such as [`VmIo`]) for them. -use super::{meta::AnyFrameMeta, Frame, Segment}; +use super::{ + meta::{AnyFrameMeta, MetaSlot}, + Frame, Segment, +}; use crate::{ mm::{ io::{FallibleVmRead, FallibleVmWrite, VmIo, VmReader, VmWriter}, paddr_to_vaddr, Infallible, }, + sync::non_null::NonNullPtr, Error, Result, }; @@ -132,13 +136,13 @@ macro_rules! impl_untyped_for { impl_untyped_for!(Frame); impl_untyped_for!(Segment); -// Here are implementations for `xarray`. +// Here are implementations for `crate::sync::rcu`. -use core::{marker::PhantomData, mem::ManuallyDrop, ops::Deref}; +use core::{marker::PhantomData, mem::ManuallyDrop, ops::Deref, ptr::NonNull}; /// `FrameRef` is a struct that can work as `&'a Frame`. /// -/// This is solely useful for [`crate::collections::xarray`]. +/// This is useful for [`crate::sync::rcu`]. pub struct FrameRef<'a, M: AnyUFrameMeta + ?Sized> { inner: ManuallyDrop>, _marker: PhantomData<&'a Frame>, @@ -152,34 +156,42 @@ impl Deref for FrameRef<'_, M> { } } -// SAFETY: `Frame` is essentially an `*const MetaSlot` that could be used as a `*const` pointer. -// The pointer is also aligned to 4. -unsafe impl xarray::ItemEntry for Frame { +// SAFETY: `Frame` is essentially an `*const MetaSlot` that could be used as a non-null +// `*const` pointer. +unsafe impl NonNullPtr for Frame { + type Target = PhantomData; + type Ref<'a> = FrameRef<'a, M> where Self: 'a; - fn into_raw(self) -> *const () { - let ptr = self.ptr; + const ALIGN_BITS: u32 = core::mem::align_of::().trailing_zeros(); + + fn into_raw(self) -> NonNull { + let ptr = NonNull::new(self.ptr.cast_mut()).unwrap(); let _ = ManuallyDrop::new(self); - ptr as *const () + ptr.cast() } - unsafe fn from_raw(raw: *const ()) -> Self { + unsafe fn from_raw(raw: NonNull) -> Self { Self { - ptr: raw as *const _, + ptr: raw.as_ptr().cast_const().cast(), _marker: PhantomData, } } - unsafe fn raw_as_ref<'a>(raw: *const ()) -> Self::Ref<'a> { + unsafe fn raw_as_ref<'a>(raw: NonNull) -> Self::Ref<'a> { Self::Ref { inner: ManuallyDrop::new(Frame { - ptr: raw as *const _, + ptr: raw.as_ptr().cast_const().cast(), _marker: PhantomData, }), _marker: PhantomData, } } + + fn ref_as_raw(ptr_ref: Self::Ref<'_>) -> core::ptr::NonNull { + NonNull::new(ptr_ref.inner.ptr.cast_mut()).unwrap().cast() + } }