On Thu, Feb 5, 2026 at 8:08 PM Richard Henderson < [email protected]> wrote:
> On 2/6/26 03: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 | 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
