diff options
author | 2019-11-13 17:37:55 -0800 | |
---|---|---|
committer | 2019-11-13 17:37:55 -0800 | |
commit | 1256e378e82cdc696f7c05846537b52ad8a63cf6 (patch) | |
tree | 0af6dfa59bb011a2a1dfac717d61292f9655bf37 | |
parent | d64198e6ee5be7da197cce0c8dcf62eddc03ee9c (diff) | |
parent | d1c33e3c226a5bf80a2db3529adb8188e6394d8e (diff) |
Merge "Fix for native bridge fallback in egl layers" am: a0a5ed3bdb am: cdb8facd6c
am: d1c33e3c22
Change-Id: I932d8af8d08f14873352ccbf52b8bb5585aa0488
-rw-r--r-- | opengl/libs/EGL/egl_layers.cpp | 20 | ||||
-rw-r--r-- | opengl/libs/EGL/egl_layers.h | 20 |
2 files changed, 26 insertions, 14 deletions
diff --git a/opengl/libs/EGL/egl_layers.cpp b/opengl/libs/EGL/egl_layers.cpp index ba7cacdbf2..408e76b0ce 100644 --- a/opengl/libs/EGL/egl_layers.cpp +++ b/opengl/libs/EGL/egl_layers.cpp @@ -379,14 +379,12 @@ void LayerLoader::LoadLayers() { // any symbol dependencies will be resolved by system libraries. They // can't safely use libc++_shared, for example. Which is one reason // (among several) we only allow them in non-user builds. - void* handle = nullptr; auto app_namespace = android::GraphicsEnv::getInstance().getAppNamespace(); if (app_namespace && !android::base::StartsWith(layer, kSystemLayerLibraryDir)) { - bool native_bridge = false; char* error_message = nullptr; - handle = OpenNativeLibraryInNamespace( - app_namespace, layer.c_str(), &native_bridge, &error_message); - if (!handle) { + dlhandle_ = OpenNativeLibraryInNamespace( + app_namespace, layer.c_str(), &native_bridge_, &error_message); + if (!dlhandle_) { ALOGE("Failed to load layer %s with error: %s", layer.c_str(), error_message); android::NativeLoaderFreeErrorMessage(error_message); @@ -394,11 +392,11 @@ void LayerLoader::LoadLayers() { } } else { - handle = dlopen(layer.c_str(), RTLD_NOW | RTLD_LOCAL); + dlhandle_ = dlopen(layer.c_str(), RTLD_NOW | RTLD_LOCAL); } - if (handle) { - ALOGV("Loaded layer handle (%llu) for layer %s", (unsigned long long)handle, + if (dlhandle_) { + ALOGV("Loaded layer handle (%llu) for layer %s", (unsigned long long)dlhandle_, layers[i].c_str()); } else { // If the layer is found but can't be loaded, try setenforce 0 @@ -411,8 +409,7 @@ void LayerLoader::LoadLayers() { std::string init_func = "AndroidGLESLayer_Initialize"; ALOGV("Looking for entrypoint %s", init_func.c_str()); - layer_init_func LayerInit = - reinterpret_cast<layer_init_func>(dlsym(handle, init_func.c_str())); + layer_init_func LayerInit = GetTrampoline<layer_init_func>(init_func.c_str()); if (LayerInit) { ALOGV("Found %s for layer %s", init_func.c_str(), layer.c_str()); layer_init_.push_back(LayerInit); @@ -425,8 +422,7 @@ void LayerLoader::LoadLayers() { std::string setup_func = "AndroidGLESLayer_GetProcAddress"; ALOGV("Looking for entrypoint %s", setup_func.c_str()); - layer_setup_func LayerSetup = - reinterpret_cast<layer_setup_func>(dlsym(handle, setup_func.c_str())); + layer_setup_func LayerSetup = GetTrampoline<layer_setup_func>(setup_func.c_str()); if (LayerSetup) { ALOGV("Found %s for layer %s", setup_func.c_str(), layer.c_str()); layer_setup_.push_back(LayerSetup); diff --git a/opengl/libs/EGL/egl_layers.h b/opengl/libs/EGL/egl_layers.h index e401b448cf..1e2783fc98 100644 --- a/opengl/libs/EGL/egl_layers.h +++ b/opengl/libs/EGL/egl_layers.h @@ -21,10 +21,15 @@ #include <unordered_map> #include <vector> -#include <EGL/egldefs.h> +#include <android/dlext.h> +#include <dlfcn.h> +#include <EGL/egldefs.h> #include "egl_platform_entries.h" +#include <nativebridge/native_bridge.h> +#include <nativeloader/native_loader.h> + typedef __eglMustCastToProperFunctionPointerType EGLFuncPointer; namespace android { @@ -54,10 +59,21 @@ public: std::vector<layer_setup_func> layer_setup_; private: - LayerLoader() : layers_loaded_(false), initialized_(false), current_layer_(0){}; + LayerLoader() : layers_loaded_(false), initialized_(false), current_layer_(0), dlhandle_(nullptr), native_bridge_(false){}; bool layers_loaded_; bool initialized_; unsigned current_layer_; + void* dlhandle_; + bool native_bridge_; + + template<typename Func = void*> + Func GetTrampoline(const char* name) const { + if (native_bridge_) { + return reinterpret_cast<Func>(android::NativeBridgeGetTrampoline( + dlhandle_, name, nullptr, 0)); + } + return reinterpret_cast<Func>(dlsym(dlhandle_, name)); + } }; }; // namespace android |