Skip to content

Commit

Permalink
Add Iovec struct to nolibc
Browse files Browse the repository at this point in the history
  • Loading branch information
lkatalin committed Apr 2, 2020
1 parent 81949c2 commit 70ec52b
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions nolibc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,30 @@ pub use x86_64::*;

// TODO: These functions are naive implementations that are not performant.

/// Buffer used by readv() and writev() syscalls
#[repr(C)]
pub struct Iovec<'a> {
/// Buffer start address
pub base: *mut u8,

/// Number of bytes to transfer
pub size: usize,

phantom: core::marker::PhantomData<&'a ()>,
}

impl<'a> AsRef<[u8]> for Iovec<'a> {
fn as_ref(&self) -> &[u8] {
unsafe { core::slice::from_raw_parts(self.base, self.size) }
}
}

impl<'a> AsMut<[u8]> for Iovec<'a> {
fn as_mut(&mut self) -> &mut [u8] {
unsafe { core::slice::from_raw_parts_mut(self.base, self.size) }
}
}

/// # Safety
///
/// All libc functions are unsafe.
Expand Down

0 comments on commit 70ec52b

Please sign in to comment.