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