Skip to content

Commit

Permalink
Allows specify offset to Uio
Browse files Browse the repository at this point in the history
  • Loading branch information
ultimaweapon committed Nov 12, 2024
1 parent 52cbd3a commit 8e3461c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
6 changes: 3 additions & 3 deletions kernel-1100/src/uio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct Uio {
}

impl okf::uio::Uio<Kernel> for Uio {
unsafe fn write(td: *mut Thread, iov: *mut IoVec) -> Option<Self> {
unsafe fn write(iov: *mut IoVec, td: *mut Thread) -> Option<Self> {
let res = (*iov).len;

if res > Self::io_max() {
Expand All @@ -34,7 +34,7 @@ impl okf::uio::Uio<Kernel> for Uio {
})
}

unsafe fn read(td: *mut Thread, iov: *mut IoVec) -> Option<Self> {
unsafe fn read(iov: *mut IoVec, off: usize, td: *mut Thread) -> Option<Self> {
let res = (*iov).len;

if res > Self::io_max() {
Expand All @@ -44,7 +44,7 @@ impl okf::uio::Uio<Kernel> for Uio {
Some(Self {
iov,
len: 1,
off: 0,
off: off.try_into().unwrap(),
res: res.try_into().unwrap(),
seg: UioSeg::Kernel,
op: UioRw::Read,
Expand Down
2 changes: 1 addition & 1 deletion src/fd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub unsafe fn write<K: Kernel>(
};

// Write.
let mut uio = K::Uio::write(td, &mut vec).unwrap();
let mut uio = K::Uio::write(&mut vec, td).unwrap();
let errno = kern.kern_writev(td, fd, &mut uio);

match NonZero::new(errno) {
Expand Down
7 changes: 5 additions & 2 deletions src/uio/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ pub trait Uio<K: Kernel>: Sized {
/// # Safety
/// - `td` cannot be null.
/// - `iov` cannot be null.
unsafe fn write(td: *mut K::Thread, iov: *mut IoVec) -> Option<Self>;
unsafe fn write(iov: *mut IoVec, td: *mut K::Thread) -> Option<Self>;

/// Returns [`None`] if [`IoVec::len`] of `iov` is greater than [`Uio::io_max()`].
///
/// # Safety
/// - `td` cannot be null.
/// - `iov` cannot be null.
unsafe fn read(td: *mut K::Thread, iov: *mut IoVec) -> Option<Self>;
///
/// # Panics
/// If `off` larger than [`isize::MAX`].
unsafe fn read(iov: *mut IoVec, off: usize, td: *mut K::Thread) -> Option<Self>;

/// Returns value of `UIO_MAXIOV`.
fn vec_max() -> usize {
Expand Down

0 comments on commit 8e3461c

Please sign in to comment.