Skip to content

Vodka Server and RPC

buntatoes edited this page Nov 28, 2026 · 2 revisions

Vodka Server and RPC

vodkaserver (vodka/src/server/) is Vodka's standalone Apache-2.0 native Zig NT kernel daemon. It coordinates shared NT kernel state across all Windows processes executing inside a Vodka prefix over a 43-opcode AF_UNIX binary RPC protocol.


Daemon Lifecycle & Prefix Security Model

Prefix Resolution & Socket Layout

vodkaserver locates the active prefix using VODKAPREFIX, falling back to $HOME/.vodka.

To guarantee strict multi-user isolation on Linux:

  1. Verifies the prefix directory is owned by getuid() via statx.
  2. Creates /tmp/.vodka-<uid>/ with 0700 permissions (rejecting symlinks, non-directories, wrong ownership, or any group/world permission bits 0o077).
  3. Creates a per-prefix subdirectory keyed by the prefix directory's device major/minor and inode (server-<dev>-<ino>/, mode 0700).
  4. Acquires an exclusive fcntl write lock (F_SETLK, F_WRLCK) on lock inside that directory. If another vodkaserver already owns the lock, vodkaserver either exits cleanly, signals it (-k), waits for it (-w), or pings it (--ping).
  5. Binds an AF_UNIX SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC master listener socket (socket).
  6. Unless -f/--foreground is specified, daemonizes cleanly using a parent/child synchronization pipe so the parent returns only after the daemon is ready to accept connections.

CLI Flags

vodkaserver implements wineserver-compatible CLI flags plus a --ping health probe:

Short Long Description
-d[N] --debug[=N] Set debug verbosity level (defaults to incrementing by 1 if N is omitted)
-f --foreground Stay in the foreground instead of daemonizing
-h --help Print CLI usage and exit
-k[N] --kill[=N] Terminate the running vodkaserver for the active prefix (optional signal number N)
-p[N] --persistent[=N] Keep the server alive for N seconds after the last client disconnects (or indefinitely if N is omitted; default linger is 3 seconds)
-v --version Print version (vodka-0.1) and exit
-w --wait Wait until the active prefix's vodkaserver exits and releases its lock
— --ping Connect to the prefix AF_UNIX socket, send a binary ping RPC frame, and verify the reply

Event Loop & Synchronization (epoll + /dev/ntsync)

  • epoll Multiplexer (event_loop.zig): Drives all listening sockets, accepted client sockets, and periodic persistence/shutdown timers in a single non-blocking Linux epoll loop.
  • Linux /dev/ntsync Bridge (sync.zig): Probes /dev/ntsync at startup for kernel-accelerated NT synchronization primitives (semaphores, mutexes, and manual/auto-reset events), with in-process userspace NT wait/signal semantics when /dev/ntsync is unavailable.

Binary Wire Protocol & vodka-proto

64-Byte Fixed Framing (wire.zig)

Every client-server RPC exchange uses ABI-verified fixed 64-byte headers matching the NT server IPC wire layout:

pub const RequestHeader = extern struct {
    req: i32,          // RpcOpcode
    request_size: u32, // Variable trailing payload bytes
    reply_size: u32,   // Max variable reply bytes expected
}; // 12 bytes

pub const ReplyHeader = extern struct {
    @"error": u32,     // NTSTATUS (0 = STATUS_SUCCESS)
    reply_size: u32,   // Actual variable reply payload bytes following header
}; // 8 bytes

pub const GenericRequest = extern union {
    header: RequestHeader,
    raw: [64]u8,
};

pub const GenericReply = extern union {
    header: ReplyHeader,
    raw: [64]u8,
};

Variable-length payloads (UTF-16/UTF-8 names, Registry value data, pipe/mailslot payloads, clipboard data) follow immediately after the 64-byte header on the stream socket.

Protocol Compiler (vodka-proto)

vodka-proto (vodka/src/server/protocol.zig) parses protocol definitions (@REQ, @REPLY, @END, struct/typedef/enum declarations, and VARARG fields) and emits strongly typed Zig wire definitions with compile-time layout assertions.


Live NT Kernel Subsystems

ServerKernel (vodka/src/server/dispatch.zig) serves 43 RPC opcodes (0–42) backed by live kernel state engines:

Subsystem Source Module RPC Opcodes & Capabilities
Core & Lifecycle dispatch.zig, wire.zig ping (0), init_first_thread (1), get_kernel_stats (42)
Object Manager & Handles object.zig, handle.zig Reference-counted NT object namespace, handle allocation, close_handle (4), dup_handle (11), access-mask checks
Synchronization sync.zig create_event (2), event_op (3: pulse/set/reset), create_mutex (7), release_mutex (8), create_semaphore (9), release_semaphore (10), /dev/ntsync probe
Windows Registry registry.zig Full hive tree (HKLM, HKCU, HKU, HKCR), reg_set_value (5), reg_get_value (6), flush_registry (12), reg_delete_value (13), and .reg text hive load/save persistence (system.reg, user.reg, userdef.reg)
Processes & Threads process.zig Process/thread table, PID/TID allocation, exit codes, create_process (14), terminate_process (15), query_process (16)
Global Atom Table atom.zig Case-insensitive global atom registry with reference counts: add_atom (17), find_atom (18), get_atom_name (19), delete_atom (20)
Named Pipes pipe.zig Byte-stream & message-mode named pipe instances: create_pipe (21), pipe_write (22), pipe_read (23)
I/O Completion Ports iocp.zig Completion packet queues with concurrency limits: create_iocp (24), post_iocp (25), dequeue_iocp (26)
Section Mappings mapping.zig Named/anonymous shared memory sections (PAGE_*, SEC_*): create_mapping (27), query_mapping (28)
Job Objects job.zig Process groups, resource/process limits, and accounting: create_job (29), assign_job (30), query_job (31)
Security Tokens & ACLs token.zig SIDs, privileges (LUID), DACL access checks: create_token (32), check_privilege (33)
Window Stations, Desktops & Clipboard winstation.zig Pre-populated interactive WinSta0, desktop/message queue management, clipboard format store: open_winstation (34), set_clipboard (35), get_clipboard (36)
Byte-Range File Locks file_lock.zig Shared/exclusive byte-range conflict detection (STATUS_FILE_LOCK_CONFLICT, STATUS_RANGE_NOT_LOCKED): lock_file (37), unlock_file (38)
Mailslots mailslot.zig Unidirectional datagram IPC queues: create_mailslot (39), mailslot_write (40), mailslot_read (41)

Client Integration in libvodka_ntdll.so

Inside libvodka_ntdll.so:

  • rpc_client.zig discovers the prefix socket (VODKAPREFIX -> /tmp/.vodka-<uid>/server-<dev>-<ino>/socket), connects over AF_UNIX, and marshals GenericRequest/GenericReply frames.
  • reg_thunks.zig routes advapi32 Registry APIs (RegOpenKeyEx*, RegCreateKeyEx*, RegSetValueEx*, RegQueryValueEx*, RegDeleteValue*, RegCloseKey, etc.) live to vodkaserver.
  • kernel_rpc_thunks.zig connects Win32 GlobalAddAtomA/GlobalFindAtomA/GlobalGetAtomNameA/GlobalDeleteAtom, CreateIoCompletionPort/PostQueuedCompletionStatus/GetQueuedCompletionStatus, job objects, named pipes, mailslots, clipboard, and LockFile/UnlockFile live to vodkaserver.

Clone this wiki locally