From nobody Fri Nov 7 13:01:08 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1547848345700710.8509727273336; Fri, 18 Jan 2019 13:52:25 -0800 (PST) Received: from localhost ([127.0.0.1]:47674 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gkc3s-0004Va-6H for importer@patchew.org; Fri, 18 Jan 2019 16:52:24 -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) 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) 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-Google-Smtp-Source: ALg8bN5PFdrIFFOJmZedcF8PtdcgTHPLqWMUhHxeslQEHKTuSdrrwvcv87dBKN5RqzlePiSb+RmQ/Q== X-Received: by 2002:a17:902:6b0c:: with SMTP id o12mr20915979plk.291.1547847187810; 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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(-) 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 =20 +SYSCALL_IMPL(dup) +{ + abi_long ret =3D get_errno(dup(arg1)); + if (ret >=3D 0) { + fd_trans_dup(arg1, ret); + } + return ret; +} + +#ifdef TARGET_NR_dup2 +SYSCALL_IMPL(dup2) +{ + abi_long ret =3D get_errno(dup2(arg1, arg2)); + if (ret >=3D 0) { + fd_trans_dup(arg1, arg2); + } + return ret; +} +#endif + +SYSCALL_IMPL(dup3) +{ + int ofd =3D arg1; + int nfd =3D arg2; + int host_flags =3D target_to_host_bitmask(arg3, fcntl_flags_tbl); + abi_long ret; + +#ifdef CONFIG_DUP3 + ret =3D dup3(ofd, nfd, host_flags); +#else + if (host_flags =3D=3D 0) { + if (ofd =3D=3D nfd) { + return -TARGET_EINVAL; + } + ret =3D dup2(ofd, nfd); + } else { + ret =3D 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,type= 4 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; =20 switch(num) { - case TARGET_NR_dup: - ret =3D get_errno(dup(arg1)); - if (ret >=3D 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 =3D get_errno(chroot(p)); unlock_user(p, arg1, 0); return ret; -#ifdef TARGET_NR_dup2 - case TARGET_NR_dup2: - ret =3D get_errno(dup2(arg1, arg2)); - if (ret >=3D 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) !=3D 0) { - return -EINVAL; - } - host_flags =3D target_to_host_bitmask(arg3, fcntl_flags_tbl); - ret =3D get_errno(dup3(arg1, arg2, host_flags)); - if (ret >=3D 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 --=20 2.17.2