Jump to content

Mostly C, VirtualBox?

Poet129
Go to solution Solved by Sauron,

Virtualbox is not an emulator. QEMU, however, is. It's also mostly written in C.

 

What code is responsible for the ability to "emulate" the cpu when hardware virtualization isn't supported? Reason I ask is, I would like to look at it.

Link to comment
Share on other sites

Link to post
Share on other sites

VirtualBox only emulates X86 systems, there is no case where hardware virtualisation is not native.

Main Rig:-

Ryzen 7 3800X | Asus ROG Strix X570-F Gaming | 16GB Team Group Dark Pro 3600Mhz | Corsair MP600 1TB PCIe Gen 4 | Sapphire 5700 XT Pulse | Corsair H115i Platinum | WD Black 1TB | WD Green 4TB | EVGA SuperNOVA G3 650W | Asus TUF GT501 | Samsung C27HG70 1440p 144hz HDR FreeSync 2 | Ubuntu 20.04.2 LTS |

 

Server:-

Intel NUC running Server 2019 + Synology DSM218+ with 2 x 4TB Toshiba NAS Ready HDDs (RAID0)

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, Master Disaster said:

VirtualBox only emulates X86 systems, there is no case where hardware virtualisation is not native.

I'm aware, I'm asking what part of the source code allows this to happen I realize that it only allows x86 OSes.

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, Poet129 said:

I'm aware, I'm asking what part of the source code allows this to happen I realize that it only allows x86 OSes.

If I understand you correctly then its important to realise that VirtualBox isn't technically emulating anything. Its an X86 emulator running on an X86 platform, instructions from the guest machine are simply processed on the host CPU via hardware passthrough. For all intents and purposes the guest machine has access to cores on your physical CPU and uses them as if they were attached to it directly.

 

As for where that happens in the code, sorry I can't help with that.

Main Rig:-

Ryzen 7 3800X | Asus ROG Strix X570-F Gaming | 16GB Team Group Dark Pro 3600Mhz | Corsair MP600 1TB PCIe Gen 4 | Sapphire 5700 XT Pulse | Corsair H115i Platinum | WD Black 1TB | WD Green 4TB | EVGA SuperNOVA G3 650W | Asus TUF GT501 | Samsung C27HG70 1440p 144hz HDR FreeSync 2 | Ubuntu 20.04.2 LTS |

 

Server:-

Intel NUC running Server 2019 + Synology DSM218+ with 2 x 4TB Toshiba NAS Ready HDDs (RAID0)

Link to comment
Share on other sites

Link to post
Share on other sites

17 minutes ago, Poet129 said:

What code is responsible for the ability to "emulate" the cpu when hardware virtualization isn't supported? Reason I ask is, I would like to look at it.

There is no one, neat single file, it's all a whole lot of interconnected stuff spread out into dozens of files.

6 minutes ago, Master Disaster said:

If I understand you correctly then its important to realise that VirtualBox isn't technically emulating anything. Its an X86 emulator running on an X86 platform, instructions from the guest machine are simply processed on the host CPU via hardware passthrough.

VirtualBox can emulate x86 without hardware-virtualization, but apparently only 32-bit systems.

Hand, n. A singular instrument worn at the end of the human arm and commonly thrust into somebody’s pocket.

Link to comment
Share on other sites

Link to post
Share on other sites

Virtualbox is not an emulator. QEMU, however, is. It's also mostly written in C.

Don't ask to ask, just ask... please 🤨

sudo chmod -R 000 /*

Link to comment
Share on other sites

Link to post
Share on other sites

3 minutes ago, WereCatf said:

There is no one, neat single file, it's all a whole lot of interconnected stuff spread out into dozens of files.

Any chance it is contained in a neat folder?

Link to comment
Share on other sites

Link to post
Share on other sites

4 minutes ago, WereCatf said:

There is no one, neat single file, it's all a whole lot of interconnected stuff spread out into dozens of files.

VirtualBox can emulate x86 without hardware-virtualization, but apparently only 32-bit systems.

Nah, it doesn't actually emulate anything, it uses a software virtualisation technique.

Quote

In the absence of hardware-assisted virtualization, VirtualBox adopts a standard software-based virtualization approach. This mode supports 32-bit guest OSs which run in rings 0 and 3 of the Intel ring architecture.

  • The system reconfigures the guest OS code, which would normally run in ring 0, to execute in ring 1 on the host hardware. Because this code contains many privileged instructions which cannot run natively in ring 1, VirtualBox employs a Code Scanning and Analysis Manager (CSAM) to scan the ring 0 code recursively before its first execution to identify problematic instructions and then calls the Patch Manager (PATM) to perform in-situ patching. This replaces the instruction with a jump to a VM-safe equivalent compiled code fragment in hypervisor memory.
  • The guest user-mode code, running in ring 3, generally runs directly on the host hardware in ring 3.

In both cases, VirtualBox uses CSAM and PATM to inspect and patch the offending instructions whenever a fault occurs. VirtualBox also contains a dynamic recompiler, based on QEMU to recompile any real mode or protected mode code entirely (e.g. BIOS code, a DOS guest, or any operating system startup).

Also this feature was dropped in VBox 6.1 and later.

Main Rig:-

Ryzen 7 3800X | Asus ROG Strix X570-F Gaming | 16GB Team Group Dark Pro 3600Mhz | Corsair MP600 1TB PCIe Gen 4 | Sapphire 5700 XT Pulse | Corsair H115i Platinum | WD Black 1TB | WD Green 4TB | EVGA SuperNOVA G3 650W | Asus TUF GT501 | Samsung C27HG70 1440p 144hz HDR FreeSync 2 | Ubuntu 20.04.2 LTS |

 

Server:-

Intel NUC running Server 2019 + Synology DSM218+ with 2 x 4TB Toshiba NAS Ready HDDs (RAID0)

Link to comment
Share on other sites

Link to post
Share on other sites

6 minutes ago, Sauron said:

Virtualbox is not an emulator. QEMU, however, is. It's also mostly written in C.

Okay I will try this and post back later.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×