Merge branch 'split-iovec' into 'master'
split out iovec from sys_uio header See merge request redox-os/relibc!1147
This commit is contained in:
@@ -0,0 +1,18 @@
|
|||||||
|
# POSIX header spec: https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/sys_uio.h.html
|
||||||
|
#
|
||||||
|
# Split out to avoid including all of sys/uio.h in sys/socket.h.
|
||||||
|
#
|
||||||
|
# POSIX headers that require iovec:
|
||||||
|
# - sys/socket.h
|
||||||
|
# - sys/uio.h (where it should be defined)
|
||||||
|
#
|
||||||
|
# sys/types.h included for c_void and size_t
|
||||||
|
sys_includes = ["sys/types.h"]
|
||||||
|
include_guard = "_RELIBC_BITS_IOVEC_H"
|
||||||
|
language = "C"
|
||||||
|
style = "Tag"
|
||||||
|
no_includes = true
|
||||||
|
cpp_compat = true
|
||||||
|
|
||||||
|
[enum]
|
||||||
|
prefix_with_name = true
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
use alloc::vec::Vec;
|
||||||
|
use core::slice;
|
||||||
|
|
||||||
|
use crate::platform::types::{c_void, size_t};
|
||||||
|
|
||||||
|
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/sys_uio.h.html>.
|
||||||
|
#[repr(C)]
|
||||||
|
#[derive(Debug, CheckVsLibcCrate)]
|
||||||
|
pub struct iovec {
|
||||||
|
pub iov_base: *mut c_void,
|
||||||
|
pub iov_len: size_t,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl iovec {
|
||||||
|
unsafe fn to_slice(&self) -> &mut [u8] {
|
||||||
|
unsafe { slice::from_raw_parts_mut(self.iov_base.cast::<u8>(), self.iov_len) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn gather(iovs: &[iovec]) -> Vec<u8> {
|
||||||
|
let mut vec = Vec::new();
|
||||||
|
for iov in iovs.iter() {
|
||||||
|
vec.extend_from_slice(unsafe { iov.to_slice() });
|
||||||
|
}
|
||||||
|
vec
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn scatter(iovs: &[iovec], vec: Vec<u8>) {
|
||||||
|
let mut i = 0;
|
||||||
|
for iov in iovs.iter() {
|
||||||
|
let slice = unsafe { iov.to_slice() };
|
||||||
|
slice.copy_from_slice(&vec[i..][..slice.len()]);
|
||||||
|
i += slice.len();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ pub mod _fenv;
|
|||||||
pub mod arpa_inet;
|
pub mod arpa_inet;
|
||||||
pub mod assert;
|
pub mod assert;
|
||||||
pub mod bits_arpainet;
|
pub mod bits_arpainet;
|
||||||
|
pub mod bits_iovec;
|
||||||
#[path = "bits_locale-t/mod.rs"]
|
#[path = "bits_locale-t/mod.rs"]
|
||||||
pub mod bits_locale_t;
|
pub mod bits_locale_t;
|
||||||
pub mod bits_pthread;
|
pub mod bits_pthread;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
sys_includes = ["stddef.h", "stdint.h", "sys/types.h", "sys/uio.h"]
|
sys_includes = ["stddef.h", "stdint.h", "sys/types.h"]
|
||||||
include_guard = "_SYS_SOCKET_H"
|
include_guard = "_SYS_SOCKET_H"
|
||||||
after_includes = """
|
after_includes = """
|
||||||
|
#include <bits/iovec.h> // for iovec
|
||||||
#include <bits/socklen-t.h> // for socklen_t
|
#include <bits/socklen-t.h> // for socklen_t
|
||||||
"""
|
"""
|
||||||
trailer = "#include <bits/sys/socket.h>"
|
trailer = "#include <bits/sys/socket.h>"
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use core::{mem, ptr};
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
error::ResultExt,
|
error::ResultExt,
|
||||||
header::{bits_socklen_t::socklen_t, sys_uio::iovec},
|
header::{bits_iovec::iovec, bits_socklen_t::socklen_t},
|
||||||
platform::{
|
platform::{
|
||||||
PalSocket, Sys,
|
PalSocket, Sys,
|
||||||
types::{
|
types::{
|
||||||
|
|||||||
@@ -2,7 +2,9 @@
|
|||||||
#
|
#
|
||||||
# Spec quotations relating to includes:
|
# Spec quotations relating to includes:
|
||||||
# - "The <sys/uio.h> header shall define the ssize_t and size_t types as described in <sys/types.h>."
|
# - "The <sys/uio.h> header shall define the ssize_t and size_t types as described in <sys/types.h>."
|
||||||
sys_includes = ["sys/types.h"]
|
#
|
||||||
|
# bits/iovec.h brings in sys/types.h
|
||||||
|
sys_includes = ["bits/iovec.h"]
|
||||||
include_guard = "_SYS_UIO_H"
|
include_guard = "_SYS_UIO_H"
|
||||||
language = "C"
|
language = "C"
|
||||||
style = "Tag"
|
style = "Tag"
|
||||||
@@ -11,3 +13,6 @@ cpp_compat = true
|
|||||||
|
|
||||||
[enum]
|
[enum]
|
||||||
prefix_with_name = true
|
prefix_with_name = true
|
||||||
|
|
||||||
|
[export.rename]
|
||||||
|
"iovec" = "struct iovec"
|
||||||
|
|||||||
@@ -2,50 +2,21 @@
|
|||||||
//!
|
//!
|
||||||
//! See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/sys_uio.h.html>.
|
//! See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/sys_uio.h.html>.
|
||||||
|
|
||||||
use alloc::vec::Vec;
|
|
||||||
use core::slice;
|
use core::slice;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
header::{errno, unistd},
|
header::{
|
||||||
|
bits_iovec::{gather, iovec, scatter},
|
||||||
|
errno, unistd,
|
||||||
|
},
|
||||||
platform::{
|
platform::{
|
||||||
self,
|
self,
|
||||||
types::{c_int, c_void, off_t, size_t, ssize_t},
|
types::{c_int, c_void, off_t, ssize_t},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const IOV_MAX: c_int = 1024;
|
pub const IOV_MAX: c_int = 1024;
|
||||||
|
|
||||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/sys_uio.h.html>.
|
|
||||||
#[repr(C)]
|
|
||||||
#[derive(Debug, CheckVsLibcCrate)]
|
|
||||||
pub struct iovec {
|
|
||||||
pub iov_base: *mut c_void,
|
|
||||||
pub iov_len: size_t,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl iovec {
|
|
||||||
unsafe fn to_slice(&self) -> &mut [u8] {
|
|
||||||
unsafe { slice::from_raw_parts_mut(self.iov_base.cast::<u8>(), self.iov_len) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe fn gather(iovs: &[iovec]) -> Vec<u8> {
|
|
||||||
let mut vec = Vec::new();
|
|
||||||
for iov in iovs.iter() {
|
|
||||||
vec.extend_from_slice(unsafe { iov.to_slice() });
|
|
||||||
}
|
|
||||||
vec
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe fn scatter(iovs: &[iovec], vec: Vec<u8>) {
|
|
||||||
let mut i = 0;
|
|
||||||
for iov in iovs.iter() {
|
|
||||||
let slice = unsafe { iov.to_slice() };
|
|
||||||
slice.copy_from_slice(&vec[i..][..slice.len()]);
|
|
||||||
i += slice.len();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Non-POSIX, see <https://man7.org/linux/man-pages/man2/readv.2.html>.
|
/// Non-POSIX, see <https://man7.org/linux/man-pages/man2/readv.2.html>.
|
||||||
#[unsafe(no_mangle)]
|
#[unsafe(no_mangle)]
|
||||||
pub unsafe extern "C" fn preadv(
|
pub unsafe extern "C" fn preadv(
|
||||||
|
|||||||
@@ -12,7 +12,8 @@ use syscall::{
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
header::{
|
header::{
|
||||||
bits_time::timespec, errno::EINVAL, signal::sigaction, sys_stat::UTIME_NOW, sys_uio::iovec,
|
bits_iovec::iovec, bits_time::timespec, errno::EINVAL, signal::sigaction,
|
||||||
|
sys_stat::UTIME_NOW,
|
||||||
},
|
},
|
||||||
out::Out,
|
out::Out,
|
||||||
platform::{PalSignal, pal::Pal, types::*},
|
platform::{PalSignal, pal::Pal, types::*},
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ use crate::{
|
|||||||
error::{Errno, Result},
|
error::{Errno, Result},
|
||||||
header::{
|
header::{
|
||||||
arpa_inet::inet_aton,
|
arpa_inet::inet_aton,
|
||||||
|
bits_iovec::iovec,
|
||||||
bits_socklen_t::socklen_t,
|
bits_socklen_t::socklen_t,
|
||||||
errno::{
|
errno::{
|
||||||
EAFNOSUPPORT, EDOM, EFAULT, EINVAL, EMSGSIZE, ENOMEM, ENOSYS, ENOTSOCK, EOPNOTSUPP,
|
EAFNOSUPPORT, EDOM, EFAULT, EINVAL, EMSGSIZE, ENOMEM, ENOSYS, ENOTSOCK, EOPNOTSUPP,
|
||||||
@@ -25,7 +26,6 @@ use crate::{
|
|||||||
CMSG_ALIGN, CMSG_DATA, CMSG_FIRSTHDR, CMSG_LEN, CMSG_NXTHDR, CMSG_SPACE, cmsghdr,
|
CMSG_ALIGN, CMSG_DATA, CMSG_FIRSTHDR, CMSG_LEN, CMSG_NXTHDR, CMSG_SPACE, cmsghdr,
|
||||||
constants::*, msghdr, sa_family_t, sockaddr, ucred,
|
constants::*, msghdr, sa_family_t, sockaddr, ucred,
|
||||||
},
|
},
|
||||||
sys_uio::iovec,
|
|
||||||
sys_un::sockaddr_un,
|
sys_un::sockaddr_un,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user