From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oi1-x22e.google.com (mail-oi1-x22e.google.com [IPv6:2607:f8b0:4864:20::22e]) by sourceware.org (Postfix) with ESMTPS id 44D25383F850 for ; Thu, 4 Mar 2021 18:41:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 44D25383F850 Received: by mail-oi1-x22e.google.com with SMTP id l133so31201775oib.4 for ; Thu, 04 Mar 2021 10:41:25 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Zu0hj713UdXPhvO6rAIcW0YFr+ZLxP/3n2UwEFvw3kI=; b=tw+ULhY8srF+aXODXBQm7MSSlgMBDmao3lBx26Rh+2OMSVm5RzopM/BsPfFmirGUYE jv67uBS5BrBdZH43VaoMZUrzV+uEGvPln0xNxIFjQLs92GR0POzvBD9GKMY3n1TbsqCW ROqHz9R+xHwEwUPnHU/c9y0NS6W9ScYte9KIxSbbe4msjArCf6d4fUFitTzKoGl++jnt F7m4/uM3K8c32+gV+jKsbkWJUqrUcjoUPC5Sh7+KoVioSL8BPB4coJwh4yQDnYZEe0kO tYs3GRm75HqPZQaUeCIKzESgzV+HWL9L0cyq2j1n5MxNyNi4qSvVQ90qS1ORytXYU2Tm ztYg== X-Gm-Message-State: AOAM530P2fBFpIwPhT99bXTJHRa4StGd+0FYRdJfp8C6WkLodW02xCkT UpNwq2Ga3oifQtpOtNklBJPSZ4+YORcTGJ8z4NI= X-Google-Smtp-Source: ABdhPJyQiouOMH4AvfKeX6P+Y6Qe9R+wO5UpYiIb1F7Ya4h+uIrqQihbO4Mp4gqIINfACHfmRFJnj7zX8hprK3x0HTQ= X-Received: by 2002:aca:1016:: with SMTP id 22mr3306787oiq.79.1614883284693; Thu, 04 Mar 2021 10:41:24 -0800 (PST) MIME-Version: 1.0 References: <20210214224505.4448-1-hjl.tools@gmail.com> <87r1lhehkw.fsf@oldenburg.str.redhat.com> <7e132276-269f-b9c6-72fe-9d771e023d29@linaro.org> In-Reply-To: <7e132276-269f-b9c6-72fe-9d771e023d29@linaro.org> From: "H.J. Lu" Date: Thu, 4 Mar 2021 10:40:48 -0800 Message-ID: Subject: [PATCH v2] Add an internal wrapper for clone, clone2 and clone3 To: Adhemerval Zanella Cc: Florian Weimer , "H.J. Lu via Libc-alpha" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3029.3 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: Thu, 04 Mar 2021 18:41:26 -0000 On Mon, Feb 15, 2021 at 6:56 AM Adhemerval Zanella via Libc-alpha wrote: > > > > On 15/02/2021 07:44, Florian Weimer via Libc-alpha wrote: > > * H. J. Lu via 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, size_t size, > >> int (*__fn) (void *__arg), void *__arg); > >> > >> to provide an abstract interface for clone, clone2 and clone3. > >> > >> 1. Simplify stack management for clone by passing stack base and size > >> to __clone_internal. > >> 2. Consolidate clone vs clone2 differences into a single file. > >> 3. Use only __clone_internal to clone a thread. If clone3 returns -1 > >> with ENOSYS, __clone_internal will fall back to clone or clone2. > >> 4. Add the x86-64 clone3 wrapper. > >> 5. Enable the public clone3 wrapper in the future after it has been > >> added to add targets. > > > > What do you think about providing a clone wrapper which reuses the > > caller's stack? That would be useful for a (v)fork-style clone. This > > variant could also be exported because the callback inherits a > > semi-valid TCB in this case. > I have this one as a TODO to improve the posix_spawn. Here is the v2 patch: 1. Update the stack size field, instead of the stack field, passed to clone3. OK for master? Thanks. -- H.J.