On Sun, Feb 8, 2026 at 7:04 PM Richard Henderson <
[email protected]> wrote:

> On 2/9/26 05:26, Warner Losh wrote:
> > From: Stacey Son <[email protected]>
> >
> > Add implementation of uuidgen(2) syscall that generates UUIDs and
> > converts them to target ABI format.
> >
> > Signed-off-by: Stacey Son <[email protected]>
> > Signed-off-by: Warner Losh <[email protected]>
> > ---
> >   bsd-user/bsd-misc.h | 29 +++++++++++++++++++++++++++++
> >   1 file changed, 29 insertions(+)
> >
> > diff --git a/bsd-user/bsd-misc.h b/bsd-user/bsd-misc.h
> > index d81b4fbaef..ad248c3b79 100644
> > --- a/bsd-user/bsd-misc.h
> > +++ b/bsd-user/bsd-misc.h
> > @@ -43,6 +43,35 @@ static inline abi_long do_bsd_reboot(abi_long how)
> >       return -TARGET_ENOSYS;
> >   }
> >
> > +/* uuidgen(2) */
> > +static inline abi_long do_bsd_uuidgen(abi_ulong target_addr, int count)
> > +{
> > +    int i;
> > +    abi_long ret;
> > +    g_autofree struct uuid *host_uuid;
>
> autofree variables *must* be initialized.
> NULL is sufficient.
>

OK. I'd forgotten that.. Thanks for the reminder.


> > +
> > +    if (count < 1 || count > 2048) {
>

I've also added a comment that 2048 is the kernel limit, but there's no
#define nor sysctl to query it.


> > +        return -TARGET_EINVAL;
> > +    }
> > +
> > +    host_uuid = g_malloc(count * sizeof(struct uuid));
> > +
> > +    ret = get_errno(uuidgen(host_uuid, count));
> > +    if (is_error(ret)) {
> > +        goto out;
> > +    }
> > +    for (i = 0; i < count; i++) {
> > +        ret = host_to_target_uuid(target_addr +
> > +            (abi_ulong)(sizeof(struct target_uuid) * i), &host_uuid[i]);
> > +        if (is_error(ret)) {
> > +            goto out;
>
> break is sufficient.
>

So it is...

Warner


> r~
>
> > +        }
> > +    }
> > +
> > +out:
> > +    return ret;
> > +}
> > +
> >   /* getdtablesize(2) */
> >   static inline abi_long do_bsd_getdtablesize(void)
> >   {
> >
>
>
>

Reply via email to