Files
6gbvram---16gb-ram/xtask/src/policy.rs
T
MarvisandClaude Fable 5.2 2849477415 Run Grand Theft Auto VI from first boot into the world
The title now boots through every first-boot and menu screen at its own
30 fps, drawing with translated shaders, with input, sound, saves and
loading served; it reaches the world, where the host GPU path still
fails (see "Not working yet").

Loader and runtime
- Crash reports unwind properly, name C++ throws and host GPU failures,
  carry the title's last debug lines and are appended to crashes.log.
- Thread notices on our own threads, reentrant late DLL loading, exit in
  the console's order, relaunch on a launch-new-game request.
- Offline guard: the title cannot reach the network (sockets, name
  lookups, WinHTTP, the media source resolver); by-name lookups and
  loads follow the import rules.
- Every runtime area the title calls is served (networking hint,
  packages, store, saves, display, UI, speech stubs, user, async pool).
  Saves persist; an update is one rename and survives a kill at any step.
- DirectStorage reads for real: shared worker pool, priorities, zlib and
  BCPack. BCPack is our own decoder; the format's constant tables ship in
  crates/victory-formats/src/bcpack-tables.bin (the asset policy's one
  exception, see docs/asset-policy.md).
- GameInput from XInput pads and the keyboard, with a keyboard stand-in
  pad; console timers (1 ms) for the whole process.
- Audio: XMA2 decoding on the emulated contexts, Opus on the decoder
  queues, the DSP interface as a stub; title memory placed below 2^40.
- Console texture layouts (sizes, tiling, detiling) and the layout
  library's imports.

GPU
- Draws, mesh dispatches and compute dispatches run on the host with
  shaders translated at first use and cached on disk; descriptor heaps,
  views, root signatures, barriers and host texture states; rectangle
  lists; comparison samplers.
- Title memory reaches the host through persistent mirrors that copy
  only pages written since the last copy; shader-written buffers are
  copied back.
- Presentation with frame pacing per event kind; framerate in the window
  caption.

Shaders
- DXIL emission for vertex, pixel, compute and mesh programs from the
  console's native code, with a differential test suite against the PC
  compile. World set: mesh 8,191 of 8,506, vertex/pixel 10,617 of
  12,346, compute 1,643 of 2,539; utility set complete.

Build
- Debugging aids (debug logs, frame capture, stack dumps, scripted keys,
  the host debug layer, the software adapter) exist only with the
  `diagnostics` feature; `[profile.diag]` keeps that build apart.

Not working yet
- In the world the host device is removed within seconds (descriptor
  handling fixes are in, unproven by a surviving run) and frames present
  black.
- 64-bit image atomics, merged geometry stages and the BVH builder's own
  shaders do not translate; reverb is silent.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
2026-11-23 23:10:01 +01:00

224 lines
6.8 KiB
Rust

