mirror of
https://github.com/MacosPorters/betterxen.git
synced 2026-11-26 11:40:43 +00:00
Compare commits
11
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0214a7bab5 | ||
|
|
7dd1329866 | ||
|
|
4b579af70d | ||
|
|
9dfdfd1134 | ||
|
|
8df13ae976 | ||
|
|
36c4fbd520 | ||
|
|
00eb6971e9 | ||
|
|
c3b0025977 | ||
|
|
e5aca73c55 | ||
|
|
281d92bfb5 | ||
|
|
3d19c756e2 |
No files matched your search
@@ -52,6 +52,8 @@ jobs:
|
||||
sh -n scripts/agent-queue.sh scripts/agent-sync.sh
|
||||
- name: Test pull request template check
|
||||
run: PYTHONPATH=scripts python3 -m unittest discover -s tests/pr_template
|
||||
- name: Test native audit JSON decoding
|
||||
run: python3 -m unittest discover -s tests/audit
|
||||
- name: Test semantic registry generator and coverage report
|
||||
run: |
|
||||
python3 -m unittest discover -s tests/semantics_generator
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
|
||||
__pycache__/
|
||||
*.pyc
|
||||
/diagnostics/probe/
|
||||
/diagnostics/gta6-candidate-*/
|
||||
/diagnostics/gta6-check/
|
||||
|
||||
|
||||
@@ -10,8 +10,11 @@ Guest execution uses original, purpose-built test programs. Commercial Xbox game
|
||||
remains unsupported.
|
||||
|
||||
### Changed
|
||||
- Removed the temporary region-list allocation from each instruction-byte fetch while preserving lookup order, execute-permission checks and error behavior (part of #104).
|
||||
- Release and bench builds now use fat link-time optimization with one codegen unit (#116). On a local Apple M5, `dbt_bench` medians over five alternating runs dropped by about 6 % for the interpreter (903 to 845 µs) and about 9 % for cold DBT (1.155 to 1.046 ms), while warm DBT (cache hits) became about 2 % slower (21.83-22.08 to 22.29-22.54 µs over four further runs). The `xenora` binary shrank from 2.73 to 2.11 MB. A clean release build of the workspace takes about 14 s instead of 6 s. Debug and test builds are unchanged.
|
||||
- The ARM64 assembler loads 64-bit constants with the fewest MOVZ or MOVN plus MOVK instructions (#92). It no longer emits MOVK for zero halfwords and starts from MOVN when more halfwords are 0xFFFF than zero, so small negative values take one instruction instead of four. On Apple M5 the DBT benchmark emits 245,168 instead of 290,184 native bytes for its 626 blocks (-15.5%) and the 1,048 integer fixture instructions 128,724 instead of 145,732 (-11.7%); benchmark run times did not change measurably. New tests check the sequences against LLVM encodings and execute 1,056 of them on the host through the JIT.
|
||||
- Resolve the tiled BC1 mip and array layer once per linearization and copy contiguous block runs within each tile row. Partial edge blocks are retained and padding slots are skipped. Closes #349.
|
||||
- Changed the default report folder of `xenora probe` and `xenora imports sync` to `diagnostics/probe`, which Git ignores (#364). Anyone relying on the earlier default has to pass `--report`.
|
||||
- Relocation reports now build their type histogram once per image, avoiding a tree lookup for every entry. Target checks and fixup order are unchanged; synthetic regressions and an opt-in relocation timing test cover the change (#109).
|
||||
- Moved the six supported gfx1030 SOPP compute control forms into the semantic registry, preserving instruction decoding and shader lowering. Part of #215.
|
||||
- Moved gfx1030 `s_mov_b32` (SOP1) into the semantic registry, preserving its existing decode domain and shader output. The move operand rule retains explicit VCC and EXEC half destinations. Part of #215.
|
||||
@@ -196,6 +199,7 @@ remains unsupported.
|
||||
native DBT.
|
||||
|
||||
### Fixed
|
||||
- Fixed the native dependency audit reading Cargo JSON and inspection-tool output in the process locale encoding; it now reads and reports UTF-8 paths and diagnostics under an ASCII locale (#363).
|
||||
- Made the static probe and the binder share one bounded import parser, after the truncated-name fix for #270. Truncated, unterminated, empty or non-ASCII names, reserved bits and endless tables are reported by the probe and refused by the binder.
|
||||
- Fixed the MXCSR flags of an unmasked floating-point overflow whose result is exact before the exponent is bounded, such as the largest binary32 value times two (#128). Only the overflow flag is set; the precision flag used to be set as well although nothing was rounded. A masked overflow still sets both flags and delivers infinity or the largest finite value, and an unmasked overflow that is also inexact still sets both. Five Intel SDM cases in `cpu_known_answers.rs` moved from open defect to verified on both engines, with three more for the other rounding modes, and the scalar and conversion sweeps now compare the precision flag in this case as well. Not compared with x86 hardware; awaiting independent review.
|
||||
- Fixed the decoder refusing an instruction whose REX prefix is followed by a legacy prefix (#69). Such a REX is ignored, as the Intel SDM (Vol. 2A, 2.2.1) specifies, so `48 66 01 D8` now runs as `add ax, bx`; it used to stop the guest with an illegal-instruction exit. The ignored byte still counts toward the instruction's length, and a REX that directly precedes the opcode behaves as before. The interpreter, the DBT and the static probe share the decoder. One SDM-derived case in `cpu_known_answers.rs` moved from refused to verified and three were added, for an ignored REX.B, an ignored REX.W before a segment prefix, and a later REX that does apply. Two REX bytes in a row and the address-size prefix stay rejected. Not compared with x86 hardware; awaiting independent review.
|
||||
|
||||
@@ -10,3 +10,10 @@ rust-version = "1.100"
|
||||
|
||||
[workspace.lints.rust]
|
||||
unsafe_op_in_unsafe_fn = "deny"
|
||||
|
||||
# Whole-program optimization for release and bench builds (#116). On an Apple M5 the
|
||||
# interpreter ran about 6 % and cold DBT about 9 % faster in `dbt_bench`, at the cost of
|
||||
# slower release builds. Debug and test builds are unaffected.
|
||||
[profile.release]
|
||||
lto = "fat"
|
||||
codegen-units = 1
|
||||
@@ -6,6 +6,9 @@ mod shaders;
|
||||
|
||||
use std::process::ExitCode;
|
||||
|
||||
/// Where `probe` writes and `imports sync` reads without `--report`.
|
||||
const DEFAULT_REPORT_DIR: &str = "diagnostics/probe";
|
||||
|
||||
fn main() -> ExitCode {
|
||||
match std::env::args().nth(1).as_deref() {
|
||||
Some("info") => {
|
||||
@@ -46,7 +49,7 @@ fn main() -> ExitCode {
|
||||
let args: Vec<String> = std::env::args().collect();
|
||||
let mut pe_path: Option<String> = None;
|
||||
let mut mode = "static".to_string();
|
||||
let mut report_dir = "diagnostics/gta6-candidate-e95020b2".to_string();
|
||||
let mut report_dir = DEFAULT_REPORT_DIR.to_string();
|
||||
|
||||
let mut i = 2;
|
||||
while i < args.len() {
|
||||
@@ -373,7 +376,7 @@ fn run_imports_generate_cli(args: &[String]) -> ExitCode {
|
||||
}
|
||||
|
||||
fn run_imports_sync_cli(args: &[String]) -> ExitCode {
|
||||
let mut report_dir = "diagnostics/gta6-candidate-e95020b2".to_string();
|
||||
let mut report_dir = DEFAULT_REPORT_DIR.to_string();
|
||||
let mut check_mode = false;
|
||||
|
||||
let mut i = 0;
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
//! Default report folder of `xenora probe` and `xenora imports sync`.
|
||||
|
||||
use std::process::Command;
|
||||
|
||||
#[test]
|
||||
fn probe_and_sync_use_the_same_default_folder() {
|
||||
let fixture = concat!(
|
||||
env!("CARGO_MANIFEST_DIR"),
|
||||
"/../../fixtures/pe/delay-imports.exe"
|
||||
);
|
||||
let folder = std::env::temp_dir().join(format!("xenora-default-{}", std::process::id()));
|
||||
std::fs::create_dir(&folder).unwrap();
|
||||
for arguments in [&["probe", "--pe", fixture][..], &["imports", "sync"]] {
|
||||
let status = Command::new(env!("CARGO_BIN_EXE_xenora"))
|
||||
.args(arguments)
|
||||
.current_dir(&folder)
|
||||
.status()
|
||||
.unwrap();
|
||||
assert!(status.success(), "{arguments:?}");
|
||||
}
|
||||
let written = ["imports.csv", "import_backlog.md"]
|
||||
.map(|name| folder.join("diagnostics/probe").join(name).is_file());
|
||||
std::fs::remove_dir_all(folder).unwrap();
|
||||
assert_eq!(written, [true, true]);
|
||||
}
|
||||
+221
-3
@@ -506,9 +506,20 @@ impl GuestMemory {
|
||||
|
||||
/// Read an instruction byte from guest memory, verifying execute permission.
|
||||
pub fn fetch_instruction_byte(&self, address: u64) -> Result<u8, MemoryError> {
|
||||
let mut buf = [0u8; 1];
|
||||
self.read_checked(address, &mut buf, Some("execute"))?;
|
||||
Ok(buf[0])
|
||||
address.checked_add(1).ok_or(MemoryError::Overflow)?;
|
||||
let region = self
|
||||
.regions
|
||||
.iter()
|
||||
.find(|region| region.base + region.data.len() as u64 > address)
|
||||
.filter(|region| region.base <= address)
|
||||
.ok_or(MemoryError::UnmappedAddress(address))?;
|
||||
if !region.permissions.execute {
|
||||
return Err(MemoryError::PermissionViolation {
|
||||
address,
|
||||
required: "execute",
|
||||
});
|
||||
}
|
||||
Ok(region.data[(address - region.base) as usize])
|
||||
}
|
||||
|
||||
/// Read a 64-bit integer (little endian) from guest memory.
|
||||
@@ -627,3 +638,210 @@ mod tests {
|
||||
assert_eq!(memory.heap_allocation_size(PROCESS_HEAP, moved), Some(1));
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod instruction_fetch_tests {
|
||||
use super::{MemoryPermissions as P, *};
|
||||
|
||||
fn denied(address: u64) -> Result<u8, MemoryError> {
|
||||
Err(MemoryError::PermissionViolation {
|
||||
address,
|
||||
required: "execute",
|
||||
})
|
||||
}
|
||||
fn missing(address: u64) -> Result<u8, MemoryError> {
|
||||
Err(MemoryError::UnmappedAddress(address))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fetch_reports_overflow_before_lookup() {
|
||||
let m = GuestMemory::new();
|
||||
for at in [0, 1, 0x1000, u64::MAX - 1] {
|
||||
assert_eq!(m.fetch_instruction_byte(at), missing(at));
|
||||
}
|
||||
assert_eq!(
|
||||
m.fetch_instruction_byte(u64::MAX),
|
||||
Err(MemoryError::Overflow)
|
||||
);
|
||||
let mut m = GuestMemory::new();
|
||||
m.map_region(u64::MAX, 0, P::NO_ACCESS).unwrap();
|
||||
assert_eq!(
|
||||
m.fetch_instruction_byte(u64::MAX),
|
||||
Err(MemoryError::Overflow)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fetch_checks_execute_permission_for_every_byte_value() {
|
||||
let bytes: Vec<u8> = (0..=255).collect();
|
||||
for flags in 0..8 {
|
||||
let permission = P {
|
||||
read: flags & 1 != 0,
|
||||
write: flags & 2 != 0,
|
||||
execute: flags & 4 != 0,
|
||||
};
|
||||
let mut m = GuestMemory::new();
|
||||
m.map_region_with_data(0x1000, bytes.len(), permission, &bytes)
|
||||
.unwrap();
|
||||
for (offset, byte) in bytes.iter().enumerate() {
|
||||
let at = 0x1000 + offset as u64;
|
||||
assert_eq!(
|
||||
m.fetch_instruction_byte(at),
|
||||
if flags & 4 != 0 {
|
||||
Ok(*byte)
|
||||
} else {
|
||||
denied(at)
|
||||
},
|
||||
"flags={flags}, at={at:x}"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fetch_handles_sparse_and_out_of_order_mappings() {
|
||||
let mut m = GuestMemory::new();
|
||||
m.map_region_with_data(0x3000, 2, P::READ_EXECUTE, &[0xc1, 0xc2])
|
||||
.unwrap();
|
||||
m.map_region_with_data(0, 2, P::READ_EXECUTE, &[0x01, 0x02])
|
||||
.unwrap();
|
||||
m.map_region_with_data(0x2000, 1, P::READ_ONLY, &[0xb1])
|
||||
.unwrap();
|
||||
m.map_region_with_data(0x1000, 2, P::READ_EXECUTE, &[0xa1, 0xa2])
|
||||
.unwrap();
|
||||
for (at, byte) in [
|
||||
(0, 1),
|
||||
(1, 2),
|
||||
(0x1000, 0xa1),
|
||||
(0x1001, 0xa2),
|
||||
(0x3000, 0xc1),
|
||||
(0x3001, 0xc2),
|
||||
] {
|
||||
assert_eq!(m.fetch_instruction_byte(at), Ok(byte));
|
||||
}
|
||||
assert_eq!(m.fetch_instruction_byte(0x2000), denied(0x2000));
|
||||
for at in [2, 0xfff, 0x1002, 0x2001, 0x2fff, 0x3002] {
|
||||
assert_eq!(m.fetch_instruction_byte(at), missing(at));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fetch_ignores_empty_mappings_at_shared_boundaries() {
|
||||
for zero_first in [false, true] {
|
||||
for execute in [false, true] {
|
||||
let mut m = GuestMemory::new();
|
||||
let permission = P {
|
||||
read: false,
|
||||
write: false,
|
||||
execute,
|
||||
};
|
||||
if zero_first {
|
||||
for _ in 0..7 {
|
||||
m.map_region(0x1000, 0, P::READ_WRITE_EXECUTE).unwrap();
|
||||
}
|
||||
}
|
||||
m.map_region_with_data(0x1000, 2, permission, &[0x34, 0x56])
|
||||
.unwrap();
|
||||
for _ in 0..7 {
|
||||
m.map_region(0x1000, 0, P::NO_ACCESS).unwrap();
|
||||
}
|
||||
for _ in 0..7 {
|
||||
m.map_region(0x1002, 0, P::READ_WRITE_EXECUTE).unwrap();
|
||||
}
|
||||
for (at, byte) in [(0x1000, 0x34), (0x1001, 0x56)] {
|
||||
assert_eq!(
|
||||
m.fetch_instruction_byte(at),
|
||||
if execute { Ok(byte) } else { denied(at) }
|
||||
);
|
||||
}
|
||||
assert_eq!(m.fetch_instruction_byte(0x1002), missing(0x1002));
|
||||
}
|
||||
}
|
||||
let mut m = GuestMemory::new();
|
||||
for at in [1, 1, 2, 0x1000] {
|
||||
m.map_region(at, 0, P::READ_WRITE_EXECUTE).unwrap();
|
||||
}
|
||||
for at in [0, 1, 2, 3, 0x1000] {
|
||||
assert_eq!(m.fetch_instruction_byte(at), missing(at));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fetch_checks_adjacent_mapping_permissions() {
|
||||
let mut m = GuestMemory::new();
|
||||
m.map_region_with_data(0x1000, 1, P::READ_EXECUTE, &[0xa5])
|
||||
.unwrap();
|
||||
m.map_region_with_data(0x1001, 1, P::READ_WRITE, &[0x5a])
|
||||
.unwrap();
|
||||
m.map_region(0x1001, 0, P::READ_EXECUTE).unwrap();
|
||||
m.map_region_with_data(0x1002, 1, P::READ_EXECUTE, &[0xc3])
|
||||
.unwrap();
|
||||
assert_eq!(m.fetch_instruction_byte(0x1000), Ok(0xa5));
|
||||
assert_eq!(m.fetch_instruction_byte(0x1001), denied(0x1001));
|
||||
assert_eq!(m.fetch_instruction_byte(0x1002), Ok(0xc3));
|
||||
assert_eq!(m.fetch_instruction_byte(0x1003), missing(0x1003));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fetch_handles_the_highest_region_end() {
|
||||
let mut m = GuestMemory::new();
|
||||
m.map_region_with_data(u64::MAX - 2, 2, P::READ_EXECUTE, &[0x12, 0x34])
|
||||
.unwrap();
|
||||
m.map_region(u64::MAX, 0, P::READ_EXECUTE).unwrap();
|
||||
assert_eq!(
|
||||
m.fetch_instruction_byte(u64::MAX - 3),
|
||||
missing(u64::MAX - 3)
|
||||
);
|
||||
assert_eq!(m.fetch_instruction_byte(u64::MAX - 2), Ok(0x12));
|
||||
assert_eq!(m.fetch_instruction_byte(u64::MAX - 1), Ok(0x34));
|
||||
assert_eq!(
|
||||
m.fetch_instruction_byte(u64::MAX),
|
||||
Err(MemoryError::Overflow)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fetch_observes_writes_clones_and_mapping_changes() {
|
||||
let mut m = GuestMemory::new();
|
||||
m.map_region_with_data(0x1000, 1, P::READ_WRITE_EXECUTE, &[0x11])
|
||||
.unwrap();
|
||||
let mut clone = m.clone();
|
||||
m.write_u8(0x1000, 0x22).unwrap();
|
||||
clone.write_u8(0x1000, 0x33).unwrap();
|
||||
assert_eq!(m.fetch_instruction_byte(0x1000), Ok(0x22));
|
||||
assert_eq!(clone.fetch_instruction_byte(0x1000), Ok(0x33));
|
||||
let base = m
|
||||
.map_virtual_allocation(0x4000, 1, P::READ_WRITE_EXECUTE)
|
||||
.unwrap();
|
||||
m.write_u8(base, 0x44).unwrap();
|
||||
assert_eq!(m.fetch_instruction_byte(base), Ok(0x44));
|
||||
assert!(m.release_virtual_allocation(base));
|
||||
assert_eq!(m.fetch_instruction_byte(base), missing(base));
|
||||
m.map_region_with_data(base, 1, P::READ_ONLY, &[0x55])
|
||||
.unwrap();
|
||||
assert_eq!(m.fetch_instruction_byte(base), denied(base));
|
||||
assert_eq!(clone.fetch_instruction_byte(base), missing(base));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fetch_keeps_first_mapping_priority_after_empty_heap_growth() {
|
||||
// Existing private allocation methods can grow a zero allocation onto an
|
||||
// earlier mapping at its base. The fetch-only patch must preserve the
|
||||
// original mapping's priority even for this already-representable state.
|
||||
let mut m = GuestMemory::new();
|
||||
m.map_region_with_data(0x1000, 1, P::READ_EXECUTE, &[0x90])
|
||||
.unwrap();
|
||||
const BASE: u64 = 0x0000_0003_0000_0000;
|
||||
m.map_region_with_data(BASE, 4, P::READ_EXECUTE, &[0x11, 0x22, 0x33, 0x44])
|
||||
.unwrap();
|
||||
let empty = m.map_heap_allocation(PROCESS_HEAP, 0).unwrap();
|
||||
assert_eq!(empty, BASE);
|
||||
assert_eq!(
|
||||
m.resize_heap_allocation(PROCESS_HEAP, empty, 2, true),
|
||||
Ok(BASE)
|
||||
);
|
||||
assert_eq!(m.fetch_instruction_byte(BASE), Ok(0x11));
|
||||
assert_eq!(m.fetch_instruction_byte(BASE + 1), Ok(0x22));
|
||||
assert_eq!(m.fetch_instruction_byte(BASE + 3), Ok(0x44));
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -70,7 +70,8 @@ uses a Win64-aligned stack and terminates with HLT. The result includes the load
|
||||
guest memory and the entry execution outcome.
|
||||
|
||||
`xenora probe --mode static` inventories ordinary and delay-loaded PE imports
|
||||
without guest execution. `missing_imports.csv` lists unresolved ordinary keys
|
||||
without guest execution. Without `--report` it writes to `diagnostics/probe`,
|
||||
where `xenora imports sync` also looks. `missing_imports.csv` lists unresolved ordinary keys
|
||||
with their import address table relative virtual addresses. The full inventory,
|
||||
`imports.csv`, marks each entry `ordinary` or `delayed` in its `import_table`
|
||||
column and records whether each key is registered, its implementation
|
||||
|
||||
@@ -17,10 +17,13 @@ python3 - <<'PY'
|
||||
import json
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
sys.stdout.reconfigure(encoding="utf-8")
|
||||
|
||||
executables = set()
|
||||
for filename in ("native-build.jsonl", "native-tests.jsonl"):
|
||||
for line in (Path("artifacts") / filename).read_text().splitlines():
|
||||
for line in (Path("artifacts") / filename).read_text(encoding="utf-8").splitlines():
|
||||
entry = json.loads(line)
|
||||
if entry.get("executable"):
|
||||
executables.add(entry["executable"])
|
||||
@@ -32,11 +35,11 @@ if not executables:
|
||||
raise SystemExit("No Cargo executable or loadable dependency artifacts found.")
|
||||
for path in sorted(executables):
|
||||
subprocess.run(["file", path], check=True)
|
||||
archs = subprocess.check_output(["lipo", "-archs", path], text=True).strip()
|
||||
archs = subprocess.check_output(["lipo", "-archs", path], encoding="utf-8").strip()
|
||||
print(archs, flush=True)
|
||||
if archs != "arm64":
|
||||
raise SystemExit(f"Non-ARM64 build artifact: {path}")
|
||||
linkage = subprocess.check_output(["otool", "-L", path], text=True)
|
||||
linkage = subprocess.check_output(["otool", "-L", path], encoding="utf-8")
|
||||
print(linkage, end="", flush=True)
|
||||
if any(name in linkage.casefold() for name in ("vulkan", "moltenvk")):
|
||||
raise SystemExit(f"Unexpected graphics linkage: {path}")
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
"""Exercise native audit JSON decoding and inspection under an ASCII locale."""
|
||||
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import platform
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
SCRIPT = (ROOT / "scripts/audit/native.sh").read_text(encoding="utf-8")
|
||||
AUDIT = SCRIPT.split("python3 - <<'PY'\n", 1)[1].rsplit("\nPY", 1)[0]
|
||||
# Reader-only cases stop before the native executable inspection.
|
||||
READER = AUDIT.split("\nif not executables:", 1)[0]
|
||||
|
||||
|
||||
class NativeJsonTests(unittest.TestCase):
|
||||
def run_audit(self, streams, code=READER):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
artifacts = Path(directory) / "artifacts"
|
||||
artifacts.mkdir()
|
||||
for name, payload in zip(
|
||||
("native-build.jsonl", "native-tests.jsonl"), streams, strict=True
|
||||
):
|
||||
(artifacts / name).write_bytes(payload)
|
||||
return subprocess.run(
|
||||
[
|
||||
sys.executable,
|
||||
"-c",
|
||||
"import locale\n"
|
||||
"assert locale.getencoding().lower() in ('ascii', 'us-ascii')\n"
|
||||
+ code
|
||||
+ "\nprint(json.dumps(sorted(executables)))\n",
|
||||
],
|
||||
cwd=directory,
|
||||
env={
|
||||
**os.environ,
|
||||
"LC_ALL": "C",
|
||||
"PYTHONCOERCECLOCALE": "0",
|
||||
"PYTHONUTF8": "0",
|
||||
},
|
||||
capture_output=True,
|
||||
encoding="utf-8",
|
||||
check=False,
|
||||
)
|
||||
|
||||
def test_utf8_in_each_cargo_stream(self):
|
||||
for stream in (0, 1):
|
||||
with self.subTest(stream=stream):
|
||||
entry = {
|
||||
"executable": "/synthetic/caf\u00e9/bin",
|
||||
"filenames": ["/synthetic/caf\u00e9/lib.dylib"],
|
||||
"message": {"rendered": "synthetic diagnostic: \u03bb"},
|
||||
}
|
||||
streams = [b'{}\n', b'{}\n']
|
||||
streams[stream] = (json.dumps(entry, ensure_ascii=False) + "\n").encode(
|
||||
"utf-8"
|
||||
)
|
||||
result = self.run_audit(streams)
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
self.assertEqual(
|
||||
json.loads(result.stdout),
|
||||
["/synthetic/caf\u00e9/bin", "/synthetic/caf\u00e9/lib.dylib"],
|
||||
)
|
||||
|
||||
def test_ascii_streams_keep_deduplicated_artifacts(self):
|
||||
entry = b'{"executable":"/synthetic/bin","filenames":["/synthetic/lib.so","/synthetic/lib.rlib"]}\n'
|
||||
result = self.run_audit([entry, entry])
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
self.assertEqual(
|
||||
json.loads(result.stdout), ["/synthetic/bin", "/synthetic/lib.so"]
|
||||
)
|
||||
|
||||
def test_invalid_utf8_is_rejected(self):
|
||||
result = self.run_audit([b'{"executable":"\xff"}\n', b'{}\n'])
|
||||
self.assertNotEqual(result.returncode, 0)
|
||||
self.assertIn("UnicodeDecodeError", result.stderr)
|
||||
|
||||
@unittest.skipUnless(
|
||||
sys.platform == "darwin" and platform.machine() == "arm64",
|
||||
"requires native ARM64 macOS inspection tools",
|
||||
)
|
||||
def test_native_inspection_of_unicode_path_under_ascii_locale(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
source = root / "fixture.c"
|
||||
source.write_text("int main(void) { return 0; }\n", encoding="utf-8")
|
||||
binary = root / "caf\u00e9"
|
||||
subprocess.run(
|
||||
["/usr/bin/clang", "-arch", "arm64", str(source), "-o", str(binary)],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
)
|
||||
entry = (
|
||||
json.dumps({"executable": str(binary)}, ensure_ascii=False) + "\n"
|
||||
).encode("utf-8")
|
||||
for stream in (0, 1):
|
||||
with self.subTest(stream=stream):
|
||||
streams = [b'{}\n', b'{}\n']
|
||||
streams[stream] = entry
|
||||
result = self.run_audit(streams, code=AUDIT)
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
self.assertIn(str(binary), result.stdout)
|
||||
self.assertIn("Checked 1 native executables", result.stdout)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user