Files

76 lines
2.3 KiB
C

#ifndef VLIBC_SYS_UIO_H
#define VLIBC_SYS_UIO_H
/*
* vlibc — <sys/uio.h>.
*
* Scatter/gather I/O: readv() and writev() transfer data between a file
* descriptor and a vector of memory buffers (POSIX.1-2008 base). Both are
* unbuffered pass-throughs to the kernel: the iovec array is handed to
* SYS_readv/SYS_writev as-is, and the kernel applies its own validation
* (iovcnt in 0..IOV_MAX, iov NULL with iovcnt > 0 faults as EFAULT). Failures
* are reported as -1 with errno set by the syscall layer.
*
* Level 1 (onlyposix): readv, writev.
*
* The Linux extensions that build on this ABI (preadv/pwritev,
* process_vm_readv/process_vm_writev, ...) are deliberately absent — they are
* not POSIX and belong to a later compatibility profile.
*
* struct iovec matches the kernel's struct iovec (x86_64: a pointer and a
* size_t, no padding). IOV_MAX is 1024, the Linux UIO_MAXIOV; the kernel
* rejects any iovcnt above it with EINVAL.
*
* None of these declarations carry an intent attribute: every function
* performs I/O with side effects and reports failures through errno, so
* const/pure would be unsound.
*/
#include <vlibc/features.h>
#include <stddef.h>
#include <sys/types.h>
#ifdef __cplusplus
extern "C" {
#endif
/* Maximum number of iovec entries a single readv()/writev() call accepts. */
#define IOV_MAX 1024
/*
* A scatter/gather segment: iov_base points at the buffer (or, for readv,
* the buffer to fill) and iov_len is its size in bytes. Kernel layout, as
* above.
*/
struct iovec
{
void *iov_base; /* starting address of the segment */
size_t iov_len; /* number of bytes in the segment */
};
/*
* Read up to the sum of iov_len bytes from fd into the iovcnt buffers of
* iov, in order; return the number of bytes read, 0 at end of file, or -1
* with errno set on error. Buffers are filled completely before the next
* one is touched.
*/
ssize_t
readv(int fd, const struct iovec *iov, int iovcnt);
/*
* Write up to the sum of iov_len bytes from the iovcnt buffers of iov to
* fd, in order; return the number of bytes written, or -1 with errno set
* on error. The kernel applies its own validation (iovcnt 0..IOV_MAX, iov
* NULL with iovcnt > 0 faults as EFAULT).
*/
ssize_t
writev(int fd, const struct iovec *iov, int iovcnt);
#ifdef __cplusplus
}
#endif
#endif /* VLIBC_SYS_UIO_H */