bsd-user: Add do_bsd_uuidgen implementation

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

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
This commit is contained in:
Stacey Son
2026-02-02 16:41:28 -07:00
committed by Warner Losh
parent 75f6b9bcad
commit 021fadcc8d

View File

@@ -32,6 +32,39 @@ 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 = NULL;
/*
* 2048 is the kernel limit, but there's no #define for it, nor any sysctl
* to query it.
*/
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)) {
break;
}
}
out:
return ret;
}
/* getdtablesize(2) */
static inline abi_long do_bsd_getdtablesize(void)
{