From patchwork Tue Dec 22 21:27:51 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: 41519 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 527BC388A826; Tue, 22 Dec 2020 21:28:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 527BC388A826 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1608672483; bh=hpwwNfh3/ZiCV3o2rt4k8/DEgtLxEeGnVXg3dDrCiL4=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=sqvK2J4Jp2phwzcT2YqVHxFgR3mlA6Fu4aMoDDz+CcflP+S8UijLs8OmMxDmFEHvn bSBHT2xYY6hWZ5eo4xsVY2zd4+dWObVrAlaGh7oRZjzwqA9+oA+aT4A5C+oLtbJol7 2bO/yakvLCZr22zCo8CS6LbzeekdeDwRIg0zYglc= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x729.google.com (mail-qk1-x729.google.com [IPv6:2607:f8b0:4864:20::729]) by sourceware.org (Postfix) with ESMTPS id E31FD383E814 for ; Tue, 22 Dec 2020 21:28:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org E31FD383E814 Received: by mail-qk1-x729.google.com with SMTP id w79so13259283qkb.5 for ; Tue, 22 Dec 2020 13:28:00 -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=hpwwNfh3/ZiCV3o2rt4k8/DEgtLxEeGnVXg3dDrCiL4=; b=r/K4naQAHisuGFXBRai5LJm5TKpp5Rlrmd5nji20gPSxGWRB1UN33Gd+7F1LCjQrMT LRImJRQ5uatk5AHXwzLhZhwmyfRbu/VzrKlYwk6LbLgWSbdTEWr5hUd9Hbl57vBlokA7 KeuQj3RUTcchDJeHpaT+xJb/qWqAYoh+UlwWHVAUpM94yKTh1p5wJWfvjKHkmZO7h9kj MTno/likFwuf6ZuzGJ+LIXTePYJcHKHlVGMzW1PFCuvUkabyEhfcapO2s8siT0hk9U9S ncGBSpF5v7+h+2UscHwULQdgEpfUt1b41f1nJ4P0rnsDdOj3lB/stlFe4XkzmgtQ/1bg MdjQ== X-Gm-Message-State: AOAM532kH37EQuIPg5QVedejeboyik0tCfYTKArpHgsmjjo3VBoC5bs4 /pysnoOB3fx+TegpOsD3m4zv4KuaUYP+bw== X-Google-Smtp-Source: ABdhPJwQROiIJEgfBGERVWiBBXa3ImLxDVlZGRW/pzuyv2CrlavwFUjORRuPzcFMAwJTuq3TTivijw== X-Received: by 2002:a37:4145:: with SMTP id o66mr23997943qka.4.1608672480205; Tue, 22 Dec 2020 13:28:00 -0800 (PST) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id h75sm4891404qke.130.2020.12.22.13.27.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Dec 2020 13:27:59 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH 1/4] support: Add xclone Date: Tue, 22 Dec 2020 18:27:51 -0300 Message-Id: <20201222212754.387111-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" It is a wrapper for Linux close 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 | 46 ++++++++++++++++++++++++++++++++++++++++++++++ support/xsched.h | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 83 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..e7efffb82b --- /dev/null +++ b/support/xclone.c @@ -0,0 +1,46 @@ +/* Auxiliary wrapper to issue the clone symbol. + 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 + . */ + +#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 __linux__ +# 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 +#endif + + return r; +} diff --git a/support/xsched.h b/support/xsched.h new file mode 100644 index 0000000000..8523f03f82 --- /dev/null +++ b/support/xsched.h @@ -0,0 +1,36 @@ +/* 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 + +#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); + +__END_DECLS + +#endif