From nobody Wed Nov 5 12:52:43 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1534619051207579.0298634808811; Sat, 18 Aug 2018 12:04:11 -0700 (PDT) Received: from localhost ([::1]:40127 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fr6W9-0006Wu-Le for importer@patchew.org; Sat, 18 Aug 2018 15:04:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55278) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fr6Tj-0005Il-W4 for qemu-devel@nongnu.org; Sat, 18 Aug 2018 15:01:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fr6Ti-0007FC-Pk for qemu-devel@nongnu.org; Sat, 18 Aug 2018 15:01:39 -0400 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]:44607) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fr6Ti-0007Eu-IA for qemu-devel@nongnu.org; Sat, 18 Aug 2018 15:01:38 -0400 Received: by mail-pg1-x543.google.com with SMTP id r1-v6so4943428pgp.11 for ; Sat, 18 Aug 2018 12:01:38 -0700 (PDT) Received: from cloudburst.twiddle.net (97-113-8-179.tukw.qwest.net. [97.113.8.179]) by smtp.gmail.com with ESMTPSA id q85-v6sm9362783pfa.151.2018.08.18.12.01.35 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 18 Aug 2018 12:01:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=RNrcFO0IIbu5SQXIoug74fiOZHpEwRgyOOs+bq08rPA=; b=PBzyN237KmYFOa/ELuHDo/FO3kGpNIfjP0GtR8wDrLc3Pj6Smbvrk5BElXIYnKd+oG ghx5HG28MbBOGgLEdnAiv5S2ln6FT1L6D5yX/NPAY5MJaXqS4nJYurde3Zbr4pSjtTSI HKbfvrSHsz84CE7MN4MYUIyTSBT3JwI0Y/tp0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=RNrcFO0IIbu5SQXIoug74fiOZHpEwRgyOOs+bq08rPA=; b=qHZTlhayT2YhUdhMm6JSHf8Mhh4rYDroCIND1csKgsj5ex0VT4NXPpSeLC0CVSRgXu fRfa9fwBjoD4bFwZENQp0Dd/wbEf01Ixn1hACiLqA/spmuow2UCBSZyn4QrTq8NmNyQl e8xU6YopFbc3kf0+uRxqlAZDV7IsyOvZLhIxaG7y0uoiOfkZV9dHHqTKfsm31MlE0Q8B GU2rU0lLmoN/1bJ1qFGaxqKwML7tUdXKM619Q7ZOIVT9cWzUHQdWLp4kJ10WAVkjeEPI VWJnTsqKxIVzPsWc6UEUo1Hu7XqR7PYx9CV9VofKaOGwQStH2Lhts0ddbLPJ5ZtKLXfc clGg== X-Gm-Message-State: AOUpUlEHgdnzvYwTkEtGxUbxuR5bZM73IReYjZbTdUhj4sw/v3AdPDBd n/i0spOhUAz25HimUa5fuUVvNv0ZLXg= X-Google-Smtp-Source: AA+uWPyGO2O0psIVcEny3xtkntY18Oi6onEN0itRsqfTf/qXFBkGGltzkzLgZNjPln7FRFJGh2UgmA== X-Received: by 2002:a62:7983:: with SMTP id u125-v6mr41476937pfc.177.1534618897189; Sat, 18 Aug 2018 12:01:37 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Sat, 18 Aug 2018 12:01:13 -0700 Message-Id: <20180818190118.12911-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180818190118.12911-1-richard.henderson@linaro.org> References: <20180818190118.12911-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::543 Subject: [Qemu-devel] [PATCH v4 11/16] linux-user: Split out preadv, pwritev, readv, writev X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: laurent@vivier.eu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Richard Henderson --- linux-user/syscall-file.inc.c | 98 +++++++++++++++++++++++++++++++++++ linux-user/syscall.c | 75 ++------------------------- linux-user/strace.list | 12 ----- 3 files changed, 102 insertions(+), 83 deletions(-) diff --git a/linux-user/syscall-file.inc.c b/linux-user/syscall-file.inc.c index aecc63682f..7eb5b968e2 100644 --- a/linux-user/syscall-file.inc.c +++ b/linux-user/syscall-file.inc.c @@ -323,6 +323,76 @@ SYSCALL_IMPL(openat) } SYSCALL_DEF(openat, ARG_ATDIRFD, ARG_STR, ARG_OPENFLAG, ARG_MODEFLAG); =20 +/* + * 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 =3D=3D 32 +SYSCALL_ARGS(preadv_pwritev) +{ + /* We have already assigned out[0-3]. */ + abi_ulong lo =3D in[4], hi =3D in[5]; + out[4] =3D ((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 =3D off; + *h =3D (off >> (HOST_LONG_BITS - 1)) >> 1; +} + +SYSCALL_IMPL(preadv) +{ + struct iovec *vec =3D lock_iovec(VERIFY_WRITE, arg2, arg3, 0); + unsigned long lo, hi; + abi_long ret; + + if (vec =3D=3D NULL) { + return -host_to_target_errno(errno); + } + + host_offset64_low_high(&lo, &hi, arg4); + ret =3D get_errno(safe_preadv(arg1, vec, arg3, lo, hi)); + unlock_iovec(vec, arg2, arg3, 1); + return ret; +} + +static const SyscallDef def_preadv =3D { + .name =3D "preadv", + .args =3D args_preadv_pwritev, + .impl =3D impl_preadv, + .arg_type =3D { ARG_DEC, ARG_PTR, ARG_DEC, ARG_DEC64 } +}; + +SYSCALL_IMPL(pwritev) +{ + struct iovec *vec =3D lock_iovec(VERIFY_READ, arg2, arg3, 1); + unsigned long lo, hi; + abi_long ret; + + if (vec =3D=3D NULL) { + ret =3D -host_to_target_errno(errno); + } + + host_offset64_low_high(&lo, &hi, arg4); + ret =3D get_errno(safe_pwritev(arg1, vec, arg3, lo, hi)); + unlock_iovec(vec, arg2, arg3, 0); + return ret; +} + +static const SyscallDef def_pwritev =3D { + .name =3D "pwritev", + .args =3D args_preadv_pwritev, + .impl =3D impl_pwritev, + .arg_type =3D { 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 =20 +SYSCALL_IMPL(readv) +{ + struct iovec *vec =3D lock_iovec(VERIFY_WRITE, arg2, arg3, 0); + abi_long ret; + + if (vec =3D=3D NULL) { + return -host_to_target_errno(errno); + } + ret =3D 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 =3D 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 =3D lock_iovec(VERIFY_READ, arg2, arg3, 1); + abi_long ret; + + if (vec =3D=3D NULL) { + return -host_to_target_errno(errno); + } + ret =3D get_errno(safe_writev(arg1, vec, arg3)); + unlock_iovec(vec, arg2, arg3, 0); + return ret; +} +SYSCALL_DEF(writev, ARG_DEC, ARG_PTR, ARG_DEC); diff --git a/linux-user/syscall.c b/linux-user/syscall.c index f757ae87b0..16824386fd 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -3456,23 +3456,6 @@ static abi_long do_getsockopt(int sockfd, int level,= int optname, return ret; } =20 -/* 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 =3D tlow | - ((unsigned long long)thigh << TARGET_LONG_BITS / 2) << - TARGET_LONG_BITS / 2; - - *hlow =3D off; - *hhigh =3D (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 =3D lock_iovec(VERIFY_WRITE, arg2, arg3, 0); - if (vec !=3D NULL) { - ret =3D get_errno(safe_readv(arg1, vec, arg3)); - unlock_iovec(vec, arg2, arg3, 1); - } else { - ret =3D -host_to_target_errno(errno); - } - } - return ret; - case TARGET_NR_writev: - { - struct iovec *vec =3D lock_iovec(VERIFY_READ, arg2, arg3, 1); - if (vec !=3D NULL) { - ret =3D get_errno(safe_writev(arg1, vec, arg3)); - unlock_iovec(vec, arg2, arg3, 0); - } else { - ret =3D -host_to_target_errno(errno); - } - } - return ret; -#if defined(TARGET_NR_preadv) - case TARGET_NR_preadv: - { - struct iovec *vec =3D lock_iovec(VERIFY_WRITE, arg2, arg3, 0); - if (vec !=3D NULL) { - unsigned long low, high; - - target_to_host_low_high(arg4, arg5, &low, &high); - ret =3D get_errno(safe_preadv(arg1, vec, arg3, low, high)); - unlock_iovec(vec, arg2, arg3, 1); - } else { - ret =3D -host_to_target_errno(errno); - } - } - return ret; -#endif -#if defined(TARGET_NR_pwritev) - case TARGET_NR_pwritev: - { - struct iovec *vec =3D lock_iovec(VERIFY_READ, arg2, arg3, 1); - if (vec !=3D NULL) { - unsigned long low, high; - - target_to_host_low_high(arg4, arg5, &low, &high); - ret =3D get_errno(safe_pwritev(arg1, vec, arg3, low, high)= ); - unlock_iovec(vec, arg2, arg3, 0); - } else { - ret =3D -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); =20 /* * Conditional syscalls. diff --git a/linux-user/strace.list b/linux-user/strace.list index f3a1b0fe31..f41b604c63 100644 --- a/linux-user/strace.list +++ b/linux-user/strace.list @@ -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 --=20 2.17.1