From patchwork Tue Oct 25 02:34:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Helge Deller X-Patchwork-Id: 13018430 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E950CC67871 for ; Tue, 25 Oct 2022 02:37:19 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1on9m6-0006YK-CO; Mon, 24 Oct 2022 22:34:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1on9ln-0006Uv-RO for qemu-devel@nongnu.org; Mon, 24 Oct 2022 22:34:28 -0400 Received: from mout.gmx.net ([212.227.17.21]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1on9li-0006fu-8c for qemu-devel@nongnu.org; Mon, 24 Oct 2022 22:34:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1666665255; bh=l+0+TgBn0P8Q+6c1mzQiS08UvHrvZ4gtQDqwpq6k67g=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject; b=WSK/kfJdAgvP20cKct4b94jHweWXYc4D8S3NtuQdQ5y6Zo+Pz8RsT31WiX4CvRNny BAtywP8T7/5ED4Cb8fCmbIadUMNP2lk1w4iVP0S74SvGBUlOoabbskjeAeRG5aG7/H tQmkt0Ydv035JEhXg0rTz/ekXpQTIqbZ6k4gZeFg= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from p100 ([92.116.136.30]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1M7sDq-1oiDp72AWw-00513U; Tue, 25 Oct 2022 04:34:15 +0200 Date: Tue, 25 Oct 2022 04:34:14 +0200 From: Helge Deller To: Laurent Vivier , qemu-devel@nongnu.org, Richard Henderson Cc: Helge Deller Subject: [PATCH v5] linux-user: Add close_range() syscall Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Provags-ID: V03:K1:0iNqPumLwof2q/0F5xKJn0rtTt+DuMWmyvOVFLPj8eKzYLB5Y8A iZr2hY/SnTzwTIvEBiMVBk/uWEHbMJGtihi8WNdV2BmQqcYFgyN2ulqvESP6/XhhOpzeIPx BaOrJc7rmo9m4Pah/nKvQsL5A3rO0Ln4XNnaFwAAo9afSdUZJ0VJLQe39K2tGk/Vs0gOyjx EouLUGcsg+JVNoy/hK81g== X-UI-Out-Filterresults: notjunk:1;V03:K0:RWuazRpU+EQ=:Z6r72k+5MwhdJvGoDirNaF gDPD0QUgwQzzPiFnFIjxE1JFh0MqWw+jM2i2qxa3yu5HCZkEHaiCt0x2EC1MCXad/u6izomIH BCWbg6UuaS8o7p6RJcMv1wXQ/6AgMjyziDhqhq4jg5d+QC3AAvzwjFNuB9mMpJkvg+94zxQSR gJxklkqmFYsr7MjrPJQjSomiDV6Fla2omgG0BfnwHoey0bsQGgL5S/fhqnmgGP6BtAhwQk2qL NCDqLF2mVBfN+mYyeUvuSTVgtJ4qIHSI08DiFeXRYp2w0GYFXcpAY/dVDqLITcPAJ5pru6wIc GEcNH4ss5W6Ury/6EMygmeUWYKEHS3rKJFGUYwhBlWPKO6vy0D+peEULLBtJP7NeQrEGIkKgE 02G2AJeNI0Pm13D3rqsc0WZZofXERcOqTCRTewoW18LFtXE6vhkUMaan780EzPjTIuAjjBf+y XhM3QJh5mF/8SfOz+AXROlXfbKGSQGC3Ajm0piPSbILZ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eU9OMVsKorUq4t Received-SPF: pass client-ip=212.227.17.21; envelope-from=deller@gmx.de; helo=mout.gmx.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Helge Deller Reviewed-by: Richard Henderson --- Changes: v5: Simplify check of arg2 against target_fd_max even more v4: Fix check of arg2 v3: fd_trans_unregister() only called if close_range() doesn't fail v2: consider CLOSE_RANGE_CLOEXEC flag diff --git a/linux-user/strace.list b/linux-user/strace.list index a87415bf3d..78796266e8 100644 --- a/linux-user/strace.list +++ b/linux-user/strace.list @@ -103,6 +103,9 @@ #ifdef TARGET_NR_close { TARGET_NR_close, "close" , "%s(%d)", NULL, NULL }, #endif +#ifdef TARGET_NR_close_range +{ TARGET_NR_close_range, "close_range" , "%s(%u,%u,%u)", NULL, NULL }, +#endif #ifdef TARGET_NR_connect { TARGET_NR_connect, "connect" , "%s(%d,%#x,%d)", NULL, NULL }, #endif diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 2e954d8dbd..c51d619a5c 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -338,6 +338,13 @@ _syscall3(int,sys_syslog,int,type,char*,bufp,int,len) #ifdef __NR_exit_group _syscall1(int,exit_group,int,error_code) #endif +#if defined(__NR_close_range) && defined(TARGET_NR_close_range) +#define __NR_sys_close_range __NR_close_range +_syscall3(int,sys_close_range,int,first,int,last,int,flags) +#ifndef CLOSE_RANGE_CLOEXEC +#define CLOSE_RANGE_CLOEXEC (1U << 2) +#endif +#endif #if defined(__NR_futex) _syscall6(int,sys_futex,int *,uaddr,int,op,int,val, const struct timespec *,timeout,int *,uaddr2,int,val3) @@ -8699,6 +8706,18 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1, case TARGET_NR_close: fd_trans_unregister(arg1); return get_errno(close(arg1)); +#if defined(__NR_close_range) && defined(TARGET_NR_close_range) + case TARGET_NR_close_range: + ret = get_errno(sys_close_range(arg1, arg2, arg3)); + if (ret == 0 && !(arg3 & CLOSE_RANGE_CLOEXEC)) { + abi_long fd, maxfd; + maxfd = MIN(arg2, target_fd_max); + for (fd = arg1; fd < maxfd; fd++) { + fd_trans_unregister(fd); + } + } + return ret; +#endif case TARGET_NR_brk: return do_brk(arg1);