From patchwork Sat May 22 03:50:13 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: 43539 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 1BAFA383B409; Sat, 22 May 2021 03:50:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1BAFA383B409 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1621655424; bh=2Eq607hGG8FiRoq7+YnjcyvW71L3Ipwr8Vb6DfFKtvY=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=rfrPiXnO1Wpt9vfIjCKvqubYJ1rBK2D8g74ZcLvSWvWhuT9V2C1un5aC/cDtbFltN t1ZSdMtJPfikzZRRPmCBrv7tNrslYCRhqEUUvhYN9ZaMMsAgARx3bC/vs5qgU6IUAE Y2vr+PIHNpXYfqZwFplwF4fGIze4+zsEAqRCYrZQ= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by sourceware.org (Postfix) with ESMTPS id D81C7384605A for ; Sat, 22 May 2021 03:50:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D81C7384605A Received: by mail-pl1-x635.google.com with SMTP id t9so3527580ply.6 for ; Fri, 21 May 2021 20:50:20 -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=2Eq607hGG8FiRoq7+YnjcyvW71L3Ipwr8Vb6DfFKtvY=; b=OrPXGY5J+IC2YwVOR3rG/7P47C0MmpobcB7ewP8xmVY/2Dd7XDZDwCoDyUhqrRq/tA 8ep9MIZRBhtCb0OXY999RBPUQPiLs2PTGnzAKp220Qpi7jfhEVd69vU1u/0jcegGbo/D rPK+h12agGxNtaPRBY8DMErOD2sirqHjEc2++xbZi59FlCulY1kcUv+PhJ7j7Fn04s7q /sTL07+5l83phJgT5G6yC3CdQIrFpFvWFA/P61jUIaruxml2DYb/lreYzslKtR4/nSMQ YPhCMFv1Iy51pyOfiRRgKdMLDT0kFQCdyoGXHIhfhqL2jw4AICA8/F7fnlgun6Y0Uz6U NZ4g== X-Gm-Message-State: AOAM531BXYEJdwZPc9jiE3q5XiQswJfzKKV2i3758DUfG81s1k7H3eqB yM60GoGgIuxK8rEl2KD0gC4= X-Google-Smtp-Source: ABdhPJxoKkUOgbboNpT+ZW+j8BhxyViMKvhMBuSBw0cxzDXNBBeQb5qyjzUW1VKI8OUwKv49VKiixw== X-Received: by 2002:a17:902:860b:b029:ef:46b8:886e with SMTP id f11-20020a170902860bb02900ef46b8886emr15305052plo.18.1621655420039; Fri, 21 May 2021 20:50:20 -0700 (PDT) Received: from gnu-cfl-2.localdomain ([172.56.38.102]) by smtp.gmail.com with ESMTPSA id f7sm5529143pfq.8.2021.05.21.20.50.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 May 2021 20:50:19 -0700 (PDT) Received: from gnu-cfl-2.. (localhost [IPv6:::1]) by gnu-cfl-2.localdomain (Postfix) with ESMTP id 3B815C037B; Fri, 21 May 2021 20:50:18 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v5 0/5] Add an internal wrapper for clone, clone2 and clone3 Date: Fri, 21 May 2021 20:50:13 -0700 Message-Id: <20210522035018.2652112-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Spam-Status: No, score=-3027.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 (*__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. Add the clone3 wrapper for x86-64. 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 cast_to_pointer to cast an integer to void * pointer Add an internal wrapper for clone, clone2 and clone3 nptl: Always pass stack size to create_thread x86-64: Add the clone3 wrapper Add static tests for __clone_internal include/clone_internal.h | 16 ++ include/libc-pointer-arith.h | 3 + nptl/allocatestack.c | 59 +------- nptl/createthread.c | 3 +- nptl/pthread_create.c | 17 ++- sysdeps/unix/sysv/linux/Makefile | 10 +- 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 | 86 +++++++++++ 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 | 132 +++++++++++++++++ sysdeps/unix/sysv/linux/x86_64/clone3.S | 92 ++++++++++++ sysdeps/unix/sysv/linux/x86_64/sysdep.h | 2 + 17 files changed, 768 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/x86_64/clone3.S