From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) by sourceware.org (Postfix) with ESMTPS id 7593F3858018 for ; Sat, 15 May 2021 12:34:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 7593F3858018 Received: by mail-pg1-x531.google.com with SMTP id s22so1255038pgk.6 for ; Sat, 15 May 2021 05:34:45 -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=eDnCW6UVBIb2S5TIxCdMLMRsPX9dx6aU3JR75oPteOg=; b=uVMnlWONry57KnGSBc7RY0WUohWBbij6CKOtZWpVNGPv8TTDDqFn1BcJuzCGJu6ucA Cds3B2iYDJTpzUbG+XD24LTvtDiFcNpcroDWewuj45ropv2O1w/B+0m87gDyKH86UJn3 7jQVleF29+62qwvrrgUab/7MJWuO46boRKyrsRHQI+PYaOzaBvU+T/wQC+qJuOHP0orP VpOzvTJ4EIkTpR50YcbQZ4qUkMDfYN2ZsEhmb2gsfFW7y6YMfX35NRklWBtWXVUsxB6f S35EHzsFhMg2NdarWsKsy5Nncqq4Fu0o6tHf3OFjwFZPchTNi+ICA8UfWUHSXj34ctRG wdnQ== X-Gm-Message-State: AOAM532uPpF71UsCqH2teW2DvW0NMG6GpOvJwB7v8J4jpWsn5xp95PcY wdsM0XLev+VzcBcWSUSUfjM= X-Google-Smtp-Source: ABdhPJx6hpoAexoByT6gMATwC/DRp+LGK9iHhIsY9bNcYlZi9URLqIMmYijin1J7WWveYy/aiRwH5g== X-Received: by 2002:a63:af02:: with SMTP id w2mr30588374pge.350.1621082084572; Sat, 15 May 2021 05:34:44 -0700 (PDT) Received: from gnu-cfl-2.localdomain ([172.56.39.231]) by smtp.gmail.com with ESMTPSA id s8sm6174254pfh.108.2021.05.15.05.34.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 May 2021 05:34:43 -0700 (PDT) Received: from gnu-cfl-2.. (localhost [IPv6:::1]) by gnu-cfl-2.localdomain (Postfix) with ESMTP id 35292C02FF; Sat, 15 May 2021 05:34:42 -0700 (PDT) From: "H.J. Lu" To: libc-alpha@sourceware.org Cc: Florian Weimer , Adhemerval Zanella Subject: [PATCH v5 0/5] Add an internal wrapper for clone, clone2 and clone3 Date: Sat, 15 May 2021 05:34:37 -0700 Message-Id: <20210515123442.1432385-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=-3029.1 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-List-Received-Date: Sat, 15 May 2021 12:34:46 -0000 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 (*__func) (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. 5. Call __clone3 if HAVE_CLONE3_WAPPER is defined. If __clone3 returns -1 with ENOSYS, fall back to clone or clone2. 6. 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 (5): Add an internal wrapper for clone, clone2 and clone3 nptl: Always pass stack size to create_thread GLIBC_PRIVATE: Export __clone_internal x86-64: Add the clone3 wrapper Add tests for __clone_internal include/clone_internal.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 | 11 +- sysdeps/unix/sysv/linux/Versions | 1 + sysdeps/unix/sysv/linux/clone-internal.c | 97 ++++++++++++ sysdeps/unix/sysv/linux/clone-offsets.sym | 5 + sysdeps/unix/sysv/linux/clone3.c | 1 + sysdeps/unix/sysv/linux/clone3.h | 55 +++++++ sysdeps/unix/sysv/linux/createthread.c | 25 +-- sysdeps/unix/sysv/linux/spawni.c | 26 ++-- .../sysv/linux/tst-align-clone-internal.c | 91 +++++++++++ sysdeps/unix/sysv/linux/tst-clone-internal.c | 51 +++++++ sysdeps/unix/sysv/linux/tst-clone2-internal.c | 142 ++++++++++++++++++ sysdeps/unix/sysv/linux/tst-clone3-internal.c | 101 +++++++++++++ .../unix/sysv/linux/tst-getpid1-internal.c | 137 +++++++++++++++++ sysdeps/unix/sysv/linux/x86_64/clone3.S | 92 ++++++++++++ sysdeps/unix/sysv/linux/x86_64/sysdep.h | 2 + 20 files changed, 841 insertions(+), 92 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/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/tst-align-clone-internal.c create mode 100644 sysdeps/unix/sysv/linux/tst-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/x86_64/clone3.S -- 2.31.1