forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add HermitOS support of vectored read/write operations
In general, the I/O interface of hermit-abi is more POSIX-like interface. Consequently, platform abstraction layer for HermitOS has slightly adjusted and some inaccuracies remove.
- Loading branch information
Showing
11 changed files
with
181 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
use crate::marker::PhantomData; | ||
use crate::os::hermit::io::{AsFd, AsRawFd}; | ||
use crate::slice; | ||
|
||
use hermit_abi::{c_void, iovec}; | ||
|
||
#[derive(Copy, Clone)] | ||
#[repr(transparent)] | ||
pub struct IoSlice<'a> { | ||
vec: iovec, | ||
_p: PhantomData<&'a [u8]>, | ||
} | ||
|
||
impl<'a> IoSlice<'a> { | ||
#[inline] | ||
pub fn new(buf: &'a [u8]) -> IoSlice<'a> { | ||
IoSlice { | ||
vec: iovec { iov_base: buf.as_ptr() as *mut u8 as *mut c_void, iov_len: buf.len() }, | ||
_p: PhantomData, | ||
} | ||
} | ||
|
||
#[inline] | ||
pub fn advance(&mut self, n: usize) { | ||
if self.vec.iov_len < n { | ||
panic!("advancing IoSlice beyond its length"); | ||
} | ||
|
||
unsafe { | ||
self.vec.iov_len -= n; | ||
self.vec.iov_base = self.vec.iov_base.add(n); | ||
} | ||
} | ||
|
||
#[inline] | ||
pub fn as_slice(&self) -> &[u8] { | ||
unsafe { slice::from_raw_parts(self.vec.iov_base as *mut u8, self.vec.iov_len) } | ||
} | ||
} | ||
|
||
#[repr(transparent)] | ||
pub struct IoSliceMut<'a> { | ||
vec: iovec, | ||
_p: PhantomData<&'a mut [u8]>, | ||
} | ||
|
||
impl<'a> IoSliceMut<'a> { | ||
#[inline] | ||
pub fn new(buf: &'a mut [u8]) -> IoSliceMut<'a> { | ||
IoSliceMut { | ||
vec: iovec { iov_base: buf.as_mut_ptr() as *mut c_void, iov_len: buf.len() }, | ||
_p: PhantomData, | ||
} | ||
} | ||
|
||
#[inline] | ||
pub fn advance(&mut self, n: usize) { | ||
if self.vec.iov_len < n { | ||
panic!("advancing IoSliceMut beyond its length"); | ||
} | ||
|
||
unsafe { | ||
self.vec.iov_len -= n; | ||
self.vec.iov_base = self.vec.iov_base.add(n); | ||
} | ||
} | ||
|
||
#[inline] | ||
pub fn as_slice(&self) -> &[u8] { | ||
unsafe { slice::from_raw_parts(self.vec.iov_base as *mut u8, self.vec.iov_len) } | ||
} | ||
|
||
#[inline] | ||
pub fn as_mut_slice(&mut self) -> &mut [u8] { | ||
unsafe { slice::from_raw_parts_mut(self.vec.iov_base as *mut u8, self.vec.iov_len) } | ||
} | ||
} | ||
|
||
pub fn is_terminal(fd: &impl AsFd) -> bool { | ||
let fd = fd.as_fd(); | ||
hermit_abi::isatty(fd.as_raw_fd()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.