From patchwork Tue May 11 01:43:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 43363 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 A8409386102E; Tue, 11 May 2021 01:44:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A8409386102E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1620697442; bh=8Ky05Ua4sx8JaT6fAlnRrpnxo1KWjt0SirVKi6Z0Obc=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=JtIOeypsZNNGuKFYyTRdiZj5Urr55f679ucpcAM/9uWCKCrkMkiJhcJXPuLQHnimo Mrmv1RcBbc3cR7YmwL63PXvxIF2JarW1lq3UsqxWwh+k/khwB2KXkYn36SCODmkelp yIgLb57SuM/f3oMS6RBRSuYY1WkCauazbUwPD7Rw= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by sourceware.org (Postfix) with ESMTPS id 947023860C3C for ; Tue, 11 May 2021 01:43:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 947023860C3C Received: by mail-pf1-x429.google.com with SMTP id i13so15034359pfu.2 for ; Mon, 10 May 2021 18:43:59 -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=8Ky05Ua4sx8JaT6fAlnRrpnxo1KWjt0SirVKi6Z0Obc=; b=NIiKaKqYNwJctLXV0ATaLdmv+DxMDE7G3+km/k0gcXmcJF/2dgQad9nLssjnBs6JwB Py4XsBWH4mcCVNi7R+f8W2LjXQnQFfoJ4mZO2OW+6/k/QrAVgeqSvvfzlZmYnMfYgoCx F/vRngLs0ZI6gFiswqvvvkh7J6+kHK+10uPMcrY7/qG55VEZRRz50N0lNNYeIyKIFLez 43YV6MrRgqR3N1p8KsJpUR1r6tGEwgS4lJWWzTPqPBoPyy8SVutteFmIibXFJXc56vJj kyJFV536j4CQETcr/te1/6WRfESQV8TvKGkRn05u7yXTTZfUR35SffTgf41HMW6tOw/6 0A1g== X-Gm-Message-State: AOAM533YUUHtcJlElfyp4MgbZG4yyDCKJgv8YCNsbwr4tf/35/7UPcdr zE4hG0g2fNk8hvMt1KwcYoY= X-Google-Smtp-Source: ABdhPJytg06SHdAw8hwd8LEoVU80g8vxw+makRYu05mJPptlNSHl0mmMEAUMc/u/M06SGZcA+oKXHg== X-Received: by 2002:a62:34c7:0:b029:28e:addf:f17a with SMTP id b190-20020a6234c70000b029028eaddff17amr28606997pfa.62.1620697438668; Mon, 10 May 2021 18:43:58 -0700 (PDT) Received: from gnu-cfl-2.localdomain ([172.56.38.197]) by smtp.gmail.com with ESMTPSA id t1sm12154965pjo.33.2021.05.10.18.43.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 May 2021 18:43:58 -0700 (PDT) Received: from gnu-cfl-2.. (localhost [IPv6:::1]) by gnu-cfl-2.localdomain (Postfix) with ESMTP id 9B6EBC0335; Mon, 10 May 2021 18:43:56 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v4 0/2] Add an internal wrapper for clone, clone2 and clone3 Date: Mon, 10 May 2021 18:43:54 -0700 Message-Id: <20210511014356.235353-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: "H.J. Lu via Libc-alpha" From: "H.J. Lu" Reply-To: "H.J. Lu" Cc: Florian Weimer Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" The clone3 system call provides a superset of the functionality of clone and clone2. It also provides a number of API improve ments, 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 (*__fn) (void *__arg), void *__arg); to provide an abstract interface for clone, clone2 and clone3. 1. Add cast_to_pointer to cast an integer to void * pointer. 2. Simplify stack management for thread creation by passing both stack base and size to create_thread. 3. Consolidate clone vs clone2 differences into a single file. 4. Use only __clone_internal to clone a thread. If clone3 returns -1 with ENOSYS, __clone_internal will fall back to clone or clone2. 5. Add the x86-64 clone3 wrapper. 6. Enable the public clone3 wrapper in the future after it has been added to all targets. H.J. Lu (2): Add an internal wrapper for clone, clone2 and clone3 nptl: Always pass stack size to create_thread include/clone3.h | 14 ++++ include/libc-pointer-arith.h | 3 + nptl/allocatestack.c | 59 ++------------- nptl/createthread.c | 3 +- nptl/pthread_create.c | 17 +++-- sysdeps/unix/sysv/linux/Makefile | 4 +- sysdeps/unix/sysv/linux/Versions | 1 + sysdeps/unix/sysv/linux/clone-internal.c | 80 ++++++++++++++++++++ sysdeps/unix/sysv/linux/clone-offsets.sym | 5 ++ sysdeps/unix/sysv/linux/clone3.c | 34 +++++++++ sysdeps/unix/sysv/linux/clone3.h | 58 ++++++++++++++ sysdeps/unix/sysv/linux/createthread.c | 25 +++--- sysdeps/unix/sysv/linux/spawni.c | 26 +++---- sysdeps/unix/sysv/linux/tst-align-clone.c | 55 +++++++++++--- sysdeps/unix/sysv/linux/tst-clone.c | 23 +++++- sysdeps/unix/sysv/linux/tst-clone2.c | 61 +++++++++++---- sysdeps/unix/sysv/linux/tst-clone3.c | 60 +++++++++++---- sysdeps/unix/sysv/linux/tst-getpid1.c | 54 ++++++++++--- sysdeps/unix/sysv/linux/x86_64/clone3.S | 92 +++++++++++++++++++++++ 19 files changed, 533 insertions(+), 141 deletions(-) create mode 100644 include/clone3.h create mode 100644 sysdeps/unix/sysv/linux/clone-internal.c create mode 100644 sysdeps/unix/sysv/linux/clone-offsets.sym 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/x86_64/clone3.S