On Fri, Mar 5, 2021 at 12:39 AM Christian Brauner 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 wrote: > > > > > > 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? > > > > 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. -- H.J.