Merge "Always call into native loader when load a native library"

This commit is contained in:
Dimitry Ivanov
2016-10-26 18:27:37 +00:00
committed by Gerrit Code Review

View File

@@ -45,6 +45,7 @@
#include "core_jni_helpers.h" #include "core_jni_helpers.h"
#include "ScopedUtfChars.h"
#define LOG_TRACE(...) #define LOG_TRACE(...)
//#define LOG_TRACE(...) ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__) //#define LOG_TRACE(...) ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__)
@@ -264,23 +265,29 @@ loadNativeCode_native(JNIEnv* env, jobject clazz, jstring path, jstring funcName
ALOGD("loadNativeCode_native"); ALOGD("loadNativeCode_native");
} }
const char* pathStr = env->GetStringUTFChars(path, NULL); ScopedUtfChars pathStr(env, path);
std::unique_ptr<NativeCode> code; std::unique_ptr<NativeCode> code;
bool needNativeBridge = false; bool needs_native_bridge = false;
std::string error_msg;
void* handle = OpenNativeLibrary(env, sdkVersion, pathStr, classLoader, libraryPath); void* handle = OpenNativeLibrary(env,
if (handle == NULL) { sdkVersion,
if (NativeBridgeIsSupported(pathStr)) { pathStr.c_str(),
handle = NativeBridgeLoadLibrary(pathStr, RTLD_LAZY); classLoader,
needNativeBridge = true; libraryPath,
} &needs_native_bridge,
} &error_msg);
env->ReleaseStringUTFChars(path, pathStr);
if (handle == nullptr) {
ALOGW("NativeActivity LoadNativeLibrary(\"%s\") failed: %s",
pathStr.c_str(),
error_msg.c_str());
return 0;
}
if (handle != NULL) {
void* funcPtr = NULL; void* funcPtr = NULL;
const char* funcStr = env->GetStringUTFChars(funcName, NULL); const char* funcStr = env->GetStringUTFChars(funcName, NULL);
if (needNativeBridge) { if (needs_native_bridge) {
funcPtr = NativeBridgeGetTrampoline(handle, funcStr, NULL, 0); funcPtr = NativeBridgeGetTrampoline(handle, funcStr, NULL, 0);
} else { } else {
funcPtr = dlsym(handle, funcStr); funcPtr = dlsym(handle, funcStr);
@@ -359,7 +366,6 @@ loadNativeCode_native(JNIEnv* env, jobject clazz, jstring path, jstring funcName
if (rawSavedState != NULL) { if (rawSavedState != NULL) {
env->ReleaseByteArrayElements(savedState, rawSavedState, 0); env->ReleaseByteArrayElements(savedState, rawSavedState, 0);
} }
}
return (jlong)code.release(); return (jlong)code.release();
} }