X-Git-Url: https://glassweightruler.freedombox.rocks/gitweb/waydroid.git/blobdiff_plain/e589328e4992ab83a538986af59fe7fd00a55c79..d8c700bbb8b7bd992b9fe9b43de8a2f3d8e8587f:/tools/helpers/arch.py?ds=sidebyside diff --git a/tools/helpers/arch.py b/tools/helpers/arch.py index af18e66..8f4543a 100644 --- a/tools/helpers/arch.py +++ b/tools/helpers/arch.py @@ -2,6 +2,21 @@ # SPDX-License-Identifier: GPL-3.0-or-later import platform import logging +import ctypes + +def is_32bit_capable(): + # man 2 personality + personality = ctypes.CDLL(None).personality + personality.restype = ctypes.c_int + personality.argtypes = [ctypes.c_ulong] + # linux/include/uapi/linux/personality.h + PER_LINUX32 = 0x0008 + # mirror e.g. https://github.com/util-linux/util-linux/blob/v2.41/sys-utils/lscpu-cputype.c#L745-L756 + pers = personality(PER_LINUX32) + if pers != -1: # success, revert back to previous persona (typically just PER_LINUX, 0x0000) + personality(pers) + return True + return False # unable to "impersonate" 32-bit host, nothing done def host(): machine = platform.machine() @@ -19,10 +34,18 @@ def host(): " architecture is not supported") def maybe_remap(target): - if target == "x86_64": + if target.startswith("x86"): with open("/proc/cpuinfo") as f: - if "sse4_2" not in f.read(): - logging.info("x86_64 CPU does not support SSE4.2, falling back to x86...") - return "x86" + cpuinfo = f.read() + if "ssse3" not in cpuinfo: + raise ValueError("x86/x86_64 CPU must support SSSE3!") + if target == "x86_64" and "sse4_2" not in cpuinfo: + logging.info("x86_64 CPU does not support SSE4.2, falling back to x86...") + return "x86" + elif target == "arm64" and platform.architecture()[0] == "32bit": + return "arm" + elif target == "arm64" and not is_32bit_capable(): + logging.info("AArch64 CPU does not appear to support AArch32, assuming arm64_only...") + return "arm64_only" return target