Commit 27a3ddf6 authored by Niels Möller's avatar Niels Möller

Implemented handling of NETTLE_FAT_OVERRIDE, for arm.

parent ce5c66d7
2015-01-20 Niels Möller <nisse@lysator.liu.se> 2015-01-20 Niels Möller <nisse@lysator.liu.se>
* fat-arm.c (get_arm_features): Check NETTLE_FAT_OVERRIDE
environment variable.
* fat-x86_64.c (get_x86_features): New function. Check * fat-x86_64.c (get_x86_features): New function. Check
NETTLE_FAT_OVERRIDE environment variable. NETTLE_FAT_OVERRIDE environment variable.
(fat_init): Use it. (fat_init): Use it.
......
...@@ -52,57 +52,85 @@ struct arm_features ...@@ -52,57 +52,85 @@ struct arm_features
int have_neon; int have_neon;
}; };
#define SKIP(s, slen, literal, llen) \
(((slen) >= (llen) && memcmp ((s), (literal), llen) == 0) \
? ((slen) -= (llen), (s) += (llen), 1) : 0)
#define MATCH(s, slen, literal, llen) \
((slen) == (llen) && memcmp ((s), (literal), llen) == 0)
static void static void
get_arm_features (struct arm_features *features) get_arm_features (struct arm_features *features)
{ {
FILE *f; const char *s;
char line[200];
int seen_arch = 0;
int seen_features = 0;
features->arch_version = 5; features->arch_version = 5;
features->have_neon = 0; features->have_neon = 0;
f = fopen ("/proc/cpuinfo", "r"); s = secure_getenv (ENV_OVERRIDE);
if (!f) if (s)
return; for (;;)
while (seen_features + seen_arch < 2 {
&& fgets (line, sizeof(line), f)) const char *sep = strchr (s, ',');
size_t length = sep ? (size_t) (sep - s) : strlen(s);
if (SKIP (s, length, "arch:", 5))
{
if (length == 1 && *s >= '0' && *s <= '9')
features->arch_version = *s - '0';
}
else if (MATCH (s, length, "neon", 4))
features->have_neon = 1;
if (!sep)
break;
s = sep + 1;
}
else
{ {
char *sep; FILE *f;
char *p; char line[200];
sep = strchr (line, ':'); int seen_arch = 0;
if (!sep) int seen_features = 0;
continue;
for (p = sep; p - line > 0 && p[-1] == '\t'; p--) f = fopen ("/proc/cpuinfo", "r");
; if (!f)
return;
*p = '\0'; while (seen_features + seen_arch < 2
p = sep+1; && fgets (line, sizeof(line), f))
if (strcmp (line, "Features") == 0)
{ {
features->have_neon = (strstr (p, " neon ") != NULL); char *sep;
seen_features = 1; char *p;
sep = strchr (line, ':');
if (!sep)
continue;
for (p = sep; p - line > 0 && p[-1] == '\t'; p--)
;
*p = '\0';
p = sep+1;
if (strcmp (line, "Features") == 0)
{
features->have_neon = (strstr (p, " neon ") != NULL);
seen_features = 1;
}
else if (strcmp (line, "CPU architecture") == 0)
{
/* Don't use strtol, since it's locale dependent. */
while (p[0] == ' ')
p++;
if (p[0] > '5' && p[0] <= '9')
features->arch_version = p[0] - '0';
else if (strcmp (p, "AArch64") == 0)
features->arch_version = 8;
seen_arch = 1;
}
} }
else if (strcmp (line, "CPU architecture") == 0) if (features->arch_version >= 8)
{ {
/* Don't use strtol, since it's locale dependent. */ /* Neon is not required, and maybe not listed in feature flags */
while (p[0] == ' ') features->have_neon = 1;
p++;
if (p[0] > '5' && p[0] <= '9')
features->arch_version = p[0] - '0';
else if (strcmp (p, "AArch64") == 0)
features->arch_version = 8;
seen_arch = 1;
} }
fclose (f);
} }
if (features->arch_version >= 8)
{
/* Neon is not required, and maybe not listed in feature flags */
features->have_neon = 1;
}
fclose (f);
} }
DECLARE_FAT_FUNC(_nettle_aes_encrypt, aes_crypt_internal_func) DECLARE_FAT_FUNC(_nettle_aes_encrypt, aes_crypt_internal_func)
...@@ -127,9 +155,9 @@ fat_init (void) ...@@ -127,9 +155,9 @@ fat_init (void)
verbose = getenv (ENV_VERBOSE) != NULL; verbose = getenv (ENV_VERBOSE) != NULL;
if (verbose) if (verbose)
fprintf (stderr, fprintf (stderr, "libnettle: cpu features: arch:%d%s\n",
"libnettle: cpu arch: %u, neon: %s\n", features.arch_version,
features.arch_version, features.have_neon ? "yes" : "no"); features.have_neon ? ",neon" : "");
if (features.arch_version >= 6) if (features.arch_version >= 6)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment