From 8c72295f47fcb820ad80fe52cbd597a76ff582ec Mon Sep 17 00:00:00 2001 From: Dr-Noob Date: Thu, 27 Apr 2023 22:35:56 +0200 Subject: [PATCH] [v1.03] Add PPC integrity check --- src/ppc/ppc.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/ppc/ppc.c b/src/ppc/ppc.c index 50b0897..70a9df5 100644 --- a/src/ppc/ppc.c +++ b/src/ppc/ppc.c @@ -44,6 +44,17 @@ struct cache* get_cache_info(struct cpuInfo* cpu) { return cach; } +bool check_package_ids_integrity(int* package_ids, int total_cores) { + for(int i=0; i < total_cores; i++) { + if(package_ids[i] >= total_cores || package_ids[i] < 0) { + printBug("check_package_ids_integrity: package_ids[%d]=%d", i, package_ids[i]); + return false; + } + } + + return true; +} + struct topology* get_topology_info(struct cache* cach) { struct topology* topo = emalloc(sizeof(struct topology)); init_topology_struct(topo, cach); @@ -68,6 +79,10 @@ struct topology* get_topology_info(struct cache* cach) { for(int i=0; i < topo->total_cores; i++) package_ids[i] = 0; } + if(!check_package_ids_integrity(package_ids, topo->total_cores)) { + return NULL; + } + // 2. Socket detection int *package_ids_count = emalloc(sizeof(int) * topo->total_cores); for(int i=0; i < topo->total_cores; i++) {