diff --git a/scripts/re/check_layout.py b/scripts/re/check_layout.py index 866c32487e..c7bdea2f24 100644 --- a/scripts/re/check_layout.py +++ b/scripts/re/check_layout.py @@ -44,11 +44,13 @@ def layout(r): consts, descs, size = lay lst = subprocess.run([XCL, 'disasm', os.path.join(D, name)], capture_output=True, text=True, encoding='utf-8', errors='replace').stdout # the pair the table pointer was copied to: s_mov sA, s0 ; s_and sB, s1, 0xff - m = re.search(r's_and_b32 s(\d+), s1, 0xff\s', lst) - if not m or not re.search(rf's_mov_b32 s{int(m.group(1)) - 1}, s0\s', lst): + low_regs = set(map(int, re.findall(r's_mov_b32 s(\d+), s0\s', lst))) + high_regs = map(int, re.findall(r's_and_b32 s(\d+), s1, 0xff\s', lst)) + high = next((reg for reg in high_regs if reg - 1 in low_regs), None) + if high is None: print(name, 'no table pointer pattern') continue - pair = f's[{int(m.group(1)) - 1}:{m.group(1)}]' + pair = f's[{high - 1}:{high}]' loads = re.findall(r's_load_dword(x\d+)? s\[?(\d+)(?::(\d+))?\]?, ' + re.escape(pair) + r', (0x[0-9a-f]+)', lst) for w, lo, hi, off in loads: off = int(off, 16) diff --git a/scripts/test_check_layout_pair.py b/scripts/test_check_layout_pair.py new file mode 100644 index 0000000000..2fe8b6d836 --- /dev/null +++ b/scripts/test_check_layout_pair.py @@ -0,0 +1,37 @@ +from contextlib import redirect_stdout +from io import StringIO +from pathlib import Path +import runpy +import struct +import subprocess +import tempfile +import unittest +from unittest.mock import patch + + +SCRIPT = Path(__file__).resolve().parent / "re" / "check_layout.py" + + +class LayoutPointerTests(unittest.TestCase): + def test_unrelated_mask_does_not_hide_the_root_argument_pair(self): + root = struct.pack("<11I", 1, 1, 24, 0, 0, 0, 2, 0, 36, 0, 0) + chunk = b"RTS0" + struct.pack("