From patchwork Wed May 5 21:41:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 43260 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 65112385741B; Wed, 5 May 2021 21:41:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 65112385741B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1620250913; bh=EkfPpZdGzw1jJnMWWfjCMXN1yOuJT7+40FBreml4dCc=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=Uu4RpcB9AEI1jZUtu9smGX4BYq6N69PPXDs5CuvOM0iTKDug+z0gOoGJ1ubA71HLj MlB6AVeKnItaYoiELK5Ft0+G0nTM/7P6L24+S00ijNJ5GohvwSUKu6bRmNAODBk2+K iaQDDmSaT+B5aNFhBYVwn8FXRnJ737aiK9/4XCuQ= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qv1-xf2c.google.com (mail-qv1-xf2c.google.com [IPv6:2607:f8b0:4864:20::f2c]) by sourceware.org (Postfix) with ESMTPS id E777E3857402 for ; Wed, 5 May 2021 21:41:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org E777E3857402 Received: by mail-qv1-xf2c.google.com with SMTP id h1so2065521qvv.10 for ; Wed, 05 May 2021 14:41:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=EkfPpZdGzw1jJnMWWfjCMXN1yOuJT7+40FBreml4dCc=; b=S6uGH28YRNY45PmVjbfryVoePJ76Xpp/MNc1PkWTAzjGIMrHlL0OAVRsayTR6YODEe LKF4w5aHfeBCDQ5NKi9FT5Jf0wwtbUrcuIO6vXk513rO0gzFhNlcxQR21buOTWn8sB5/ U4seeE7+RPJYkHwq04YLn4BQHJGcl95Q/ZoSDhlo5itAv0h2z3Y+JDEce7xFbFh2zirF s9vzKxluW+7fRrcNdpPbYffGT6QFK81QKcszQeFwa5+JDNao3kzmRNLNJhnjcZouTpQ7 TR+qajdxnZuO0C6yDXbHFyTWDEoUYnOFL0/TEUncjYObGBqGN/MpKFzeWwdXK4ju+K9L sI9w== X-Gm-Message-State: AOAM530+mfhUrQz6XIT8j9lULLhp6hugtdnx+ccnjCPb08cIFHYR/dzb Fz9Aig5KTAT3wstb8MXGMz8o0R0OnOWP+Q== X-Google-Smtp-Source: ABdhPJzzEOERmdgyCPOFywQIuQO9f5jYaOOv8A8PpRMFvkR7HH9FMU5LQJ9+u49tWi03eoaZeYGbkg== X-Received: by 2002:ad4:5baf:: with SMTP id 15mr999235qvq.34.1620250909247; Wed, 05 May 2021 14:41:49 -0700 (PDT) Received: from birita.. ([177.194.37.86]) by smtp.googlemail.com with ESMTPSA id t9sm466146qkg.121.2021.05.05.14.41.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 May 2021 14:41:49 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v5 2/5] support: Add xclone Date: Wed, 5 May 2021 18:41:40 -0300 Message-Id: <20210505214143.3649585-2-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210505214143.3649585-1-adhemerval.zanella@linaro.org> References: <20210505214143.3649585-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" Changes from v4: * Rebased against master. --- 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). --- 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 3f127b7128..d8b1c92890 100644 --- a/support/Makefile +++ b/support/Makefile @@ -96,6 +96,7 @@ libsupport-routines = \ xchroot \ xclock_gettime \ xclock_settime \ + 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