]>
glassweightruler.freedombox.rocks Git - waydroid.git/blob - tools/helpers/arch.py
1 # Copyright 2021 Oliver Smith
2 # SPDX-License-Identifier: GPL-3.0-or-later
7 def is_32bit_capable():
9 personality
= ctypes
.CDLL(None).personality
10 personality
.restype
= ctypes
.c_int
11 personality
.argtypes
= [ctypes
.c_ulong
]
12 # linux/include/uapi/linux/personality.h
14 # mirror e.g. https://github.com/util-linux/util-linux/blob/v2.41/sys-utils/lscpu-cputype.c#L745-L756
15 pers
= personality(PER_LINUX32
)
16 if pers
!= -1: # success, revert back to previous persona (typically just PER_LINUX, 0x0000)
19 return False # unable to "impersonate" 32-bit host, nothing done
22 machine
= platform
.machine()
31 if machine
in mapping
:
32 return maybe_remap(mapping
[machine
])
33 raise ValueError("platform.machine '" + machine
+ "'"
34 " architecture is not supported")
36 def maybe_remap(target
):
37 if target
.startswith("x86"):
38 with open("/proc/cpuinfo") as f
:
40 if "ssse3" not in cpuinfo
:
41 raise ValueError("x86/x86_64 CPU must support SSSE3!")
42 if target
== "x86_64" and "sse4_2" not in cpuinfo
:
43 logging
.info("x86_64 CPU does not support SSE4.2, falling back to x86...")
45 elif target
== "arm64" and platform
.architecture()[0] == "32bit":
47 elif target
== "arm64" and not is_32bit_capable():
48 logging
.info("AArch64 CPU does not appear to support AArch32, assuming arm64_only...")