//! Rule #1, statically: the repository only ever contains small text files
//! that we wrote. See docs/asset-policy.md.
//!
//! This is an allowlist, not a blocklist: a file passes only if its name is
//! on the list, it is not too big, it is text, and it does not smuggle data
//! inside text (long hex/base64 runs).
use std::path::Path;
use std::process::Command;
use anyhow::{Context, Result, bail};
const MAX_FILE_SIZE: usize = 512 * 1024;
const MAX_ENCODED_RUN: usize = 512;
const ALLOWED_EXTENSIONS: &[&str] = &[
"rs", "toml", "md", "txt", "lock", "yml", "yaml", "json", "hlsl", "hlsli", "ps1", "cmd", "sh",
];
const ALLOWED_NAMES: &[&str] = &[
".gitignore",
".gitattributes",
".editorconfig",
".victory-root",
"pre-commit",
"LICENSE",
"LICENSE-MIT",
"LICENSE-APACHE",
];
/// Paths explicitly exempted, with a reason. Keep this empty if at all possible.
const EXCEPTIONS: &[(&str, &str)] = &[(
"crates/victory-formats/src/bcpack-tables.bin",
"the BCPack format's constant tables: nothing decodes without them and they cannot be derived (owner's decision, 2026-11-23; docs/asset-policy.md)",
)];
/// Signatures of formats that must never be committed.
const FORBIDDEN_MAGIC: &[(&[u8], &str)] = &[
(b"MZ", "PE executable"),
(b"DXBC", "shader container"),
(b"DDS ", "DDS texture"),
(b"RIFF", "RIFF (audio/video)"),
(b"BC\xC0\xDE", "LLVM bitcode"),
(b"Microsoft C/C++ MSF", "PDB"),
(b"!<arch>", "library archive"),
(b"PK\x03\x04", "zip"),
(b"7z\xBC\xAF", "7-zip"),
(b"MSCF", "cabinet"),
(b"\xD0\xCF\x11\xE0", "MSI/OLE"),
];
pub fn run(root: &Path, staged: bool) -> Result<()> {
let files = list_files(root, staged)?;
let mut violations = Vec::new();
for path in &files {
if EXCEPTIONS.iter().any(|(p, _)| p == path) {
continue;
}
let content = if staged {
let out = Command::new("git")
.args(["show", &format!(":{path}")])
.current_dir(root)
.output()?;
if !out.status.success() {
continue; // deleted in the index
}
out.stdout
} else {
match std::fs::read(root.join(path)) {
Ok(c) => c,
Err(_) => continue,
}
};
for problem in check(path, &content) {
violations.push(format!("{path}: {problem}"));
}
}
if violations.is_empty() {
println!("asset policy: {} files ok", files.len());
return Ok(());
}
for v in &violations {
eprintln!("POLICY: {v}");
}
bail!(
"{} asset-policy violation(s). Nothing from the game may be committed; \
see docs/asset-policy.md",
violations.len()
)
}
fn list_files(root: &Path, staged: bool) -> Result<Vec<String>> {
let git = |args: &[&str]| -> Result<Option<Vec<String>>> {
let out = Command::new("git")
.args(args)
.current_dir(root)
.output()
.context("running git")?;
if !out.status.success() {
return Ok(None);
}
Ok(Some(
out.stdout
.split(|&b| b == 0)
.filter(|s| !s.is_empty())
.map(|s| String::from_utf8_lossy(s).replace('\\', "/"))
.collect(),
))
};
if staged {
return git(&[
"diff",
"--cached",
"--name-only",
"--diff-filter=ACMR",
"-z",
])?
.context("--staged needs a git repository");
}
if let Some(mut tracked) = git(&[
"ls-files",
"-z",
"--cached",
"--others",
"--exclude-standard",
])? {
tracked.sort();
tracked.dedup();
return Ok(tracked);
}
// Not a git repository: walk everything except build output.
Ok(walkdir::WalkDir::new(root)
.into_iter()
.filter_entry(|e| !matches!(e.file_name().to_str(), Some("target" | ".git")))
.filter_map(Result::ok)
.filter(|e| e.file_type().is_file())
.filter_map(|e| {
e.path()
.strip_prefix(root)
.ok()
.map(|p| p.to_string_lossy().replace('\\', "/"))
})
.collect())
}
/// All problems with one file. Pure, for testing.
pub fn check(path: &str, content: &[u8]) -> Vec<String> {
let mut problems = Vec::new();
let name = path.rsplit('/').next().unwrap_or(path);
let ext = name.rsplit_once('.').map(|(_, e)| e.to_ascii_lowercase());
let allowed = ALLOWED_NAMES.contains(&name)
|| ext
.as_deref()
.is_some_and(|e| ALLOWED_EXTENSIONS.contains(&e));
if !allowed {
problems.push("file type not on the allowlist".to_owned());
}
if content.len() > MAX_FILE_SIZE {
problems.push(format!(
"{} bytes exceeds the {MAX_FILE_SIZE}-byte limit",
content.len()
));
}
for (magic, what) in FORBIDDEN_MAGIC {
if content.starts_with(magic) {
problems.push(format!("looks like a {what}"));
}
}
if content.contains(&0) {
problems.push("binary content (NUL bytes)".to_owned());
} else if let Some(run) = longest_encoded_run(content)
&& run > MAX_ENCODED_RUN
{
problems.push(format!("{run}-character hex/base64 run (embedded data?)"));
}
problems
}
/// Longest run of characters that could be hex or base64 payload.
fn longest_encoded_run(content: &[u8]) -> Option<usize> {
let is_payload = |b: &u8| b.is_ascii_alphanumeric() || matches!(b, b'+' | b'/' | b'=');
content.split(|b| !is_payload(b)).map(<[u8]>::len).max()
}
#[cfg(test)]
mod tests {
use super::check;
/// Enforces the policy wherever tests run, even in clones without the hook.
#[test]
fn repository_passes_policy() {
super::run(&crate::workspace_root(), false).unwrap();
}
#[test]
fn accepts_source() {
assert!(check("crates/x/src/lib.rs", b"fn main() {}\n").is_empty());
assert!(check(".gitignore", b"/target/\n").is_empty());
assert!(check(".githooks/pre-commit", b"#!/bin/sh\n").is_empty());
}
#[test]
fn rejects_game_like_files() {
assert!(!check("assets/tex.dds", b"DDS \x7c\0\0\0").is_empty());
assert!(
!check("notes.txt", b"MZ\x90\0").is_empty(),
"magic wins over extension"
);
assert!(
!check("data.bin", b"hello").is_empty(),
"extension not allowed"
);
assert!(
!check("a.rs", &vec![b'a'; 600 * 1024]).is_empty(),
"too big"
);
}
#[test]
fn rejects_data_smuggled_into_text() {
let blob = format!("const DATA: &str = \"{}\";", "A1".repeat(400));
assert!(!check("src/blob.rs", blob.as_bytes()).is_empty());
}
}