Message ID | 20210526123956.2712353-1-hjl.tools@gmail.com |
---|---|
Headers |
Return-Path: <libc-alpha-bounces@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 F0A6C384C001; Wed, 26 May 2021 12:40:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F0A6C384C001 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1622032804; bh=9L4YEfxwyBARX3cT6iH2FwpgvGd4nIMjO2eh9wLR3RA=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=TiHapTARpPhfn4NWxH2XB02K5DLkhy/y/+WMovTQJtDt5uZEJm60UENWBunuDBo7n NukOhZiopIUD1XokhbTlUUlA3xuAeOdq0KnGPPWc90u0cr4B54f73ocIBvOV2Q8VHS CfKUrYuxrkyg4BCir224oPBRhJ78Cx7YvVZwqKIg= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) by sourceware.org (Postfix) with ESMTPS id 8FB11384F026 for <libc-alpha@sourceware.org>; Wed, 26 May 2021 12:40:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 8FB11384F026 Received: by mail-pg1-x529.google.com with SMTP id t193so839890pgb.4 for <libc-alpha@sourceware.org>; Wed, 26 May 2021 05:40:01 -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=9L4YEfxwyBARX3cT6iH2FwpgvGd4nIMjO2eh9wLR3RA=; b=bSQuVCr+9SEh1DDrZS4HhiEI5voXrzz7plrUCpqRI5qs1e+1X2DxX5FbgDnh/8GOgT 0Z5BpLguAonRC5uYeAXlh9Fh/w05n5f89vbtk/YnItZUduwfOfYBljssqxndc4BN/zKn EqUFJA2BckVyxS+WgntUIjPbxVYVyXQql4ie/AzEVEAbYA/rZdBvQsPna5ssxiD2l0WY ZApr1NXAaNmbmFnoBtK96PDSxVZp8RfIB1QgtdxwZ+XNUhY/ZOoG8r/kzLu4sznjLycw Dn8lSOSbim36S7yo/oFoXjX/qTS9j9vZM99x3pHW+zbOW6tUri6F4+zHKUJpZBAKTONY ny3A== X-Gm-Message-State: AOAM530uuMJkkZyjA3bMv+w8b+AJ8Yl59wZq9AZUTDUpoRl/waoa80qU 26omoGA4kXVKW3TFWNGFhDw= X-Google-Smtp-Source: ABdhPJyTyo2jd4BtfPz0AXwWAOlKuXxbRG0XNeotPHDiPdw8gNVb1Sm9m8QWvVxrMnKPWKUQ8G2cig== X-Received: by 2002:a63:da15:: with SMTP id c21mr11162868pgh.227.1622032800744; Wed, 26 May 2021 05:40:00 -0700 (PDT) Received: from gnu-cfl-2.localdomain ([172.56.38.102]) by smtp.gmail.com with ESMTPSA id v15sm15574739pfm.187.2021.05.26.05.39.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 May 2021 05:40:00 -0700 (PDT) Received: from gnu-cfl-2.. (localhost [IPv6:::1]) by gnu-cfl-2.localdomain (Postfix) with ESMTP id 02A48C0364; Wed, 26 May 2021 05:39:57 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v7 0/3] Add an internal wrapper for clone, clone2 and clone3 Date: Wed, 26 May 2021 05:39:53 -0700 Message-Id: <20210526123956.2712353-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.7 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@sourceware.org Sender: "Libc-alpha" <libc-alpha-bounces@sourceware.org> |
Series |
Add an internal wrapper for clone, clone2 and clone3
|
|
Message
H.J. Lu
May 26, 2021, 12:39 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. Tested with build-many-glibcs.py. 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/createthread.c | 3 +- nptl/pthread_create.c | 17 ++- 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/createthread.c | 25 ++-- 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 + 17 files changed, 854 insertions(+), 91 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