From 6f195a24421099296f7228d31a7afe7ea87bcee9 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Wed, 22 May 2024 08:37:38 +0200 Subject: [PATCH] using for readv/writev the same interface like UNIX --- src/syscalls/mod.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/syscalls/mod.rs b/src/syscalls/mod.rs index 219aff7b2a..39c49c8e78 100644 --- a/src/syscalls/mod.rs +++ b/src/syscalls/mod.rs @@ -72,7 +72,7 @@ struct iovec { pub iov_len: usize, } -const IOV_MAX: usize = 1024; +const IOV_MAX: i32 = 1024; pub(crate) fn init() { Lazy::force(&SYS); @@ -433,13 +433,14 @@ pub unsafe extern "C" fn sys_read(fd: FileDescriptor, buf: *mut u8, len: usize) } #[hermit_macro::system] -pub unsafe extern "C" fn sys_readv(fd: i32, iov: *const iovec, iovcnt: usize) -> isize { +#[no_mangle] +pub unsafe extern "C" fn sys_readv(fd: i32, iov: *const iovec, iovcnt: i32) -> isize { if iovcnt > IOV_MAX { return (-crate::errno::EINVAL).try_into().unwrap(); } let mut count: isize = 0; - let slice = unsafe { core::slice::from_raw_parts(iov, iovcnt) }; + let slice = unsafe { core::slice::from_raw_parts(iov, iovcnt.try_into().unwrap()) }; for i in slice { let buf = unsafe { core::slice::from_raw_parts_mut(i.iov_base, i.iov_len) }; @@ -479,13 +480,13 @@ pub unsafe extern "C" fn sys_write(fd: FileDescriptor, buf: *const u8, len: usiz #[hermit_macro::system] #[no_mangle] -pub unsafe extern "C" fn sys_writev(fd: FileDescriptor, iov: *const iovec, iovcnt: usize) -> isize { +pub unsafe extern "C" fn sys_writev(fd: FileDescriptor, iov: *const iovec, iovcnt: i32) -> isize { if iovcnt > IOV_MAX { return (-crate::errno::EINVAL).try_into().unwrap(); } let mut count: isize = 0; - let slice = unsafe { core::slice::from_raw_parts(iov, iovcnt) }; + let slice = unsafe { core::slice::from_raw_parts(iov, iovcnt.try_into().unwrap()) }; for i in slice { let buf = unsafe { core::slice::from_raw_parts(i.iov_base, i.iov_len) };