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>
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
---
bsd-user/bsd-misc.h | 33 +++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+)
diff --git a/bsd-user/bsd-misc.h b/bsd-user/bsd-misc.h
index 7587ffd605..9f1cc8a0cd 100644
--- a/bsd-user/bsd-misc.h
+++ b/bsd-user/bsd-misc.h
@@ -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)
{
--
2.52.0