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

Warner Losh posted 24 patches 3 days, 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>
There is a newer version of this series
[PATCH 15/24] bsd-user: Add do_bsd_uuidgen implementation
Posted by Warner Losh 3 days, 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 | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/bsd-user/bsd-misc.h b/bsd-user/bsd-misc.h
index d81b4fbaef..b722c63437 100644
--- a/bsd-user/bsd-misc.h
+++ b/bsd-user/bsd-misc.h
@@ -43,6 +43,40 @@ 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;
+    struct uuid *host_uuid;
+
+    if (count < 1 || count > 2048) {
+        return -TARGET_EINVAL;
+    }
+
+    host_uuid = g_malloc(count * sizeof(struct uuid));
+
+    if (host_uuid == NULL) {
+        return -TARGET_ENOMEM;
+    }
+
+    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:
+    g_free(host_uuid);
+    return ret;
+}
+
 /* getdtablesize(2) */
 static inline abi_long do_bsd_getdtablesize(void)
 {

-- 
2.52.0
Re: [PATCH 15/24] bsd-user: Add do_bsd_uuidgen implementation
Posted by Richard Henderson 3 days, 7 hours ago
On 2/6/26 03: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 | 34 ++++++++++++++++++++++++++++++++++
>   1 file changed, 34 insertions(+)
> 
> diff --git a/bsd-user/bsd-misc.h b/bsd-user/bsd-misc.h
> index d81b4fbaef..b722c63437 100644
> --- a/bsd-user/bsd-misc.h
> +++ b/bsd-user/bsd-misc.h
> @@ -43,6 +43,40 @@ 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;
> +    struct uuid *host_uuid;
> +
> +    if (count < 1 || count > 2048) {
> +        return -TARGET_EINVAL;
> +    }
> +
> +    host_uuid = g_malloc(count * sizeof(struct uuid));
> +
> +    if (host_uuid == NULL) {

g_malloc will never return null.

> +        return -TARGET_ENOMEM;
> +    }
> +
> +    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:
> +    g_free(host_uuid);
> +    return ret;
> +}

Can be improved with g_autofree instead of goto.


r~
Re: [PATCH 15/24] bsd-user: Add do_bsd_uuidgen implementation
Posted by Warner Losh 2 days, 16 hours ago
On Thu, Feb 5, 2026 at 8:08 PM Richard Henderson <
richard.henderson@linaro.org> wrote:

> On 2/6/26 03: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 | 34 ++++++++++++++++++++++++++++++++++
> >   1 file changed, 34 insertions(+)
> >
> > diff --git a/bsd-user/bsd-misc.h b/bsd-user/bsd-misc.h
> > index d81b4fbaef..b722c63437 100644
> > --- a/bsd-user/bsd-misc.h
> > +++ b/bsd-user/bsd-misc.h
> > @@ -43,6 +43,40 @@ 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;
> > +    struct uuid *host_uuid;
> > +
> > +    if (count < 1 || count > 2048) {
> > +        return -TARGET_EINVAL;
> > +    }
> > +
> > +    host_uuid = g_malloc(count * sizeof(struct uuid));
> > +
> > +    if (host_uuid == NULL) {
>
> g_malloc will never return null.
>
> > +        return -TARGET_ENOMEM;
> > +    }
> > +
> > +    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:
> > +    g_free(host_uuid);
> > +    return ret;
> > +}
>
> Can be improved with g_autofree instead of goto.
>

Will fix both...

Warner