| 1 | """Verify the freestanding ARM desktop init entry point and its startup ABI.""" |
| 2 | import subprocess |
| 3 | |
| 4 | |
| 5 | def readelf(path, *flags): |
| 6 | return subprocess.check_output(["readelf", "--wide", *flags, path], text=True) |
| 7 | |
| 8 | |
| 9 | def verify_static(path): |
| 10 | header = dict(line.strip().split(":", 1) for line in readelf(path, "-h").splitlines() if ":" in line) |
| 11 | if header["Machine"].strip() != "AArch64" or not header["Type"].strip().startswith("EXEC "): |
| 12 | raise ValueError(f"{path} must be an AArch64 executable") |
| 13 | records = [line.split() for line in readelf(path, "-l").splitlines() if line.split()] |
| 14 | segments = {record[0] for record in records} |
| 15 | if segments & {"INTERP", "DYNAMIC"} or "LOAD" not in segments: |
| 16 | raise ValueError(f"{path} must start directly without a dynamic loader") |
| 17 | for record in records: |
| 18 | if record[0] == "LOAD" and int(record[5], 16): |
| 19 | if int(record[1], 16) % 16384 != int(record[2], 16) % 16384: |
| 20 | raise ValueError(f"{path} cannot load on 16 KiB Vinix pages: {record}") |
| 21 | return int(header["Entry point address"], 16) |
| 22 | |
| 23 | |
| 24 | entry = verify_static("desktop-init") |
| 25 | verify_static("desktop-watchdog") |
| 26 | symbols = {} |
| 27 | for line in readelf("desktop-init", "-s").splitlines(): |
| 28 | cols = line.split() |
| 29 | if len(cols) == 8 and cols[0][:-1].isdigit() and cols[6] != "UND": |
| 30 | symbols[cols[7]] = int(cols[1], 16) |
| 31 | if symbols.get("_start") != entry or "vinit_syscall" not in symbols: |
| 32 | raise ValueError("desktop init is missing the Vinix entry or syscall implementation") |
| 33 | |