# google/android-emulator-hypervisor-driver architecture

> Architecture diagram of the GitHub repository google/android-emulator-hypervisor-driver, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/google/android-emulator-hypervisor-driver
- Repository: https://github.com/google/android-emulator-hypervisor-driver

## Overview

##### Project type and purpose
- This is a kernel-level hypervisor driver for Windows, originally forked from KVM, that accelerates the Android Emulator by exposing Intel VT-x or AMD SVM features to user-mode emulator code.
- It comprises a Windows kernel driver (AEHD – Android Emulator Hypervisor Driver) plus associated user-space install/packaging scripts.

##### File structure
Top-level files & folders:
- aehd/, aehd_main.c/.h, aehd_types.h, aehd_ver.h: MSVC solution & entry points for the driver.
- arch/x86/: KVM’s architecture-specific implementation (VMX/SVM, CPUID, MMU, LAPIC, APIC, PMU, paging, interrupt emulation).
- asmgen/: a small tool to generate assembly stubs or tables.
- assembly/x64/: assembly helpers for x64 build.
- /: shared headers (uAPI, Linux-KVM compatibility, KVM-host types).
- virt/kvm/: core KVM logic (VM creation, run loop, IRQ chip abstraction).
- package/: packaging script for building the driver installer.
- sign/: INF and DDF scripts for code signing and driver package creation.
- ntkrutils.c/.h: Windows kernel helper functions.
- .sln/.vcxproj: Visual Studio build artifacts.

##### README for additional insights
- Confirms: Windows driver, supports Intel and AMD VT extensions, integrates with Android Emulator user-space via an installer or manual driver install.
- Mentions packaging, silent install, Hyper-V must be disabled, target OS versions.

##### Elements
- Clear labels: “Android Emulator”, “AEHD Driver”, “KVM Core”, “Arch/x86 VMX/SVM”, “ASM Stubs”, “Windows Kernel APIs”, “Installer/Signer”
– From emulator to driver (IOCTLs)
– From driver into KVM Core & Arch modules
– From build scripts to final signed pkg
– Green for user-space components
– Blue for kernel modules
– Orange for build/packaging tools
– Grey for hardware

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "User-space"
        UE["Android Emulator"]:::user
    end

    subgraph "Build Pipeline"
        AG["asmgen (asmgen/asmgen.c)"]:::build
        AGProj["asmgen/asmgen.vcxproj"]:::build
        ASMStub["Assembly Stubs (assembly/x64/assembly.asm)"]:::build
        VSsln["AEHD Solution (aehd/aehd.sln)"]:::build
        VScproj["AEHD Project (aehd/aehd.vcxproj)"]:::build
        PKG["Package Script (package/make_package.sh)"]:::build
        SIGNINF["Signing INF (sign/aehd/aehd.inf)"]:::build
        SIGNDDF["Signing DDF (sign/aehd/aehd.ddf)"]:::build
        Installer["Driver Installer"]:::build
    end

    subgraph "Kernel Hypervisor"
        subgraph "AEHD Kernel Driver"
            DriverMain["AEHD Entry Points (aehd_main.c/.h, types.h, ver.h)"]:::kernel
            NTK["Windows Helpers (ntkrutils.c/.h)"]:::kernel
            WDF["Windows Kernel APIs"]:::kernel
        end

        subgraph "KVM Core Module"
            KVMMain["virt/kvm/kvm_main.c"]:::kernel
            IRQ["virt/kvm/irqchip.c"]:::kernel
        end

        subgraph "Arch Layer (x86 VMX/SVM)"
            ArchC["arch/x86/kvm/*.c"]:::kernel
            ArchH["arch/x86/kvm/*.h"]:::kernel
        end

        Shared["Shared Headers (include/)"]:::kernel
    end

    HW["Virtualization Hardware (VT-x/SVM)"]:::hardware

    UE -->|"IOCTLs"| DriverMain
    DriverMain -->|uses| KVMMain
    DriverMain -->|uses| NTK
    DriverMain -->|invokes| WDF
    KVMMain -->|"calls"| ArchC
    ArchC -->|uses| ASMStub
    ArchC -->|includes| Shared
    KVMMain -->|includes| Shared
    DriverMain -->|controls| HW
    ArchC -->|configures| HW

    AGProj -->|builds| AG
    AG -->|generates| ASMStub
    VSsln -->|compiles| DriverMain
    VScproj -->|compiles| DriverMain
    VSsln -->|compiles| KVMMain
    VScproj -->|compiles| KVMMain
    PKG -->|bundles| VSsln
    PKG -->|bundles| VScproj
    PKG -->|"packages driver"| Installer
    SIGNINF -->|signs| Installer
    SIGNDDF -->|signs| Installer
    Installer -->|installs| DriverMain

    click AG "https://github.com/google/android-emulator-hypervisor-driver/blob/master/asmgen/asmgen.c"
    click AGProj "https://github.com/google/android-emulator-hypervisor-driver/blob/master/asmgen/asmgen.vcxproj"
    click ASMStub "https://github.com/google/android-emulator-hypervisor-driver/blob/master/assembly/x64/assembly.asm"
    click VSsln "https://github.com/google/android-emulator-hypervisor-driver/blob/master/aehd/aehd.sln"
    click VScproj "https://github.com/google/android-emulator-hypervisor-driver/blob/master/aehd/aehd.vcxproj"
    click PKG "https://github.com/google/android-emulator-hypervisor-driver/blob/master/package/make_package.sh"
    click SIGNINF "https://github.com/google/android-emulator-hypervisor-driver/blob/master/sign/aehd/aehd.inf"
    click SIGNDDF "https://github.com/google/android-emulator-hypervisor-driver/blob/master/sign/aehd/aehd.ddf"
    click KVMMain "https://github.com/google/android-emulator-hypervisor-driver/blob/master/virt/kvm/kvm_main.c"
    click IRQ "https://github.com/google/android-emulator-hypervisor-driver/blob/master/virt/kvm/irqchip.c"
    click ArchC "https://github.com/google/android-emulator-hypervisor-driver/tree/master/arch/x86/kvm/"
    click Shared "https://github.com/google/android-emulator-hypervisor-driver/tree/master/include/"
    click DriverMain "https://github.com/google/android-emulator-hypervisor-driver/blob/master/aehd_main.c"
    click NTK "https://github.com/google/android-emulator-hypervisor-driver/blob/master/ntkrutils.c"

    classDef user fill:#e0ffe0,stroke:#333,stroke-width:1px
    classDef kernel fill:#e0f0ff,stroke:#333,stroke-width:1px
    classDef build fill:#fff0e0,stroke:#333,stroke-width:1px
    classDef hardware fill:#eeeeee,stroke:#333,stroke-width:1px
```
