From patchwork Sat Aug 18 19:01:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 144500 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2202733ljj; Sat, 18 Aug 2018 12:05:07 -0700 (PDT) X-Google-Smtp-Source: AA+uWPxzFvX1xwv3wCKJpYh0ay3sAI+WOJvLNWrJpyUIyW6jBp1Egj0l51Gjgw3Fi4QuavX647FC X-Received: by 2002:ac8:7254:: with SMTP id l20-v6mr12492643qtp.108.1534619107783; Sat, 18 Aug 2018 12:05:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534619107; cv=none; d=google.com; s=arc-20160816; b=l7aoefA/VmwWDs6Q7MWCvkoYH/NzqA00HWvJyipRQnX/fOgla3et3i5aG/S3icZZtJ QN0P9gkPpTrIuqxqzG3lmq7Gd82muCU8g9a0B45oBhLuh4M2AXYb40WE9AU6BDieOAnp Rgtx5HNZGP228ouRp5FGmyxAOp4wqg9x8c2o/R0FTNgVggL0ios1wQhFaFWxDvmi8CqE a4unFVkKCUbEZC8SNExFyVhNiyzoW/1j1KyKLqBFgCwD46aBMPjR8dpYtkP7siasHLdt vGOQa07KzhGR7o8p6tBW2+O7YKiFSgsakdC1pk8AX0wc/gP8oNQPnEEH7O/5hCdbWRyM Vapw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=RNrcFO0IIbu5SQXIoug74fiOZHpEwRgyOOs+bq08rPA=; b=Te+c7QHwur0NGQogRWKAbeJDkOvhhqtSg3RF26YdKagDmHjYVMzBG4gyZaCFt6Htqh KhD1yiaUtF1navM9NpI69/HgxPbhY1+1OpbiIgk9sMi4gNaB2oGC9zEP+TOafMNCj0BA vMWxXsEVuz+/5n18w8xuCLQkke/UhesRovvFgZw/CCLy4r7wGFqTQE7bBlYi87xtEWie tmfciHcAZDzWT586GhtNc94js8YvbIXqPxh3Kn5cXXS58wZclL8z4QW5nWRmYL4OHcsk aVqpZG4YkotSFtfuuG4jJLfBjTGYZ15fxSMEQolNOThQeaZViYR9Sr3igmwYvrQMcQBM +mHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=PBzyN237; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id v2-v6si979497qtg.400.2018.08.18.12.05.07 for (version=TLS1 cipher=AES128-SHA bits=128/128); Sat, 18 Aug 2018 12:05:07 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=PBzyN237; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:40127 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fr6X5-0006Wu-9A for patch@linaro.org; Sat, 18 Aug 2018 15:05:07 -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) 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-Received: by 2002:a62:7983:: with SMTP id u125-v6mr41476937pfc.177.1534618897189; Sat, 18 Aug 2018 12:01:37 -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) 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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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(-) -- 2.17.1 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); +/* + * 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); 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; } -/* 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. 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