Skip to content

Linux: a native runtime, no Wine - #526

Closed
spidercraft wants to merge 71 commits into
Marvisak:mainfrom
spidercraft:linux-native-runtime
Closed

spidercraft wants to merge 71 commits into
Marvisak:mainfrom
spidercraft:linux-native-runtime

Conversation

@spidercraft

@spidercraft spidercraft commented Nov 24, 2026 •

Copy link
Copy Markdown

What

A native Linux build of the runtime: victory run <exe> --execute runs the title as an ELF program, with no Wine and no Windows DLL. The title's x86-64 code still runs unchanged in our process; on Linux we also supply what the Windows loader, kernel and system DLLs supply on Windows. The Windows build is unchanged (it type-checks with no diagnostics after every commit here). The design, the rules each part follows and the status are in docs/linux.md.

Builds on #523 and #524 (their commits are the first two here) and includes #177's commits, the fix for image atomics on float-read textures that NVIDIA's compiler crashed on (with the test from #226).

Where things live

Part Where
PE mapper, TEB at the GS base, static TLS, guest threads, entry victory-loader/src/linux/{image,teb,tls,thread}.rs
SEH: signals to EXCEPTION_RECORD/CONTEXT, .pdata dispatcher and unwinder, host frames between title frames, crash report victory-loader/src/linux/{seh,signals,unwind,context,asm}.rs
Region table behind VirtualAlloc (64 KiB granularity, guard pages, placeholders, memfd physical pool) victory-loader/src/linux/vm.rs
Our implementation of the DLLs HostPolicy passes through on Windows: kernel32/ntdll (handle table, waits, locks, threads, thread pool, time, memory, heap, files, text), the UCRT, ws2_32/winhttp (offline), bcrypt, crypt32, advapi32, COM, user32, XAudio2, Spatial Audio, Media Foundation stubs victory-hle/src/linux/<dll>_<slice>.rs, found by host::imp::resolve on Linux
The Windows-only HLE modules, now on both: xmem, files, storage, lifecycle, xsystem, apu, dstorage victory-hle/src/modules/* (per-OS host functions only where they differ)
Host D3D12: vkd3d-proton built as native libraries and loaded at run time; window, keyboard and gamepads from SDL3 (loaded at run time); D3D12/DXGI bindings generated at build time (windows 0.62 does not build on Linux) victory-gpu, victory-shader, crates/victory-windows

The title-facing ABI is win64 everywhere (#524); the CRT-style exports (exit, the CRT file functions) were extern "C" and are fixed here too.

How to run

docs/linux.md: build vkd3d-proton natively (meson), point VICTORY_VKD3D at it; optionally Microsoft's DXC Linux release for VICTORY_DXIL/VICTORY_DXCOMPILER (Arch's directx-shader-compiler 1.10.2605 asserts on every shader). SDL3 and the Vulkan loader come from the distribution.

Tested

Linux (CachyOS, Ryzen 9 7950X3D, RTX 5090, NVIDIA 620.73):

  • cargo test --workspace: 416 passed, 0 failed, 12 ignored, without game data. Guest code under test is PE fixtures we build with lld-link against an xwin SDK (skipped without it): the loader probe, an SEH fixture (__try/__except around real faults, C++ throw/catch/rethrow across threads, unhandled-fault report), and device tests with VICTORY_VKD3D (compute, clear and readback, pipelines from translated shaders, 120 frames to a window).
  • cargo check --workspace --all-targets --all-features --target x86_64-pc-windows-msvc: no diagnostics.
  • With the title: it boots at its 30 fps, shows the start-up screens and the first-boot flow (settings, legal, terms) with scripted keys, keeps its profile and saves, loads the story and reaches the world (game state running, player and population placed): 3 of 3 runs stayed there for 200 s at 1.1-1.8 fps (the world itself still draws dark, as the README says for Windows).
  • victory translate --validate over the title's shaders on Linux: the same validated counts as the validator reports there; every emitted vertex, pixel and mesh program makes a pipeline.

Two fixes found on Linux that also concern Windows

Not done yet

  • World frames are GPU-bound now (200-520 ms of GPU time), plus about 100-150 ms of write-watch bookkeeping that checking runs instead of blocks would cut.
  • B5G5R5A1/B4G4R4A4 render targets of that size are refused by the host here; wave64-only compute pipelines are refused (as on Windows with such GPUs).
  • Locales other than en-US data, share modes on files, waitable timers, APCs, and the DLL functions the title does not import, are left out on purpose.

No game data in the repository, the tests or this description.

🤖 Generated with Claude Code

Ortomanic and others added 30 commits November 24, 2026 02:06
A texture UAV read as float and used atomically in the same program got
the float handle for its atomic: dxil-spirv then emitted OpAtomicOr on a
float texel pointer (invalid SPIR-V), and the NVIDIA compiler crashed in
vkCreateComputePipelines when GTA VI entered its world (two programs:
c12c1f7296419a5b, 8358f9eef7931421). With the type in the key the atomic
gets its own uint handle; all dumped SPIR-V validates.
Since the world bring-up, main no longer builds on Linux: victory-gpu
names host_resource outside its cfg(windows), and victory-hle reaches
Windows-only modules (xmem, files, lifecycle, the text entry dialog).
This gates those uses only, as the smallest base for a native Linux
runtime:

- view_format and the D3D12 allocator hookup are Windows-only, like
  what they call.
- XLaunchNewGame ends the title only on Windows; the text entry dialog
  answers "dismissed" elsewhere.
- translate --validate / --pipelines refuse to start off Windows (no
  host DXIL validator or D3D12 there); translation itself runs.
- Tests that parse the test binary as a PE image, or use Windows title
  paths, are ignored off Windows with the reason.

Tested: Linux (CachyOS, rustc 1.98.1): cargo test --workspace passes
(162 passed, 13 ignored). cargo check --target x86_64-pc-windows-msvc
--all-targets gives the same diagnostics as before (none).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Title code calls our exports, and is called by us, with the Windows x64
convention. `extern "system"` is that convention only on Windows; on
Linux it is SysV, so a native Linux runtime would receive the title's
arguments in the wrong registers. `"win64"` is the same convention on
every x86-64 host, so this changes nothing on Windows.

Callbacks we hand to the host's own APIs stay `"system"` (the crash
reporter's exception handlers, the write watch handler, window and
dialog procedures, EnumWindows, our TLS callback, the probe test's
CreateThread start routine). The title fixture keeps `"system"`: it is
built only as a Windows PE.

Tested: cargo check --workspace --all-targets --all-features for
x86_64-pc-windows-msvc: no diagnostics; on Linux cargo test --workspace
passes (162 passed, 13 ignored).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
docs/linux.md: what the native Linux runtime supplies in place of the
Windows loader, kernel and system DLLs, where each part lives, and the
rules every part follows (win64 ABI, one handle table, one region table,
no Wine and no system DLL forwarding).

- victory-loader::linux: the platform; for now the last-error and
  region-table seams (teb, vm) the other parts call.
- victory-hle::linux: our implementation of the DLLs HostPolicy passes
  through on Windows; host::imp::resolve looks imports up there on
  Linux (exports by ordinal are named #<n>).
- libc as a direct dependency on Linux.

Tested: cargo test --workspace on Linux; Windows target type-checks
with no diagnostics.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Guest thread spawn (a plain host thread for now), SEH image
registration and the handle table, with the signatures the loader,
kernel32 and file slices code against while they are built in parallel.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The title reserves, commits, protects and queries memory with Windows
semantics, and the xmem port needs shared physical pages on Linux. The
region table gives VirtualAlloc/Free/Protect/Query those semantics over
mmap: 64 KiB granularity, reserve vs commit, large pages (MAP_HUGETLB,
else MADV_HUGEPAGE), MEM_RESET, guard pages with a take_guard hook for
the fault handler, placeholders, memfd sections with views and aliases,
and a physical page pool. Host memory is answered from the kernel's own
table (PROCMAP_QUERY, else /proc/self/maps).

Guest heap blocks are host malloc blocks, so either side can free what
the other allocated; HeapSize reports the exact size through a slack
byte at the end of each block.

Tested: cargo test -p victory-loader linux::vm (11), victory-hle linux:: (5)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Title code on Linux needs the kernel32 objects it creates, waits for and
locks with, implemented over futexes since nothing on the host serves
them.

- handles: the one handle table (values 4, 8, ... reused, pseudo handles
  -1 and -2, named objects) and the wait engine. A waiting thread links a
  per-thread futex word to each object; `update` changes an object under
  the one wait lock and wakes its waiters, each of which re-checks its own
  wait. So `Waitable::try_acquire` keeps its signature for the file and
  socket slices; `signalled` and `take_abandoned` default sensibly. No
  lock is held while sleeping.
- Events (named, manual and auto reset), mutexes (owner, recursion,
  abandonment at owner exit), semaphores, thread objects (signalled with
  their exit code), the process object.
- SuspendThread's engine: a signal that parks the thread only in title
  code; inside a wait or lock sleep the thread parks before it next tries
  for anything, so a suspended thread is given no lock or signal
  (the lesson of Leonida's runtime).
- CRITICAL_SECTION, SRWLOCK, CONDITION_VARIABLE, INIT_ONCE and
  WaitOnAddress live in the title's own memory at Windows sizes; the
  condition variable keeps the two fixes Leonida's runtime needed (read
  the sequence before counting; only wakes uncount sleepers).
- The process: ids, ExitProcess, command line, environment (our changes
  over the host's), start-up info, last error, debugger checks,
  EncodePointer, FlushProcessWriteBuffers.

Tested: cargo test -p victory-hle linux:: (22 tests: wake ordering,
timed-out sleeper vs wake, wait-all all-or-nothing, mutex abandonment, a
suspended waiter takes nothing, layouts).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On Linux nothing maps the title for us, so linux::image maps the original
image itself: at its preferred base (MAP_FIXED_NOREPLACE) or relocated on
a 64 KiB boundary, sections copied and protected, then made known to the
region table and the exception dispatcher. Binding, title DLLs (found
without regard to case), delay-load slots, TLS callbacks, DllMain and
spawn_main keep the shape of the Windows path, so the front end shares it.
thunks.rs now builds on both: the unimplemented-import stub is the same.

Every thread that runs title code gets a TEB at its GS base (wrgsbase, else
arch_prctl) with its real stack bounds, the PEB (image base, process
parameters, empty loader lists), last error, TlsSlots, TlsExpansionSlots
and FLS storage, at Windows offsets checked by a test. Static TLS hands out
the indices itself (exe 0, DLLs 1.. in load order), so unlike Windows
nothing is patched; every thread has a block for every image. Guest
threads start with the Windows x87 control word and MXCSR, run the
attached images' thread notices, and ExitThread resumes at their guest
frame without unwinding title frames.

The new probe-title fixture is a CRT-free DLL for the hle-probe to import
on Linux, where there is no system DLL to rename.

Tested: cargo test --workspace on Linux (171 passed, 13 ignored; the new
load_probe_linux maps, binds and calls hle-probe and runs its CRT DllMain
and TLS callbacks on guest threads); Windows cargo check --all-targets
--all-features clean; cargo xtask policy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Windows path's config, manifest, storage, console, title DLLs, binding
and late LoadLibrary handling are portable now that the Linux loader has
the same shape, so run() serves both, with cfg only where they differ: no
prepared copy, no files mounts yet (that module is not ported), crash
reporting and console timers stay Windows-only, and the PEB gets the
process parameters. On Linux the DLLs the title ships beside its exe
(vcruntime140, msvcp140, ...) are mapped, since no host DLL stands in.

Tested: victory run on the title maps its executable at its preferred
base with TLS index 0 and its seven DLLs, binds them; --execute starts the
guest main thread and stops in vcruntime140's DllMain, whose
InitializeCriticalSectionEx (kernel32) is not implemented yet. Windows
cargo check clean.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Title threads on Linux start through the loader's guest-thread spawn; the
title sizes and pins its job threads from the processor facts, so those
come from the host's real topology.

- CreateThread / CreateRemoteThreadEx (CREATE_SUSPENDED, the group
  affinity and ideal processor attributes), thread handles signalled with
  the exit code, OpenThread, SuspendThread / ResumeThread, Sleep,
  SwitchToThread, GetCurrentThreadStackLimits.
- Priorities and ideal processors are remembered and read back; affinity
  masks pin the host thread (sched_setaffinity), a processor this machine
  lacks folding onto one it has.
- TLS slots behind victory_loader::linux::teb::tls_slots (a thread-local
  until the TEB holds them at gs:[0x1480]); index 0 never handed out.
  FLS with its callbacks at thread exit and on FlsFree for every thread.
- GetLogicalProcessorInformation(Ex) from sysfs: cores with their SMT
  siblings numbered next to each other, caches, packages, one NUMA node
  and one group. GetNativeSystemInfo, GlobalMemoryStatusEx,
  IsProcessorFeaturePresent from cpuid.

Tested: cargo test -p victory-hle linux:: (31 tests); layout asserts for
SYSTEM_INFO, SYSTEM_LOGICAL_PROCESSOR_INFORMATION(_EX) record sizes,
MEMORYSTATUSEX, GROUP_AFFINITY, PROCESSOR_NUMBER.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The title and the files module open, read, list and manage files through
kernel32; on Linux nothing served it. Host paths spelled the Windows way
(either separator, an optional drive that means nothing on the host) are
resolved without regard to case one component at a time, as NTFS would
find them, and the errors are Windows' (FILE_NOT_FOUND vs PATH_NOT_FOUND,
ALREADY_EXISTS after CREATE_ALWAYS/OPEN_ALWAYS, ...).

OVERLAPPED transfers complete inside the call, signal their event and
post to the associated completion port, which is one of the answers
Windows gives; ports, GetOverlappedResult and CancelIo follow from that.
handles::Object gains set_signal so the file layer can set an event the
sync slice owns.

Tested: cargo test -p victory-hle linux:: (16)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The title reads the time, keeps lock-free lists and runs work, timers and
waits on the system thread pool; on Linux all of it is ours.

- Time: QueryPerformanceCounter at 10 MHz (CLOCK_MONOTONIC), tick counts
  including sleep (CLOCK_BOOTTIME), FILETIME and SYSTEMTIME now (UTC and
  local), FileTimeToSystemTime and back with Windows' range checks.
- SLIST_HEADER in the x64 layout, lock-free with cmpxchg16b (inline asm:
  the intrinsic becomes a libatomic call in debug builds) and a sequence
  against ABA.
- The thread pool: work, timers (one-shot and periodic, relative and
  absolute due times, disarm and close while a callback runs) and waits
  on any waitable handle, QueueUserWorkItem, WaitFor...Callbacks with
  cancel, DisassociateCurrentThreadFromCallback. Workers are guest threads
  added on demand; timers and waits are kept by host threads that never
  run title code.

Tested: cargo test -p victory-hle linux:: (41 tests), 60 more runs of
them six at a time with no failure.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The plan keeps one D3D12 code path: on Linux the host D3D12 is
vkd3d-proton built as native libraries and loaded at run time
(`hostlib`, `VICTORY_VKD3D`). Its COM is SysV there, as is
`extern "system"`, so the windows-rs vtables match it unchanged.
The `windows` crate itself does not build on Linux (its
`windows-future` needs Windows-only parts of windows-core), so
`victory-windows` generates the same Direct3D, D3D12 and DXGI
bindings with windows-bindgen at build time, plus the few core
items windows-core only has on Windows; users name it `windows`.

The validator runs against DXC's libdxil.so with the same vtable
slots, but only when VICTORY_DXIL names it: 1.10.2605 traps on some
of our modules.

Tested: cargo test -p victory-shader --features host, 69 passed with
VICTORY_VKD3D set (VALU and pipeline tests on the RTX 5090 through
vkd3d-proton 3.2), 69 passed without it (device tests skip); Windows
cargo check clean.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Clippy's points in the new files (no busy-wait look-alike in the
suspend handshake, a volatile read in a test loop, checked division),
the handle-table example as text so it is no ignored doctest, and the
status of the slice in docs/linux.md, with the signal SuspendThread
takes so the signal slice knows it.

Tested: cargo test --workspace on Linux (203 passed, 13 ignored); cargo
clippy -p victory-hle shows nothing in src/linux; the Windows target
type-checks with no diagnostics; victory census --missing over the game
lists none of this slice's imports.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
KMutex::new(true) recorded the creator's id but gave the creator no thread
object, so a host thread that created a mutex owned and exited holding it
never abandoned it: every later wait for it timed out.

Tested: cargo test --workspace on Linux (203 passed, 13 ignored); the
mutex test now creates one owned on a thread that exits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Grand Theft Auto VI plays its sound through Spatial Audio: it makes an
MMDeviceEnumerator with CoCreateInstance, activates ISpatialAudioClient
on the default render device and fills 10 ms buffers of static channel
objects each time the stream's event is set. On Windows that is the
host's WASAPI; on Linux mmdevapi.rs serves one device with those
interfaces, and a device thread sets the event, downmixes the objects to
stereo and plays them.

audio_out.rs plays through PulseAudio, which PipeWire also serves, via
libpulse-simple loaded with dlopen: three C functions, no crate and no
build-time headers, and a machine without a sound server keeps running
on a silent clock. cpal would pull in alsa-sys and a link-time
libasound for the same job.

combase.rs: CoInitializeEx and friends, CoCreateInstance (our device
enumerator, REGDB_E_CLASSNOTREG otherwise), task memory, CoCreateGuid,
StringFromGUID2, PropVariantClear, the WinRT start-up, error and HSTRING
functions vccorlib140 imports, and the helpers our COM objects share.
oleaut32.rs: BSTRs, also by ordinal.

handles.rs gets a stand-in Event with the sync slice's signatures
(new, set, reset); that slice's version replaces it.

Tested: cargo test -p victory-hle on Linux (spatial stream passes with
the event, device and property lookups as the title makes them, HSTRING
and BSTR layouts); the ignored a_tone_reaches_the_sound_server played a
tone through PipeWire.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Bink plays a video's sound through xaudio2_9.dll (ordinal 1,
XAudio2Create), the host's on Windows. Ours runs one guest thread per
engine with a pass every 10 ms: engine and voice callbacks with no lock
held (so OnBufferEnd may submit the next buffer), source voices decoded
from the title's buffers (integer PCM and float, plain or extensible)
and linearly resampled to the mastering rate, submix voices by stage,
output matrices and volumes, then the mastering voice downmixed to
stereo into an audio_out stream whose blocking writes pace the passes.
Loops, flushes, discontinuities and GetState behave as documented;
effects and filters are kept but not run, as reverb is silent on
Windows today. FAudio would give the same voice model, but in C with a
SysV ABI: every method and callback would still need a win64 shim here,
and it is not installed by default.

Tested: cargo test -p victory-hle on Linux (buffer completion and
stream-end callbacks with a resubmit from OnBufferEnd, flush of a
stopped voice, a 24 kHz source through a submix, default matrices,
structure layouts).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The kernel32 slice kept TLS slots in a thread-local until threads had a
TEB; with the loader's TEBs in place, tls_slots() returns gs:[0x1480]
of a thread that has one, so title code reading its TEB directly and
TlsGetValue agree. Threads without a TEB keep the thread-local.

Tested: cargo test --workspace on Linux: 211 passed, 13 ignored. The
real executable now reaches its first UCRT start-up call.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The title and the DLLs it ships (msvcp140, vcruntime140, ...) import
about 250 UCRT functions through the api-ms-win-crt-* sets. On Linux
nothing serves them, and glibc's are the wrong ABI and the wrong
semantics: long is 32 bits, wchar_t 16, errno numbers differ above 34,
printf has its own specifiers and buffer rules, the _s functions
report through the invalid-parameter handler.

One module per API set (ucrt_runtime, heap, string, convert, math,
stdio, time, locale, environment, filesystem, utility), plus the printf
and scanf engines (ucrt_format, ucrt_scan) that stdio lists. The C
locale only. Heap blocks are plain host malloc blocks; _aligned_* keep
the UCRT's layout. The FILE keeps the UCRT's first 48 bytes so
msvcp140's basic_filebuf can work through _get_stream_buffer_pointers.
_beginthreadex goes through the kernel32 slice's CreateThread when it
exists, else the guest thread seam.

Tested: cargo test --workspace (207 passed, 13 ignored; 45 new);
victory census --missing on the game: 0 missing in every
api-ms-win-crt row; Windows cargo check with stub CC: no diagnostics;
cargo xtask policy ok.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Title code and msvcp140 convert, compare and case-map text and ask for
the user's locale through kernel32. Code pages are UTF-8, 1252 (CP_ACP)
and 437 (CP_OEMCP), as on an English console, with Windows' handling of
ill-formed UTF-8. Comparison and LCMapString sort keys share one
four-level word sort; FormatMessage serves the system texts the runtime
reports. The user locale is en-US unless LC_ALL or LANG maps cleanly to
a known locale.

An opt-in test reads a file of the game dump (VICTORY_GAME_DIR), named
in another case, through an overlapped handle.

Tested: cargo test --workspace (198 passed, 13 ignored); victory-hle
linux:: with VICTORY_GAME_DIR (26); Windows cargo check clean

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	crates/victory-hle/src/linux/mod.rs
#	docs/linux.md
The calling-convention change covered extern "system" only. exit,
abort, terminate and _invalid_parameter_noinfo_noreturn in the kernel
module, and the CRT file functions in the files module (with the host
CRT functions they forward to), were extern "C": the Windows x64
convention on Windows, SysV on Linux, so on Linux exit(code) read a
garbage code. They are "win64" now; nothing changes on Windows.

On Linux, exit also runs our UCRT's shutdown (the title's atexit table,
the EXE's thread_local destructors, stream buffers), which the host
CRT's exit does on Windows.

Tested: cargo test --workspace on Linux: 255 passed, 13 ignored;
Windows target type-checks with no diagnostics.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Title code expects Windows SEH: faults and RaiseException dispatched
through the images' .pdata to the language handlers in its own
vcruntime, with RtlUnwindEx, STATUS_UNWIND_CONSOLIDATE for C++ catch
blocks, vectored handlers and the unhandled-exception filter. On Linux
nothing provides that, so victory-loader::linux now does:

- context.rs: CONTEXT, EXCEPTION_RECORD, DISPATCHER_CONTEXT and the rest
  with their Windows layouts checked by a test.
- unwind.rs: the function-table registry (images from register_image,
  RtlAddFunctionTable, table callbacks), RtlLookupFunctionEntry and
  RtlVirtualUnwind for every unwind code, chained info and both epilogue
  forms. A pc in our own code gets a boundary entry: walks end there.
- seh.rs: the two-phase dispatcher, RtlUnwindEx, RtlRestoreContext,
  vectored and continue handlers, the top-level filter, and a crash
  report in the Windows reporter's format (crash_log.rs, now shared with
  crash.rs) to stderr and crashes.log before the process ends.
- asm.rs: every call into title code goes through one routine with
  hand-built unwind data (saved nonvolatiles and a machine frame), so a
  title walk started in a handler crosses our Rust frames and nested or
  collided cases are answered as ntdll does; capture_stub! gives an
  export its caller's context.
- signals.rs: SIGSEGV/SIGBUS/SIGILL/SIGFPE/SIGTRAP in title code become
  exceptions dispatched on the faulting stack; faults in our own code
  go to the handler before ours. A hook lets the region table report
  PAGE_GUARD hits.

victory-hle::linux serves the Rtl* names, RaiseException, the vectored
handler functions, UnhandledExceptionFilter and a few small neighbours;
the portable kernel module's SetUnhandledExceptionFilter now reaches the
dispatcher on Linux. The asset policy allows .cpp for the guest fixture
(tests/fixtures/seh-probe, our own code built with clang-cl).

Tested: cargo test --workspace (178 passed, 13 ignored), incl. unwind
code units, raise and fault dispatch, and seh_guest: __try/__except/
__finally, C++ throw/catch through the static vcruntime, vectored
handlers, a backtrace and an unhandled fault's report and exit status;
the SEH tests also in release; Windows cargo check (no diagnostics);
cargo xtask policy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	crates/victory-hle/src/linux/mod.rs
#	docs/linux.md
kernel32_process stubbed FormatMessageA/W (always "not found") and
kernel32_text implements them for system messages; whichever module
came first in modules() hid the other. The stub is gone, and a test
fails when two modules serving one DLL export the same name.

Tested: cargo test --workspace on Linux: 292 passed, 13 ignored.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- The sync slice's Event implements Object::set_signal, which the file
  layer calls to set an OVERLAPPED's event; it went to the trait's
  default (false) before, so waiters on it never woke. The overlapped
  test now uses the real event and waits on it.
- The PE mapper records each image's headers and sections in the
  region table with the protection VirtualQuery reports on Windows,
  and forgets the image when it is unmapped.

Tested: cargo test --workspace on Linux: 292 passed, 13 ignored; the
probe test checks PAGE_READONLY headers and PAGE_EXECUTE_READ code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Resolves the module lists and the status table. Two kernel32 functions
came from both the process and the exception slices; one copy of each
stays: DebugBreak from kernel32_exception (raises EXCEPTION_BREAKPOINT
with the caller's context; an int3 in our own frame was a host fault),
IsDebuggerPresent from kernel32_process (reads TracerPid).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The policy of modules::net on Windows, on Linux sockets: the title can
talk to itself over loopback (it binds a TCP listener), connects and
datagram sends anywhere else fail with WSAENETUNREACH, a bind to all
interfaces is narrowed to loopback, and lookups answer localhost and
address literals only (WSAHOST_NOT_FOUND otherwise). ws2_32.rs
translates what differs from Linux: sockaddr families, fd_set (select
runs on poll), hostent and addrinfo layouts, socket option levels and
names, MSG_WAITALL, and errno to WSA codes; the exports the title takes
by ordinal are listed under their Winsock 1.1 numbers.

winhttp.rs: sessions open, WinHttpConnect fails with
ERROR_WINHTTP_CANNOT_CONNECT for every server as it does for
off-machine ones on Windows, so the request functions only ever see
invalid handles; closing an async session sends HANDLE_CLOSING; and
WinHttpCrackUrl is real, since libHttpClient and XCurl parse URLs
with it.

Tested: cargo test -p victory-hle on Linux (loopback listener, accept,
select, non-blocking recv, unreachable destinations, offline lookups,
URL cracking into pointers and buffers, structure layouts).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
spidercraft and others added 3 commits November 24, 2026 05:55
On Linux every submission copied the title's GPU memory whole (5-13 GB
per world frame, about 0.5 fps): there is no GetWriteWatch, and the
Windows guard on view memory was off. The region table now guards every
64 KiB block a copy took (private memory and views alike) with
mprotect, and the fault handler takes the first write to one before
anything else sees it, from title code or ours: the block is writable
again and counts written. The state the handler touches is one bit per
block in a lazily backed reservation: lock-free and allocation-free.

The table keeps answering the protection the title set, and every change
of protection or mapping (commit, decommit, release, VirtualProtect,
views, physical pages, aliases) opens the guarded blocks it touches
first. It also knows which blocks show the same section pages, so a page
shown at several addresses is guarded at all of them and a write through
any counts for each; writes into the pool outside the views
(DirectStorage's write_physical and page windows, freed pages reading
zero) open the blocks showing them. Kernel writes (read(2) into a
guarded block returns EFAULT) are opened first in the Linux file layer
(ReadFile, the UCRT's read) and in DirectStorage's raw reads, as Windows
does. A write fault on a block another thread just opened is retried
after a write probe (an atomic or of zero) says it is writable.

victory-gpu's journal is shared: only "pages written since the last
asking" is per OS (GetWriteWatch plus the view guard on Windows, the
region table on Linux). Windows behaviour is unchanged.

Tested: cargo test --workspace (414 passed, 12 ignored; new
vm::tests::guarded_blocks_see_every_writer and
writes_through_any_alias_count), Windows cargo check (no diagnostics),
cargo xtask policy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The first compile in DXC's libdxcompiler (the indirect argument clamp,
at the world's first indirect execution) installs LLVM's own handlers
for SIGSEGV, SIGBUS, SIGILL and SIGFPE (SA_RESETHAND). After it, the
next fault in title code did not reach our handler and the kernel ended
the process: a title exception from then on, and with write watching
the next write to a guarded block (seen: title-main storing into the
174 MB buffer, a core and no line from us).

LLVM registers once per process, so the clamp's DXIL is now compiled
once, at the host device's creation (before any copy guards title
memory), and signals::reclaim() puts our handlers back right after it.

Tested: argument_clamp_builds with VICTORY_DXCOMPILER now checks the
handler is ours after the compile (it was LLVM's before); cargo test
--workspace (414 passed, 12 ignored); Windows cargo check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
docs/linux.md: write watching is done on Linux (how the region table
guards, what the kernel cannot do and who opens for it). watch::open
steps over bitmap words with nothing guarded: releasing a big
reservation walked every block of it.

Tested: cargo test --workspace (414 passed, 12 ignored), cargo xtask
policy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@KoLolX3

KoLolX3 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Check on Linux, not Windows: pass. Head 323168050 merged onto main d2a4bae1f (clean merge).

  • Native tests of the seven crates that build on Linux (core, formats, game, loader, pe, pipeline, shader): PR 140 passed, 0 failed, main 92 passed, 7 failed. The 7 tests that fail on main no longer fail.
  • Whole workspace, native Linux (what this PR is for): cargo check --workspace --all-targets ok and cargo test --workspace ok: 412 passed, 0 failed, 12 ignored. On main the same check fails to build (3 errors). Only the test run, not the new native runtime itself (no game, no GPU host).
  • Windows cross type-check of the whole workspace (cargo xwin check --workspace --target x86_64-pc-windows-msvc, covers victory-gpu, victory-hle and the app): PR ok, main ok.
  • Tests this PR adds: 192, of which 41 ran in the native run (the pass count rose by 41); the other 151 are in code this run does not execute (cfg(windows) modules, the victory-gpu and victory-hle crates, or ignored tests), and were not run.
  • rustfmt: unformatted hunks, PR 756, main 168.
  • Failing on main here as well (not this PR): 7 tests in victory-loader and victory-pe that parse their own test binary as a PE image, which is an ELF file on Linux.
  • Not run: victory-gpu / victory-hle tests and the game itself.

On: AMD Ryzen 7 5700, 62 GB RAM, Artix Linux 7.3.4-artix1-2, rustc 1.98.1 (the repo's pinned toolchain), cargo-xwin 0.24.1. No game data. Automated check only: the code itself was not reviewed.

spidercraft and others added 4 commits November 24, 2026 07:00
… length

The world load stalled in most runs on the RTX 5090: one host submission
never finished and the title's watchdog ended the run. It was not a spinning shader: each stall came with an
NVIDIA Xid 13 "SM Warp Exception: MMU Fault" in the kernel log, after which
the channel stops and the fence is never signalled.

With the lists' commands serialized and a GPU breadcrumb per command, the
faulting command was a dispatch of compute 72f552f4553fb5f9 every time.
Dropping its raw (offen) buffer loads, alone, let the run reach the world;
dropping its structured loads or its images did not. Its raw offsets come
from data arithmetic ((x - 1) * stride and the like) that wraps to near
2^32. The console's buffer loads bound such an offset by the record count
and read 0; through vkd3d-proton's robust raw access chains on NVIDIA
620.73 they faulted instead. Descriptor QA (vkd3d-proton built with
enable_descriptor_qa) found no bad descriptor, never freeing slot and
shadow resources changed nothing, and no view runs past its host buffer.

Every raw buffer load, store and atomic through a view now takes its byte
offset bounded by RAW_OFFSET_MAX (0x7FFF_FFF0): still past any view, so
reads give 0 and writes are dropped, as on the console; the bound keeps
offset plus access below 2^31.

Root SRVs are bare addresses on vkd3d-proton (nothing bounds them), and
the mesh programs' vertex fetch builds descriptors without a record limit
around them, at indices from data. Each root SRV now gets a user-data
dword (at its parameter's own index) with the bytes its host buffer holds
from the address; loads not wholly within it read offset 0 and return 0,
and a root SRV with no host memory behind it is bound to scratch with
length 0 instead of being left unset. All raw loads go through one helper
(raw_load) for this.

Tested: 6 runs in a row reach the world and stay there for 200 s (0.6-0.8
fps, 960-5300 draws a frame), no watchdog, no Xid; before, 4 of 5 runs
stalled at the world load (12 of 14 with diagnostics builds). cargo test
--workspace 414 passed, 12 ignored; victory-shader (host) and victory-gpu
device tests on vkd3d-proton pass, with two new ones (raw offsets past the
limit, root SRV length); Windows type-check clean; cargo xtask policy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Finding the world-load stall needed the command the GPU never finished:
the 5-second watcher only listed a stuck list's last commands, and
dispatches without barriers between them overlap, so even a timestamp
says little about which one hangs.

With timing on (diagnostics builds), each noted command now ends with a
global UAV barrier and a marker-out write of its index to a mapped
read-back dword (WriteBufferImmediate; vkd3d-proton writes it with
vkCmdWriteBufferMarkerAMD at bottom of pipe). A list still running after
5 s names the first command not finished and logs every command of the
list. The barrier serializes a timed list's commands, which also makes
the per-command times exact.

VICTORY_SHADER_SAVE=<dir> saves each shader container the title passes,
as <hash>.<stage>, so `victory shader-info --disasm` and `victory
translate --pipelines` (with VKD3D_SHADER_DUMP_PATH for the SPIR-V) can
take one program apart. The files go where the user says, never into the
repository.

Tested: the stall runs named compute 72f552f4553fb5f9 as the unfinished
command in serialized lists (and the fix in the previous commit removed
the stall); cargo test --workspace 414 passed, 12 ignored; Windows
type-check clean; cargo xtask policy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cobrabm12

cobrabm12 commented Nov 24, 2026 •

Copy link
Copy Markdown

Linux hardware test on an 8 GB Radeon RX 7600 (Navi 33), Mesa RADV 26.2.5, SDL 3.4.18. I built the Linux runtime at d46727f, native vkd3d-proton at 30b0eb9bc12d and used Microsoft's Linux DXC v1.9.2609. I used the default Series X profile and a local save that had completed first-boot setup. The native runtime used its own storage implementation.

The account picker responded to keyboard input. The illustrated load advanced to the “Vice City, Two Years Ago” chapter card. The runtime logged 240 successful mesh pipeline creations before I stopped the run. In four successive intervals during the transition it reported 0.9, 0.5, 0.9 and 1.0 fps. The final visible frame was black. Player movement and a visible world remain unverified.

On the same PC, the Windows runtime at ffe310e under Wine 11.21 exited at the first mesh pipeline, both with the default storage implementation and with a Leonida provider. Across these tests the graphics software versions also differ, so this comparison identifies a working route to the chapter card without establishing the cause of the difference.

CPU validation of the shaders used in this run

I matched all 1,257 distinct shader containers seen during startup, loading and the first scene to the local installation. For each build I called the same translator as the native runtime and checked every emitted module with Microsoft's Linux DXIL validator (DXC v1.9.2609).

Linux build Validated Unsupported by translator Rejected by validator
#526 at d46727f 958 288 11
With #180 987 269 1
With #193 973 273 11
With #180 and #193 1,002 254 1
With #180, #704 (includes #193), and the stable signature ordering from #306 1,003 254 0

All 958 baseline successes still validated. Of the 45 additional successes, 37 were compute, six pixel and two mesh shaders. On the #180 + #193 build, applying the signature ordering change alone cleared the remaining mesh output-signature error. The #704 integration also includes its descriptor-heap prerequisites cbb50b8, 3c81420 and e8d3b64 and builds natively. Rendering and frame rate on that build are still unverified.

@toothpaste011

toothpaste011 commented Nov 24, 2026 •

Copy link
Copy Markdown

Tested linux-native-runtime (d46727f) on Gentoo (kernel 7.0.10, Niri/Wayland, Intel Core Ultra 7 265K, RTX 5070 Ti, native vkd3d-proton ec20719452e916b, Microsoft Linux DXC v1.9.2609).

Intel CPU boot crash (0xc000001d / SIGILL)

On Intel CPUs, boot traps immediately with an unhandled 0xc000001d (SIGILL) on clzero (0f 01 fc) because crash.rs::emulate_amd_only (clzero, monitorx/mwaitx, clwb, SSE4a extrq/insertq) isn't ported to victory_loader::linux::signals yet.

Opened a fix against linux-native-runtime in spidercraft#3 (handles SIGILL directly on ucontext_t, collapses clzero loops, updates XSAVE xstate_bv bit 1 for SSE4a, and adds synthetic ucontext_t unit tests so AMD hosts and CI exercise every branch alongside the live-execution test).

Hardware results after the fix (RTX 5070 Ti, Wayland/Niri)

  • Boot, first-boot setup screens, menus, and loading run at a locked 30.0 fps (1.2–2.6 ms GPU; DXC indirect argument clamp compiles and runs).
  • Reaches the world loop at 1.2–2.6 fps (~2,000–3,900 draws/frame, ~1,558 translated shaders / 1,039 cached pipelines), with no crashes or NVIDIA driver hangs.
  • World-stage host notes on RTX 5070 Ti:
    • 116 host pipelines refused by vkd3d-proton (Required WaveSize range [64, 64], but supported range is [32, 32]).
    • 1x WARN victory_gpu::descriptor::host: no free dynamic descriptor slots: a table is not made n=7 on world entry.

@x3ero0 x3ero0 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One gap in the offline socket policy on Linux, with a fix in spidercraft#1. Reviewed and tested at d46727f on Linux x86-64 (NVIDIA): cargo test --workspace passes there.

Comment on lines +413 to +417
pub extern "win64" fn listen(s: Socket, backlog: i32) -> i32 {
let fd = fd_or_fail!(s);
// SAFETY: plain call on our descriptor.
if unsafe { libc::listen(fd, backlog) } != 0 { os_fail() } else { 0 }
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

listen goes straight to the kernel, and Linux binds an unbound socket to all interfaces at that point (0.0.0.0 and a port it chooses), so other machines can connect in. That gets around the narrowing bind does. Winsock returns WSAEINVAL for listen on an unbound socket, so refusing it here matches Windows.

The same happens with a first sendto from an unbound datagram socket: it is bound to 0.0.0.0 and can then receive datagrams from the network.

spidercraft#1 fixes both against this branch, with a test: listen fails with WSAEINVAL unless the socket has a loopback address, and sendto binds an unbound datagram socket to loopback first.

@onpeek

onpeek commented Nov 24, 2026

Copy link
Copy Markdown

Ran GTA VI on this branch natively (RTX 4070, Arch) and hit three bugs. Fixes against linux-native-runtime are in spidercraft#2:

  • GetProcAddress returned null for title DLLs mapped by our PE loader. GTA VI's FidelityFX loader looks up ffxCreateContext in amd_fidelityfx_upscaler_xbox.dll and calls it, so the game crashed about 4 s in (call to 0x0). With the fix it gets past the menus to the world load.
  • cas16 (cmpxchg16b) could get rbx as an in(reg) operand, which the manual rbx swap then clobbered. The SList tests segfaulted. Fixed registers now.
  • host_and_guest_blocks_mix was flaky under parallel tests (it read an uninitialized malloc byte and used a wrong upper bound).

@x3ero0

x3ero0 commented Nov 24, 2026 •

Copy link
Copy Markdown

Test report for d46727f on NVIDIA, with every run inside a bubblewrap sandbox. (I left the review comment about listen earlier; the fix for that is spidercraft#1.)

Setup: RTX 5080, driver 620.70, Ryzen 7 9800X3D, CachyOS (kernel 7.3.5), KDE Wayland, SDL3 on Wayland. Native vkd3d-proton built from 30b0eb9. Diagnostics build, Series X 1.0.2.1, an existing local save, menus driven by VICTORY_KEYS.

Sandbox: bwrap --unshare-all --clearenv, no network namespace beyond loopback, no home directory, the game folder read-only, only the cache and data folders writable, the Wayland socket and the NVIDIA device nodes bound. The runtime needs nothing else. Audio was not exposed, so pa_simple_new fails and it plays silently, as designed.

Build and tests

  • Builds natively; run maps and binds with 0 missing imports.
  • cargo test --workspace: 416 passed, 0 failed.
  • linux::vm::tests::physical_pages_map_alias_and_free failed once in five full-workspace runs (region_size 65536, expected 196608 at vm.rs:1875) and passed alone six times in a row. It looks order- or parallelism-dependent; I have not looked into it.

Title runs

Run Length Last frame Result
1 95 s 1376 0xc0000005 at game_scarlett_master.exe+0xc4b94e (write 0x670fc04), in the world
2 260 s 1715 ran to the time limit
3 260 s 1686 ran to the time limit
4 430 s 2121 ran to the time limit
5 430 s 1569 ran to the time limit; with DXC v1.9.2609 (VICTORY_DXCOMPILER)

What the log gives as causes

Message Runs 1 to 4 Run 5 (DXC)
Indirect execution dropped, not bounded (no clamp...) several hundred draws and dispatches per world frame none
Compute pipelines refused, Required WaveSize range [64, 64], but supported range is [32, 32] 79 to 99 142
Shaders that do not translate 95 to 142 523
no host texture (2560x1440, formats 86 and 115) 2 2
host view heap capped at 1000000, asked 1245184 1 1
Device methods not implemented, slots 0x1c8 and 0x218 1 each 1 each

With DXC the indirect draws run, more of the title's pipelines get requested (hence the higher counts), frames get slower (mean 2.2 fps against 3.2 in run 4), and the scene is still dark. So on this card the missing picture is not the dropped indirect execution.

On the DXC dependency: without VICTORY_DXCOMPILER every indirect execution is dropped, and Arch's package is unusable as docs/linux.md says. #190 builds the same clamp with the shader crate's own writer, so merging or rebasing onto it would remove the need for a compiler here too. I tried that design on this branch: with the clamp emitted that way and no DXC, a run reaches the world with zero not bounded drops.

Single machine, one GPU, runs of a few minutes; I did not play past the opening sequence.

@Marvisak

Copy link
Copy Markdown
Owner

Automated triage for the maintainers. Closing because it is outside the project's scope (VIctory targets Windows hosts; ports, launchers and tooling for other platforms are not being taken).

Native Linux runtime, 38,000 lines over 155 files (own loader, SEH, a new crate with a build script, libc and serde_json, a docs/linux.md design document, an edit to xtask/src/policy.rs): a port, out of scope.

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

@Marvisak Marvisak closed this Nov 25, 2026
blockgameentity referenced this pull request in blockgameentity/zafer Nov 25, 2026
The PR was 131 commits behind main; its conflicts are resolved here:
- calling convention: the PR's `extern "win64"` everywhere wins, since
  every function title code calls is win64 on both platforms (docs/linux.md).
- dxgi: keeps main's `crate::device::is_device` (every device interface
  level), which the PR's narrower `[device::IID]` broke for Device1..8.
- crash.rs: main's richer detail (memory_at, instruction_bytes, the C++
  throw) is fed into the PR's shared `crash_log::Report` format.
- thunks.rs: main's crash-log write for a trapped import, plus the PR's
  Linux ThunkBlock; both test modules kept.
- lower.rs: main's `nonuniform_handles`/`wave_ops` and the PR's
  `annotations` test fields coexist; both test bodies kept.
- files.rs/storage.rs/xuser.rs/lifecycle.rs: PR's Linux doc text and win64
  signatures, with main's test bodies which need Windows-only cfgs.

Three follow-up fixes from the PR's review comments are applied on top:
- ws2_32: an unbound socket never gets all interfaces (x3ero0's review,
  spidercraft/VIctory#1).
- GetProcAddress reads the exports of title DLLs we mapped, cmpxchg16b
  fixed registers, deterministic heap test (onpeek, #2).
- AMD-only Zen 2 instructions (clzero, SSE4a extrq/insertq) emulated in
  the SIGILL handler (toothpaste011, #3).

Also adds a Nix flake, a dev shell (default and windows-cross), a
shell.nix shim and .envrc, and allowlists .nix/.envrc in the asset policy.
geiyiliyabumo pushed a commit to geiyiliyabumo/VIctory that referenced this pull request Nov 25, 2026
…ave empty bodies

GDK manifests often write TitleId as 0x639AA8DD, which from_str_radix
rejected, leaving the id 0. A self-closing element also took the text up
to the next tag as its body.

Fixes Marvisak#526.

Tested: cargo test -p victory-hle (138 pass), clippy, fmt, xtask policy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants