From patchwork Sun May 19 20:36:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 164541 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp4806106ili; Sun, 19 May 2019 14:19:06 -0700 (PDT) X-Google-Smtp-Source: APXvYqw74J8A4Pd3buPXmKXGIuxDLFCn5Ry/hvZJQHi6Hcu7WfnrbWvLFncOkNcSRwANNDLnvuUu X-Received: by 2002:a50:ce5b:: with SMTP id k27mr19291055edj.48.1558300746155; Sun, 19 May 2019 14:19:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558300746; cv=none; d=google.com; s=arc-20160816; b=D2CRHaTNIREUMHRYNHzzwFq6Xl6w9gMXiMC9NuJcl99oruyu/H2ylY2fO6SEtLD6ZJ /R6DdIYMyT0JWNSLSuH6VFaaDjFnwDGB+tuVdnPnk4A+nM3UwjVsXvp0n6DYjztIld4z 3p2iw8bhzzD11OfnC2BZUsG6IcVYsZqaexeroBwtbXjUw+fVOG+fQiUIl+qjrTSmRBoR TkoduY77bbwYwSbOk5CI0UJxRrX/2NHNaoL+z4g31gTw5eENdHUnpJ2p+UUYFpgJjP0J S/BLJ/DHNlo5BUWh+8D6jCWVpsBnOCVjujv7VaZSVVGaTOAbUIR45CHo0uqin2bS6QPp oHfw== 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; bh=tO0MYq1BfTpb+Rq4mEcLzQaoCNhvveoe+wDeU1tkEl4=; b=d7QHa9iGGUBcmAZny/kv7IgsDIK6tBVahUH3Xg9QVzE3EAgHACGpeYhaA5FvogoeGQ 5PiuW5OwefzWKRMw4SwZBi/Qlxq/R9WNDGf8lxjwi/z254LgfjgScbYkGgJbY5aRQzNw CmuYh5xgpsS7cQMb/TMHLH998H+2KqG6PKXPWggHb06UQtvSTOUbS0nt9KOsto6wJoNb zXH7Kh7bmcH+qYiQFGsD2eHfcRjzivdaChVARTTd6wQ7gXfdfQQkFtOErY6QDPzJEeFv +o+nPvGzm/Mg2N3t35ii4WIc4SMNMYiMCRWdhga5kJ4w3ILD0A6Al4ijzAfaS3V1/AD0 ecwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=JchIpMmG; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 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. [209.51.188.17]) by mx.google.com with ESMTPS id g38si6844792edg.96.2019.05.19.14.19.05 for (version=TLS1 cipher=AES128-SHA bits=128/128); Sun, 19 May 2019 14:19:06 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=JchIpMmG; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 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 ([127.0.0.1]:53708 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hSTCy-0005QS-Ug for patch@linaro.org; Sun, 19 May 2019 17:19:05 -0400 Received: from eggs.gnu.org ([209.51.188.92]:50744) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hSSZf-0003et-AW for qemu-devel@nongnu.org; Sun, 19 May 2019 16:38:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hSSZd-0004QM-OO for qemu-devel@nongnu.org; Sun, 19 May 2019 16:38:27 -0400 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]:34263) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hSSZd-0004NW-Fj for qemu-devel@nongnu.org; Sun, 19 May 2019 16:38:25 -0400 Received: by mail-pf1-x441.google.com with SMTP id n19so6182901pfa.1 for ; Sun, 19 May 2019 13:38:24 -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=tO0MYq1BfTpb+Rq4mEcLzQaoCNhvveoe+wDeU1tkEl4=; b=JchIpMmGQzlbAZh0Xr/Y31cWysRgPDnxvatEZVGc5KkGSEl2yUXMqvnEs+txrnxyC+ KdzXK7cQVKuDZlXiLAOET5jWNVefAscgas8GkF3SP98bTlJlHJkbW8jUo3VaZdlE+SML E9FIS1LLNZiA3vQIF8fgyLbkV+7TA5ahQj7mshVzGARXKUbu3RR7YwHlMkJdhSXXvJ9L MccM4nuagbwuR3YzpzvYXhZiqTliEIQ6E+sqwEZT2JnKrPGrRn9Xgz0yfHyDNvbFJu4A 4/Nl72R2oeUROVd81jfY+/73eYzYdN4tXSs23Lw+BxFayExackAZTKl+OoGyWOVDox// 7tOA== 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=tO0MYq1BfTpb+Rq4mEcLzQaoCNhvveoe+wDeU1tkEl4=; b=QYvrQfURLoO/nM9+W9L0yGVBl9VtTxGFplBQwstuJMbG/vi7RXWNjpTWl9C4NGQk9z NWPPDAX2RPa1sN7+MxplUXJSGdT/vT1klibujI3y5cDjASIGeVJnNJmE9qNjKYqVuGqx jt+RYt6DteFfV4LS+UApfsKIkmRFDtwoPkk9LNGy5W0pkVdAT9mfGdiT9hyjBXplbuxR hoY3dPsFMmZUhkGMZhGZc4lJ6BnkGEw4Dr0/KLn3yYoEAgSQh33XJi3eYxZN2m4TNb2h MvjBWJp8/6RlMrO+D+D5OZvS6YbVzfwmxVHeM2q3x7zfDJxKD86+f99Khkrl+sLdNehB JEbw== X-Gm-Message-State: APjAAAWKzRuKxRpz8Z/yCXy3p62U3PqC9usSXHZV4sokW8m0R59/tvK5 e8/BlbihOL3RqbmuzV9yWR+Uun7XivQ= X-Received: by 2002:a65:5c89:: with SMTP id a9mr71874534pgt.334.1558298303006; Sun, 19 May 2019 13:38:23 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id i7sm11397448pfo.19.2019.05.19.13.38.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 19 May 2019 13:38:22 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Sun, 19 May 2019 13:36:54 -0700 Message-Id: <20190519203726.20729-43-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190519203726.20729-1-richard.henderson@linaro.org> References: <20190519203726.20729-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::441 Subject: [Qemu-devel] [PATCH v7 42/74] linux-user: Split out dup, dup2, dup3 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" Note that dup3 is universally available for guests. Implement host support with syscall when !CONFIG_DUP3. Signed-off-by: Richard Henderson --- linux-user/syscall-defs.h | 5 +++++ linux-user/syscall-file.inc.c | 42 +++++++++++++++++++++++++++++++++++ linux-user/syscall.c | 33 +++------------------------ linux-user/strace.list | 6 ----- 4 files changed, 50 insertions(+), 36 deletions(-) -- 2.17.1 diff --git a/linux-user/syscall-defs.h b/linux-user/syscall-defs.h index 8b6d8f75ff..062adddd75 100644 --- a/linux-user/syscall-defs.h +++ b/linux-user/syscall-defs.h @@ -34,6 +34,11 @@ SYSCALL_DEF(close, ARG_DEC); #ifdef TARGET_NR_creat SYSCALL_DEF(creat, ARG_STR, ARG_MODEFLAG); #endif +SYSCALL_DEF(dup, ARG_DEC); +#ifdef TARGET_NR_dup2 +SYSCALL_DEF(dup2, ARG_DEC, ARG_DEC); +#endif +SYSCALL_DEF(dup3, ARG_DEC, ARG_DEC, ARG_OPENFLAG); SYSCALL_DEF(exit, ARG_DEC); SYSCALL_DEF(execve, ARG_STR, ARG_PTR, ARG_PTR); SYSCALL_DEF(execveat, ARG_ATDIRFD, ARG_STR, ARG_PTR, ARG_PTR, ARG_ATFLAG); diff --git a/linux-user/syscall-file.inc.c b/linux-user/syscall-file.inc.c index 5ed8b78c79..7d97dd1ec1 100644 --- a/linux-user/syscall-file.inc.c +++ b/linux-user/syscall-file.inc.c @@ -94,6 +94,48 @@ SYSCALL_IMPL(creat) } #endif +SYSCALL_IMPL(dup) +{ + abi_long ret = get_errno(dup(arg1)); + if (ret >= 0) { + fd_trans_dup(arg1, ret); + } + return ret; +} + +#ifdef TARGET_NR_dup2 +SYSCALL_IMPL(dup2) +{ + abi_long ret = get_errno(dup2(arg1, arg2)); + if (ret >= 0) { + fd_trans_dup(arg1, arg2); + } + return ret; +} +#endif + +SYSCALL_IMPL(dup3) +{ + int ofd = arg1; + int nfd = arg2; + int host_flags = target_to_host_bitmask(arg3, fcntl_flags_tbl); + abi_long ret; + +#ifdef CONFIG_DUP3 + ret = dup3(ofd, nfd, host_flags); +#else + if (host_flags == 0) { + if (ofd == nfd) { + return -TARGET_EINVAL; + } + ret = dup2(ofd, nfd); + } else { + ret = syscall(__NR_dup3, ofd, nfd, host_flags); + } +#endif + return get_errno(ret); +} + SYSCALL_IMPL(faccessat) { return do_faccessat(arg1, arg2, arg3); diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 0d6a9b7a6c..bab9a57ee0 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -204,6 +204,9 @@ _syscall0(int, sys_gettid) * Performing a bogus syscall is easier than boilerplating * the replacement functions here in C. */ +#ifndef __NR_dup3 +#define __NR_dup3 -1 +#endif #ifndef __NR_syncfs #define __NR_syncfs -1 #endif @@ -5373,12 +5376,6 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, void *p; switch(num) { - case TARGET_NR_dup: - ret = get_errno(dup(arg1)); - if (ret >= 0) { - fd_trans_dup(arg1, ret); - } - return ret; #ifdef TARGET_NR_pipe case TARGET_NR_pipe: return do_pipe(cpu_env, arg1, 0, 0); @@ -5433,30 +5430,6 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, ret = get_errno(chroot(p)); unlock_user(p, arg1, 0); return ret; -#ifdef TARGET_NR_dup2 - case TARGET_NR_dup2: - ret = get_errno(dup2(arg1, arg2)); - if (ret >= 0) { - fd_trans_dup(arg1, arg2); - } - return ret; -#endif -#if defined(CONFIG_DUP3) && defined(TARGET_NR_dup3) - case TARGET_NR_dup3: - { - int host_flags; - - if ((arg3 & ~TARGET_O_CLOEXEC) != 0) { - return -EINVAL; - } - host_flags = target_to_host_bitmask(arg3, fcntl_flags_tbl); - ret = get_errno(dup3(arg1, arg2, host_flags)); - if (ret >= 0) { - fd_trans_dup(arg1, arg2); - } - return ret; - } -#endif #ifdef TARGET_NR_getpgrp case TARGET_NR_getpgrp: return get_errno(getpgrp()); diff --git a/linux-user/strace.list b/linux-user/strace.list index cdbc59bffd..2f78f4685b 100644 --- a/linux-user/strace.list +++ b/linux-user/strace.list @@ -91,12 +91,6 @@ #ifdef TARGET_NR_dipc { TARGET_NR_dipc, "dipc" , NULL, NULL, NULL }, #endif -#ifdef TARGET_NR_dup -{ TARGET_NR_dup, "dup" , NULL, NULL, NULL }, -#endif -#ifdef TARGET_NR_dup2 -{ TARGET_NR_dup2, "dup2" , NULL, NULL, NULL }, -#endif #ifdef TARGET_NR_epoll_create { TARGET_NR_epoll_create, "epoll_create" , NULL, NULL, NULL }, #endif