virtualization or OS ?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
extremecoder
Member
Member
Posts: 59
Joined: Tue May 23, 2006 11:00 pm

virtualization or OS ?

Post by extremecoder »

I want to write a code which will determine whether it runs on a physical system or inside a virtualized environment / software ? Would this be possible ?
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: virtualization or OS ?

Post by Troy Martin »

Well, if the virtualization/emulation software has certain flags in CPUID, that can be used to determine if the machine is software-based or not.
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
skyking
Member
Member
Posts: 174
Joined: Sun Jan 06, 2008 8:41 am

Re: virtualization or OS ?

Post by skyking »

extremecoder wrote:I want to write a code which will determine whether it runs on a physical system or inside a virtualized environment / software ? Would this be possible ?
If you're referring to emulated environment, no not in general. However the emulator may have behavior that the emulated system does not, but that would need to be specific to the emulator. Why do you ask? Do your system need to do something different when it's run in the emulator? If the emulator does not support some specific hardware then you have to test for the presence of that hardware (which you must anyway). The emulator may have hardware that is not present on normal system as well, but the same goes here - you have to test for the presence of the hardware you are going to use. Also the CPU in the emulator may behave slightly differently which probably should be possible to determine via the CPUID.
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Re: virtualization or OS ?

Post by jal »

extremecoder wrote:I want to write a code which will determine whether it runs on a physical system or inside a virtualized environment / software ? Would this be possible ?
If you are referring to eht AMD/Intel virtualization extensions, then yes, you can. I think some status register contains some flag indicating it runs in virtualization. Check the Intel/AMD docs for specifics.


JAL
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: virtualization or OS ?

Post by Combuster »

Another nice one is to check if Virtual Mode Extensions actually work. Qemu and derivatives, as well as VirtualPC, report VME support but don't actually do it. Especially useful when the VM predates the vmx era.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Post Reply