pub struct DescriptorEngine { /* private fields */ }Expand description
描述符校验引擎
提供完整的描述符校验、所有权管理和守恒等式校验。
单线程无锁设计:内部状态通过原子类型以 &self 变更
(单 Owner 持有 XskSocket,生命周期内不跨线程共享)。
§Ordering 论证
本引擎由单个 XskSocket 独占持有,生命周期内不跨线程共享(单 Owner
顺序访问,无并发发布场景)。原子类型仅用于以 &self 变更内部状态,
因此全部使用 Ordering::Relaxed:不存在跨线程 happens-before 需求。
若未来引入跨线程共享(如 Arc<DescriptorEngine>),必须重审本论证。
Implementations§
Source§impl DescriptorEngine
impl DescriptorEngine
Sourcepub fn new(max_frames: u64) -> Result<Self>
pub fn new(max_frames: u64) -> Result<Self>
创建描述符校验引擎(默认 4096 字节帧,shift = 12,fail-closed)
§参数
max_frames- 最大帧数量(必须 ≤ 2^20,即 20-bit 帧索引域)
§返回
Ok(Self)- 引擎实例Err(DescriptorError::InvalidCapacity)-max_frames > 2^20, 拒绝构造:超域帧索引与MAX_FRAME_INDEX契约冲突
Sourcepub fn with_frame_shift(max_frames: u64, frame_shift: u32) -> Result<Self>
pub fn with_frame_shift(max_frames: u64, frame_shift: u32) -> Result<Self>
创建描述符校验引擎(显式帧移位,fail-closed)
§参数
max_frames- 最大帧数量(必须 ≤ 2^20,即 20-bit 帧索引域)frame_shift- log2(frame_size),合法区间 11..=15 (帧大小 2048..=32768 字节)
§返回
Ok(Self)- 引擎实例Err(DescriptorError::InvalidFrameShift)-frame_shift非法, 拒绝构造:防止frame_index << frame_shift在 debug shift-overflow panic / release 移位掩码静默错误地址Err(DescriptorError::InvalidCapacity)-max_frames > 2^20, 拒绝构造:20-bit frame index 域容量上限为 2^20(MAX_FRAME_INDEX+ 1), 超域帧索引会与Descriptor::from_xdp的越界拒绝语义冲突
Sourcepub fn frame_shift(&self) -> u32
pub fn frame_shift(&self) -> u32
获取帧移位(log2(frame_size))
Sourcepub fn release(&self, desc: &Descriptor) -> Result<()>
pub fn release(&self, desc: &Descriptor) -> Result<()>
Sourcepub fn rollback_allocate(&self, frame_index: u32) -> bool
pub fn rollback_allocate(&self, frame_index: u32) -> bool
Sourcepub fn transfer_ownership(
&self,
desc: &Descriptor,
old_owner: u16,
new_owner: u16,
) -> Result<Descriptor>
pub fn transfer_ownership( &self, desc: &Descriptor, old_owner: u16, new_owner: u16, ) -> Result<Descriptor>
Sourcepub fn is_allocated(&self, index: u32) -> bool
pub fn is_allocated(&self, index: u32) -> bool
查询帧是否已被引擎分配(位图是否置位)
供 Fill Ring 预填/补填路径判定「帧是否已登记」:与 allocate 的
AlreadyAllocated fail-closed 配套,避免从 0 重复登记已分配帧。
Sourcepub fn bump_generation(&self) -> Result<u64>
pub fn bump_generation(&self) -> Result<u64>
增加全局代际号(fail-closed:与 transfer_ownership 同域约束)
代际域为 u16(Descriptor.generation: u16);原实现可无限增长,
与 transfer_ownership「超 u16::MAX 拒绝」语义不一致——调用方若把
返回值截断成 u16 会静默回绕。超域时返回错误而非截断。
§返回
Ok(u64)- 递增后的新代际号(≤ u16::MAX)Err(DescriptorError::TransactionFailed)- 代际号超出 u16 范围
Sourcepub fn conservation_stats(&self) -> (u64, u64)
pub fn conservation_stats(&self) -> (u64, u64)
获取守恒统计
Sourcepub fn verify_conservation(&self) -> bool
pub fn verify_conservation(&self) -> bool
检查守恒等式:allocated == freed + active
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for DescriptorEngine
impl RefUnwindSafe for DescriptorEngine
impl Send for DescriptorEngine
impl Sync for DescriptorEngine
impl Unpin for DescriptorEngine
impl UnsafeUnpin for DescriptorEngine
impl UnwindSafe for DescriptorEngine
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more