| 1 | """Verify the freestanding ARM desktop init entry point and its startup ABI.""" |
| 2 | import subprocess |
| 3 | |
| 4 | |
| 5 | def readelf(*flags): |
| 6 | return subprocess.check_output(["readelf", "--wide", *flags, "desktop-init"], text=True) |
| 7 | |
| 8 | |
| 9 | header = dict(line.strip().split(":", 1) for line in readelf("-h").splitlines() if ":" in line) |
| 10 | if header["Machine"].strip() != "AArch64" or not header["Type"].strip().startswith("EXEC "): |
| 11 | raise ValueError("desktop init must be an AArch64 executable") |
| 12 | entry = int(header["Entry point address"], 16) |
| 13 | records = [line.split() for line in readelf("-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("desktop init 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"desktop init cannot load on 16 KiB Vinix pages: {record}") |
| 21 | symbols = {} |
| 22 | for line in readelf("-s").splitlines(): |
| 23 | cols = line.split() |
| 24 | if len(cols) == 8 and cols[0][:-1].isdigit() and cols[6] != "UND": |
| 25 | symbols[cols[7]] = int(cols[1], 16) |
| 26 | if symbols.get("_start") != entry or "vinit_syscall" not in symbols: |
| 27 | raise ValueError("desktop init is missing the Vinix entry or syscall implementation") |
| 28 | |