Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash Seen with unspecified micro arch for Windows On Arm devices when getting the cpu micro arch info to check the core type #235

Open
yganup opened this issue Apr 4, 2024 · 0 comments
Labels

Comments

@yganup
Copy link

yganup commented Apr 4, 2024

For WOA(windows on ARM) devices where the CPU string does not match any string in woa_chips, cpuinfo_get_uarch returns NULL (index = 0 and cpuinfo_uarchs_count = 0 for unspecified CPU).

const struct cpuinfo_uarch_info* cpuinfo_get_uarch(uint32_t index) {
	if (!cpuinfo_is_initialized) {
		cpuinfo_log_fatal("cpuinfo_get_%s called before cpuinfo is initialized", "uarch");
	}
#if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64 || CPUINFO_ARCH_RISCV32 || CPUINFO_ARCH_RISCV64
	if CPUINFO_UNLIKELY (index >= cpuinfo_uarchs_count) {
		 return NULL; 
	}
	return &cpuinfo_uarchs[index];
#else
	if CPUINFO_UNLIKELY (index != 0) {
		return NULL;
	}
	return &cpuinfo_global_uarch;
#endif

To gracefully handle return of cpuinfo_uarch_info below are the 2 methods can be used

  1. Return a dummy cpuinfo_uarch_info struct with uarch = cpuinfo_uarch_unknown (0) instead of NULL.
  2. As part of usage guidelines for cpuinfo_get_uarch, Include NULL checking for return value
// check for ARM cortex a-53 CPU 
cpuinfo_uarch_info *cpu_data = cpuinfo_get_uarch(cpuinfo_get_current_uarch_index())

if( cpu_data!= NULL)
{
 switch (cpu_data->uarch){
   case cpuinfo_uarch_cortex_a53:
   case cpuinfo_uarch_cortex_a55r0:
   case cpuinfo_uarch_cortex_a55:
     return true;
   default:
     return false;
 }
return false

This would help stability of libraries/binaries using cpuinfo on devices with unknown micro arch for Windows on ARM devices .
Also I would assume the same issue would be seen for other platforms as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants