UserBuffer

Struct UserBuffer 

Source
pub struct UserBuffer {
    data: *mut u8,
    len: usize,
}
Expand description

用户缓冲区结构体

Fields§

§data: *mut u8§len: usize

Implementations§

Source§

impl UserBuffer

Source

pub fn new(data: *mut u8, len: usize) -> Self

创建一个新的用户缓冲区

§参数:
  • data: 指向用户缓冲区的指针
  • len: 缓冲区的长度
Source

pub unsafe fn copy_from_user(self) -> Vec<u8>

从用户缓冲区向内核缓冲区复制数据

§Safety
  • 调用方必须保证 self.data .. self.data + self.len 是用户空间中有效且已映射的可读内存;
  • 与目标内核缓冲区不重叠(此处目标是新分配的 Vec,天然满足);
  • 若无法在此处静态保证有效性,应在更高一层先做页表/范围校验。
Source

pub unsafe fn copy_to_user(self, data: &[u8])

将内核缓冲区数据拷贝到用户缓冲区 超过用户缓冲区长度的部分将被截断

§Safety
  • 调用方必须保证 self.data .. self.data + self.len 是用户空间中有效且已映射的可写内存;
  • 与源切片不重叠(此处源在内核内存,通常不与用户缓冲重叠)。
Source

pub fn range_sane(&self) -> bool

TODO: 运行时做一次“粗略”范围校验(不保证已映射,仅做地址区间与溢出检查) 建议在 syscall 层或结合 MemorySpace 做页表级校验。

Source

pub fn len(&self) -> usize

返回用户缓冲区长度

Source

pub fn is_empty(&self) -> bool

判断用户缓冲区是否为空

Auto Trait Implementations§

§

impl Freeze for UserBuffer

§

impl RefUnwindSafe for UserBuffer

§

impl !Send for UserBuffer

§

impl !Sync for UserBuffer

§

impl Unpin for UserBuffer

§

impl UnwindSafe for UserBuffer

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.