#define ARR_SIZE(x) (sizeof(x)/sizeof(x[0]))
#define SO_NAME_MAX (4096)
+
#define IMPOSSIBLE_LIB_NAME "/mixed/"
#define IMPOSSIBLE_LIB_LEN (sizeof(IMPOSSIBLE_LIB_NAME)-1)
+
#define ARMABI "armeabi"
#define ARMV7ABI "armeabi-v7a"
#define ARM64ABI "arm64-v8a"
#define X86ABI "x86"
#define X8664ABI "x86_64"
-#define ARMABI_NAME_PREFIX "arm"
#define APK_LIB "lib/"
#define APK_LIB_LEN (sizeof(APK_LIB) - 1)
#define P_LOG(...)
#endif
-#define OEMWHITE "/vendor/etc/misc/.OEMWhiteList"
-#define OEMBLACK "/vendor/etc/misc/.OEMBlackList"
-#define THIRDPARTY "/vendor/etc/misc/.ThirdPartySO"
+#define LISTPATH "/vendor/etc/misc/"
+#define OEMWHITE LISTPATH ".OEMWhiteList"
+#define OEMBLACK LISTPATH ".OEMBlackList"
+#define THIRDPARTY LISTPATH ".ThirdPartySO"
// load once, hold until poweroff
static Vector <char*> thirdPartySO;
static const char* iaRelated[] = {"intel", "intl", "atom", "x86", "x64"};
-//////////////////////////////////////////////////////////////////////
+void freeAllString(Vector<char*>& list) {
+ Vector<char*>::iterator it = list.begin();
+ while (it != list.end()) {
+ if (*it != NULL) {
+ P_LOG("freeAllSring %p , %s", it, *it);
+ free(*it);
+ *it = NULL;
+ }
+ it++;
+ }
+}
+
void getConfig(const char* cfgFile , Vector<char*>& cfgVec) {
int read = -1;
char *line = NULL;
return;
}
+ freeAllString(cfgVec);
+ cfgVec.clear();
+
while ((read = getline(&line, &len, fp)) != -1) {
int i = 0 , j = 0;
char *cfgline = (char*)malloc(len);
- if (!cfgline) {
+ if (cfgline == NULL) {
P_LOG("malloc error");
break;
}
fclose(fp);
}
-//////////////////////////////////////////////////////////////////////
-void freeAllString(Vector<char*>& list) {
- Vector<char*>::iterator it = list.begin();
- while (it != list.end()) {
- if (*it != NULL) {
- P_LOG("freeAllSring %p , %s", it, *it);
- free(*it);
- *it = NULL;
- }
- it++;
- }
-}
-
-//////////////////////////////////////////////////////////////////////
bool isInOEMWhiteList(const char* pkgName) {
bool result = false;
- if (!pkgName) return result;
+ if (pkgName == NULL) {
+ return result;
+ }
if (!whiteload) {
getConfig(OEMWHITE, cfgWhite);
return result;
}
-//////////////////////////////////////////////////////////////////////
bool isInOEMBlackList(const char* pkgName) {
bool result = false;
- if (!pkgName) return result;
+ if (pkgName == NULL) {
+ return result;
+ }
if (!blackload) {
getConfig(OEMBLACK, cfgBlack);
return result;
}
-
-//////////////////////////////////////////////////////////////////////
bool isReliableLib(Vector<char*>& libList) {
unsigned sz = libList.size();
int len = ARR_SIZE(iaRelated);
return false;
}
-
-//////////////////////////////////////////////////////////////////////
static bool isValidELF(char* buffer) {
if (buffer[EI_MAG0] != ELFMAG0 &&
buffer[EI_MAG1] != ELFMAG1 &&
uint16_t machine_code = *((uint16_t*)(&buffer[ELF_MACHINE_OFFSET]));
bool mixed = false;
if (isX86_64) {
- if (machine_code != EM_X86_64)
+ if (machine_code != EM_X86_64) {
mixed = true;
+ }
} else {
- if (machine_code != EM_386)
+ if (machine_code != EM_386) {
mixed = true;
+ }
}
return mixed;
}
size_t sz = thirdPartySO.size();
for (size_t i = 0; i < sz; i++) {
// thirdPartySO[i] won't be NULL
+ assert(thirdPartySO[i] != NULL);
size_t n = strlen(thirdPartySO[i]);
// three char for ".so"
int j = libLen - 4;
P_LOG("in insertionSort, list size = %d\n", list.size());
for (size_t i = 1; i < list.size(); i++) {
- char* x = list[i];
-
int j = i - 1;
+ char* x = list[i];
P_LOG("sort 1. x=%s, i=%d, j=%d\n", x, i, j);
while (j >= 0 && (strcmp(list[j], x) > 0)) {
list.replaceAt(list[j], j + 1);
}
}
-
-
-//////////////////////////////////////////////////////////////////////
// Use armRef as a reference, compare all libraries of iaRef with all
// libraries of armRef.If the two are match or iaRef is more, iaRef
// will be returned with *result and true is return value. Or else,
}
result = compareLibList(*iaRef3rdPartyLibList, *armRef3rdPartyLibList);
+ armRef3rdPartyLibList->clear();
delete armRef3rdPartyLibList;
+ iaRef3rdPartyLibList->clear();
delete iaRef3rdPartyLibList;
return result;
}
}
-size_t ABIPicker::getSpecficABILibCount(const char* abiName) {
+bool ABIPicker::isABILibValid(const char* abiName) {
Vector<char*>* specificAbiLibList = getLibList(abiName);
- return specificAbiLibList && specificAbiLibList->size();
+ return ((specificAbiLibList && specificAbiLibList->size()) > 0);
}
bool ABIPicker::foundMixedELF(const char* abiName) {
return true;
}
-
-//////////////////////////////////////////////////////////////////////
ABIPicker::ABIPicker(const char* pkgName, Vector<ScopedUtfChars*> abiList) {
mLibList = new Vector<struct libInfo*>();
mpkgName = strdup(pkgName);
- if (!mpkgName) {
+ if (mpkgName == NULL) {
P_LOG("ABIPicker Construct Allocated space fails");
}
Vector<ScopedUtfChars*>::iterator it = abiList.begin();
struct libInfo* tmp = (struct libInfo*)calloc(1,
sizeof(struct libInfo));
- if (!tmp) {
+ if (tmp == NULL) {
P_LOG("ABIPicker Construct Allocated space fail %s", (*it)->c_str());
break;
}
it++;
}
mLibList->clear();
- delete(mLibList);
+ delete mLibList;
}
bool ABIPicker::buildNativeLibList(void* apkHandle) {
bool ret = false;
- if (!apkHandle) {
+ if (apkHandle == NULL) {
ALOGE("apkHandle is NULL\n");
return ret;
}
unCompBuff = NULL;
unCompBuff = (char*)malloc(unCompLen);
- if (!unCompBuff) {
+ if (unCompBuff == NULL) {
ALOGE("malloc failed size %d\n", unCompLen);
ret = false;
break;
bool x8664HasMixedELF = foundMixedELF(X8664ABI);
bool x86HasMixedELF = foundMixedELF(X86ABI);
- size_t armv7LibCount = getSpecficABILibCount(ARMV7ABI);
- size_t armv5LibCount = getSpecficABILibCount(ARMABI);
- size_t armv8LibCount = getSpecficABILibCount(ARM64ABI);
- size_t x86LibCount = x86HasMixedELF ? 0 : getSpecficABILibCount(X86ABI);
- size_t x8664LibCount = x8664HasMixedELF ? 0 : getSpecficABILibCount(X8664ABI);
- P_LOG("armv7LibCount:%d armv5LibCount:%d armv8LibCount:%d x86LibCount:%d x8664LibCount:%d", armv7LibCount, armv5LibCount, armv8LibCount, x86LibCount, x8664LibCount);
+ bool armv7LibValid = isABILibValid(ARMV7ABI);
+ bool armv5LibValid = isABILibValid(ARMABI);
+ bool armv8LibValid = isABILibValid(ARM64ABI);
+ bool x86LibValid = x86HasMixedELF ? 0 : isABILibValid(X86ABI);
+ bool x8664LibValid = x8664HasMixedELF ? 0 : isABILibValid(X8664ABI);
// in OEMBlackList, need to be supported by bt
// but in case of armlib doesn't exist, we choose x86 or x86_64
if (isInOEMBlackList(mpkgName)) {
- if (armv7LibCount > 0) {
+ if (armv7LibValid) {
return getAbiIndex(ARMV7ABI);
- } else if (armv5LibCount > 0) {
+ } else if (armv5LibValid) {
return getAbiIndex(ARMABI);
- } else if (armv8LibCount > 0) {
+ } else if (armv8LibValid) {
return getAbiIndex(ARM64ABI);
}
}
char arm64Ref[ABI_NAME_MAX_LENGTH];
- if (armv8LibCount > 0) {
+ if (armv8LibValid) {
snprintf(arm64Ref, sizeof(ARM64ABI), "%s", ARM64ABI);
} else {
arm64Ref[0] = '\0';
}
char arm32Ref[ABI_NAME_MAX_LENGTH];
- if (armv7LibCount > 0) {
+ if (armv7LibValid) {
snprintf(arm32Ref, sizeof(ARMV7ABI), "%s", ARMV7ABI);
- } else if (armv5LibCount > 0) {
+ } else if (armv5LibValid) {
snprintf(arm32Ref, sizeof(ARMABI), "%s", ARMABI);
} else {
arm32Ref[0] = '\0';
}
char ia32Ref[ABI_NAME_MAX_LENGTH];
- if (x86LibCount > 0) {
+ if (x86LibValid) {
snprintf(ia32Ref, sizeof(X86ABI), "%s", X86ABI);
} else {
ia32Ref[0] = '\0';
}
char ia64Ref[ABI_NAME_MAX_LENGTH];
- if (x8664LibCount > 0) {
+ if (x8664LibValid) {
snprintf(ia64Ref, ABI_NAME_MAX_LENGTH, "%s", X8664ABI);
} else {
ia64Ref[0] = '\0';
return (jint)abiType;
}
+ int abiIndex = 0;
abiFlag[apkdir_size] = '/';
abiFlag[apkdir_size + 1] = '.';
- for (int i = 0; i < numAbis; i++) {
+ for (abiIndex = 0; abiIndex < numAbis; abiIndex++) {
ScopedUtfChars* abiName = new ScopedUtfChars(env,
- (jstring)env->GetObjectArrayElement(javaCpuAbisToSearch, i));
- assert(abiName != NULL);
- assert(abiName->c_str() != NULL);
- if (strlcpy(abiFlag + apkdir_size + 2, abiName->c_str(), 256 - apkdir_size - 2)
- == abiName->size()) {
- if (access(abiFlag, F_OK) == 0) {
- abiType = i;
- for (int j = 0; j < i; ++j) {
- delete supportedAbis[j];
- }
- delete abiName;
- return (jint)abiType;
- }
+ (jstring)env->GetObjectArrayElement(javaCpuAbisToSearch, abiIndex));
+ supportedAbis.push_back(abiName);
+ if (abiName == NULL || abiName->c_str() == NULL || abiName->size() <= 0) {
+ break;
+ }
+ if ((strlcpy(abiFlag + apkdir_size + 2, abiName->c_str(), 256 - apkdir_size - 2)
+ == abiName->size()) && (access(abiFlag, F_OK) == 0)) {
+ abiType = abiIndex;
+ break;
}
+ }
- supportedAbis.push_back(abiName);
+ if (abiIndex < numAbis) {
+ for (int j = 0; j < abiIndex; ++j) {
+ if (supportedAbis[j] != NULL) {
+ delete supportedAbis[j];
+ }
+ }
+ return (jint)abiType;
}
do {
- if (abiType < 0 || abiType >= numAbis ) {
+ if (abiType < 0 || abiType >= numAbis) {
break;
}
if (abiType >= 0 && abiType < numAbis &&
(strlcpy(abiFlag + apkdir_size + 2, supportedAbis[abiType]->c_str(),
256 - apkdir_size - 2) == supportedAbis[abiType]->size())) {
- creat(abiFlag, 0644);
+ int flagFp = creat(abiFlag, 0644);
+ if (flagFp != -1) {
+ close(flagFp);
+ }
}
} while(0);