native: compiled .NET wasm JIT modules cached on disk by their bytes (GEX_WASMJIT_CACHE=0 off); kernel: a pin that lands elsewhere is said when it happens

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_d2453757b8a84fdbb4ee7c9e093141df
This commit is contained in:
velzieandClaude Opus 5.5 committed 2026-10-07 20:27:10 -04:00
1 parent 4fb41ebeb7
commit 691acaa9d3
2 files changed
+25 -1

No files matched your search

+10
View File
@@ -5127,6 +5127,11 @@ impl Kernel {
Some((name.clone(), offset)),
)?;
if let Some((path, base)) = pinned {
// Said as it happens: the end-of-run report is lost when the
// process is killed (a game run ends at its timeout).
if base != start {
eprintln!("[pin] {path} WANTED {base:#x} GOT {start:#x}");
}
self.pin_landed.push((path, base, start));
}
let mut tmp = vec![0u8; len as usize];
@@ -5191,6 +5196,11 @@ impl Kernel {
self.mem.mmap(addr, len, prot_bits, flags, "")?
};
if let Some((path, base)) = pinned {
// Said as it happens: the end-of-run report is lost when the
// process is killed (a game run ends at its timeout).
if base != start {
eprintln!("[pin] {path} WANTED {base:#x} GOT {start:#x}");
}
self.pin_landed.push((path, base, start));
}
// Anonymous memory is defined to read as zero. Pages that already
+15 -1
View File
@@ -91,6 +91,13 @@ fn instantiate(
let _ = std::fs::write(std::path::Path::new(&dir).join(format!("m{n:05}.wasm")), &wasm);
}
let engine = caller.data().jit.as_ref().map(|j| j.engine.clone()).ok_or_else(|| anyhow!("wasmjit: no engine"))?;
// The module cache's directory and this build's name: compiled JIT modules are kept on disk by
// their bytes, so the next run of the same program loads them instead of compiling
// (`GEX_WASMJIT_CACHE=0` turns it off; Hollow Knight's start-up compiles thousands).
let disk = caller.data().jit.as_ref().and_then(|j| j.cache.clone()).filter(|_| {
static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
*ON.get_or_init(|| std::env::var("GEX_WASMJIT_CACHE").map_or(true, |v| v != "0"))
});
let module = {
let key = {
use std::hash::{Hash, Hasher};
@@ -104,7 +111,14 @@ fn instantiate(
Some(m) => m.clone(),
None => {
// Through gex_cache, so gex-rt (which links no compiler) can load it.
let m = match gex_cache::compile(&engine, &wasm) {
let compiled = match &disk {
Some((dir, build)) => {
let k = gex_cache::key(build, [b"wasmjit".as_slice(), &wasm]);
gex_cache::load_or_compile_at(&engine, &dir.join("wasmjit").join(format!("{k}.cwasm")), &wasm)
}
None => gex_cache::compile(&engine, &wasm),
};
let m = match compiled {
Ok(m) => m,
Err(e) => {
// `GEX_DUMP_BAD_WASM=DIR`: keep a module the engine refused, as for gex's own.