@@ -323,6 +323,76 @@ SYSCALL_IMPL(openat)
}
SYSCALL_DEF(openat, ARG_ATDIRFD, ARG_STR, ARG_OPENFLAG, ARG_MODEFLAG);
+/*
+ * Both preadv and pwritev merge args 4/5 into a 64-bit offset.
+ * Moreover, the parts are *always* in little-endian order.
+ */
+#if TARGET_ABI_BITS == 32
+SYSCALL_ARGS(preadv_pwritev)
+{
+ /* We have already assigned out[0-3]. */
+ abi_ulong lo = in[4], hi = in[5];
+ out[4] = ((hi << (TARGET_ABI_BITS - 1)) << 1) | lo;
+ return def;
+}
+#else
+#define args_preadv_pwritev NULL
+#endif
+
+/* Perform the inverse operation for the host. */
+static inline void host_offset64_low_high(unsigned long *l, unsigned long *h,
+ uint64_t off)
+{
+ *l = off;
+ *h = (off >> (HOST_LONG_BITS - 1)) >> 1;
+}
+
+SYSCALL_IMPL(preadv)
+{
+ struct iovec *vec = lock_iovec(VERIFY_WRITE, arg2, arg3, 0);
+ unsigned long lo, hi;
+ abi_long ret;
+
+ if (vec == NULL) {
+ return -host_to_target_errno(errno);
+ }
+
+ host_offset64_low_high(&lo, &hi, arg4);
+ ret = get_errno(safe_preadv(arg1, vec, arg3, lo, hi));
+ unlock_iovec(vec, arg2, arg3, 1);
+ return ret;
+}
+
+static const SyscallDef def_preadv = {
+ .name = "preadv",
+ .args = args_preadv_pwritev,
+ .impl = impl_preadv,
+ .arg_type = { ARG_DEC, ARG_PTR, ARG_DEC, ARG_DEC64 }
+};
+
+SYSCALL_IMPL(pwritev)
+{
+ struct iovec *vec = lock_iovec(VERIFY_READ, arg2, arg3, 1);
+ unsigned long lo, hi;
+ abi_long ret;
+
+ if (vec == NULL) {
+ ret = -host_to_target_errno(errno);
+ }
+
+ host_offset64_low_high(&lo, &hi, arg4);
+ ret = get_errno(safe_pwritev(arg1, vec, arg3, lo, hi));
+ unlock_iovec(vec, arg2, arg3, 0);
+ return ret;
+}
+
+static const SyscallDef def_pwritev = {
+ .name = "pwritev",
+ .args = args_preadv_pwritev,
+ .impl = impl_pwritev,
+ .arg_type = { ARG_DEC, ARG_PTR, ARG_DEC, ARG_DEC64 }
+};
+
SYSCALL_IMPL(read)
{
abi_long ret;
@@ -414,6 +484,20 @@ SYSCALL_IMPL(readlinkat)
SYSCALL_DEF(readlinkat, ARG_ATDIRFD, ARG_STR, ARG_PTR, ARG_DEC);
#endif
+SYSCALL_IMPL(readv)
+{
+ struct iovec *vec = lock_iovec(VERIFY_WRITE, arg2, arg3, 0);
+ abi_long ret;
+
+ if (vec == NULL) {
+ return -host_to_target_errno(errno);
+ }
+ ret = get_errno(safe_readv(arg1, vec, arg3));
+ unlock_iovec(vec, arg2, arg3, 1);
+ return ret;
+}
+SYSCALL_DEF(readv, ARG_DEC, ARG_PTR, ARG_DEC);
+
SYSCALL_IMPL(write)
{
TargetFdDataFunc trans = fd_trans_target_to_host_data(arg1);
@@ -438,3 +522,17 @@ SYSCALL_IMPL(write)
return ret;
}
SYSCALL_DEF(write, ARG_DEC, ARG_PTR, ARG_DEC);
+
+SYSCALL_IMPL(writev)
+{
+ struct iovec *vec = lock_iovec(VERIFY_READ, arg2, arg3, 1);
+ abi_long ret;
+
+ if (vec == NULL) {
+ return -host_to_target_errno(errno);
+ }
+ ret = get_errno(safe_writev(arg1, vec, arg3));
+ unlock_iovec(vec, arg2, arg3, 0);
+ return ret;
+}
+SYSCALL_DEF(writev, ARG_DEC, ARG_PTR, ARG_DEC);
@@ -3456,23 +3456,6 @@ static abi_long do_getsockopt(int sockfd, int level, int optname,
return ret;
}
-/* Convert target low/high pair representing file offset into the host
- * low/high pair. This function doesn't handle offsets bigger than 64 bits
- * as the kernel doesn't handle them either.
- */
-static void target_to_host_low_high(abi_ulong tlow,
- abi_ulong thigh,
- unsigned long *hlow,
- unsigned long *hhigh)
-{
- uint64_t off = tlow |
- ((unsigned long long)thigh << TARGET_LONG_BITS / 2) <<
- TARGET_LONG_BITS / 2;
-
- *hlow = off;
- *hhigh = (off >> HOST_LONG_BITS / 2) >> HOST_LONG_BITS / 2;
-}
-
static struct iovec *lock_iovec(int type, abi_ulong target_addr,
abi_ulong count, int copy)
{
@@ -10000,60 +9983,6 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
/* NOTE: the flock constant seems to be the same for every
Linux platform */
return get_errno(safe_flock(arg1, arg2));
- case TARGET_NR_readv:
- {
- struct iovec *vec = lock_iovec(VERIFY_WRITE, arg2, arg3, 0);
- if (vec != NULL) {
- ret = get_errno(safe_readv(arg1, vec, arg3));
- unlock_iovec(vec, arg2, arg3, 1);
- } else {
- ret = -host_to_target_errno(errno);
- }
- }
- return ret;
- case TARGET_NR_writev:
- {
- struct iovec *vec = lock_iovec(VERIFY_READ, arg2, arg3, 1);
- if (vec != NULL) {
- ret = get_errno(safe_writev(arg1, vec, arg3));
- unlock_iovec(vec, arg2, arg3, 0);
- } else {
- ret = -host_to_target_errno(errno);
- }
- }
- return ret;
-#if defined(TARGET_NR_preadv)
- case TARGET_NR_preadv:
- {
- struct iovec *vec = lock_iovec(VERIFY_WRITE, arg2, arg3, 0);
- if (vec != NULL) {
- unsigned long low, high;
-
- target_to_host_low_high(arg4, arg5, &low, &high);
- ret = get_errno(safe_preadv(arg1, vec, arg3, low, high));
- unlock_iovec(vec, arg2, arg3, 1);
- } else {
- ret = -host_to_target_errno(errno);
- }
- }
- return ret;
-#endif
-#if defined(TARGET_NR_pwritev)
- case TARGET_NR_pwritev:
- {
- struct iovec *vec = lock_iovec(VERIFY_READ, arg2, arg3, 1);
- if (vec != NULL) {
- unsigned long low, high;
-
- target_to_host_low_high(arg4, arg5, &low, &high);
- ret = get_errno(safe_pwritev(arg1, vec, arg3, low, high));
- unlock_iovec(vec, arg2, arg3, 0);
- } else {
- ret = -host_to_target_errno(errno);
- }
- }
- return ret;
-#endif
case TARGET_NR_getsid:
return get_errno(getsid(arg1));
#if defined(TARGET_NR_fdatasync) /* Not on alpha (osf_datasync ?) */
@@ -12125,8 +12054,12 @@ static const SyscallDef *syscall_table(int num)
*/
S(close);
S(openat);
+ S(preadv);
+ S(pwritev);
S(read);
+ S(readv);
S(write);
+ S(writev);
/*
* Conditional syscalls.
@@ -1028,9 +1028,6 @@
#ifdef TARGET_NR_pread64
{ TARGET_NR_pread64, "pread64" , NULL, NULL, NULL },
#endif
-#ifdef TARGET_NR_preadv
-{ TARGET_NR_preadv, "preadv" , NULL, NULL, NULL },
-#endif
#ifdef TARGET_NR_prlimit64
{ TARGET_NR_prlimit64, "prlimit64" , NULL, NULL, NULL },
#endif
@@ -1058,9 +1055,6 @@
#ifdef TARGET_NR_pwrite64
{ TARGET_NR_pwrite64, "pwrite64" , NULL, NULL, NULL },
#endif
-#ifdef TARGET_NR_pwritev
-{ TARGET_NR_pwritev, "pwritev" , NULL, NULL, NULL },
-#endif
#ifdef TARGET_NR_query_module
{ TARGET_NR_query_module, "query_module" , NULL, NULL, NULL },
#endif
@@ -1073,9 +1067,6 @@
#ifdef TARGET_NR_readdir
{ TARGET_NR_readdir, "readdir" , NULL, NULL, NULL },
#endif
-#ifdef TARGET_NR_readv
-{ TARGET_NR_readv, "readv" , NULL, NULL, NULL },
-#endif
#ifdef TARGET_NR_reboot
{ TARGET_NR_reboot, "reboot" , NULL, NULL, NULL },
#endif
@@ -1608,9 +1599,6 @@
#ifdef TARGET_NR_waitpid
{ TARGET_NR_waitpid, "waitpid" , "%s(%d,%p,%#x)", NULL, NULL },
#endif
-#ifdef TARGET_NR_writev
-{ TARGET_NR_writev, "writev" , "%s(%d,%p,%#x)", NULL, NULL },
-#endif
#ifdef TARGET_NR_utimensat
{ TARGET_NR_utimensat, "utimensat", NULL, print_utimensat, NULL },
#endif
Signed-off-by: Richard Henderson <richard.henderson@linaro.org> --- linux-user/syscall-file.inc.c | 98 +++++++++++++++++++++++++++++++++++ linux-user/syscall.c | 75 ++------------------------- linux-user/strace.list | 12 ----- 3 files changed, 102 insertions(+), 83 deletions(-) -- 2.17.1