Skip to content

Commit acef78c

Browse files
author
zanpeeters
committed
Reset buffer length before every call to sysctlbyname.
1 parent d1c2528 commit acef78c

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

cpuid_arm64.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,15 +374,20 @@ int detect(void)
374374
}
375375
#else
376376
#ifdef __APPLE__
377+
length64 = sizeof(value64);
377378
sysctlbyname("hw.ncpu",&value64,&length64,NULL,0);
378379
cpulowperf=value64;
380+
length64 = sizeof(value64);
379381
sysctlbyname("hw.nperflevels",&value64,&length64,NULL,0);
380382
if (value64 > 1) {
383+
length64 = sizeof(value64);
381384
sysctlbyname("hw.perflevel0.cpusperl2",&value64,&length64,NULL,0);
382385
cpuhiperf=value64;
386+
length64 = sizeof(value64);
383387
sysctlbyname("hw.perflevel1.cpusperl2",&value64,&length64,NULL,0);
384388
cpulowperf=value64;
385389
}
390+
length64 = sizeof(value64);
386391
sysctlbyname("hw.cpufamily",&value64,&length64,NULL,0);
387392
if (value64 ==131287967|| value64 == 458787763 ) return CPU_VORTEX; //A12/M1
388393
if (value64 == 3660830781) return CPU_VORTEX; //A15/M2
@@ -467,6 +472,7 @@ int n=0;
467472
printf("#define NUM_CORES_HP %d\n",cpuhiperf);
468473
#endif
469474
#ifdef __APPLE__
475+
length64 = sizeof(value64);
470476
sysctlbyname("hw.physicalcpu_max",&value,&length,NULL,0);
471477
printf("#define NUM_CORES %d\n",value);
472478
if (cpulowperf >0)
@@ -698,13 +704,17 @@ void get_cpuconfig(void)
698704
case CPU_VORTEX:
699705
printf("#define VORTEX \n");
700706
#ifdef __APPLE__
707+
length64 = sizeof(value64);
701708
sysctlbyname("hw.l1icachesize",&value64,&length64,NULL,0);
702709
printf("#define L1_CODE_SIZE %lld \n",value64);
710+
length64 = sizeof(value64);
703711
sysctlbyname("hw.cachelinesize",&value64,&length64,NULL,0);
704712
printf("#define L1_CODE_LINESIZE %lld \n",value64);
705713
printf("#define L1_DATA_LINESIZE %lld \n",value64);
714+
length64 = sizeof(value64);
706715
sysctlbyname("hw.l1dcachesize",&value64,&length64,NULL,0);
707716
printf("#define L1_DATA_SIZE %lld \n",value64);
717+
length64 = sizeof(value64);
708718
sysctlbyname("hw.l2cachesize",&value64,&length64,NULL,0);
709719
printf("#define L2_SIZE %lld \n",value64);
710720
#endif

0 commit comments

Comments
 (0)