From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from hall.aurel32.net (hall.aurel32.net [IPv6:2001:bc8:30d7:100::1]) by sourceware.org (Postfix) with ESMTPS id 344893858035 for ; Mon, 24 Jan 2022 22:49:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 344893858035 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=aurel32.net Authentication-Results: sourceware.org; spf=none smtp.mailfrom=aurel32.net DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=aurel32.net ; s=202004.hall; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Content-Type:From:Reply-To: Subject:Content-ID:Content-Description:X-Debbugs-Cc; bh=cOfsNPTvZcPBe2//fsgK8zyLBIxj7QnDUXEqjoxCDIY=; b=YyzFzh1mRO30H6tb9gEmmwPGNP aj/9E9khsyqnD07oZK4QfwSnPBiztzRZAQIY40sT9rNiMe7WRrbY+RRuj5kkbH+JKuqyXm6UTJqaY 8qkYTIC02E/tprNikl48q3lNo4IOjFijESvU+iLRf4WDKcKhpdrTBNMWWiVXBcMi6FGCKiFWO7PwX DxIbPz99V+tTbLdg4KOuqU6YgZCBOYupcp0XzguwfNitS8Ly/ng4yRaJk/dhW26/hjg2zDDRWezlh gEtT2jQm9upddpyfTNAE4zxroSu3+PWl0kyzG5wvGfdcPsyIeDUp8aVmev3uVa5dUS2P/Lbhwgh1P rwA3FaMQ==; Received: from [2a01:e34:ec5d:a741:8a4c:7c4e:dc4c:1787] (helo=ohm.rr44.fr) by hall.aurel32.net with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nC88x-00FSYK-WA; Mon, 24 Jan 2022 23:49:00 +0100 Received: from aurel32 by ohm.rr44.fr with local (Exim 4.95) (envelope-from ) id 1nC88x-00FwjM-5l; Mon, 24 Jan 2022 23:48:59 +0100 From: Aurelien Jarno To: libc-stable@sourceware.org Subject: [COMMITTED 2.33 4/7] support: Add xclone Date: Mon, 24 Jan 2022 23:48:54 +0100 Message-Id: <20220124224857.3799610-4-aurelien@aurel32.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124224857.3799610-1-aurelien@aurel32.net> References: <20220124224857.3799610-1-aurelien@aurel32.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_PASS, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-stable@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-stable mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 24 Jan 2022 22:49:04 -0000 From: Adhemerval Zanella It is a wrapper for Linux clone syscall, to simplify the call to the use only the most common arguments and remove architecture specific handling (such as ia64 different name and signature). (cherry picked from commit de8995a2a04163617c1a233b4b81356ef9f9741f) --- support/Makefile | 1 + support/xclone.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ support/xsched.h | 34 ++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+) create mode 100644 support/xclone.c create mode 100644 support/xsched.h diff --git a/support/Makefile b/support/Makefile index 3c0eb200c2..f631846c07 100644 --- a/support/Makefile +++ b/support/Makefile @@ -92,6 +92,7 @@ libsupport-routines = \ xchdir \ xchroot \ xclock_gettime \ + xclone \ xclose \ xchmod \ xconnect \ diff --git a/support/xclone.c b/support/xclone.c new file mode 100644 index 0000000000..924d2b8754 --- /dev/null +++ b/support/xclone.c @@ -0,0 +1,50 @@ +/* Auxiliary functions to issue the clone syscall. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifdef __linux__ +# include +# include /* For _STACK_GROWS_{UP,DOWN}. */ +# include + +pid_t +xclone (int (*fn) (void *arg), void *arg, void *stack, size_t stack_size, + int flags) +{ + pid_t r = -1; + +# ifdef __ia64__ + extern int __clone2 (int (*fn) (void *arg), void *stack, size_t stack_size, + int flags, void *arg, ...); + r = __clone2 (f, stack, stack_size, flags, arg, /* ptid */ NULL, + /* tls */ NULL, /* ctid */ ctid); +# else +# if _STACK_GROWS_DOWN + r = clone (fn, stack + stack_size, flags, arg, /* ptid */ NULL, + /* tls */ NULL, /* ctid */ NULL); +# elif _STACK_GROWS_UP + r = clone (fn, stack, flags, arg, /* ptid */ NULL, /* tls */ NULL, + &ctid); +# endif +# endif + + if (r < 0) + FAIL_EXIT1 ("clone: %m"); + + return r; +} +#endif diff --git a/support/xsched.h b/support/xsched.h new file mode 100644 index 0000000000..eefd731940 --- /dev/null +++ b/support/xsched.h @@ -0,0 +1,34 @@ +/* Wrapper for sched.h functions. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef SUPPORT_XSCHED_H +#define SUPPORT_XSCHED_H + +__BEGIN_DECLS + +#include +#include + +#ifdef __linux__ +pid_t xclone (int (*fn) (void *arg), void *arg, void *stack, + size_t stack_size, int flags); +#endif + +__END_DECLS + +#endif -- 2.34.1