title: Detect virtualized OS from an application?
body: <p>I need to detect whether my application is running within a virtualized OS instance or not.</p>
  
  <p>I've found <A HREF="http://www.codeproject.com/KB/system/VmDetect.aspx" rel="noreferrer">an article</A> with some useful information on the topic. The same article appears in multiple places, I'm unsure of the original source. <A HREF="http://www.vmware.com/" rel="noreferrer">VMware</A> implements a particular invalid x86 instruction to return information about itself, while <A HREF="http://www.microsoft.com/windows/products/winfamily/virtualpc/default.mspx" rel="noreferrer">VirtualPC</A> uses a magic number and I/O port with an IN instruction.</p>
  
  <p>This is workable, but appears to be undocumented behavior in both cases. I suppose a future release of VMWare or VirtualPC might change the mechanism. Is there a better way? Is there a supported mechanism for either product?</p>
  
  <p>Similarly, is there a way to detect <A HREF="http://www.xen.org/" rel="noreferrer">Xen</A> or <A HREF="http://www.virtualbox.org/" rel="noreferrer">VirtualBox</A>?</p>
  
  <p>I'm not concerned about cases where the platform is deliberately trying to hide itself. For example, honeypots use virtualization but sometimes obscure the mechanisms that malware would use to detect it. I don't care that my app would think it is not virtualized in these honeypots, I'm just looking for a "best effort" solution.</p>
  
  <p>The application is mostly Java, though I'm expecting to use native code plus JNI for this particular function. Windows XP/Vista support is most important, though the mechanisms described in the referenced article are generic features of x86 and don't rely on any particular OS facility.</p>