Skip to content

Architecture

buntatoes edited this page Nov 29, 2026 · 3 revisions

Architecture

Vodka is a 100% standalone Windows compatibility runtime built from scratch as a modular set of native ELF binaries, shared Unix boundary libraries, and cross-compiled Windows PE modules. Engineered in Zig (0.17.1+) and architecture-specific inline assembly (x86_64, i386, aarch64) under the Apache License 2.0, every boundary separates Linux/POSIX host mechanics from Microsoft Windows ABI execution for Linux and Pisco.


High-Level Runtime Architecture

flowchart TD
    CLI["vodka (CLI Launcher)"] --> Preloader["vodka-preloader / vodka64-preloader (Freestanding ELF + Inline Asm)"]
    Preloader -->|"Reserves Win32 VA ranges & hands off to ld-linux"| Loader["vodka-loader / vodka64 (ELF Host Loaders)"]
    Loader -->|"dlopen + vodka_main"| Ntdll["libvodka_ntdll.so (Unix Boundary, PE64 & CS=0x23 WoW64, SEH/VEH)"]

    Ntdll -->|"Maps PE64 / PE32, Forwarders & TLS"| App["Windows Apps (116 Native PE64 Programs) & 731 PE Modules (DLLs, Drivers, TypeLibs, Compat16)"]
    App -->|"Win64 <-> SysV & CS=0x23 <-> CS=0x33 Gates"| Ntdll

    Ntdll -->|"43-Opcode 64-byte Binary RPC over AF_UNIX"| Server["vodkaserver (NT Kernel Daemon)"]
    Server -->|"Synchronization"| NTSync["Linux /dev/ntsync & epoll"]
    Server -->|"Hive Persistence + vodka.inf"| RegFiles["Prefix .reg Files"]

    Ntdll -->|"Futex Win32 Sync, BCrypt getrandom, WinHTTP TLS"| LinuxHost["Linux Kernel (futex, sigaction, getrandom, POSIX TCP/libssl)"]

    Ntdll -->|"GUI / WSI Bridge"| Wayland["libvodkawayland.so (Zero-Dep Wayland Driver)"]
    Wayland -->|"AF_UNIX Wire Protocol + memfd SHM"| Compositor["Wayland Compositor"]

    Ntdll -->|"Dynamic Vulkan 1.4 WSI & D3D11-over-Vulkan"| Vulkan["Host Vulkan 1.4 ICD (libvulkan.so.1)"]
    Vulkan -->|"Wayland WSI / GPU Queues"| GPU["Host GPU (RADV / Vulkan Driver)"]

    Ntdll -->|"WASAPI / XAudio2 / DirectSound / WinMM"| Audio["libvodka_audio.so (Native Audio Engine)"]
    Audio -->|"dlopen"| AudioHost["PipeWire (libpipewire-0.3) / ALSA (libasound)"]
Loading

Process Bootstrap Pipeline

Vodka's entire process bootstrap pipeline — preloaders, host loaders, prefix INF engine, and desktop/bundle metadata — is implemented natively in Zig and inline assembly with zero external C dependencies.

1. Top-Level CLI Launcher (vodka)

vodka (vodka/src/cli/main.zig) is the user-facing launcher. It:

  • Resolves its own runtime bindir via /proc/self/exe (falling back to argv[0]).
  • Computes the relative installed libdir from compile-time bindir/libdir build options.
  • Locates the matching host architecture directory (/x86_64-unix, /i386-unix, /aarch64-unix, or /arm-unix) and loads ntdll.so / libvodka_ntdll.so, then transfers control to vodka_main.

2. Freestanding ELF & Mach-O Preloaders (vodka-preloader, vodka64-preloader, macho_preloader.zig)

  • Linux ELF Preloader (vodka/src/preloader/main.zig, elf_util.zig): Compiled completely freestanding (link_libc = false, zero dynamic dependencies, zero ELF relocations, zero stack protector/red-zone overhead) for x86_64, i386, and aarch64 Linux:
    • Uses an architecture-specific naked _start assembly entry point and issues raw Linux kernel syscalls (mmap/mmap2, mprotect, open/openat, read, write, close, prctl, arch_prctl/set_thread_area).
    • Reserves Win32 low-memory, DOS, and top-down virtual address space regions before ld-linux can occupy them.
    • Parses and honors VODKAPRELOADRESERVE= (and WINEPRELOADRESERVE=) address ranges.
    • Maps the target ELF loader (vodka-loader / vodka64) and its PT_INTERP dynamic linker (ld-linux).
    • Exposes GDB _r_debug / _r_debug_state hooks.
    • Resolves and patches vodka_r_debug/vodka_main_preload_info (and compatibility aliases) in place via DT_GNU_HASH / DT_HASH.
    • Rewrites the Linux ELF auxiliary vector (auxv), shifts argv, and jumps directly to ld-linux's entry point with a clean ABI register/stack state.
    • Builds as a fixed-base static executable at 0x7d400000 on i386 and as a static PIE executable on 64-bit targets (x86_64, aarch64).
  • Darwin Mach-O Preloader (vodka/src/preloader/macho_preloader.zig): Pure-Zig + inline-assembly Mach-O preloader cross-compiling cleanly for x86_64-macos and aarch64-macos.

