On Tue, Aug 29, 2023 at 2:58 PM Richard Henderson <
richard.hender...@linaro.org> wrote:

> On 8/27/23 08:57, Karim Taha wrote:
> > From: Stacey Son <s...@freebsd.org>
> >
> > Signed-off-by: Stacey Son <s...@freebsd.org>
> > Signed-off-by: Karim Taha <kariem.taha...@gmail.com>
> > ---
> >   bsd-user/freebsd/os-proc.h    | 32 ++++++++++++++++++++++++++++++++
> >   bsd-user/freebsd/os-syscall.c |  4 ++++
> >   2 files changed, 36 insertions(+)
> >
> > diff --git a/bsd-user/freebsd/os-proc.h b/bsd-user/freebsd/os-proc.h
> > index 94824d737a..1eaba908a5 100644
> > --- a/bsd-user/freebsd/os-proc.h
> > +++ b/bsd-user/freebsd/os-proc.h
> > @@ -248,4 +248,36 @@ static inline abi_long do_freebsd_rfork(void
> *cpu_env, abi_long flags)
> >
> >   }
> >
> > +/* pdfork(2) */
> > +static inline abi_long do_freebsd_pdfork(void *cpu_env, abi_ulong
> target_fdp,
> > +        abi_long flags)
> > +{
> > +    abi_long ret;
> > +    abi_ulong child_flag;
> > +    int fd;
> > +
> > +    fork_start();
> > +    ret = pdfork(&fd, flags);
> > +    if (ret == 0) {
> > +        /* child */
> > +        child_flag = 1;
> > +        target_cpu_clone_regs(cpu_env, 0);
> > +    } else {
> > +        /* parent */
> > +        child_flag = 0;
> > +    }
> > +    if (put_user_s32(fd, target_fdp)) {
> > +        return -TARGET_EFAULT;
> > +    }
>
> I *think* this copy belongs in the parent?


I think that it's copied out in both cases. For normal fork, this would
be 0 for the pid. However, it appears to return the same FD to both
the parent and child (see your next comment), so it should be in both
paths. And even if it returned something different for parent and child
(which seems unlikely given how the code is setup), we want to return
the fd each one sees. So either way, I think this code is correct.


> It's really hard to follow the path of new
> process creation within the freebsd kernel.
>

Agreed.


> Anyway, the rest looks fine so I'll give an
>
> Acked-by: Richard Henderson <richard.hender...@linaro.org>
>

Reviewed-by: Warner Losh <i...@bsdimp.com>

Reply via email to