Skip to content

Commit

Permalink
Revert "using for readv/writev the same interface like UNIX"
Browse files Browse the repository at this point in the history
This reverts commit 6f195a2.
  • Loading branch information
stlankes committed May 22, 2024
1 parent 90d048a commit a5b91d1
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/syscalls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ struct iovec {
pub iov_len: usize,
}

const IOV_MAX: i32 = 1024;
const IOV_MAX: usize = 1024;

pub(crate) fn init() {
Lazy::force(&SYS);
Expand Down Expand Up @@ -450,13 +450,13 @@ pub unsafe extern "C" fn sys_read(fd: FileDescriptor, buf: *mut u8, len: usize)
/// before proceeding to the next.
#[hermit_macro::system]
#[no_mangle]
pub unsafe extern "C" fn sys_readv(fd: i32, iov: *const iovec, iovcnt: i32) -> isize {
pub unsafe extern "C" fn sys_readv(fd: i32, iov: *const iovec, iovcnt: usize) -> isize {
if !(0..=IOV_MAX).contains(&iovcnt) {
return (-crate::errno::EINVAL).try_into().unwrap();
}

let mut read_bytes: isize = 0;
let iovec_buffers = unsafe { core::slice::from_raw_parts(iov, iovcnt.try_into().unwrap()) };
let iovec_buffers = unsafe { core::slice::from_raw_parts(iov, iovcnt) };

for iovec_buf in iovec_buffers {
let buf = unsafe { core::slice::from_raw_parts_mut(iovec_buf.iov_base, iovec_buf.iov_len) };
Expand Down Expand Up @@ -511,13 +511,13 @@ pub unsafe extern "C" fn sys_write(fd: FileDescriptor, buf: *const u8, len: usiz
/// complete area before proceeding to the next.
#[hermit_macro::system]
#[no_mangle]
pub unsafe extern "C" fn sys_writev(fd: FileDescriptor, iov: *const iovec, iovcnt: i32) -> isize {
pub unsafe extern "C" fn sys_writev(fd: FileDescriptor, iov: *const iovec, iovcnt: usize) -> isize {
if !(0..=IOV_MAX).contains(&iovcnt) {
return (-crate::errno::EINVAL).try_into().unwrap();
}

let mut written_bytes: isize = 0;
let iovec_buffers = unsafe { core::slice::from_raw_parts(iov, iovcnt.try_into().unwrap()) };
let iovec_buffers = unsafe { core::slice::from_raw_parts(iov, iovcnt) };

for iovec_buf in iovec_buffers {
let buf = unsafe { core::slice::from_raw_parts(iovec_buf.iov_base, iovec_buf.iov_len) };
Expand Down

0 comments on commit a5b91d1

Please sign in to comment.