From patchwork Tue Jun 12 00:51:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 138270 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp4699957lji; Mon, 11 Jun 2018 17:56:40 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLvOYzsQTdhM5jY5bd6hYtmiP9ZMgmeTQ686dtQf5XWhvHcfhwJcR0gDpw/ma90a+aX1+Vq X-Received: by 2002:a37:d708:: with SMTP id m8-v6mr1371250qki.48.1528765000566; Mon, 11 Jun 2018 17:56:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528765000; cv=none; d=google.com; s=arc-20160816; b=syy8DysGbl/W0ImYnpJ6JIpcjjDsFNalgyT83pOQ/DL7hW9Ed6uEWmA7t66G5CPHKV kAWsw9WVdmusXE0S4ee+hcxKov/a2GELsjicRFrj9eRW4jISx8UjVWr6tixkx1Z22/vw ObO4leZvmXwcRAmIlTK3oVelHACfYajtLrbH64VCVfCYjwkVLhrvNtrcDl9iFM2wPj2N 7g7/3oa61pNforRj/2INIZeO3zvtxp6YbpzMPEhnWJfDVBiiur5AggALxhdlgJ1PlDDM aJBIXu42th8TFEjQtSwXkBavMmh9EgXmWdoY72j4+DSKdFmzaMlwKqbUtz/KU2JOiAE2 vbyA== 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=+K9eHyBZxh1DjMdZCJtk1X/Nq7l/oIzgsW2DZPPVyqw=; b=bIdZhapHpok6HucIUH7nl+QeCzK3AtoLRRis6PR1dx8eiF1qKaR13oKgwp6RghQBbm dd7kKbaLXxukuvI5lzzuKyT9w660r0sZrn2iIhW7q69XZ3PEFOYg7mIfdt0aKewwb/AG 0W/h0vNiWfKWU/IMbKci0coJEJJltFtI4ZjG1xGIPRp3Ztui59emguh0WB7BKJLd0wb1 Ju7C7rFZfQqLGU1KlcmKL6I+iTIhIxm55RNRUXjRXlt6D7cmXUJizsTUXd23DvKXUn0S AbB2HUG06NKf6/Zjr7usfVYoVb6UCz/JVcojye7sXoec/eBycUU7W/uOAkW0DDkNGDV2 P40w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=BzzlGUQF; 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 h134-v6si2250559qke.208.2018.06.11.17.56.40 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 11 Jun 2018 17:56:40 -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=BzzlGUQF; 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]:52028 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSXbz-0000NF-W9 for patch@linaro.org; Mon, 11 Jun 2018 20:56:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59389) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSXXw-0005M2-12 for qemu-devel@nongnu.org; Mon, 11 Jun 2018 20:52:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fSXXu-0007ht-IX for qemu-devel@nongnu.org; Mon, 11 Jun 2018 20:52:28 -0400 Received: from mail-pg0-x244.google.com ([2607:f8b0:400e:c05::244]:34760) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fSXXu-0007h6-9r for qemu-devel@nongnu.org; Mon, 11 Jun 2018 20:52:26 -0400 Received: by mail-pg0-x244.google.com with SMTP id q4-v6so9531607pgr.1 for ; Mon, 11 Jun 2018 17:52:26 -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=+K9eHyBZxh1DjMdZCJtk1X/Nq7l/oIzgsW2DZPPVyqw=; b=BzzlGUQFVl296KTHKipjjnS7xaSLqivCzTt4tc+7slUrqzV63dUd+M2ng9TkSez4ON JlXsFgQSKVuh6u4KxJVfOcPKilYWfDfj/HW+HN1BlGeVt7YnQSAWk+ZmZ8bRtjTv2afd YTUn8eZOUKF5kdNuYfLaf1+Z5M+PYi4RsDvXg= 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=+K9eHyBZxh1DjMdZCJtk1X/Nq7l/oIzgsW2DZPPVyqw=; b=NFhqGZxCNPpZU9YLwrXH1hNye5avSHoaAn7JMAp/FgN1089i0t5TJkErnPiyXcxa1f DDopPQwN9qahoQILPw+ukURYD9LNnarKgwIDPv5jwBGsVN7P6EfrGlhTDoybWtMuxotG rPsEdTBq0ZQcrLDLuDVLmbhtgiPJ1Mof/F4aY0KF2I/N8Rh8A7VrF3UcIltwI/KypjJ4 JSkiENz4zSY36o/IOasYvWTFw7HOXRpZL8W4zynGh7Rvw3xsv4tSy+3p9WXJsgdg4X7R rxs6wf+mVag/KzLjgOJm3WwBStrI8S3Rmd4kKEbiivjp2Wyun/QYBOOW+A3+ffXHWXo5 O3Wg== X-Gm-Message-State: APt69E3SpzZek18F9BC2S8+IGixDgL6BHb36Z+zID4ga53QcnAiRvzf0 fnZr+wTJ4/HAAN5mIwAUziAC22rpHow= X-Received: by 2002:a63:a00a:: with SMTP id r10-v6mr1238471pge.222.1528764745000; Mon, 11 Jun 2018 17:52:25 -0700 (PDT) Received: from cloudburst.twiddle.net (rrcs-173-198-77-219.west.biz.rr.com. [173.198.77.219]) by smtp.gmail.com with ESMTPSA id l26-v6sm43362802pgn.55.2018.06.11.17.52.22 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 11 Jun 2018 17:52:24 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 11 Jun 2018 14:51:41 -1000 Message-Id: <20180612005145.3375-16-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180612005145.3375-1-richard.henderson@linaro.org> References: <20180612005145.3375-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::244 Subject: [Qemu-devel] [PATCH v3 15/19] linux-user: Split out pread64, pwrite64 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: peter.maydell@linaro.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Richard Henderson --- linux-user/syscall.h | 44 +++++++++++++++++++++ linux-user/syscall.c | 70 ---------------------------------- linux-user/syscall_file.c | 61 +++++++++++++++++++++++++++-- linux-user/gen_syscall_list.py | 2 + linux-user/strace.list | 6 --- 5 files changed, 104 insertions(+), 79 deletions(-) -- 2.17.1 Reviewed-by: Philippe Mathieu-Daudé diff --git a/linux-user/syscall.h b/linux-user/syscall.h index 3fc49d5b65..a157e25bba 100644 --- a/linux-user/syscall.h +++ b/linux-user/syscall.h @@ -174,6 +174,50 @@ struct iovec *lock_iovec(int type, abi_ulong target_addr, void unlock_iovec(struct iovec *vec, abi_ulong target_addr, abi_ulong count, int copy); +/* Returns true if syscall NUM expects 64bit types aligned even + * on pairs of registers. + */ +static inline bool regpairs_aligned(void *cpu_env, int num) +{ +#ifdef TARGET_ARM + return ((CPUARMState *)cpu_env)->eabi; +#elif defined(TARGET_MIPS) && TARGET_ABI_BITS == 32 + return true; +#elif defined(TARGET_PPC) && !defined(TARGET_PPC64) + /* SysV AVI for PPC32 expects 64bit parameters to be passed on + * odd/even pairs of registers which translates to the same as + * we start with r3 as arg1 + */ + return true; +#elif defined(TARGET_SH4) + /* SH4 doesn't align register pairs, except for p{read,write}64 */ + switch (num) { + case TARGET_NR_pread64: + case TARGET_NR_pwrite64: + return true; + default: + return false; + } +#elif defined(TARGET_XTENSA) + return true; +#else + return false; +#endif +} + +static inline uint64_t target_offset64(abi_ulong word0, abi_ulong word1) +{ +#if TARGET_ABI_BITS == 32 +# ifdef TARGET_WORDS_BIGENDIAN + return ((uint64_t)word0 << 32) | word1; +# else + return ((uint64_t)word1 << 32) | word0; +# endif +#else + return word0; +#endif +} + /* Temporary declarations from syscall_foo.c back to main syscall.c. * These indicate incomplete conversion. */ diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 381ee9c3a2..cdc9787240 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -642,38 +642,6 @@ static inline int next_free_host_timer(void) } #endif -/* ARM EABI and MIPS expect 64bit types aligned even on pairs or registers */ -#ifdef TARGET_ARM -static inline int regpairs_aligned(void *cpu_env, int num) -{ - return ((((CPUARMState *)cpu_env)->eabi) == 1) ; -} -#elif defined(TARGET_MIPS) && (TARGET_ABI_BITS == 32) -static inline int regpairs_aligned(void *cpu_env, int num) { return 1; } -#elif defined(TARGET_PPC) && !defined(TARGET_PPC64) -/* SysV AVI for PPC32 expects 64bit parameters to be passed on odd/even pairs - * of registers which translates to the same as ARM/MIPS, because we start with - * r3 as arg1 */ -static inline int regpairs_aligned(void *cpu_env, int num) { return 1; } -#elif defined(TARGET_SH4) -/* SH4 doesn't align register pairs, except for p{read,write}64 */ -static inline int regpairs_aligned(void *cpu_env, int num) -{ - switch (num) { - case TARGET_NR_pread64: - case TARGET_NR_pwrite64: - return 1; - - default: - return 0; - } -} -#elif defined(TARGET_XTENSA) -static inline int regpairs_aligned(void *cpu_env, int num) { return 1; } -#else -static inline int regpairs_aligned(void *cpu_env, int num) { return 0; } -#endif - #define ERRNO_TABLE_SIZE 1200 /* target_to_host_errno_table[] is initialized from @@ -6864,22 +6832,6 @@ void syscall_init(void) } } -#if TARGET_ABI_BITS == 32 -static inline uint64_t target_offset64(uint32_t word0, uint32_t word1) -{ -#ifdef TARGET_WORDS_BIGENDIAN - return ((uint64_t)word0 << 32) | word1; -#else - return ((uint64_t)word1 << 32) | word0; -#endif -} -#else /* TARGET_ABI_BITS == 32 */ -static inline uint64_t target_offset64(uint64_t word0, uint64_t word1) -{ - return word0; -} -#endif /* TARGET_ABI_BITS != 32 */ - #ifdef TARGET_NR_truncate64 static inline abi_long target_truncate64(void *cpu_env, const char *arg1, abi_long arg2, @@ -10078,28 +10030,6 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, #else #error unreachable #endif -#endif -#ifdef TARGET_NR_pread64 - case TARGET_NR_pread64: - if (regpairs_aligned(cpu_env, num)) { - arg4 = arg5; - arg5 = arg6; - } - if (!(p = lock_user(VERIFY_WRITE, arg2, arg3, 0))) - return -TARGET_EFAULT; - ret = get_errno(pread64(arg1, p, arg3, target_offset64(arg4, arg5))); - unlock_user(p, arg2, ret); - return ret; - case TARGET_NR_pwrite64: - if (regpairs_aligned(cpu_env, num)) { - arg4 = arg5; - arg5 = arg6; - } - if (!(p = lock_user(VERIFY_READ, arg2, arg3, 1))) - return -TARGET_EFAULT; - ret = get_errno(pwrite64(arg1, p, arg3, target_offset64(arg4, arg5))); - unlock_user(p, arg2, 0); - return ret; #endif case TARGET_NR_getcwd: if (!(p = lock_user(VERIFY_WRITE, arg1, arg2, 0))) diff --git a/linux-user/syscall_file.c b/linux-user/syscall_file.c index 4cc7051847..aae9c49599 100644 --- a/linux-user/syscall_file.c +++ b/linux-user/syscall_file.c @@ -378,15 +378,70 @@ SYSCALL_IMPL(openat) } SYSCALL_DEF(openat, ARG_ATDIRFD, ARG_STR, ARG_OPENFLAG, ARG_MODEFLAG); +/* Both pread64 and pwrite64 merge args into a 64-bit offset, + * but the input registers and ordering are target specific. + */ +#if TARGET_ABI_BITS == 32 +SYSCALL_ARGS(pread64_pwrite64) +{ + /* We have already assigned out[0-2]. */ + int off = regpairs_aligned(cpu_env, TARGET_NR_pread64); + out[3] = target_offset64(in[3 + off], in[4 + off]); + return def; +} +#else +#define args_pread64_pwrite64 NULL +#endif + +SYSCALL_IMPL(pread64) +{ + void *p = lock_user(VERIFY_WRITE, arg2, arg3, 0); + abi_long ret; + + if (!p) { + return -TARGET_EFAULT; + } + ret = get_errno(pread64(arg1, p, arg3, arg4)); + unlock_user(p, arg2, ret); + return ret; +} + +const SyscallDef def_pread64 = { + .name = "pread64", + .args = args_pread64_pwrite64, + .impl = impl_pread64, + .arg_type = { ARG_DEC, ARG_PTR, ARG_DEC, ARG_DEC64 } +}; + +SYSCALL_IMPL(pwrite64) +{ + void *p = lock_user(VERIFY_READ, arg2, arg3, 0); + abi_long ret; + + if (!p) { + return -TARGET_EFAULT; + } + ret = get_errno(pwrite64(arg1, p, arg3, arg4)); + unlock_user(p, arg2, 0); + return ret; +} + +const SyscallDef def_pwrite64 = { + .name = "pwrite64", + .args = args_pread64_pwrite64, + .impl = impl_pwrite64, + .arg_type = { ARG_DEC, ARG_PTR, ARG_DEC, ARG_DEC64 } +}; + /* 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; + /* We have already assigned out[0-2]. */ + abi_ulong lo = in[3], hi = in[4]; + out[3] = ((hi << (TARGET_ABI_BITS - 1)) << 1) | lo; return def; } #else diff --git a/linux-user/gen_syscall_list.py b/linux-user/gen_syscall_list.py index ce6dca742c..7481d030ee 100644 --- a/linux-user/gen_syscall_list.py +++ b/linux-user/gen_syscall_list.py @@ -27,7 +27,9 @@ import sys unconditional_syscalls = [ "close", "openat", + "pread64", "preadv", + "pwrite64", "pwritev", "read", "readv", diff --git a/linux-user/strace.list b/linux-user/strace.list index d5ee55ac82..d978cefa31 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_pread64 -{ TARGET_NR_pread64, "pread64" , 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_pwrite64 -{ TARGET_NR_pwrite64, "pwrite64" , NULL, NULL, NULL }, -#endif #ifdef TARGET_NR_query_module { TARGET_NR_query_module, "query_module" , NULL, NULL, NULL }, #endif