diff --git a/kernel/src/objects/cap.rs b/kernel/src/objects/cap.rs index 0052667..5fc2330 100644 --- a/kernel/src/objects/cap.rs +++ b/kernel/src/objects/cap.rs @@ -35,7 +35,6 @@ impl RawCap { } } -#[derive(Clone)] pub struct CapEntry { pub cap: Cell, pub link: Link, @@ -59,6 +58,14 @@ impl CapEntry { } } +impl Clone for CapEntry { + fn clone(&self) -> Self { + let mut cte = Self::new(self.cap.get()); + cte.link = self.link.clone(); + cte + } +} + impl From for CapEntry { fn from(value: RawCap) -> Self { Self::new(value) diff --git a/lib/utils/src/linked_list.rs b/lib/utils/src/linked_list.rs index a91f750..7062d61 100644 --- a/lib/utils/src/linked_list.rs +++ b/lib/utils/src/linked_list.rs @@ -10,7 +10,7 @@ macro_rules! LinkHelperImpl { }; } -pub trait LinkHelper: Clone { +pub trait LinkHelper: Sized { const LINK_OFFSET: usize; /// # Safety @@ -20,7 +20,6 @@ pub trait LinkHelper: Clone { } } -#[derive(Clone)] pub struct Link { pub prev: Cell>>, pub next: Cell>>, @@ -35,6 +34,15 @@ impl Default for Link { } } +impl Clone for Link { + fn clone(&self) -> Self { + Self { + prev: Cell::new(self.prev.get()), + next: Cell::new(self.next.get()), + } + } +} + impl Link { /// # Safety /// LINK_OFFSET must be a valid field offset of T @@ -113,7 +121,6 @@ impl Link { mod tests { use super::*; - #[derive(Clone)] struct Node { link: Link, value: i32,