mirror of
https://github.com/QuixiAI/nvdriver.git
synced 2026-12-06 06:28:39 +00:00
- tools/decode_original_pt_bounded.py (4777575187): only suppress non-zero exit status when stop is 'line_limit' or 'error_limit', so 'decoder_shutdown_timeout' exits non-zero. - tools/check_compat_layout.py (4777575220): replace hardcoded /home/geodd DEFAULT_ANALYSIS with home-relative Path.home() / 'nvidia-driver/analysis-580.178.04'. - tests/offline/test_oracle_check_and_pt_decoder_tools.py (4777575238): add negative -O-safe tests covering alarm-vector drift, mismatched i386/x86_64 layouts, and decoder shutdown timeouts.
80 lines
3.3 KiB
Python
80 lines
3.3 KiB
Python
#!/usr/bin/env python3
|
|
"""Compile-only i386/x86_64 exact-header wire layout check."""
|
|
import hashlib
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import struct
|
|
import subprocess
|
|
import tempfile
|
|
|
|
R = Path(__file__).resolve().parent.parent
|
|
DEFAULT_ANALYSIS = Path.home() / "nvidia-driver/analysis-580.178.04"
|
|
|
|
|
|
def resolve_include_dirs():
|
|
analysis = Path(os.environ.get("NV_RS_ANALYSIS_ROOT") or DEFAULT_ANALYSIS)
|
|
common_candidates = []
|
|
if os.environ.get("NV_RS_KERNEL_SRC"):
|
|
common_candidates.append(Path(os.environ["NV_RS_KERNEL_SRC"]) / "common/inc")
|
|
common_candidates.extend([
|
|
analysis / "extracted/kernel/common/inc",
|
|
Path("/usr/src/nvidia-580.178.04/common/inc"),
|
|
Path("/usr/src/nvidia-srv-580.178.04/common/inc"),
|
|
])
|
|
sdk_candidates = []
|
|
if os.environ.get("OPEN_GPU_ROOT"):
|
|
sdk_candidates.append(Path(os.environ["OPEN_GPU_ROOT"]) / "src/common/sdk/nvidia/inc")
|
|
sdk_candidates.append(analysis / "reference/open-gpu-kernel-modules-580.178.04/src/common/sdk/nvidia/inc")
|
|
|
|
common_inc = next((p for p in common_candidates if (p / "nv-ioctl.h").is_file() and (p / "nvtypes.h").is_file()), None)
|
|
sdk_inc = next((p for p in sdk_candidates if (p / "nvos.h").is_file()), None)
|
|
if common_inc is None or sdk_inc is None:
|
|
raise SystemExit(
|
|
"Unable to locate NVIDIA 580.178.04 headers (nv-ioctl.h, nvtypes.h, nvos.h); "
|
|
"set NV_RS_ANALYSIS_ROOT or NV_RS_KERNEL_SRC + OPEN_GPU_ROOT."
|
|
)
|
|
return [common_inc, sdk_inc]
|
|
|
|
|
|
def main():
|
|
incs = resolve_include_dirs()
|
|
results = {}
|
|
with tempfile.TemporaryDirectory() as d:
|
|
for bits in (32, 64):
|
|
obj = Path(d) / f"layout{bits}.o"
|
|
raw = Path(d) / f"layout{bits}.bin"
|
|
subprocess.run(
|
|
[
|
|
"cc", f"-m{bits}", "-std=c11", "-Wall", "-Werror", "-ffreestanding", "-fno-pic",
|
|
"-c", *[f"-I{i}" for i in incs], str(R / "tests/oracles/compat-layout.c"),
|
|
"-o", str(obj),
|
|
],
|
|
check=True,
|
|
)
|
|
subprocess.run(["objcopy", "--dump-section", f".rodata={raw}", str(obj)], check=True)
|
|
data = raw.read_bytes()
|
|
results[str(bits)] = list(struct.unpack("<" + "I" * (len(data) // 4), data))
|
|
if not (results["32"] and results["64"] and results["32"][0] == 4 and results["64"][0] == 8):
|
|
raise SystemExit(f"unexpected pointer widths: 32-bit={results['32'][:1]}, 64-bit={results['64'][:1]}")
|
|
if results["32"][1:] != results["64"][1:]:
|
|
raise SystemExit("i386 and x86_64 wire layouts differ beyond pointer width")
|
|
report = {
|
|
"passed": True,
|
|
"scope": "Compile-only i386/x86_64 exact-header layout proof; not a 32-bit process runtime test.",
|
|
"layouts": results,
|
|
"all_wire_sizes_offsets_alignment_equal": True,
|
|
"files": {
|
|
str(p): hashlib.sha256(p.read_bytes()).hexdigest()
|
|
for p in [R / "tests/oracles/compat-layout.c", incs[0] / "nv-ioctl.h", incs[0] / "nvtypes.h", incs[1] / "nvos.h"]
|
|
},
|
|
}
|
|
report_path = R / "reports/compat-layout-validation.json"
|
|
report_path.parent.mkdir(parents=True, exist_ok=True)
|
|
report_path.write_text(json.dumps(report, indent=2) + "\n")
|
|
print("i386 and x86_64 layouts match except pointer width")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|