@samitouri / QOSamiQemu / commits / 7cbe2f914c

bsd-user: Add host_to_target_uuid for uuidgen(2)

Add host_to_target_uuid() to convert host struct uuid to target ABI for the uuidgen(2) syscall. Signed-off-by: Stacey Son <sson@FreeBSD.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Signed-off-by: Warner Losh <imp@bsdimp.com>

Stacey Son committed Feb 2, 2026 at 14:46 UTC 7cbe2f914c9bc492a5e60573b5402f6b84a00a71
1 file changed +35
bsd-user/bsd-misc.c new
+35
@@ -0,0 +1,35 @@
1 +/*
2 + * BSD misc system call conversions routines
3 + *
4 + * Copyright (c) 2013 Stacey D. Son
5 + *
6 + * SPDX-License-Identifier: GPL-2.0-or-later
7 + */
8 +#include "qemu/osdep.h"
9 +
10 +#include <sys/uuid.h>
11 +
12 +#include "qemu.h"
13 +#include "qemu-bsd.h"
14 +
15 +/*
16 + * BSD uuidgen(2) struct uuid conversion
17 + */
18 +abi_long host_to_target_uuid(abi_ulong target_addr, struct uuid *host_uuid)
19 +{
20 + struct target_uuid *target_uuid;
21 +
22 + if (!lock_user_struct(VERIFY_WRITE, target_uuid, target_addr, 0)) {
23 + return -TARGET_EFAULT;
24 + }
25 + __put_user(host_uuid->time_low, &target_uuid->time_low);
26 + __put_user(host_uuid->time_mid, &target_uuid->time_mid);
27 + __put_user(host_uuid->time_hi_and_version,
28 + &target_uuid->time_hi_and_version);
29 + host_uuid->clock_seq_hi_and_reserved =
30 + target_uuid->clock_seq_hi_and_reserved;
31 + host_uuid->clock_seq_low = target_uuid->clock_seq_low;
32 + memcpy(host_uuid->node, target_uuid->node, TARGET_UUID_NODE_LEN);
33 + unlock_user_struct(target_uuid, target_addr, 1);
34 + return 0;
35 +}