3. Host Runtime Loaders (vodka-loader & vodka64)

vodka-loader (vodka/src/loader/main.zig) and vodka64 (vodka/src/loader/loader64.zig) are PIE ELF binaries compiled with rdynamic = true and linked with libpthread:

  • vodka64: Dedicated 64-bit host loader installed across x86_64-unix, i386-unix (dual-arch bridge), and aarch64-unix, featuring an inline-assembly cpuid (x86_64) / mrs (aarch64) 64-bit CPU capability probe, VODKAPRELOADRESERVE= support, vodka_r_debug/vodka_main_preload_info dynamic symbol exports, direct ntdll.so / libvodka_ntdll.so lookup, and --loader64-info diagnostics.
  • vodka-loader: General multi-arch host loader supporting --loader-info diagnostics, dual-arch launch layouts (i386-unix/vodka64[-preloader] -> x86_64-unix), and native libvodka_ntdll.so (vodka_main) invocation.

4. Prefix Setup INF Engine & Desktop/Bundle Metadata (vodka/src/loader/)

  • Prefix Setup INF (vodka.inf & inf_engine.zig): From-scratch prefix installation manifest (zig-out/share/vodka/vodka.inf) paired with a pure-Zig INF parser, %String% & Windows DIRID macro expander, and .reg registry hive compiler.
  • Desktop & Bundle Metadata (vodka.desktop, vodka_info.plist.in, desktop_bundle.zig): Standalone XDG desktop entry (zig-out/share/applications/vodka.desktop) and Apple bundle Info.plist template (zig-out/share/vodka/vodka_info.plist.in) with programmatic generator/validator support.

Core Runtime Boundaries

libvodka_ntdll.so (PE64 & Hardware CS=0x23 WoW64 Loader + Unix Boundary)

libvodka_ntdll.so (vodka/src/ntdll/, also installed as lib/vodka/<arch>-unix/ntdll.so) is the central Unix-side runtime engine:

  • PE Parsing, Forwarders & TLS (pe.zig, virtual.zig, loader.zig, exec.zig): Parses PE32/PE64 headers, maps sections with Win32 page protections, applies IMAGE_REL_BASED_DIR64 and HIGHLOW relocations, resolves Import Address Tables (IATs) recursively across DLL dependencies, resolves recursive PE Export Directory forwarders (dll.symbol), allocates full PE64 IMAGE_TLS_DIRECTORY64 (GS:[0x58] / TEB64.ThreadLocalStoragePointer) slots and initializes _tls_index prior to DllMain, and executes DllMain(DLL_PROCESS_ATTACH).
  • x86_64 SEH & VEH Signal Recovery (seh.zig): Registers PE64 .pdata exception tables on module load, implements RtlLookupFunctionEntry and .xdata RtlVirtualUnwind, installs Linux sigaction(SA_SIGINFO) handlers translating SIGSEGV/SIGBUS/SIGFPE/SIGILL/SIGTRAP into Windows EXCEPTION_POINTERS, and supports full EXCEPTION_CONTINUE_EXECUTION register restoration.
  • Hardware CS=0x23 PE32 / WoW64 Execution (wow64.zig): Maps i386 PE32 images below 4 GiB (MAP_32BIT), applies HIGHLOW relocations, sets flat 32-bit DS/ES (0x2B), initializes TEB32/PEB32, enters hardware 32-bit compatibility mode (CS=0x23), and bridges 32-bit stdcall API imports across a dynamic CS=0x23 <-> CS=0x33 call gate into Vodka's 64-bit runtime.
  • Thread/Process Environment (teb.zig): Constructs ABI-exact TEB64/PEB64/FastPebLock/RtlUserProcessParameters (setting user GS base via SYS_arch_prctl(ARCH_SET_GS) on x86_64) and inline-assembly trampolines (callWin64_1, callWin64_2, callWin64_3) that translate System V AMD64 calls to Microsoft x64 ABI (rcx/rdx/r8/r9, 32-byte shadow space, 16-byte stack alignment).
  • Modular Win64 Thunk Layers:
    • win32_deep_thunks.zig — Linux futex-backed SRWLOCK, CONDITION_VARIABLE, InitOnce, WaitOnAddress, recursive CRITICAL_SECTION, and Win32 Mutex synchronization; per-thread 1088-slot TLS & FLS storage; OS-backed bcrypt.dll (Linux getrandom + SHA-256/SHA-512/SHA-1/MD5); OS-backed winhttp.dll (POSIX TCP + dynamic libssl.so TLS); UTF-8 <-> UTF-16LE conversion; and MinGW/UCRT C++ runtime thunks (_beginthreadex, stdio, heap, locale).
    • crt_win32_thunks.zig — UCRT/MinGW startup thunks, Win32 process/sync/registry compatibility thunks, and ntdll.dll native syscall thunks.
    • os_thunks.zig & proc_thunks.zig — Filesystem, console, heap, virtual memory, timers, environment, threads, process creation, pipes, and directory enumeration.
    • reg_thunks.zig & kernel_rpc_thunks.zig — Live 43-opcode AF_UNIX RPC bridge to vodkaserver for Registry, atoms, IOCP, jobs, pipes, mailslots, clipboard, and file locks.
    • vk_thunks.zig — Dynamic Vulkan 1.4 ICD & Wayland WSI swapchain bridge (vulkan-1.dll -> libvulkan.so.1).
    • dxgi_crt_thunks.zig — Live D3D11-over-Vulkan / DXGI adapter & device bridge, GDI DIB software rasterizer, and extended C11 CRT thunks.
    • gui_thunks.zig — Win32 128-entry message queue and User32/GDI32 windowing bridge into libvodkawayland.so.
    • net_input_thunks.zig — WinSock2, WinMM, and XInput/evdev thunks.
    • desktop_thunks.zig — COM (ole32), Shell (shell32/shlwapi), PSAPI, IP Helper, SetupAPI, and Crypto/Cert thunks.
    • audio_thunks.zig — WASAPI IAudioClient/IAudioRenderClient COM vtables, PipeWire/ALSA probe, and XAudio2/DirectSound bridge.
    • game_fixes.zig — Compartmentalized per-game workaround registry gated strictly by executable basename so title-specific flags never regress other applications.

