public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: "H.J. Lu" <hjl.tools@gmail.com>
To: Christian Brauner <christian.brauner@ubuntu.com>
Cc: Adhemerval Zanella <adhemerval.zanella@linaro.org>,
	Florian Weimer <fweimer@redhat.com>,
	 "H.J. Lu via Libc-alpha" <libc-alpha@sourceware.org>
Subject: PING^1 [PATCH v3] Add an internal wrapper for clone, clone2 and clone3
Date: Thu, 18 Mar 2021 16:18:45 -0700	[thread overview]
Message-ID: <CAMe9rOrVvezv9+Y7fr9UsS-ntNNcwOd0pJSzP3yzmE6faFOmiw@mail.gmail.com> (raw)
In-Reply-To: <CAMe9rOrYKmHQJ8rTvqXP0UHVzzFPm0Nr6b8cByRCN5GzBTyyXw@mail.gmail.com>

On Fri, Mar 5, 2021 at 8:59 AM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> On Fri, Mar 5, 2021 at 12:39 AM Christian Brauner
> <christian.brauner@ubuntu.com> wrote:
> >
> > On Thu, Mar 04, 2021 at 10:50:29AM -0800, H.J. Lu via Libc-alpha wrote:
> > > On Thu, Mar 4, 2021 at 10:40 AM H.J. Lu <hjl.tools@gmail.com> wrote:
> > > >
> > > > On Mon, Feb 15, 2021 at 6:56 AM Adhemerval Zanella via Libc-alpha
> > > > <libc-alpha@sourceware.org> 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?
> > >
> > > Really add the patch this time :-).
> > >
> > > --
> > > H.J.
> >
> > Just a small comment.
> >
>
> > > +      __set_errno (0);
> > > +      /* Map clone3 arguments to clone arguments.  */
> > > +      int flags = cl_args->flags | cl_args->exit_signal;
> > > +      void *stack = (void *) (uintptr_t) cl_args->stack;
> > > +
> > > +#ifdef __ia64__
> > > +      ret = __clone2 (fn, stack, (size_t) cl_args->stack_size,
> > > +                   flags, arg,
> > > +                   (void *) (uintptr_t) cl_args->parent_tid,
> > > +                   (void *) (uintptr_t) cl_args->tls,
> > > +                   (void *) (uintptr_t) cl_args->child_tid);
> >
> > Should glibc maybe just carry a few simple macros to do this instead of
> > open-coding the casting? (We do in systemd and LXC for example.):
> >
> > #define PTR_TO_INT(p) ((int)((intptr_t)(p)))
> > #define INT_TO_PTR(u) ((void *)((intptr_t)(u)))
> >
> > #define PTR_TO_PID(p) ((pid_t)((intptr_t)(p)))
> > #define PID_TO_PTR(u) ((void *)((intptr_t)(u)))
> >
> > #define PTR_TO_UINT64(p) ((uint64_t)((uintptr_t)(p)))
> >
> > #define PTR_TO_U64(p) ((__u64)((uintptr_t)(p)))
> >
> > #define UINT_TO_PTR(u) ((void *) ((uintptr_t) (u)))
> >
> > #define PTR_TO_USHORT(p) ((unsigned short)((uintptr_t)(p)))
> >
>
> Fixed.
>
> Here is the v3 patch.   OK for master?
>
> Changes from v2:
>
> 1. Add cast_to_pointer to cast an integer to void * pointer.
>

PING.

-- 
H.J.

  reply	other threads:[~2021-03-18 23:19 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-14 22:45 [PATCH] " H.J. Lu
2021-02-15 10:44 ` Florian Weimer
2021-02-15 14:17   ` H.J. Lu
2021-02-15 14:27     ` Florian Weimer
2021-02-15 14:44       ` H.J. Lu
2021-02-15 14:39   ` Adhemerval Zanella
2021-03-04 18:40     ` [PATCH v2] " H.J. Lu
2021-03-04 18:50       ` H.J. Lu
2021-03-05  8:32         ` Christian Brauner
2021-03-05 16:59           ` [PATCH v3] " H.J. Lu
2021-03-18 23:18             ` H.J. Lu [this message]
2021-04-19 12:56             ` PING^1 " H.J. Lu
2021-05-10  8:17             ` Florian Weimer
2021-05-10 23:56               ` H.J. Lu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAMe9rOrVvezv9+Y7fr9UsS-ntNNcwOd0pJSzP3yzmE6faFOmiw@mail.gmail.com \
    --to=hjl.tools@gmail.com \
    --cc=adhemerval.zanella@linaro.org \
    --cc=christian.brauner@ubuntu.com \
    --cc=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).