From patchwork Fri Jan 18 21:31:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 156070 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3740377jaa; Fri, 18 Jan 2019 13:50:42 -0800 (PST) X-Google-Smtp-Source: ALg8bN4bwS5YMHUrGEsPraMbYK5ZzP51cUAgzMhAu45zp6AQKfUT//jCNoLdpjaLH0zZaYLWxA1M X-Received: by 2002:adf:a1d2:: with SMTP id v18mr17378576wrv.87.1547848242771; Fri, 18 Jan 2019 13:50:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547848242; cv=none; d=google.com; s=arc-20160816; b=FNc0X2B43wZxLxhl1/jIz5KXn4FlP7MFqZ7BNvdizBICIwXyh2JRHfXl7qsXX7Wbxf wd7YpLa338+JClACoZnekxFosqPk6sNYBU1v54LLg68UaxBliE+c1W2h5Jbzpa8hWaIs Uu3y3GoYhGByv8pSM7K1Zk6DDl1Em7tghguFTITDm/eG9+Q9+zv+tMdZXemTbN3pcJNL YrjuqBQxak5/ZJm+XC0HVssUhMG2gW+ItvPrdY7MWLlRX9LsKSE2KfVQ7HxAIlK70DIi fSiIMyXNX1/KUQcLkGHm6XFxDfqyDVezYXU1UlOdqid4+mKmepct0YPPOn5/ePn5aRnK Lxnw== 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=vmCtoR9C6IQTdM473qGfZ62d2l6KdjovhF6X9LQHAX4=; b=KihR4IAA5d40aJIZiI1h68q+f1I4Zwvk+tWWUD4127tVrWXETFVLgEAGbr4t5RFJ4w zQUinEnizwnWNg5f6+mbiSiz+psA6b1FK06Qt2M3Be3p75O14aloHJC5E0cqPHLicLIQ saO5Pil3IX7Ik8oi8odtFFs7uNy+xi6wmk3vX/pRPeTka4h31zdIl9dmXMNrIXUGErKC V/CtTRaMJeKUkv4mH/g44D6u+ZgOAqTbpuT0bZVI00iDgpaZAF0TjQBvNhaeL2BOKWBb iLkrvviYTjd5L+7JjRDhBysxToZZu/q79BecvHolkC1dGyxXaznfN02ij7zAB31N9ZU8 LVnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=i81tnu+j; 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 t6si59773745wrw.74.2019.01.18.13.50.42 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 18 Jan 2019 13:50:42 -0800 (PST) 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=i81tnu+j; 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]:47655 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gkc2D-0003JX-6P for patch@linaro.org; Fri, 18 Jan 2019 16:50:41 -0500 Received: from eggs.gnu.org ([209.51.188.92]:56469) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gkblI-0005rk-9j for qemu-devel@nongnu.org; Fri, 18 Jan 2019 16:33:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gkblG-0005dZ-7I for qemu-devel@nongnu.org; Fri, 18 Jan 2019 16:33:11 -0500 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]:42957) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gkblG-0005cN-1N for qemu-devel@nongnu.org; Fri, 18 Jan 2019 16:33:10 -0500 Received: by mail-pl1-x644.google.com with SMTP id y1so6881297plp.9 for ; Fri, 18 Jan 2019 13:33:09 -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=vmCtoR9C6IQTdM473qGfZ62d2l6KdjovhF6X9LQHAX4=; b=i81tnu+jii7bS6piBYNl9xEACuyeafryIFG9apcXFnDTq8e7L9vY47Yj9YZ5NW6f9B RTEwAo6/ZsoCac6c4zUXcl1MBB/ABMf9Kr5/zgafv3XmR6d9JPFxxk0rz5geZ5h9y9jb ntSwC08v2+DPaSH9nUuhhDrXlRqVTSzuHGAkI= 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=vmCtoR9C6IQTdM473qGfZ62d2l6KdjovhF6X9LQHAX4=; b=qxTXlplVwHxUuxuzMGWm+IGUZgTlguKIyTrDOgz1IVgRqvUzyHCqHRnNFbcTcoTNIG mST01e/9A6hGx4WfFEeIhB3QPd87JCSgD5jEAiBnKBkSXqbeJpquDV2R1zMCDlSKk7Qj I9Z9H6/AZwyPX8RPQhiC/beVuFN9YCGdYzpTh7RXkcuORhQ9SkwgV5CYdsiUpEh1J8kX HxoabCJ+n6LYAhCUQy5GRKzavcAYW5mw2kTgS/pb14Syxv2XkOe2000p0kYbwBQDXKgg tVFJjN/CCCXZtrmhIi/4tqq7h+yGq+KhB0pizpQ4vEfr7BmdmGH97rZKxxANTDJ0xDTQ HRXQ== X-Gm-Message-State: AJcUukfgMXB1VWRxSHpCZdSRVKNbirWSsFb2RFCr9exjmuo8plWaTyhM WpARoiNi2YMHakU9QHgnpsuN8ft62Yw= X-Received: by 2002:a17:902:6b0c:: with SMTP id o12mr20915979plk.291.1547847187810; Fri, 18 Jan 2019 13:33:07 -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.33.05 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 18 Jan 2019 13:33:07 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Sat, 19 Jan 2019 08:31:16 +1100 Message-Id: <20190118213122.22865-43-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::644 Subject: [Qemu-devel] [PATCH v6 43/49] 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.2 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 83174c5781..5e8298fdb3 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 7874a48840..29a9d5fce4 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -204,6 +204,9 @@ static type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5, \ * Performing a bogus sysacll is lazier than boilerplating * the replacement functions here in C. */ +#ifndef __NR_dup3 +#define __NR_dup3 -1 +#endif #ifndef __NR_syncfs #define __NR_syncfs -1 #endif @@ -5320,12 +5323,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); @@ -5380,30 +5377,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 678feeeb7b..151b0eb42d 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