Page 1 of 3
[Answered]How to detect Virtual Box (OS Level)
Posted: Fri Aug 12, 2016 8:51 am
by Octacone
Okay, so today I was working on BGA a bit.
Once I completed my BGA driver I noticed something interesting. VirtualBox and Bochs use 0xE0000000 LFB address and Qemu uses 0xFD000008 LFB address. Now, I found out how to detect Bochs, if Bochs isn't detected then I set LFB to Qemu's LFB. Now how do I detect Virtual Box?
Re: How to detect Virtual Box (OS Level)
Posted: Fri Aug 12, 2016 8:57 am
by Ch4ozz
octacone wrote:Okay, so today I was working on BGA a bit.
Once I completed my BGA driver I noticed something interesting. VirtualBox and Bochs use 0xE0000000 LFB address and Qemu uses 0xFD000008 LFB address. Now, I found out how to detect Bochs, if Bochs isn't detected then I set LFB to Qemu's LFB. Now how do I detect Virtual Box?
Check the ACPI tables or the AHCI device names.
Im pretty sure there is an easier way, but thats the two I noticed during developing my os
Anyways, why do you hardcode this?
Re: How to detect Virtual Box (OS Level)
Posted: Fri Aug 12, 2016 9:03 am
by Octacone
Ch4ozz wrote:octacone wrote:Okay, so today I was working on BGA a bit.
Once I completed my BGA driver I noticed something interesting. VirtualBox and Bochs use 0xE0000000 LFB address and Qemu uses 0xFD000008 LFB address. Now, I found out how to detect Bochs, if Bochs isn't detected then I set LFB to Qemu's LFB. Now how do I detect Virtual Box?
Check the ACPI tables or the AHCI device names.
Im pretty sure there is an easier way, but thats the two I noticed during developing my os
That is not going to work atm (I don't have ACPI or ACHI).
Ch4ozz wrote:Anyways, why do you hardcode this?
?? Detection or LFB?
Re: How to detect Virtual Box (OS Level)
Posted: Fri Aug 12, 2016 9:12 am
by SpyderTL
VirtualBox has a "VirtualBox Guest Service" device on the PCI bus, with Vendor ID 0x80EE and Device ID 0xCAFE.
If this exists, you can assume you're running under VirtualBox. Not sure what difference it makes, though.
Re: How to detect Virtual Box (OS Level)
Posted: Fri Aug 12, 2016 9:16 am
by Octacone
SpyderTL wrote:VirtualBox has a "VirtualBox Guest Service" device on the PCI bus, with Vendor ID 0x80EE and Device ID 0xCAFE.
If this exists, you can assume you're running under VirtualBox. Not sure what difference it makes, though.
Very interesting. Can I use ports to detect this or I need to write PCI scanner? Thanks for the hint!
Re: How to detect Virtual Box (OS Level)
Posted: Fri Aug 12, 2016 9:21 am
by sleephacker
You don't need to detect if you're running on bochs/QEMU/virtualbox, I've never used BGA but according to the
wiki you can obtain the LFB address through PCI, which is probably more reliable than using hardcoded values.
EDIT: you would need to write a PCI scanner for both options.
Re: How to detect Virtual Box (OS Level)
Posted: Fri Aug 12, 2016 9:32 am
by Octacone
sleephacker wrote:You don't need to detect if you're running on bochs/QEMU/virtualbox, I've never used BGA but according to the
wiki you can obtain the LFB address through PCI, which is probably more reliable than using hardcoded values.
EDIT: you would need to write a PCI scanner for both options.
Yeah, I should probably detect LFB rather than defining it. Thanks!!! Going to do it that way.
Also: why does paging mess up my LBF, when I enable paging I can't plot pixels.
Re: How to detect Virtual Box (OS Level)
Posted: Fri Aug 12, 2016 10:10 am
by ~
You could see if the whole hardware device environment is the same that VirtualBox has (the same device IDs....).
You could search for VirtualBox BIOS signatures, strings that mention it, BIOS splash bitmaps that correspond to VirtualBox.
You could see if there are VirtualBox-style folder shares.
You could inspect for anything that has to do with VirtualBox in memory.
Re: How to detect Virtual Box (OS Level)
Posted: Fri Aug 12, 2016 10:30 am
by Octacone
~ wrote:You could see if the whole hardware device environment is the same that VirtualBox has (the same device IDs....).
You could search for VirtualBox BIOS signatures, strings that mention it, BIOS splash bitmaps that correspond to VirtualBox.
You could see if there are VirtualBox-style folder shares.
You should inspect for anything that has to do with VirtualBox in memory.
Wow, didn't know that there were so many ways. I think that the best way of detecting Virtual Box is by searching for device IDs. +1
Re: How to detect Virtual Box (OS Level)
Posted: Fri Aug 12, 2016 10:52 am
by Octacone
SpyderTL wrote:VirtualBox has a "VirtualBox Guest Service" device on the PCI bus, with Vendor ID 0x80EE and Device ID 0xCAFE.
If this exists, you can assume you're running under VirtualBox. Not sure what difference it makes, though.
How to do this? I want to check Vendor ID/Device ID. So I need a function that sees if a device exists? So what buses/slots I should be looking at? I don't want to write an entire PCI system just to check if a device exists. There must be a way to check if a device with give ID exists. Right?
Re: How to detect Virtual Box (OS Level)
Posted: Fri Aug 12, 2016 12:06 pm
by Kazinsal
You have to write a whole PCI bus enumerator in order to reliably find devices.
Considering you'd have to do that anyways in order to write drivers for just about anything, you might as well do it now.
Re: How to detect Virtual Box (OS Level)
Posted: Fri Aug 12, 2016 12:28 pm
by BrightLight
Detecting VirtualBox just to use BGA isn't worth it.
There is no real proof that a new VirtualBox version won't have the framebuffer at 0xE0000000. Instead, you should read the framebuffer from BAR0 of the PCI BGA device (device 0x1234:0x1111), and if it doesn't exist, only then should you use 0xE0000000. QEMU has a PCI BGA, and, as you have pointed out, uses the framebuffer at 0xFD000000.
EDIT: A PCI enumerator is very simple, actually. Once you have a routine to read and write registers to the PCI configuration space, most of it is done with common sense.
Re: How to detect Virtual Box (OS Level)
Posted: Fri Aug 12, 2016 12:40 pm
by Octacone
omarrx024 wrote:Detecting VirtualBox just to use BGA isn't worth it.
There is no real proof that a new VirtualBox version won't have the framebuffer at 0xE0000000. Instead, you should read the framebuffer from BAR0 of the PCI BGA device (device 0x1234:0x1111), and if it doesn't exist, only then should you use 0xE0000000. QEMU has a PCI BGA, and, as you have pointed out, uses the framebuffer at 0xFD000000.
EDIT: A PCI enumerator is very simple, actually. Once you have a routine to read and write registers to the PCI configuration space, most of it is done with common sense.
I have a function that detects both Bochs and VirtualBox and if they don't get detected system makes an assumption that the emulator equals to Qemu. Atm I can read from 32Bit PCI, is that useful? It has (bus, device, function, offset).
I just need if(CheckVendor("0xCAFE") == true)
Re: How to detect Virtual Box (OS Level)
Posted: Fri Aug 12, 2016 12:58 pm
by Octacone
What do I need to input in:
uint32_t Read32BitPCI(uint8_t bus, uint8_t device, uint8_t function, uint32_t offset)
Can I see if my vendor id device exists using that?
Another IDEA
I can skip Virtual Box detection if I find a way to detect Qemu <------
Re: How to detect Virtual Box (OS Level)
Posted: Fri Aug 12, 2016 1:11 pm
by Octacone
This turned into my worst nightmare.
Is there a simple way to detect Qemu? I bet that somebody know the answer.