[LTP] Query: Adding support for clone3()

Viresh Kumar viresh.kumar@linaro.org
Fri Feb 28 11:24:32 CET 2020


On 28-02-20, 09:58, Cyril Hrubis wrote:
> Hi!
> > I was looking to start implementation of clone3() syscall in LTP
> > and am a bit confused here and need your help in doing the same.
> > 
> > LTP abstracts the call to clone() syscall in lib/cloner.c and the current
> > prototype of it looks like this.
> > 
> >        int clone(int (*fn)(void *), void *stack, int flags, void *arg, ...
> >                  /* pid_t *parent_tid, void *tls, pid_t *child_tid */ );
> 
> This function is there mostly for implementation of container testscases
> so that they does not need to deal with the clone() syscall complexity.

Right.

> > One of the challenges with the implementation of clone3() is that
> > there is no glibc wrapper available. And in case of clone() glibc
> > wrapper isn't ordinary as it takes care of calling fn() and handling
> > few stack related things, apart from calling the real syscall.
> > 
> > I am confused now on how should I write support for clone3().
> > 
> > Any suggestions will be appreciated. Thanks.
> 
> Let's just add the code into lapi/clone.h, would that work for you?

Which code are you talking about ?

Here is some stuff about the glibc wrapper for clone() from an stackoverflow
page [1]:

clone(void (*fn)(void *), void *stack_pointer)
{
    push fn onto stack_pointer
    syscall_clone()
    if (child) {
        pop fn off of stack
        fn();
        exit();
    }
}

This takes care of calling fn() and doing some stack related stuff.
The kernel syscall doesn't expect the fn() argument but only the
userspace calls do. How should I handle the extra stuff that userspace
expects for a clone() call ?

-- 
viresh

[1] https://stackoverflow.com/questions/18904292/is-it-true-that-fork-calls-clone-internally


More information about the ltp mailing list