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 A64263858CDA for ; Thu, 18 Aug 2022 10:02:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A64263858CDA 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=VisY8DkGTSV9dYPEWGBZhnEmmTMmgxJwT6Dl4nMQuB0=; b=HihcM2yzoZmopd2cpoulDrxShD wIDSBKQDwqRpnEpR6o/4CtTXI0BkEMYYiOcmqD0OBK3qvFMMPiXzuZ8DiOhcv6u3CmV8n9fc9Uz2d AnGJK1xtFbTOz8Dz1Q9dxzQRag92apqzUoOtxvFIPJ0V6b87DXLfyc0e1yXOHYDj+sWBrKWy/Y3ul BFcrkUXlyUdWY/Aj5pIJI/Lyiihl9nf33Hn+pN2jI1ToEM6D1RCkO0HVAFEzwCiCksB8yiFjuZpDx ky8rLgP8QYVCgBgYdnsrPwRnKP6kf5EOx5kvGeI3MzHPAHbH0dv+mkWG8YDdwgLLUtw3HluG0XY6Q TlDQmikQ==; Received: from [2a01:e0a:406:7381:3e0e:d27:becd:e47b] (helo=ohm.aurel32.net) by hall.aurel32.net with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1oOcMG-00Apv9-BV; Thu, 18 Aug 2022 12:02:36 +0200 Received: from aurel32 by ohm.aurel32.net with local (Exim 4.96) (envelope-from ) id 1oOcM8-008OzN-2o; Thu, 18 Aug 2022 12:02:28 +0200 From: Aurelien Jarno To: libc-stable@sourceware.org Subject: [COMMITTED 2.31 3/7] support: Add xclone Date: Thu, 18 Aug 2022 12:02:21 +0200 Message-Id: <20220818100225.2002653-3-aurelien@aurel32.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220818100225.2002653-1-aurelien@aurel32.net> References: <20220818100225.2002653-1-aurelien@aurel32.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-13.4 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, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: Thu, 18 Aug 2022 10:02:41 -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 a40a2f5bca..05e8c292b7 100644 --- a/support/Makefile +++ b/support/Makefile @@ -86,6 +86,7 @@ libsupport-routines = \ xchdir \ xchroot \ xclock_gettime \ + xclone \ xclose \ xconnect \ xcopy_file_range \ 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.35.1