Checking the guest's environment

The hypervisor provides a mechanism that allows a guest to determine if it is running in a virtualized environment and in particular, a QNX hypervisor environment.

ARM platforms

On ARM platforms, check the model property in the Flattened Device Tree (FDT) that describes the guest's system. If this property is set with QVM-v8A, then the system is hosted in a QNX hypervisor VM.

x86 platforms

For x86 platforms, see your hardware documentation to learn which CPUID register bit your guest needs to check to know if it is running in a hypervisor, and where in the register it needs to look for the VM ID string. The ID string for QNX hypervisor VMs is “QNXQVMBS”.

Below is an example of C code that a QNX guest might use to check if it is running in a QNX hypervisor on an x86 platform:

#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <arpa/inet.h>
 
int cpuid(uint32_t id, uint32_t *regs) {
       asm volatile ("cpuid"
             : "=a" (regs[0]), "=b" (regs[1]), "=c" (regs[2]), "=d" (regs[3])
             : "a" (id), "c" (0));
       return 0;
}
 
static const char * const qnxstr = "QNXQVMBS";
 
int main(int argc, char *argv[])
{
       uint32_t regs[4];
 
       cpuid(1, regs);
       if ((regs[2] & (1 << 31)) == 0) {
             puts("We are not running in a hypervisor");
             return 1; /* not a hypervisor */
       }
 
       /* It is a hypervisor, but is it OUR hypervisor? */
       cpuid(0x40000000, regs);
       regs[1] = htonl(regs[1]);
       regs[2] = htonl(regs[2]);
       if (memcmp(&regs[1], qnxstr, 4) != 0 || memcmp(&regs[2], qnxstr + 4, 4) != 0) {
             puts("This is a hypervisor but not a QNX hypervisor system");
             return 1; /* not ours :( */
       }
 
       /* It is a QNX hypervisor. */
       puts("This is a QNX QVM hypervisor system");

       return 0;
}

Linux and Android guests

You can adapt the C code above for Linux and Android guests on x86, or run the cpuid utility.