This source file includes following definitions.
- is_running_under_qemu_user
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #include <stdbool.h>
20 #ifdef __linux__
21 # include <fcntl.h>
22 # include <string.h>
23 # include <unistd.h>
24 #endif
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39 static bool
40 is_running_under_qemu_user (void)
41 {
42 #ifdef __linux__
43 char buf[4096 + 1];
44 int fd;
45
46 # if defined __m68k__
47 fd = open ("/proc/hardware", O_RDONLY);
48 if (fd >= 0)
49 {
50 int n = read (fd, buf, sizeof (buf) - 1);
51 close (fd);
52 if (n > 0)
53 {
54 buf[n] = '\0';
55 if (strstr (buf, "qemu") != NULL)
56 return true;
57 }
58 }
59 # endif
60
61 fd = open ("/proc/cpuinfo", O_RDONLY);
62 if (fd >= 0)
63 {
64 int n = read (fd, buf, sizeof (buf) - 1);
65 close (fd);
66 if (n > 0)
67 {
68 buf[n] = '\0';
69 # if defined __hppa__
70 if (strstr (buf, "QEMU") != NULL)
71 return true;
72 # endif
73 # if !(defined __i386__ || defined __x86_64__)
74 if (strstr (buf, "AuthenticAMD") != NULL
75 || strstr (buf, "GenuineIntel") != NULL)
76 return true;
77 # endif
78 # if !(defined __arm__ || defined __aarch64__)
79 if (strstr (buf, "ARM") != NULL
80 || strcasestr (buf, "aarch64") != NULL)
81 return true;
82 # endif
83 # if !defined __sparc__
84 if (strcasestr (buf, "SPARC") != NULL)
85 return true;
86 # endif
87 # if !defined __powerpc__
88 if (strstr (buf, "POWER") != NULL)
89 return true;
90 # endif
91 }
92 }
93
94
95
96 #endif
97
98 return false;
99 }