Compare commits

..
Author SHA1 Message Date
elforeign 5df1f9146f docs: require claiming an issue before starting work
Signed-off-by: elforeign <324243036+elforeign@users.noreply.github.com>
2026-11-24 00:48:25 -06:00
Ranveer Soni 48e42d6d4b Merge pull request #182 from atesahmet0/fix/75-static-probe-c7
Fix C7 instruction boundaries and trusted fixture probe reporting
2026-11-24 12:12:44 +05:30
ates 60f4f38da1 Fix C7 instruction boundaries and trusted fixture probe reporting
Signed-off-by: ates <ahmetrizaates@hotmail.com>
2026-11-24 09:32:34 +03:00
Ranveer Soni 951189c61b Merge pull request #167 from elforeign/feat/texture-bc-formats
texture: BC2, BC3, BC4 and BC5 CPU block decoders
2026-11-24 11:58:17 +05:30
6 changed files with 154 additions and 6 deletions

No files matched your search

+4 -1
View File
@@ -1,6 +1,8 @@
## Summary
<!-- What changes, and why? Link an issue if relevant. -->
<!-- What changes, and why? -->
Closes #<!-- the issue you claimed -->
## Implementation and evidence
@@ -23,6 +25,7 @@
## Checklist
- [ ] I claimed the linked issue before starting, and the claim was still mine when I opened this pull request.
- [ ] I reviewed the changes and disclosed material AI assistance below, if applicable.
- [ ] The change preserves native ARM64 and Metal-first requirements.
- [ ] I added relevant tests or explained why they are not applicable.
+13
View File
@@ -45,6 +45,19 @@ No AI slop (section 29).
Read docs/interfaces.md and docs/progress.md before implementation.
## Claiming work before you start
Several people and coding agents work on this repository at the same time. An issue with no visible claim is the only signal that a task is free, so claim before you edit anything.
1. **Check.** Read the issue's comments, assignees and labels, its linked pull requests, and open pull requests that touch the same files. If someone holds a live claim, pick another task. Do not start parallel work on a claimed task.
2. **Claim.** Comment `/claim` on the issue (or run `scripts/agent-queue.sh claim <n>`). Where the claim workflow is enabled, wait for its grant comment and the `claimed-by:<login>` label; a refusal names the reason. Where it is not enabled yet, your comment is the claim and the earliest valid claim comment wins. One issue per claim; claim follow-up tasks separately.
3. **Respect file ownership.** Two claimed tasks never edit the same files at the same time. If the issue lists files, edit only those; ask the maintainer before widening the list.
4. **Keep it alive.** A claim lapses 24 hours after the latest grant, `/progress <what changed>` comment, or push to the linked pull request. Post `/progress` at least once a day while you work. Lapsed tasks return to the queue and may be claimed by anyone.
5. **Release.** If you stop, comment `/release` so the task returns to the queue. Use `/blocked <reason>` instead if you are waiting on another task.
6. **Link.** Open the pull request from a branch named `task/<n>-<slug>` with `Closes #<n>` in its description.
An agent acting for a contributor claims in that contributor's name and must not claim work for areas that contributor may not claim (`.github/agent-queue.json`). Never remove, overwrite or ignore another person's claim; ask the maintainer to `/reassign` instead. See `docs/coordination/agent-tasks.md` when present.
## Changelog maintenance
- At the start of every engineering task, read `CHANGELOG.md` alongside the relevant project documentation. Review the existing `[Unreleased]` entries before implementation to avoid duplicating completed work.
+1
View File
@@ -11,6 +11,7 @@ remains unsupported.
### Added
- Added explicit claim-before-work rules for contributors and coding agents to `AGENTS.md`, `CONTRIBUTING.md` and the pull request template: check for existing claims, claim with `/claim`, keep a 24-hour lease alive with `/progress`, `/release` when stopping, and link the claimed issue. Without the claim workflow, the earliest valid claim comment wins.
- Added CPU block decoders for BC2, BC3, BC4 and BC5 (UNORM and SNORM) in `xenora-texture`, with tests whose expected texels were derived by hand from the Microsoft and Khronos block-compression specifications. Interpolated values truncate toward zero, as the existing BC1 decoder does; GPU upload and sampling of these formats are not implemented yet.
- Added `dbt::tests::sib_store_executes_through_the_native_dbt`, an independent DBT execution
test that runs the SIB store form `mov [rsp + 0x20], rbx` through the native ARM64 DBT and
+1
View File
@@ -6,6 +6,7 @@ Xenora is an experimental Xbox Series X|S recompilation framework for Apple Sili
- Read `README.md` and, when present, `AGENTS.md`, `docs/interfaces.md`, `docs/status.toml` and the relevant architecture decisions.
- Discuss substantial changes in an issue before implementing them; small fixes do not require prior approval.
- Claim an issue before working on it by commenting `/claim`, and check that nobody else holds a live claim first. Claims lapse after 24 hours without a `/progress` comment or a push; comment `/release` if you stop. Coding agents follow the same rules; see "Claiming work before you start" in `AGENTS.md`.
- Use a native ARM64 macOS environment with Rust and the appropriate Xcode/Metal tools. LLVM AMDGPU tools are needed for ISA fixture generation; extra tooling depends on the subsystem.
- Keep changes focused and preserve existing public interfaces unless a change is justified and documented.
+75 -5
View File
@@ -89,6 +89,14 @@ fn decode_one(slice: &[u8], rva: u32, va: u64) -> Option<CfgDecoded> {
pc += 1;
}
// Recognize the operand-size override for C7 without changing how the
// probe classifies prefixes on unrelated opcodes.
let operand_override =
b0 == 0x66 && matches!(slice.get(pc..), Some([0xc7, ..] | [0x40..=0x4f, 0xc7, ..]));
if operand_override {
b0 = slice[pc];
pc += 1;
}
let mut rex_w = false;
let mut op = b0;
@@ -142,6 +150,51 @@ fn decode_one(slice: &[u8], rva: u32, va: u64) -> Option<CfgDecoded> {
is_interp = true;
fall_through = false;
}
0xC7 => {
if let Some(&modrm) = slice.get(pc) {
pc += 1;
let mode = modrm >> 6;
let rm = modrm & 7;
if modrm & 0x38 != 0 {
mnemonic = format!("unsupported c7 extension (modrm 0x{modrm:02x})");
notes = "unknown instruction boundary".into();
fall_through = false;
} else {
pc += modrm_extra_len(modrm, slice, pc);
let imm16 = operand_override && !rex_w;
let imm_len = if imm16 { 2 } else { 4 };
if let Some(imm) = slice.get(pc..pc + imm_len) {
pc += imm_len;
let (width, value) = if imm16 {
(16, i32::from(i16::from_le_bytes(imm.try_into().unwrap())))
} else {
(
if rex_w { 64 } else { 32 },
i32::from_le_bytes(imm.try_into().unwrap()),
)
};
mnemonic = format!("mov r/m{width}, {value} (modrm 0x{modrm:02x})");
// The native C7 memory path always writes eight bytes and
// does not apply segment bases or decode a SIB byte.
is_dbt = mode == 3
|| (mode == 0 && rm != 4 && rex_w && !matches!(slice[0], 0x64 | 0x65));
is_dbt &= !operand_override;
if !is_dbt {
notes = "MOV immediate operand form lacks native semantics".into();
}
} else {
pc = slice.len();
fall_through = false;
}
}
} else {
fall_through = false;
}
if mnemonic.is_empty() {
mnemonic = "truncated c7".into();
notes = "incomplete MOV immediate encoding".into();
}
}
0xC2 => {
// RETN imm16
if pc + 2 <= slice.len() {
@@ -443,8 +496,10 @@ fn modrm_extra_len(modrm: u8, slice: &[u8], after_modrm: usize) -> usize {
extra += 1; // disp8
} else if mode == 2 {
extra += 4; // disp32
} else if mode == 0 && rm == 5 {
extra += 4; // RIP-relative disp32
} else if mode == 0
&& (rm == 5 || (rm == 4 && slice.get(after_modrm).is_some_and(|sib| sib & 7 == 5)))
{
extra += 4; // RIP-relative or SIB with no base
}
// Clamp to what's actually available
extra.min(slice.len().saturating_sub(after_modrm))
@@ -1048,7 +1103,7 @@ pub fn run_probe_and_export<O: AsRef<Path>>(
// 1. imports.csv
let mut imports_csv = String::from(
"module,symbol_or_ordinal,iat_rva,category,registered_binding,implementation_status,is_alias,canonical_module,startup_priority,startup_cluster\n",
"module,symbol_or_ordinal,iat_rva,category,registered_binding,implementation_status,is_alias,canonical_module,startup_priority,startup_cluster,trusted_runner_binding\n",
);
let mut missing_csv = String::from("module,symbol_or_ordinal,iat_rva\n");
let mut modules = BTreeSet::new();
@@ -1058,6 +1113,9 @@ pub fn run_probe_and_export<O: AsRef<Path>>(
let mut counts = BTreeMap::<&str, usize>::new();
let mut clusters = BTreeMap::<(u8, &str), (usize, usize)>::new();
let mut aliases = 0;
// The runner admits exactly these bytes and installs a private draw handler.
let trusted_fixture = bytes == include_bytes!("../../../fixtures/pe/trusted-runner.exe");
let mut trusted_runner_slots = 0;
let mut missing = 0;
for imp in &report.imports {
let module_key = imp.dll.to_ascii_lowercase();
@@ -1071,6 +1129,10 @@ pub fn run_probe_and_export<O: AsRef<Path>>(
let module = imp.dll.replace('"', "\"\"");
let symbol = imp.symbol.replace('"', "\"\"");
let key = format!("\"{module}\",\"{symbol}\",0x{:08x}", imp.iat_rva);
let trusted_binding = trusted_fixture
&& imp.dll.eq_ignore_ascii_case("xenora.dll")
&& imp.symbol == "fixture_draw";
trusted_runner_slots += usize::from(trusted_binding);
let status = imp.coverage_label();
let canonical = imp.canonical_module.as_deref().unwrap_or("");
let is_alias = imp.canonical_module.is_some() && !imp.dll.eq_ignore_ascii_case(canonical);
@@ -1086,7 +1148,7 @@ pub fn run_probe_and_export<O: AsRef<Path>>(
let canonical = canonical.replace('"', "\"\"");
let _ = writeln!(
imports_csv,
"{key},{},{},{status},{is_alias},\"{canonical}\",{priority},{cluster}",
"{key},{},{},{status},{is_alias},\"{canonical}\",{priority},{cluster},{trusted_binding}",
imp.category, imp.is_supported
);
if !imp.is_supported {
@@ -1140,6 +1202,7 @@ pub fn run_probe_and_export<O: AsRef<Path>>(
"total_imports": {},
"imported_dlls_count": {},
"unresolved_imports": {},
"trusted_runner_binding_slots": {trusted_runner_slots},
"distinct_import_keys": {},
"distinct_symbol_names_and_scoped_ordinals": {},
"canonical_registered_services": {},
@@ -1207,7 +1270,7 @@ pub fn run_probe_and_export<O: AsRef<Path>>(
let _ = writeln!(md, "- **Section Alignment**: `4096` bytes");
let _ = writeln!(md, "- **File Alignment**: `512` bytes\n");
let _ = writeln!(md, "## Sections Census (10)");
let _ = writeln!(md, "## Sections Census ({})", report.parsed.sections.len());
for s in &report.parsed.sections {
let _ = writeln!(
md,
@@ -1274,6 +1337,13 @@ pub fn run_probe_and_export<O: AsRef<Path>>(
"- **Unresolved standard import thunks**: `{missing}`. See `missing_imports.csv`. A registered handler may be a stub.\n"
);
if trusted_runner_slots > 0 {
let _ = writeln!(
md,
"The trusted runner supplies `xenora.dll!fixture_draw` for this fixture. The standard registry counts above exclude that private handler.\n"
);
}
let _ = writeln!(md, "## First Static DBT Blocker");
if let Some(insn) = &report.first_unsupported_dbt_insn {
let hex_bytes = insn
+60
View File
@@ -199,3 +199,63 @@ fn probe_distinguishes_aliases_from_unavailable_services() {
assert!(json.contains("\"recognized_unsupported_slots\": 1"));
std::fs::remove_dir_all(path).unwrap();
}
#[test]
fn trusted_runner_callback_and_report_match_the_fixture() {
let pe = include_bytes!("../../../fixtures/pe/trusted-runner.exe");
let path = std::env::temp_dir().join(format!("xenora-probe-trusted-{}", std::process::id()));
let report = run_probe_and_export(pe, &path, &ProbeConfig::default()).unwrap();
let read = |name| std::fs::read_to_string(path.join(name)).unwrap();
let md = read("candidate_static_report.md");
let json = read("candidate_static_report.json");
let imports = read("imports.csv");
std::fs::remove_dir_all(path).unwrap();
let callback: Vec<_> = report
.instruction_records
.iter()
.filter(|i| i.rva >= 0x1040)
.collect();
assert_eq!(
callback.iter().map(|i| i.rva).collect::<Vec<_>>(),
[0x1040, 0x1047, 0x104e]
);
assert_eq!(callback[1].bytes, [0x48, 0xc7, 0, 17, 0, 0, 0]);
assert!(callback[1].is_supported_dbt);
assert!(!callback[1].is_supported_interp);
assert!(report.first_unsupported_dbt_insn.is_none());
assert!(md.contains("Sections Census (4)"));
assert!(json.contains("\"sections_count\": 4"));
assert!(!report.imports[0].is_supported);
assert!(
imports
.lines()
.any(|line| line.contains("fixture_draw") && line.ends_with(",true"))
);
assert!(json.contains("\"trusted_runner_binding_slots\": 1"));
assert!(json.contains("\"unresolved_imports\": 1"));
}
#[test]
fn probe_consumes_complete_c7_operands_even_when_native_support_is_missing() {
for (encoding, supported) in [
(&[0x48, 0xc7, 0x05, 0, 0, 0, 0, 17, 0, 0, 0][..], true),
(&[0xc7, 0xc0, 17, 0, 0, 0], true),
(&[0x66, 0xc7, 0xc0, 17, 0], false),
(&[0xc7, 0x00, 17, 0, 0, 0], false),
(&[0x48, 0xc7, 0x40, 4, 17, 0, 0, 0], false),
(&[0x48, 0xc7, 0x04, 0x25, 0, 0, 0, 0, 17, 0, 0, 0], false),
] {
let mut pe = create_synthetic_probe_pe();
let end = 0x200 + encoding.len();
pe[0x200..end].copy_from_slice(encoding);
pe[end] = 0xcc;
let report = probe_pe_bytes(&pe, &ProbeConfig::default()).unwrap();
let records = report.instruction_records;
assert_eq!(records.len(), 2);
assert_eq!(records[0].bytes, encoding);
assert_eq!(records[0].is_supported_dbt, supported);
assert_eq!(records[1].rva, 0x1000 + encoding.len() as u32);
assert!(!records[1].is_supported_dbt);
}
}