vodkaserver (NT Kernel Daemon)

vodkaserver (vodka/src/server/) runs per-prefix over a private AF_UNIX stream socket (/tmp/.vodka-<uid>/server-<dev>-<ino>/socket with 0700 directory permissions and an fcntl write lock). Multiple Vodka processes sharing a prefix communicate with it using fixed 64-byte GenericRequest / GenericReply frames across 43 RPC opcodes (0–42). See Vodka Server and RPC.

libvodkawayland.so (Native Wayland Display Driver)

libvodkawayland.so (vodka/src/wayland/) implements the Wayland binary wire protocol directly over AF_UNIX (sendmsg/recvmsg + SCM_RIGHTS file-descriptor passing) with zero libwayland-client dependency. See Vulkan, DXGI, and Wayland.

libvodka_audio.so (Native Audio Engine)

libvodka_audio.so (vodka/src/audio/) provides a lock-free SPSC PCM ring buffer, sample format conversion (i16/i24/i32/f32), WASAPI endpoint/session/client management, and dynamic dlopen backends for PipeWire (libpipewire-0.3.so.0) and ALSA (libasound.so.2) with automatic software sink fallback in headless environments. See Audio Engine.


Source Tree Organization

vodka/
├── build/
│   └── dll_manifest.zig  # Declarative manifest for all 731 cross-compiled 3-arch PE modules (-Ddll-set=core|gaming|full)
└── src/
    ├── audio/            # libvodka_audio.so & vodka-audio (PipeWire, ALSA, WASAPI, SPSC ring buffer)
    ├── cli/              # vodka top-level launcher
    ├── dlls/             # 731 3-arch PE modules (DLLs, WoW64, ntoskrnl/hal, 20 .sys drivers, TypeLibs, themes, 16-bit/VxD), shared core engines & 24 PE test binaries
    ├── install/          # vodka-install atomic staging installer
    ├── loader/           # vodka-loader, vodka64, inf_engine, vodka.inf, desktop_bundle, vodka.desktop, vodka_info.plist.in
    ├── ntdll/            # libvodka_ntdll.so & vodka-pe (PE64 + CS=0x23 WoW64 loader, SEH/VEH, futex sync, BCrypt/WinHTTP, Vulkan 1.4 WSI, D3D11-over-Vulkan)
    ├── preloader/        # vodka-preloader & vodka64-preloader (freestanding ELF + Darwin Mach-O)
    ├── programs/         # Shared win_rt.zig + 116 native cross-compiled PE64 Windows programs
    ├── server/           # vodkaserver 43-opcode NT kernel daemon & vodka-proto compiler
    ├── tools/            # 21-tool pure-Zig build, Unicode/NLS (7 .nls tables), WinAPI ABI, debug, & CI toolchain
    └── wayland/          # libvodkawayland.so & vodka-wayland zero-dependency Wayland driver

Clone this wiki locally