+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