[v0.98][ARM] Compiles and does not segfault in ARM running macOS

This commit is contained in:
Dr-Noob
2021-08-02 12:02:41 +01:00
parent a3c6f15658
commit 4998cf3c82
2 changed files with 67 additions and 48 deletions

View File

@@ -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,6 +137,7 @@ 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);
@@ -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__
return feat;
}
#elif defined __APPLE__ || __MACH__ #elif defined __APPLE__ || __MACH__
struct features* get_features_info() { #endif
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; 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;
} }

View File

@@ -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));