From 3e4db84c4fe4e2e078e1cfd2720f3b069fd13183 Mon Sep 17 00:00:00 2001 From: Dmytro Chystiakov Date: Thu, 7 Nov 2019 12:09:36 -0800 Subject: Fix for native bridge fallback in egl layers Add trampoline to support native bridge for egl layers Test: Run CtsGpuToolsHostTestCases module Bug: b/144108378 Change-Id: I0f6f155b0f423760949efa79680082c87a4ef2f3 Signed-off-by: Dmytro Chystiakov --- opengl/libs/EGL/egl_layers.cpp | 20 ++++++++------------ 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 ac01dc8f96..9b1b522731 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(dlsym(handle, init_func.c_str())); + layer_init_func LayerInit = GetTrampoline(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(dlsym(handle, setup_func.c_str())); + layer_setup_func LayerSetup = GetTrampoline(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 #include -#include +#include +#include +#include #include "egl_platform_entries.h" +#include +#include + typedef __eglMustCastToProperFunctionPointerType EGLFuncPointer; namespace android { @@ -54,10 +59,21 @@ public: std::vector 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 + Func GetTrampoline(const char* name) const { + if (native_bridge_) { + return reinterpret_cast(android::NativeBridgeGetTrampoline( + dlhandle_, name, nullptr, 0)); + } + return reinterpret_cast(dlsym(dlhandle_, name)); + } }; }; // namespace android -- cgit v1.2.3-59-g8ed1b