From nobody Fri Nov 7 12:59:48 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.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 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1547847443176945.1306247411899; Fri, 18 Jan 2019 13:37:23 -0800 (PST) Received: from localhost ([127.0.0.1]:47460 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gkbpJ-0000UE-KQ for importer@patchew.org; Fri, 18 Jan 2019 16:37:21 -0500 Received: from eggs.gnu.org ([209.51.188.92]:55871) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gkbk6-0004tG-9e for qemu-devel@nongnu.org; Fri, 18 Jan 2019 16:31:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gkbk5-0004K3-60 for qemu-devel@nongnu.org; Fri, 18 Jan 2019 16:31:58 -0500 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]:45977) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gkbk4-0004II-VC for qemu-devel@nongnu.org; Fri, 18 Jan 2019 16:31:57 -0500 Received: by mail-pl1-x642.google.com with SMTP id a14so6865602plm.12 for ; Fri, 18 Jan 2019 13:31:56 -0800 (PST) Received: from cloudburst.twiddle.net ([2001:8000:10e0:a000:c673:a6b6:fdef:1933]) by smtp.gmail.com with ESMTPSA id v12sm5833667pgg.41.2019.01.18.13.31.53 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 18 Jan 2019 13:31:54 -0800 (PST) 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=I6X/MozJcMBqJ6YJKlH5AoTg3Rm23QUrPNJcn9bFsPY=; b=IwgB15aQo6B0xlOYdrPbcxf8ZkRQhlPzj5kMVbQFJOKMnWVHUf38MwkkyKzi3Pvd8h hHMt2VfWnl9Q9QAhZIF6xhf0meRFPUyx3pwX6wGqCtzNbUUjTn+DuiwboMX2qJ7JOmx8 RR2UvDBwavo6ddvBEkcCP77EZuSsp+WyTqlGY= 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=I6X/MozJcMBqJ6YJKlH5AoTg3Rm23QUrPNJcn9bFsPY=; b=rzKkJC7WHWKrwvJf7LJ0YQ2oLpADgrK2CP/Tkh68hOMO0NW6aQu5xQIfXl0zwcUaYO PSUBlsCSEidsOpsuFpQ8Fo8CLXuYVho5CajNfkJud1276Igl8m92xtyy/NLuQWBTziuZ 9rvsC6Zncsvqt7WYuPVoA5u7odpBT6/c59JaEWLKfTh4xewgQ+HLYIPbnhSyWzWvb7Po Kww50eL9oWAG6iW6sarDwR/RLGDV/c/2704twXqloRqT2rZhZ8gTfTVYUEpjbhEnA6ni xXgOe9lz+Rbwg6uaqsdr99n0ZOnI+85HzFTc5MTHIpMONUlpm32Wapuho43kwY49zqiC obJA== X-Gm-Message-State: AJcUukcTCfQHINqaB2YNTIBWAumgf3bQFcs1uVqnR+nl5Hz7G+Qrwc2F bStYLmyBtjaDlBdeUiUZqGgJsrkl0ko= X-Google-Smtp-Source: ALg8bN7zF1zILR7pxNx3MNbovelbyO7ApbPv30kyyUt6b4kly99Q0oz5ETKVetvZCp7ttH6xQ3GxzQ== X-Received: by 2002:a17:902:8f97:: with SMTP id z23mr20955607plo.283.1547847115577; Fri, 18 Jan 2019 13:31:55 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Sat, 19 Jan 2019 08:30:45 +1100 Message-Id: <20190118213122.22865-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190118213122.22865-1-richard.henderson@linaro.org> References: <20190118213122.22865-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::642 Subject: [Qemu-devel] [PATCH v6 12/49] linux-user: Split out preadv, pwritev 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) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Richard Henderson --- linux-user/syscall-defs.h | 6 ++++ linux-user/syscall-file.inc.c | 64 +++++++++++++++++++++++++++++++++++ linux-user/syscall.c | 49 --------------------------- linux-user/strace.list | 6 ---- 4 files changed, 70 insertions(+), 55 deletions(-) diff --git a/linux-user/syscall-defs.h b/linux-user/syscall-defs.h index 027793d5d0..ae89be0e87 100644 --- a/linux-user/syscall-defs.h +++ b/linux-user/syscall-defs.h @@ -27,6 +27,12 @@ SYSCALL_DEF_FULL(pread64, .impl =3D impl_pread64, SYSCALL_DEF_FULL(pwrite64, .impl =3D impl_pwrite64, .args =3D args_pread64_pwrite64, .arg_type =3D { ARG_DEC, ARG_PTR, ARG_DEC, ARG_DEC64 }); +SYSCALL_DEF_FULL(preadv, .impl =3D impl_preadv, + .args =3D args_preadv_pwritev, + .arg_type =3D { ARG_DEC, ARG_PTR, ARG_DEC, ARG_DEC64 }); +SYSCALL_DEF_FULL(pwritev, .impl =3D impl_pwritev, + .args =3D args_preadv_pwritev, + .arg_type =3D { ARG_DEC, ARG_PTR, ARG_DEC, ARG_DEC64 }); SYSCALL_DEF(read, ARG_DEC, ARG_PTR, ARG_DEC); #ifdef TARGET_NR_readlink SYSCALL_DEF(readlink, ARG_STR, ARG_PTR, ARG_DEC); diff --git a/linux-user/syscall-file.inc.c b/linux-user/syscall-file.inc.c index e79cfabf56..63401684c3 100644 --- a/linux-user/syscall-file.inc.c +++ b/linux-user/syscall-file.inc.c @@ -379,6 +379,70 @@ SYSCALL_IMPL(pwrite64) return ret; } =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-2]. */ + abi_ulong lo =3D in[3], hi =3D in[4]; + out[3] =3D (((uint64_t)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) +{ + int fd =3D arg1; + abi_ulong target_vec =3D arg2; + int count =3D arg3; + uint64_t off =3D arg4; + struct iovec *vec =3D lock_iovec(VERIFY_WRITE, target_vec, count, 0); + unsigned long lo, hi; + abi_long ret; + + if (vec =3D=3D NULL) { + return -TARGET_EFAULT; + } + + host_offset64_low_high(&lo, &hi, off); + ret =3D get_errno(safe_preadv(fd, vec, count, lo, hi)); + unlock_iovec(vec, target_vec, count, 1); + return ret; +} + +SYSCALL_IMPL(pwritev) +{ + int fd =3D arg1; + abi_ulong target_vec =3D arg2; + int count =3D arg3; + uint64_t off =3D arg4; + struct iovec *vec =3D lock_iovec(VERIFY_READ, target_vec, count, 1); + unsigned long lo, hi; + abi_long ret; + + if (vec =3D=3D NULL) { + return -TARGET_EFAULT; + } + + host_offset64_low_high(&lo, &hi, off); + ret =3D get_errno(safe_pwritev(fd, vec, count, lo, hi)); + unlock_iovec(vec, target_vec, count, 0); + return ret; +} + SYSCALL_IMPL(read) { int fd =3D arg1; diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 80806c0150..9606f15a09 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -2403,23 +2403,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) { @@ -8949,38 +8932,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)); -#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 ?) */ diff --git a/linux-user/strace.list b/linux-user/strace.list index c7e573669d..586eb55482 100644 --- a/linux-user/strace.list +++ b/linux-user/strace.list @@ -1025,9 +1025,6 @@ #ifdef TARGET_NR_prctl { TARGET_NR_prctl, "prctl" , 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 @@ -1052,9 +1049,6 @@ #ifdef TARGET_NR_putpmsg { TARGET_NR_putpmsg, "putpmsg" , 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 --=20 2.17.2