vinix-ports / vinix-desktop-init / check-init.py
27 lines · 23 sloc · 1.34 KB · d7ac018690d796b9dbbe34d117a9a38fc1de38b1
Raw
1"""Verify the freestanding ARM desktop init entry point and its startup ABI."""
2import subprocess
3
4
5def readelf(*flags):
6 return subprocess.check_output(["readelf", "--wide", *flags, "desktop-init"], text=True)
7
8
9header = dict(line.strip().split(":", 1) for line in readelf("-h").splitlines() if ":" in line)
10if header["Machine"].strip() != "AArch64" or not header["Type"].strip().startswith("EXEC "):
11 raise ValueError("desktop init must be an AArch64 executable")
12entry = int(header["Entry point address"], 16)
13records = [line.split() for line in readelf("-l").splitlines() if line.split()]
14segments = {record[0] for record in records}
15if segments & {"INTERP", "DYNAMIC"} or "LOAD" not in segments:
16 raise ValueError("desktop init must start directly without a dynamic loader")
17for 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}")
21symbols = {}
22for 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)
26if symbols.get("_start") != entry or "vinit_syscall" not in symbols:
27 raise ValueError("desktop init is missing the Vinix entry or syscall implementation")
28