ReactOS 0.4.16-dev-1311-g81a4d83
vm_detect.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Kernel-Mode Tests
3 * LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
4 * PURPOSE: VM detection code
5 * COPYRIGHT: Copyright 2025 Dmitry Borisov <di.sean@protonmail.com>
6 */
7
8/* INCLUDES *******************************************************************/
9
10#include <kmt_test.h>
11
12/* FUNCTIONS ******************************************************************/
13
14#if defined(_M_IX86) || defined(_M_AMD64)
15extern BOOLEAN VmIsVMware(VOID);
16
17static
19VmIsHypervisorPresent(VOID)
20{
21 INT CpuInfo[4];
22
23 __cpuid(CpuInfo, 1);
24
25 return !!(CpuInfo[2] & 0x80000000);
26}
27
28static
30VmIsVbox(VOID)
31{
32 ULONG PciId, BytesRead;
33 PCI_SLOT_NUMBER Slot;
34
35 Slot.u.AsULONG = 0;
36 Slot.u.bits.DeviceNumber = 4;
37 Slot.u.bits.FunctionNumber = 0;
38
40 0,
41 Slot.u.AsULONG,
42 &PciId,
44 sizeof(PciId));
45 return (BytesRead == sizeof(PciId)) && (PciId == 0xCAFE80EE);
46}
47#endif // defined(_M_IX86) || defined(_M_AMD64)
48
49/*
50 * NOTE: We make no attempt to support every software in existence.
51 * Only VMs used by Testman are checked.
52 */
55{
56#if defined(_M_IX86) || defined(_M_AMD64)
57 return VmIsHypervisorPresent() || VmIsVbox() || VmIsVMware();
58#else
59 return FALSE;
60#endif
61}
unsigned char BOOLEAN
#define FALSE
Definition: types.h:117
ULONG NTAPI HalGetBusDataByOffset(IN BUS_DATA_TYPE BusDataType, IN ULONG BusNumber, IN ULONG SlotNumber, IN PVOID Buffer, IN ULONG Offset, IN ULONG Length)
Definition: bus.c:73
PPC_QUAL void __cpuid(int CPUInfo[], const int InfoType)
Definition: intrin_ppc.h:682
@ PCIConfiguration
Definition: miniport.h:93
union _PCI_SLOT_NUMBER::@4181 u
struct _PCI_SLOT_NUMBER::@4181::@4182 bits
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
int32_t INT
Definition: typedefs.h:58
uint32_t ULONG
Definition: typedefs.h:59
BOOLEAN KmtDetectVirtualMachine(VOID)
Definition: vm_detect.c:54
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PLONGLONG _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_opt_ PULONG_PTR BytesRead
Definition: wdfiotarget.h:870