Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/lib/libc/gen Provide separate functions to check for r...



details:   https://anonhg.NetBSD.org/src/rev/7a78f7f82075
branches:  trunk
changeset: 1013238:7a78f7f82075
user:      gson <gson%NetBSD.org@localhost>
date:      Sun Aug 23 11:00:18 2020 +0000

description:
Provide separate functions to check for running under qemu in general
and for running under qemu's built-in TCG CPU emulation (as opposed to
hardware virtualization via NVMM or KVM).

diffstat:

 tests/lib/libc/gen/isqemu.h |  24 +++++++++++++++++++++++-
 1 files changed, 23 insertions(+), 1 deletions(-)

diffs (46 lines):

diff -r 970782f5a4ec -r 7a78f7f82075 tests/lib/libc/gen/isqemu.h
--- a/tests/lib/libc/gen/isqemu.h       Sun Aug 23 10:53:27 2020 +0000
+++ b/tests/lib/libc/gen/isqemu.h       Sun Aug 23 11:00:18 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: isqemu.h,v 1.4 2015/01/03 14:21:05 gson Exp $  */
+/*     $NetBSD: isqemu.h,v 1.5 2020/08/23 11:00:18 gson Exp $  */
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -33,14 +33,36 @@
  */
 #include <sys/param.h>
 #include <sys/sysctl.h>
+#include <sys/drvctlio.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
 #include <stdbool.h>
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
 #include <err.h>
+#include <unistd.h>
 
 static __inline bool
 isQEMU(void) {
+       struct devlistargs dla = {
+              .l_devname = "qemufwcfg0",
+              .l_childname = NULL,
+              .l_children = 0,
+       };
+       int fd = open(DRVCTLDEV, O_RDONLY, 0);
+       if (fd == -1)
+              return false;
+       if (ioctl(fd, DRVLISTDEV, &dla) == -1) {
+              close(fd);
+              return false;
+       }
+       close(fd);
+       return true;
+}
+
+static __inline bool
+isQEMU_TCG(void) {
 #if defined(__i386__) || defined(__x86_64__)
        char name[1024];
        size_t len = sizeof(name);



Home | Main Index | Thread Index | Old Index