mirror of
https://github.com/Dr-Noob/cpufetch.git
synced 2026-03-25 16:00:39 +01:00
[v0.98][ARM] Compiles and does not segfault in ARM running macOS
This commit is contained in:
@@ -125,7 +125,6 @@ void init_cpu_info(struct cpuInfo* cpu) {
|
|||||||
cpu->next_cpu = NULL;
|
cpu->next_cpu = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __linux__
|
|
||||||
// We assume all cpus share the same hardware
|
// We assume all cpus share the same hardware
|
||||||
// capabilities but I'm not sure it is always
|
// capabilities but I'm not sure it is always
|
||||||
// true...
|
// true...
|
||||||
@@ -138,13 +137,14 @@ struct features* get_features_info() {
|
|||||||
*ptr = false;
|
*ptr = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __linux__
|
||||||
errno = 0;
|
errno = 0;
|
||||||
long hwcaps = getauxval(AT_HWCAP);
|
long hwcaps = getauxval(AT_HWCAP);
|
||||||
|
|
||||||
if(errno == ENOENT) {
|
if(errno == ENOENT) {
|
||||||
printWarn("Unable to retrieve AT_HWCAP using getauxval");
|
printWarn("Unable to retrieve AT_HWCAP using getauxval");
|
||||||
}
|
}
|
||||||
#ifdef __aarch64__
|
#ifdef __aarch64__
|
||||||
else {
|
else {
|
||||||
feat->AES = hwcaps & HWCAP_AES;
|
feat->AES = hwcaps & HWCAP_AES;
|
||||||
feat->CRC32 = hwcaps & HWCAP_CRC32;
|
feat->CRC32 = hwcaps & HWCAP_CRC32;
|
||||||
@@ -152,7 +152,7 @@ struct features* get_features_info() {
|
|||||||
feat->SHA2 = hwcaps & HWCAP_SHA2;
|
feat->SHA2 = hwcaps & HWCAP_SHA2;
|
||||||
feat->NEON = hwcaps & HWCAP_ASIMD;
|
feat->NEON = hwcaps & HWCAP_ASIMD;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
else {
|
else {
|
||||||
feat->NEON = hwcaps & HWCAP_NEON;
|
feat->NEON = hwcaps & HWCAP_NEON;
|
||||||
}
|
}
|
||||||
@@ -167,27 +167,14 @@ struct features* get_features_info() {
|
|||||||
feat->SHA1 = hwcaps & HWCAP2_SHA1;
|
feat->SHA1 = hwcaps & HWCAP2_SHA1;
|
||||||
feat->SHA2 = hwcaps & HWCAP2_SHA2;
|
feat->SHA2 = hwcaps & HWCAP2_SHA2;
|
||||||
}
|
}
|
||||||
#endif
|
#endif // ifdef __aarch64__
|
||||||
|
#elif defined __APPLE__ || __MACH__
|
||||||
|
#endif
|
||||||
|
|
||||||
return feat;
|
return feat;
|
||||||
}
|
}
|
||||||
#elif defined __APPLE__ || __MACH__
|
|
||||||
struct features* get_features_info() {
|
|
||||||
struct features* feat = malloc(sizeof(struct features));
|
|
||||||
|
|
||||||
bool *ptr = &(feat->AES);
|
|
||||||
for(uint32_t i = 0; i < sizeof(struct features)/sizeof(bool); i++, ptr++) {
|
|
||||||
*ptr = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return feat;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct cpuInfo* get_cpu_info() {
|
|
||||||
struct cpuInfo* cpu = malloc(sizeof(struct cpuInfo));
|
|
||||||
init_cpu_info(cpu);
|
|
||||||
|
|
||||||
|
void get_cpu_info_linux(struct cpuInfo* cpu) {
|
||||||
int ncores = get_ncores_from_cpuinfo();
|
int ncores = get_ncores_from_cpuinfo();
|
||||||
bool success = false;
|
bool success = false;
|
||||||
int32_t* freq_array = malloc(sizeof(uint32_t) * ncores);
|
int32_t* freq_array = malloc(sizeof(uint32_t) * ncores);
|
||||||
@@ -237,6 +224,34 @@ struct cpuInfo* get_cpu_info() {
|
|||||||
cpu->hv = malloc(sizeof(struct hypervisor));
|
cpu->hv = malloc(sizeof(struct hypervisor));
|
||||||
cpu->hv->present = false;
|
cpu->hv->present = false;
|
||||||
cpu->soc = get_soc();
|
cpu->soc = get_soc();
|
||||||
|
}
|
||||||
|
|
||||||
|
void get_cpu_info_mach(struct cpuInfo* cpu) {
|
||||||
|
cpu->midr = 0;
|
||||||
|
cpu->arch = get_uarch_from_midr(cpu->midr, cpu);
|
||||||
|
|
||||||
|
cpu->cach = get_cache_info(cpu);
|
||||||
|
cpu->feat = get_features_info();
|
||||||
|
cpu->topo = malloc(sizeof(struct topology));
|
||||||
|
cpu->freq = malloc(sizeof(struct frequency));
|
||||||
|
cpu->freq->base = UNKNOWN_FREQ;
|
||||||
|
cpu->freq->max = 1000000000;
|
||||||
|
|
||||||
|
cpu->num_cpus = 1;
|
||||||
|
cpu->hv = malloc(sizeof(struct hypervisor));
|
||||||
|
cpu->hv->present = false;
|
||||||
|
cpu->soc = get_soc();
|
||||||
|
}
|
||||||
|
|
||||||
|
struct cpuInfo* get_cpu_info() {
|
||||||
|
struct cpuInfo* cpu = malloc(sizeof(struct cpuInfo));
|
||||||
|
init_cpu_info(cpu);
|
||||||
|
|
||||||
|
#ifdef __linux__
|
||||||
|
get_cpu_info_linux(cpu);
|
||||||
|
#elif defined __APPLE__ || __MACH__
|
||||||
|
get_cpu_info_mach(cpu);
|
||||||
|
#endif
|
||||||
|
|
||||||
return cpu;
|
return cpu;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -587,6 +587,7 @@ struct system_on_chip* get_soc() {
|
|||||||
soc->soc_vendor = SOC_VENDOR_UNKNOWN;
|
soc->soc_vendor = SOC_VENDOR_UNKNOWN;
|
||||||
soc->process = UNKNOWN;
|
soc->process = UNKNOWN;
|
||||||
|
|
||||||
|
#ifdef __linux__
|
||||||
bool isRPi = is_raspberry_pi();
|
bool isRPi = is_raspberry_pi();
|
||||||
if(isRPi) {
|
if(isRPi) {
|
||||||
soc = guess_soc_raspbery_pi(soc);
|
soc = guess_soc_raspbery_pi(soc);
|
||||||
@@ -612,6 +613,9 @@ struct system_on_chip* get_soc() {
|
|||||||
printWarn("SoC detection failed using Android: Found '%s' string", soc->raw_name);
|
printWarn("SoC detection failed using Android: Found '%s' string", soc->raw_name);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
#elif defined __APPLE__ || __MACH__
|
||||||
|
soc->raw_name = NULL;
|
||||||
|
#endif
|
||||||
|
|
||||||
if(soc->raw_name == NULL) {
|
if(soc->raw_name == NULL) {
|
||||||
soc->raw_name = malloc(sizeof(char) * (strlen(STRING_UNKNOWN)+1));
|
soc->raw_name = malloc(sizeof(char) * (strlen(STRING_UNKNOWN)+1));
|
||||||
|
|||||||
Reference in New Issue
Block a user