Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 569834d8 authored by Dimitry Ivanov's avatar Dimitry Ivanov
Browse files

Always call into native loader when load a native library

Namespace has been enabled at native bridge side. And, native loader
wraps both dynamic linker and native bridge now. Frameworks on longer
call native bridge directly when it load a native library, but still
remember whether native bridge is needed for each library.

Bug: http://b/28242460


Change-Id: I6b25e0621168cea0885c890c544b355a68309fa7
Signed-off-by: default avatarZhenhua WANG <zhenhua.wang@intel.com>
parent 189bbd9f
Loading
Loading
Loading
Loading
+90 −84
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@

#include "core_jni_helpers.h"

#include "ScopedUtfChars.h"

#define LOG_TRACE(...)
//#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");
    }

    const char* pathStr = env->GetStringUTFChars(path, NULL);
    ScopedUtfChars pathStr(env, path);
    std::unique_ptr<NativeCode> code;
    bool needNativeBridge = false;

    void* handle = OpenNativeLibrary(env, sdkVersion, pathStr, classLoader, libraryPath);
    if (handle == NULL) {
        if (NativeBridgeIsSupported(pathStr)) {
            handle = NativeBridgeLoadLibrary(pathStr, RTLD_LAZY);
            needNativeBridge = true;
        }
    bool needs_native_bridge = false;
    std::string error_msg;

    void* handle = OpenNativeLibrary(env,
                                     sdkVersion,
                                     pathStr.c_str(),
                                     classLoader,
                                     libraryPath,
                                     &needs_native_bridge,
                                     &error_msg);

    if (handle == nullptr) {
        ALOGW("NativeActivity LoadNativeLibrary(\"%s\") failed: %s",
              pathStr.c_str(),
              error_msg.c_str());
        return 0;
    }
    env->ReleaseStringUTFChars(path, pathStr);

    if (handle != NULL) {
    void* funcPtr = NULL;
    const char* funcStr = env->GetStringUTFChars(funcName, NULL);
        if (needNativeBridge) {
    if (needs_native_bridge) {
        funcPtr = NativeBridgeGetTrampoline(handle, funcStr, NULL, 0);
    } else {
        funcPtr = dlsym(handle, funcStr);
@@ -359,7 +366,6 @@ loadNativeCode_native(JNIEnv* env, jobject clazz, jstring path, jstring funcName
    if (rawSavedState != NULL) {
        env->ReleaseByteArrayElements(savedState, rawSavedState, 0);
    }
    }

    return (jlong)code.release();
}