[PATCH v2 15/24] bsd-user: Add do_bsd_uuidgen implementation

Warner Losh posted 24 patches 16 hours ago
Maintainers: Warner Losh <imp@bsdimp.com>, Kyle Evans <kevans@freebsd.org>, Riku Voipio <riku.voipio@iki.fi>, Paolo Bonzini <pbonzini@redhat.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>
[PATCH v2 15/24] bsd-user: Add do_bsd_uuidgen implementation
Posted by Warner Losh 16 hours ago
From: Stacey Son <sson@FreeBSD.org>

Add implementation of uuidgen(2) syscall that generates UUIDs and
converts them to target ABI format.

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 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;
+
+    if (count < 1 || count > 2048) {
+        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;
+        }
+    }
+
+out:
+    return ret;
+}
+
 /* getdtablesize(2) */
 static inline abi_long do_bsd_getdtablesize(void)
 {

-- 
2.52.0
Re: [PATCH v2 15/24] bsd-user: Add do_bsd_uuidgen implementation
Posted by Richard Henderson 10 hours ago
On 2/9/26 05:26, Warner Losh wrote:
> From: Stacey Son <sson@FreeBSD.org>
> 
> Add implementation of uuidgen(2) syscall that generates UUIDs and
> converts them to target ABI format.
> 
> Signed-off-by: Stacey Son <sson@FreeBSD.org>
> Signed-off-by: Warner Losh <imp@bsdimp.com>
> ---
>   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.

> +
> +    if (count < 1 || count > 2048) {
> +        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.


r~

> +        }
> +    }
> +
> +out:
> +    return ret;
> +}
> +
>   /* getdtablesize(2) */
>   static inline abi_long do_bsd_getdtablesize(void)
>   {
>
Re: [PATCH v2 15/24] bsd-user: Add do_bsd_uuidgen implementation
Posted by Warner Losh 8 hours ago
On Sun, Feb 8, 2026 at 7:04 PM Richard Henderson <
richard.henderson@linaro.org> wrote:

> On 2/9/26 05:26, Warner Losh wrote:
> > From: Stacey Son <sson@FreeBSD.org>
> >
> > Add implementation of uuidgen(2) syscall that generates UUIDs and
> > converts them to target ABI format.
> >
> > Signed-off-by: Stacey Son <sson@FreeBSD.org>
> > Signed-off-by: Warner Losh <imp@bsdimp.com>
> > ---
> >   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)
> >   {
> >
>
>
>