From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qt1-x831.google.com (mail-qt1-x831.google.com [IPv6:2607:f8b0:4864:20::831]) by sourceware.org (Postfix) with ESMTPS id B597F383803E for ; Wed, 23 Jun 2021 18:51:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B597F383803E Received: by mail-qt1-x831.google.com with SMTP id w26so2865733qto.13 for ; Wed, 23 Jun 2021 11:51:22 -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=WM6JMiGYKqiDnRhU+eSyqP7igawh7WkpXSl3LCxAbqs=; b=aFwSbgOngCyxStmuuyyWtuZ1mbbRyk24VVykDQozW1+AcJ3wnNn31r940RKYSMQM8m 4TU4p3YXm3SxlHjtIT3S02r3HurpJKmAqCZ9ck4NULVXXq2vOqyG7+T7pzth+dgUCVmJ MyoHhqb4owaUIgG9CK9fa5lD5xFfCUDUXnfrRRjahMB8dTNs7sthBuE9IVCMr3XxCrwi xP1LoYDq0u+ItK50Dh5Fqy+p4JJ1NYknvqKJBbd2goUInAA+JZk1PPsZ8lT0eAG3LRLc MPneG+Ptupg+Gg/Fsa3rn5+SmdknPKUb8im030dnmxv1nu9PSDWbSMihUNsfBeM+pNlo tjxA== X-Gm-Message-State: AOAM533lIGST8nCXZmimK9J0NvcWgE4vriNNQtiITSNxkZPb8dcmUmTa Oea7HVqyn3iJ6uGbVeJGSWZ0Ix60pMkscA== X-Google-Smtp-Source: ABdhPJzveAuCnVULn6dbuAb41JBf8JNBzSejD7wru7W6JXn2i3pCODwC0HU60yzCVN4tfyNyFMg8mA== X-Received: by 2002:ac8:5bc8:: with SMTP id b8mr1282282qtb.386.1624474282168; Wed, 23 Jun 2021 11:51:22 -0700 (PDT) Received: from birita.. ([177.194.59.218]) by smtp.gmail.com with ESMTPSA id c11sm492293qth.29.2021.06.23.11.51.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Jun 2021 11:51:21 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH v6 2/5] support: Add xclone Date: Wed, 23 Jun 2021 15:51:12 -0300 Message-Id: <20210623185115.395812-3-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210623185115.395812-1-adhemerval.zanella@linaro.org> References: <20210623185115.395812-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.4 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-List-Received-Date: Wed, 23 Jun 2021 18:51:24 -0000 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 f5410545a1..a462781718 100644 --- a/support/Makefile +++ b/support/Makefile @@ -104,6 +104,7 @@ libsupport-routines = \ xclock_gettime_time64 \ xclock_settime \ xclock_settime_time64 \ + 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.30.2