From patchwork Sun Jun 10 03:02:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 138173 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp2613787lji; Sat, 9 Jun 2018 21:14:10 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIk2jv5jJfgHpXtiefGt36zmfFTmrVc/jgAzAQ/e05OiFhYpQDd9jlKkuQd5ZlVn/w4k90n X-Received: by 2002:aed:3601:: with SMTP id e1-v6mr11679660qtb.23.1528604050557; Sat, 09 Jun 2018 21:14:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528604050; cv=none; d=google.com; s=arc-20160816; b=fFPSM9brZDk8jA9YozZGBThdEOTbMz0HJPJ9+h9KSWT/S2FnOpV20gAPry485rtqfw FpoaiYbZJvQcoLe83it2W5wq6+p7llPtXbrqQRSQCenwnIms5+/fdS6vVo/vOw6ExpbC NtVMzdecejMe3wdv2ZaoeC0yG3nnEbL0+mhOTKePHsP1lBXbJke1F2dc1XU6tyYLGV4I SAPbRLUv7FzyX9vOt7CzBljg/3DEfpm+0k/I7ikdviKUVSgXob+RKGdHVJ87Au5+Mybi G35na2CRvJufuM6wexqbRvj3//DMoiy42aDPoye4gAJ9o7uYvYWLIq6HJVTUKmhIu9qT tSqQ== 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=4wG+S4fZiyUq1Pu/Hlt9nQvToX/s4he+oqXriYQ+nrE=; b=JGOuVv+JOvpYLG2LvzfCCpEawYDOPxl04xeEzb8VtLFnW57+3AFm3vYaJth39ORgco C4tCw5HU24tDao2QNcfP1QtjnblF1DEWgVJQLehp8E+8szdoBuSH6J7dIs67PC6EeVac pB4ogLpTToCYT3g1UN4O6pXIFlgXGZJ3TnaKKHlGDMuj1QtLv5AAoVGeCt8SdJqSgVGH xDBhg7PnG/ghyB3TGyCpG+HWQ3c4umjQlLYdl8t0JrigtRCHn/BVuz0dhEwETcXeH+Tv 9TdcG9LAcMTfr3fa71rookQaRqWERuoy0EH2TLhLqOo5h/bWGcf1biNC6AWMmQFhkG/B tIeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=i6XtmTyV; 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 f186-v6si270692qkc.404.2018.06.09.21.14.10 for (version=TLS1 cipher=AES128-SHA bits=128/128); Sat, 09 Jun 2018 21:14:10 -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=i6XtmTyV; 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]:42573 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRrk1-0007zO-WD for patch@linaro.org; Sun, 10 Jun 2018 00:14:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41388) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRqfi-0004NI-QZ for qemu-devel@nongnu.org; Sat, 09 Jun 2018 23:05:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fRqfh-0004g0-F0 for qemu-devel@nongnu.org; Sat, 09 Jun 2018 23:05:38 -0400 Received: from mail-pl0-x243.google.com ([2607:f8b0:400e:c01::243]:42799) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fRqfh-0004fp-5y for qemu-devel@nongnu.org; Sat, 09 Jun 2018 23:05:37 -0400 Received: by mail-pl0-x243.google.com with SMTP id w17-v6so10391244pll.9 for ; Sat, 09 Jun 2018 20:05:37 -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=4wG+S4fZiyUq1Pu/Hlt9nQvToX/s4he+oqXriYQ+nrE=; b=i6XtmTyVqXw4eTIoQI9ep+OTk2pINavCKlfYCesPml+ns+oy4zDqCQeYJVwSH4HFHu KVk/YIuoHNilln7YDB71hK4/oqzygRdPMvzQb8WJfbgu/soJwiwE5GADWvyQk1lnoDnf yAeI1q410NzvXl3cfWvAakUI8bSo5OvDfyEVw= 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=4wG+S4fZiyUq1Pu/Hlt9nQvToX/s4he+oqXriYQ+nrE=; b=LMzyMo3aKkaM6wksJ0hG5XBbUpNpXSFr63QBXYaJFu/fIftLDEudyVH4TBETX1pVD4 aTUQgx/KpDSAKAHqJMhFun3/Zx2EDEgWk4KBjzpcl1yt+h03dMAsKTz2QhB3I4WFwqxC cjaQ2eTzbrhfJCgvhGopnGxCDlsEi7q/yE1H76eN1TYU4ZlfjzDdj6nmSff+2xCN/FKt vr2MnAuAJPDu/2ble7VO9UfQKGgaOEK23t0CLJR7b235NPU3FKftpfdGNJ1R7yDJU40p rJDG9ccz1ZDcrbf6og09uri+m7Eqi1othkSBtFU92G57SV4mWD8HsI03lw6ZQ1Qny95n cV+Q== X-Gm-Message-State: APt69E0klsnd+0pPotxRdpZEfWJquRfTzMyemVHaiZO0lrKt5SjG2qoS w8PcVmebiBjU6EWlxxvn4A53iMip4jI= X-Received: by 2002:a17:902:123:: with SMTP id 32-v6mr2225164plb.255.1528599936004; Sat, 09 Jun 2018 20:05:36 -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 y17-v6sm31712718pfe.33.2018.06.09.20.05.34 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 09 Jun 2018 20:05:35 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Sat, 9 Jun 2018 17:02:04 -1000 Message-Id: <20180610030220.3777-93-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180610030220.3777-1-richard.henderson@linaro.org> References: <20180610030220.3777-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:c01::243 Subject: [Qemu-devel] [PATCH v2 092/108] linux-user: Split out futex, utimensat 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" At the same time, merge do_futex into the new function. All targets define utimensat; remove the ifdef. Signed-off-by: Richard Henderson --- linux-user/syscall.c | 161 ++++++++++++++++++++++--------------------- 1 file changed, 81 insertions(+), 80 deletions(-) -- 2.17.1 diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 8406b9d8d3..800b79276f 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -602,8 +602,7 @@ static int sys_getcwd1(char *buf, size_t size) return strlen(buf)+1; } -#ifdef TARGET_NR_utimensat -#if defined(__NR_utimensat) +#ifdef __NR_utimensat #define __NR_sys_utimensat __NR_utimensat _syscall4(int,sys_utimensat,int,dirfd,const char *,pathname, const struct timespec *,tsp,int,flags) @@ -615,7 +614,6 @@ static int sys_utimensat(int dirfd, const char *pathname, return -1; } #endif -#endif /* TARGET_NR_utimensat */ #if defined(__NR_renameat2) #define __NR_sys_renameat2 __NR_renameat2 @@ -7024,58 +7022,6 @@ static abi_long host_to_target_statfs64(abi_ulong target_addr, } #endif -/* ??? Using host futex calls even when target atomic operations - are not really atomic probably breaks things. However implementing - futexes locally would make futexes shared between multiple processes - tricky. However they're probably useless because guest atomic - operations won't work either. */ -static int do_futex(target_ulong uaddr, int op, int val, target_ulong timeout, - target_ulong uaddr2, int val3) -{ - struct timespec ts, *pts; - int base_op; - - /* ??? We assume FUTEX_* constants are the same on both host - and target. */ -#ifdef FUTEX_CMD_MASK - base_op = op & FUTEX_CMD_MASK; -#else - base_op = op; -#endif - switch (base_op) { - case FUTEX_WAIT: - case FUTEX_WAIT_BITSET: - if (timeout) { - pts = &ts; - target_to_host_timespec(pts, timeout); - } else { - pts = NULL; - } - return get_errno(safe_futex(g2h(uaddr), op, tswap32(val), - pts, NULL, val3)); - case FUTEX_WAKE: - return get_errno(safe_futex(g2h(uaddr), op, val, NULL, NULL, 0)); - case FUTEX_FD: - return get_errno(safe_futex(g2h(uaddr), op, val, NULL, NULL, 0)); - case FUTEX_REQUEUE: - case FUTEX_CMP_REQUEUE: - case FUTEX_WAKE_OP: - /* For FUTEX_REQUEUE, FUTEX_CMP_REQUEUE, and FUTEX_WAKE_OP, the - TIMEOUT parameter is interpreted as a uint32_t by the kernel. - But the prototype takes a `struct timespec *'; insert casts - to satisfy the compiler. We do not need to tswap TIMEOUT - since it's not compared to guest memory. */ - pts = (struct timespec *)(uintptr_t) timeout; - return get_errno(safe_futex(g2h(uaddr), op, val, pts, - g2h(uaddr2), - (base_op == FUTEX_CMP_REQUEUE - ? tswap32(val3) - : val3))); - default: - return -TARGET_ENOSYS; - } -} - #if defined(TARGET_NR_signalfd) || defined(TARGET_NR_signalfd4) /* signalfd siginfo conversion */ @@ -8574,6 +8520,58 @@ IMPL(ftruncate64) } #endif +IMPL(futex) +{ + target_ulong uaddr = arg1; + int op = arg2; + int val = arg3; + target_ulong timeout = arg4; + target_ulong uaddr2 = arg5; + int val3 = arg6; + struct timespec ts, *pts; + int base_op; + + /* ??? We assume FUTEX_* constants are the same on both host + and target. */ +#ifdef FUTEX_CMD_MASK + base_op = op & FUTEX_CMD_MASK; +#else + base_op = op; +#endif + switch (base_op) { + case FUTEX_WAIT: + case FUTEX_WAIT_BITSET: + if (timeout) { + pts = &ts; + target_to_host_timespec(pts, timeout); + } else { + pts = NULL; + } + return get_errno(safe_futex(g2h(uaddr), op, tswap32(val), + pts, NULL, val3)); + case FUTEX_WAKE: + return get_errno(safe_futex(g2h(uaddr), op, val, NULL, NULL, 0)); + case FUTEX_FD: + return get_errno(safe_futex(g2h(uaddr), op, val, NULL, NULL, 0)); + case FUTEX_REQUEUE: + case FUTEX_CMP_REQUEUE: + case FUTEX_WAKE_OP: + /* For FUTEX_REQUEUE, FUTEX_CMP_REQUEUE, and FUTEX_WAKE_OP, the + TIMEOUT parameter is interpreted as a uint32_t by the kernel. + But the prototype takes a `struct timespec *'; insert casts + to satisfy the compiler. We do not need to tswap TIMEOUT + since it's not compared to guest memory. */ + pts = (struct timespec *)(uintptr_t) timeout; + return get_errno(safe_futex(g2h(uaddr), op, val, pts, + g2h(uaddr2), + (base_op == FUTEX_CMP_REQUEUE + ? tswap32(val3) + : val3))); + default: + return -TARGET_ENOSYS; + } +} + #ifdef TARGET_NR_futimesat IMPL(futimesat) { @@ -12425,6 +12423,32 @@ IMPL(utime) } #endif +IMPL(utimensat) +{ + struct timespec *tsp = NULL, ts[2]; + abi_long ret; + char *p; + + if (arg3) { + if (target_to_host_timespec(&ts[0], arg3) || + target_to_host_timespec(&ts[1], arg3 + + sizeof(struct target_timespec))) { + return -TARGET_EFAULT; + } + tsp = ts; + } + if (!arg2) { + return get_errno(sys_utimensat(arg1, NULL, tsp, arg4)); + } + p = lock_user_string(arg2); + if (!p) { + return -TARGET_EFAULT; + } + ret = get_errno(sys_utimensat(arg1, path(p), tsp, arg4)); + unlock_user(p, arg2, 0); + return ret; +} + #ifdef TARGET_NR_utimes IMPL(utimes) { @@ -12579,31 +12603,6 @@ static abi_long do_syscall1(void *cpu_env, unsigned num, abi_long arg1, void *p; switch(num) { -#if defined(TARGET_NR_utimensat) - case TARGET_NR_utimensat: - { - struct timespec *tsp, ts[2]; - if (!arg3) { - tsp = NULL; - } else { - target_to_host_timespec(ts, arg3); - target_to_host_timespec(ts+1, arg3+sizeof(struct target_timespec)); - tsp = ts; - } - if (!arg2) - ret = get_errno(sys_utimensat(arg1, NULL, tsp, arg4)); - else { - if (!(p = lock_user_string(arg2))) { - return -TARGET_EFAULT; - } - ret = get_errno(sys_utimensat(arg1, path(p), tsp, arg4)); - unlock_user(p, arg2, 0); - } - } - return ret; -#endif - case TARGET_NR_futex: - return do_futex(arg1, arg2, arg3, arg4, arg5, arg6); #if defined(TARGET_NR_inotify_init) && defined(__NR_inotify_init) case TARGET_NR_inotify_init: ret = get_errno(sys_inotify_init()); @@ -13388,6 +13387,7 @@ static impl_fn *syscall_table(unsigned num) #ifdef TARGET_NR_ftruncate64 SYSCALL(ftruncate64); #endif + SYSCALL(futex); #ifdef TARGET_NR_futimesat SYSCALL(futimesat); #endif @@ -13858,6 +13858,7 @@ static impl_fn *syscall_table(unsigned num) #ifdef TARGET_NR_utime SYSCALL(utime); #endif + SYSCALL(utimensat); #ifdef TARGET_NR_utimes SYSCALL(utimes); #endif