@samitouri / QOSamiQemu / commits / 021fadcc8d

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>

Stacey Son committed Feb 2, 2026 at 16:41 UTC 021fadcc8da866547429a2c91334eb1ff2c4ab34
1 file changed +33
bsd-user/bsd-misc.h
+33
@@ -32,6 +32,39 @@ static inline abi_long do_bsd_reboot(abi_long how)
32 return -TARGET_ENOSYS;
33 }
34
35 +/* uuidgen(2) */
36 +static inline abi_long do_bsd_uuidgen(abi_ulong target_addr, int count)
37 +{
38 + int i;
39 + abi_long ret;
40 + g_autofree struct uuid *host_uuid = NULL;
41 +
42 + /*
43 + * 2048 is the kernel limit, but there's no #define for it, nor any sysctl
44 + * to query it.
45 + */
46 + if (count < 1 || count > 2048) {
47 + return -TARGET_EINVAL;
48 + }
49 +
50 + host_uuid = g_malloc(count * sizeof(struct uuid));
51 +
52 + ret = get_errno(uuidgen(host_uuid, count));
53 + if (is_error(ret)) {
54 + goto out;
55 + }
56 + for (i = 0; i < count; i++) {
57 + ret = host_to_target_uuid(target_addr +
58 + (abi_ulong)(sizeof(struct target_uuid) * i), &host_uuid[i]);
59 + if (is_error(ret)) {
60 + break;
61 + }
62 + }
63 +
64 +out:
65 + return ret;
66 +}
67 +
68 /* getdtablesize(2) */
69 static inline abi_long do_bsd_getdtablesize(void)
70 {