Message ID | 20210601145516.3553627-1-hjl.tools@gmail.com |
---|---|
Headers |
Return-Path: <libc-alpha-bounces+patchwork=sourceware.org@sourceware.org> 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 8DDC039D3C04 for <patchwork@sourceware.org>; Tue, 1 Jun 2021 15:00:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8DDC039D3C04 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1622559605; bh=xhbGJsa0OCQFCXKW5GtLIHk3gRwMUKGOjFklKnelRP4=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=SNS8SWJ/mfTDG20mMtDp8hP42JUZIk0TFPFfC8QpFW24MNnlaKUhtKpXyJahPOlql Qu2gcf9ANl77wDNoHbDJ4aPX1MfKdZjeLBBwUtwhAR1zPactCIEM8b4O0Cil92Mm5m XnSz6yDkqSzPZopqiV6v8FLZEK6iiLb9x0UNY0Ms= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by sourceware.org (Postfix) with ESMTPS id 167A839BF41C for <libc-alpha@sourceware.org>; Tue, 1 Jun 2021 14:55:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 167A839BF41C Received: by mail-pf1-x42f.google.com with SMTP id q25so3785839pfh.7 for <libc-alpha@sourceware.org>; Tue, 01 Jun 2021 07:55:19 -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:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=xhbGJsa0OCQFCXKW5GtLIHk3gRwMUKGOjFklKnelRP4=; b=mJuNJPy7Q3GBjlrFpATo/fppO4dBmR6kU/6BEg/GlJu9x7biR+1y194XtLXTGd1ni+ Tgn7uJybIAOl4iOXAyNkz1qBm4py5sVp5EmYBBU5Xy9INwM2eTPkAxFv0+/KAMZcmIgV gNzpl7S43x1qXPXXy4hH+P884MAnfE33QXsNBkLKuiCCMWE2HfYT4CM8a55csIqmDJEe zS8bBa+hfHmMKth6U2H8nkX8MC5nf3E/C4n+SjcEPjjBnei4y2U9eGL0piYMHN2rC8Va prvy/FZRszrv7UprZygAFBzziqQhfOiz+4iSSHGk7QnSfo21DRscQ/GaPcftRFXjMEx7 4+/Q== X-Gm-Message-State: AOAM530P0PFwcPtQZ7rjhAhRjfBMc3jwVMuWdmgLqDrUkUx5zx3VJv1G Z25NOfFBr9DswnvVG1cPc44= X-Google-Smtp-Source: ABdhPJwJa8zBCHjoqnWKNelOfH6S/Itg8Xi6/hn666kgV3ndl0Cvrf8NtIFnfWs8J2a0DpIbgCQhDA== X-Received: by 2002:a63:5218:: with SMTP id g24mr27994763pgb.309.1622559318184; Tue, 01 Jun 2021 07:55:18 -0700 (PDT) Received: from gnu-cfl-2.localdomain ([172.56.38.102]) by smtp.gmail.com with ESMTPSA id s6sm2373832pjr.29.2021.06.01.07.55.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Jun 2021 07:55:17 -0700 (PDT) Received: from gnu-cfl-2.. (localhost [IPv6:::1]) by gnu-cfl-2.localdomain (Postfix) with ESMTP id 26CABC0305; Tue, 1 Jun 2021 07:55:16 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v8 0/3] Add an internal wrapper for clone, clone2 and clone3 Date: Tue, 1 Jun 2021 07:55:13 -0700 Message-Id: <20210601145516.3553627-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3028.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=no 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 <libc-alpha.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/libc-alpha>, <mailto:libc-alpha-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/libc-alpha/> List-Post: <mailto:libc-alpha@sourceware.org> List-Help: <mailto:libc-alpha-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/libc-alpha>, <mailto:libc-alpha-request@sourceware.org?subject=subscribe> From: "H.J. Lu via Libc-alpha" <libc-alpha@sourceware.org> Reply-To: "H.J. Lu" <hjl.tools@gmail.com> Cc: Florian Weimer <fweimer@redhat.com> Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" <libc-alpha-bounces+patchwork=sourceware.org@sourceware.org> |
Series |
Add an internal wrapper for clone, clone2 and clone3
|
|
Message
H.J. Lu
June 1, 2021, 2:55 p.m. UTC
The clone3 system call provides a superset of the functionality of clone and clone2. It also provides a number of API improvements, including the ability to specify the size of the child's stack area which can be used by kernel to compute the shadow stack size when allocating the shadow stack. Add: extern int __clone_internal (struct clone_args *__cl_args, int (*__func) (void *__arg), void *__arg); to provide an abstract interface for clone, clone2 and clone3. 1. Simplify stack management for thread creation by passing both stack base and size to create_thread. 2. Consolidate clone vs clone2 differences into a single file. 3. Call __clone3 if HAVE_CLONE3_WAPPER is defined. If __clone3 returns -1 with ENOSYS, fall back to clone or clone2. 4. Use only __clone_internal to clone a thread. Since the stack size argument for create_thread is now unconditional, always pass stack size to create_thread. 5. Enable the public clone3 wrapper in the future after it has been added to all targets. NB: Sandbox should return ENOSYS on clone3 if it is rejected: https://bugs.chromium.org/p/chromium/issues/detail?id=1213452#c5 H.J. Lu (3): Add an internal wrapper for clone, clone2 and clone3 x86-64: Add the clone3 wrapper Add static tests for __clone_internal include/clone_internal.h | 16 ++ nptl/allocatestack.c | 59 +------- nptl/pthread_create.c | 38 +++-- sysdeps/unix/sysv/linux/Makefile | 11 +- sysdeps/unix/sysv/linux/clone-internal.c | 91 ++++++++++++ sysdeps/unix/sysv/linux/clone3.c | 1 + sysdeps/unix/sysv/linux/clone3.h | 60 ++++++++ sysdeps/unix/sysv/linux/spawni.c | 26 ++-- .../sysv/linux/tst-align-clone-internal.c | 87 +++++++++++ sysdeps/unix/sysv/linux/tst-clone2-internal.c | 137 ++++++++++++++++++ sysdeps/unix/sysv/linux/tst-clone3-internal.c | 99 +++++++++++++ .../unix/sysv/linux/tst-getpid1-internal.c | 133 +++++++++++++++++ .../sysv/linux/tst-misalign-clone-internal.c | 86 +++++++++++ sysdeps/unix/sysv/linux/x86_64/clone3.S | 92 ++++++++++++ sysdeps/unix/sysv/linux/x86_64/sysdep.h | 2 + 15 files changed, 850 insertions(+), 88 deletions(-) create mode 100644 include/clone_internal.h create mode 100644 sysdeps/unix/sysv/linux/clone-internal.c create mode 100644 sysdeps/unix/sysv/linux/clone3.c create mode 100644 sysdeps/unix/sysv/linux/clone3.h create mode 100644 sysdeps/unix/sysv/linux/tst-align-clone-internal.c create mode 100644 sysdeps/unix/sysv/linux/tst-clone2-internal.c create mode 100644 sysdeps/unix/sysv/linux/tst-clone3-internal.c create mode 100644 sysdeps/unix/sysv/linux/tst-getpid1-internal.c create mode 100644 sysdeps/unix/sysv/linux/tst-misalign-clone-internal.c create mode 100644 sysdeps/unix/sysv/linux/x86_64/clone3.S