From 81cced6ebeb4419a78a8892ec7d7e28f5582d24a Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Thu, 25 Jan 2024 12:02:34 -0500 Subject: [PATCH] add preadv2 and pwritev2 syscall wrappers, flag value macros --- include/sys/uio.h | 7 +++++++ src/linux/preadv2.c | 17 +++++++++++++++++ src/linux/pwritev2.c | 17 +++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 src/linux/preadv2.c create mode 100644 src/linux/pwritev2.c diff --git a/include/sys/uio.h b/include/sys/uio.h index 90e5939e..8b5e3de7 100644 --- a/include/sys/uio.h +++ b/include/sys/uio.h @@ -39,6 +39,13 @@ ssize_t pwritev (int, const struct iovec *, int, off_t); #ifdef _GNU_SOURCE ssize_t process_vm_writev(pid_t, const struct iovec *, unsigned long, const struct iovec *, unsigned long, unsigned long); ssize_t process_vm_readv(pid_t, const struct iovec *, unsigned long, const struct iovec *, unsigned long, unsigned long); +ssize_t preadv2 (int, const struct iovec *, int, off_t, int); +ssize_t pwritev2 (int, const struct iovec *, int, off_t, int); +#define RWF_HIPRI 0x00000001 +#define RWF_DSYNC 0x00000002 +#define RWF_SYNC 0x00000004 +#define RWF_NOWAIT 0x00000008 +#define RWF_APPEND 0x00000010 #endif #ifdef __cplusplus diff --git a/src/linux/preadv2.c b/src/linux/preadv2.c new file mode 100644 index 00000000..5e7ab70f --- /dev/null +++ b/src/linux/preadv2.c @@ -0,0 +1,17 @@ +#define _GNU_SOURCE +#include +#include +#include "syscall.h" + +ssize_t preadv2(int fd, const struct iovec *iov, int count, off_t ofs, int flags) +{ +#ifdef SYS_preadv + if (!flags) { + if (ofs==-1) return readv(fd, iov, count); + return syscall_cp(SYS_preadv, fd, iov, count, + (long)(ofs), (long)(ofs>>32)); + } +#endif + return syscall_cp(SYS_preadv2, fd, iov, count, + (long)(ofs), (long)(ofs>>32), flags); +} diff --git a/src/linux/pwritev2.c b/src/linux/pwritev2.c new file mode 100644 index 00000000..ece90d7c --- /dev/null +++ b/src/linux/pwritev2.c @@ -0,0 +1,17 @@ +#define _GNU_SOURCE +#include +#include +#include "syscall.h" + +ssize_t pwritev2(int fd, const struct iovec *iov, int count, off_t ofs, int flags) +{ +#ifdef SYS_pwritev + if (!flags) { + if (ofs==-1) return writev(fd, iov, count); + return syscall_cp(SYS_pwritev, fd, iov, count, + (long)(ofs), (long)(ofs>>32)); + } +#endif + return syscall_cp(SYS_pwritev2, fd, iov, count, + (long)(ofs), (long)(ofs>>32), flags); +}