From patchwork Wed Dec 23 16:36:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 41537 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 80BF73850434; Wed, 23 Dec 2020 16:37:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 80BF73850434 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1608741421; bh=qd+acn6g7g88iA4uHQrks8tNXX0mvymXAOhGUhm564I=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=Ace4++7YLXBQ2kFjdSo8sy+5+yRtjYP13QJMIcmUm+kBdjZpulMEzm7hSh7C/uB4s UAB+GENLfqk1EGSyD/Q7MfqpFI5zLhJFJpT7uRQfHe0r6ynudzORK9W7LgdEoJvN2a di9QbG0DNDSnDaPCq8kG6hmoqkB3RGM9ha9zCDI8= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qt1-x82c.google.com (mail-qt1-x82c.google.com [IPv6:2607:f8b0:4864:20::82c]) by sourceware.org (Postfix) with ESMTPS id D1AC53858023 for ; Wed, 23 Dec 2020 16:36:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D1AC53858023 Received: by mail-qt1-x82c.google.com with SMTP id z9so11637508qtn.4 for ; Wed, 23 Dec 2020 08:36:56 -0800 (PST) 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:mime-version :content-transfer-encoding; bh=qd+acn6g7g88iA4uHQrks8tNXX0mvymXAOhGUhm564I=; b=Np+30zNehJL6RDFdYGV3UrsSRRqdXhEdoCPQ0Pt5eKN5nUOXIrpwvUCRB0V0p7aYCA MGmXtJv9Fd+QtQ4NcQ/6xgLSn+lo9fkBnE6qbJirr7yPsGwGBit80oAsIwOZFFjoD2F6 bu1837OVHFbrlpxc6xRNR341PCEi9Dlxmjl1O4mA1jPRVcsXDBL7BPansrSXz6UqJWNe B6Qmgv7SiJjuAddp6VObv5sePz9tWUBRzSQ6RlIKOhjZYfK2acDD2NrdcMaJllgL2s8i YFiEUGpS8tQiGUzEIIvZV91TeBy0vxtyMcyNMOYjVgu9YcnKXoqEO3o4+/W5ijI0a052 R8WA== X-Gm-Message-State: AOAM532BGlNKE9DsbIrxaaCeScTXBmOBJ/KM3g0I1vewxpVhztjsNb2j AE9mZZU3pBZb8naV98r9dzil1fByL5gfzQ== X-Google-Smtp-Source: ABdhPJyP1atCvejZoQ4eh9O9R3hmUOoRslbvVsiQ3582GHLp3pfI14kv0k9FLdmUjyUKdhkNXbZc9A== X-Received: by 2002:ac8:1c92:: with SMTP id f18mr22115029qtl.234.1608741416220; Wed, 23 Dec 2020 08:36:56 -0800 (PST) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id h16sm15946118qko.135.2020.12.23.08.36.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Dec 2020 08:36:55 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH v3 1/4] support: Add xclone Date: Wed, 23 Dec 2020 13:36:48 -0300 Message-Id: <20201223163651.2634504-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Spam-Status: No, score=-13.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 Cc: Florian Weimer Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" Changes from previous version: - Fixed typos and corrected one line file description. --- 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 | 38 ++++++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 support/xclone.c create mode 100644 support/xsched.h diff --git a/support/Makefile b/support/Makefile index 3198eb5022..aecd27316e 100644 --- a/support/Makefile +++ b/support/Makefile @@ -89,6 +89,7 @@ libsupport-routines = \ xcalloc \ 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..027b367ba1 --- /dev/null +++ b/support/xclone.c @@ -0,0 +1,50 @@ +/* Auxiliary functions to issue the clone syscall. + Copyright (C) 2020 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..1b7ce7286f --- /dev/null +++ b/support/xsched.h @@ -0,0 +1,38 @@ +/* Wrapper for sched.h functions. + Copyright (C) 2020 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__ +# define DEFINE_STACK(name, size) \ + char name[size] __attribute__ ((aligned)) + +pid_t +xclone (int (*fn) (void *arg), void *arg, void *stack, size_t stack_size, + int flags); +#endif + +__END_DECLS + +#endif