brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.4 KiB · d19beca Raw
41 lines · plain
1void __init_cpu_features_resolver(unsigned long hwcap,2                                  const __ifunc_arg_t *arg) {3  if (__atomic_load_n(&__aarch64_cpu_features.features, __ATOMIC_RELAXED))4    return;5 6  // ifunc resolvers don't have hwcaps in arguments on Android API lower7  // than 30. If so, set feature detection done and keep all CPU features8  // unsupported (zeros). To detect this case in runtime we check existence9  // of memfd_create function from Standard C library which was introduced in10  // Android API 30.11  int memfd_create(const char *, unsigned int) __attribute__((weak));12  if (!memfd_create)13    return;14 15  __init_cpu_features_constructor(hwcap, arg);16}17 18void CONSTRUCTOR_ATTRIBUTE __init_cpu_features(void) {19  // CPU features already initialized.20  if (__atomic_load_n(&__aarch64_cpu_features.features, __ATOMIC_RELAXED))21    return;22 23  // Don't set any CPU features,24  // detection could be wrong on Exynos 9810.25  if (__isExynos9810())26    return;27 28  unsigned long hwcap = getauxval(AT_HWCAP);29  unsigned long hwcap2 = getauxval(AT_HWCAP2);30  unsigned long hwcap3 = getauxval(AT_HWCAP3);31  unsigned long hwcap4 = getauxval(AT_HWCAP4);32 33  __ifunc_arg_t arg;34  arg._size = sizeof(__ifunc_arg_t);35  arg._hwcap = hwcap;36  arg._hwcap2 = hwcap2;37  arg._hwcap3 = hwcap3;38  arg._hwcap4 = hwcap4;39  __init_cpu_features_constructor(hwcap | _IFUNC_ARG_HWCAP, &arg);40}41