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

Commit e266c375 authored by Dimitry Ivanov's avatar Dimitry Ivanov Committed by Gerrit Code Review
Browse files

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

parents ab005465 569834d8
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();
}