1 /* Determine whether the current process is running under QEMU.
2 Copyright (C) 2021-2024 Free Software Foundation, Inc.
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
9 This file is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 /* Written by Bruno Haible <bruno@clisp.org>, 2021. */
25 /* This function determines whether the current process is running under QEMU
28 It does so by looking at parts of the environment that QEMU does not emulate
31 For comparison, the techniques given in the paper
32 Thomas Raffetseder, Christopher Kruegel, Engin Kirda
33 "Detecting System Emulators"
35 https://publik.tuwien.ac.at/files/pub-inf_5317.pdf
36 apply to both the QEMU system mode and QEMU user mode. */
39 is_running_under_qemu_user (void)
46 fd
= open ("/proc/hardware", O_RDONLY
);
49 int n
= read (fd
, buf
, sizeof (buf
) - 1);
54 if (strstr (buf
, "qemu") != NULL
)
60 fd
= open ("/proc/cpuinfo", O_RDONLY
);
63 int n
= read (fd
, buf
, sizeof (buf
) - 1);
69 if (strstr (buf
, "QEMU") != NULL
)
72 # if !(defined __i386__ || defined __x86_64__)
73 if (strstr (buf
, "AuthenticAMD") != NULL
74 || strstr (buf
, "GenuineIntel") != NULL
)
77 # if !(defined __arm__ || defined __aarch64__)
78 if (strstr (buf
, "ARM") != NULL
79 || strcasestr (buf
, "aarch64") != NULL
)
82 # if !defined __sparc__
83 if (strcasestr (buf
, "SPARC") != NULL
)
86 # if !defined __powerpc__
87 if (strstr (buf
, "POWER") != NULL
)
93 /* If you need more heuristics, look at system calls that are not perfectly
94 well emulated in qemu/linux-user/syscall.c. */