Files
spoopyghosty0--frameport/native/a32translator/tools/gen_syscalls.py
T
UnicronNLandClaude Opus 5.5 4f042f7225 native/a32translator: AArch32 -> AArch64 user-mode translator (a32run)
Interpreter + JIT for ARM, Thumb-2, VFPv4 and NEON, ARM EABI syscall
translation, signals, threads and self-modifying code. Runs static bionic
programs on the Frame. Tests: A64 encoders vs llvm-mc, a differential
instruction fuzzer and program tests against qemu-arm. Not shipped; the
README lists the steps towards running 32-bit-only APKs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 14:41:43 +02:00

41 lines
1.7 KiB
Python

#!/usr/bin/env python3
"""Generates src/arm_syscalls.h (guest ARM EABI syscall numbers + names) from the NDK's arm asm/unistd-eabi.h.
python tools/gen_syscalls.py [--ndk native/.cache/ndk-27.2.12479018]
"""
import argparse
import re
from pathlib import Path
HERE = Path(__file__).resolve().parent.parent
def main():
ap = argparse.ArgumentParser()
ap.add_argument("--ndk", default=str(HERE.parent / ".cache/ndk-27.2.12479018"))
a = ap.parse_args()
inc = Path(a.ndk) / "toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/arm-linux-androideabi/asm"
nums = {}
for line in (inc / "unistd-eabi.h").read_text().splitlines():
m = re.match(r"#define __NR_(\w+) \(__NR_SYSCALL_BASE \+ (\d+)\)", line)
if m:
nums[m.group(1)] = int(m.group(2))
for line in (inc / "unistd.h").read_text().splitlines():
m = re.match(r"#define __ARM_NR_(\w+) \(__ARM_NR_BASE \+ (\d+)\)", line)
if m and m.group(1) != "BASE":
nums["ARM_" + m.group(1)] = 0x0F0000 + int(m.group(2))
out = ["/* Generated by tools/gen_syscalls.py from the NDK's arm asm/unistd-eabi.h: guest syscall numbers. */",
"#ifndef A32_ARM_SYSCALLS_H", "#define A32_ARM_SYSCALLS_H", ""]
for name, n in sorted(nums.items(), key=lambda kv: kv[1]):
out.append(f"#define G_NR_{name} {n}")
out += ["", "static const struct { int nr; const char *name; } g_syscall_names[] = {"]
for name, n in sorted(nums.items(), key=lambda kv: kv[1]):
out.append(f' {{{n}, "{name}"}},')
out += ["};", "", "#endif", ""]
(HERE / "src/arm_syscalls.h").write_text("\n".join(out))
print(f"{len(nums)} syscalls")
if __name__ == "__main__":
main()