Loading libs/graphicsenv/Android.bp +2 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,8 @@ cc_library_shared { cflags: ["-Wall", "-Werror"], shared_libs: [ "libbase", "libcutils", "libdl_android", "liblog", ], Loading libs/graphicsenv/GraphicsEnv.cpp +116 −26 Original line number Diff line number Diff line Loading @@ -18,20 +18,26 @@ #define LOG_TAG "GraphicsEnv" #include <graphicsenv/GraphicsEnv.h> #include <mutex> #include <dlfcn.h> #include <android-base/file.h> #include <android-base/properties.h> #include <android-base/strings.h> #include <android/dlext.h> #include <log/log.h> #include <sys/prctl.h> #include <mutex> // TODO(b/37049319) Get this from a header once one exists extern "C" { android_namespace_t* android_get_exported_namespace(const char*); android_namespace_t* android_create_namespace(const char* name, const char* ld_library_path, const char* default_library_path, uint64_t type, android_namespace_t* android_create_namespace(const char* name, const char* ld_library_path, const char* default_library_path, uint64_t type, const char* permitted_when_isolated_path, android_namespace_t* parent); bool android_link_namespaces(android_namespace_t* from, android_namespace_t* to, const char* shared_libs_sonames); enum { ANDROID_NAMESPACE_TYPE_ISOLATED = 1, Loading @@ -41,6 +47,69 @@ extern "C" { namespace android { enum NativeLibrary { LLNDK = 0, VNDKSP = 1, }; static constexpr const char* kNativeLibrariesSystemConfigPath[] = {"/etc/llndk.libraries.txt", "/etc/vndksp.libraries.txt"}; static std::string vndkVersionStr() { #ifdef __BIONIC__ std::string version = android::base::GetProperty("ro.vndk.version", ""); if (version != "" && version != "current") { return "." + version; } #endif return ""; } static void insertVndkVersionStr(std::string* fileName) { LOG_ALWAYS_FATAL_IF(!fileName, "fileName should never be nullptr"); size_t insertPos = fileName->find_last_of("."); if (insertPos == std::string::npos) { insertPos = fileName->length(); } fileName->insert(insertPos, vndkVersionStr()); } static bool readConfig(const std::string& configFile, std::vector<std::string>* soNames) { // Read list of public native libraries from the config file. std::string fileContent; if (!base::ReadFileToString(configFile, &fileContent)) { return false; } std::vector<std::string> lines = base::Split(fileContent, "\n"); for (auto& line : lines) { auto trimmedLine = base::Trim(line); if (!trimmedLine.empty()) { soNames->push_back(trimmedLine); } } return true; } static const std::string getSystemNativeLibraries(NativeLibrary type) { static const char* androidRootEnv = getenv("ANDROID_ROOT"); static const std::string rootDir = androidRootEnv != nullptr ? androidRootEnv : "/system"; std::string nativeLibrariesSystemConfig = rootDir + kNativeLibrariesSystemConfigPath[type]; insertVndkVersionStr(&nativeLibrariesSystemConfig); std::vector<std::string> soNames; if (!readConfig(nativeLibrariesSystemConfig, &soNames)) { ALOGE("Failed to retrieve library names from %s", nativeLibrariesSystemConfig.c_str()); return ""; } return base::Join(soNames, ':'); } /*static*/ GraphicsEnv& GraphicsEnv::getInstance() { static GraphicsEnv env; return env; Loading @@ -48,8 +117,8 @@ namespace android { void GraphicsEnv::setDriverPath(const std::string path) { if (!mDriverPath.empty()) { ALOGV("ignoring attempt to change driver path from '%s' to '%s'", mDriverPath.c_str(), path.c_str()); ALOGV("ignoring attempt to change driver path from '%s' to '%s'", mDriverPath.c_str(), path.c_str()); return; } ALOGV("setting driver path to '%s'", path.c_str()); Loading Loading @@ -85,20 +154,41 @@ void GraphicsEnv::setDebugLayers(const std::string layers) { android_namespace_t* GraphicsEnv::getDriverNamespace() { static std::once_flag once; std::call_once(once, [this]() { if (mDriverPath.empty()) return; // If the sphal namespace isn't configured for a device, don't support updatable drivers. // We need a parent namespace to inherit the default search path from. auto sphalNamespace = android_get_exported_namespace("sphal"); if (!sphalNamespace) return; if (mDriverPath.empty()) return; auto vndkNamespace = android_get_exported_namespace("vndk"); if (!vndkNamespace) return; mDriverNamespace = android_create_namespace("gfx driver", nullptr, // ld_library_path mDriverPath.c_str(), // ld_library_path mDriverPath.c_str(), // default_library_path ANDROID_NAMESPACE_TYPE_SHARED | ANDROID_NAMESPACE_TYPE_ISOLATED, nullptr, // permitted_when_isolated_path sphalNamespace); nullptr); const std::string llndkLibraries = getSystemNativeLibraries(NativeLibrary::LLNDK); if (llndkLibraries.empty()) { mDriverNamespace = nullptr; return; } if (!android_link_namespaces(mDriverNamespace, nullptr, llndkLibraries.c_str())) { ALOGE("Failed to link default namespace[%s]", dlerror()); mDriverNamespace = nullptr; return; } const std::string vndkspLibraries = getSystemNativeLibraries(NativeLibrary::VNDKSP); if (vndkspLibraries.empty()) { mDriverNamespace = nullptr; return; } if (!android_link_namespaces(mDriverNamespace, vndkNamespace, vndkspLibraries.c_str())) { ALOGE("Failed to link vndk namespace[%s]", dlerror()); mDriverNamespace = nullptr; return; } }); return mDriverNamespace; } Loading opengl/libs/EGL/Loader.cpp +13 −2 Original line number Diff line number Diff line Loading @@ -261,6 +261,7 @@ void Loader::close(void* driver) void Loader::init_api(void* dso, char const * const * api, char const * const * ref_api, __eglMustCastToProperFunctionPointerType* curr, getProcAddressType getProcAddress) { Loading @@ -270,6 +271,15 @@ void Loader::init_api(void* dso, char scrap[SIZE]; while (*api) { char const * name = *api; if (ref_api) { char const * ref_name = *ref_api; if (std::strcmp(name, ref_name) != 0) { *curr++ = nullptr; ref_api++; continue; } } __eglMustCastToProperFunctionPointerType f = (__eglMustCastToProperFunctionPointerType)dlsym(dso, name); if (f == NULL) { Loading Loading @@ -314,6 +324,7 @@ void Loader::init_api(void* dso, } *curr++ = f; api++; if (ref_api) ref_api++; } } Loading Loading @@ -525,14 +536,14 @@ void *Loader::load_driver(const char* kind, } if (mask & GLESv1_CM) { init_api(dso, gl_names, init_api(dso, gl_names_1, gl_names, (__eglMustCastToProperFunctionPointerType*) &cnx->hooks[egl_connection_t::GLESv1_INDEX]->gl, getProcAddress); } if (mask & GLESv2) { init_api(dso, gl_names, init_api(dso, gl_names, nullptr, (__eglMustCastToProperFunctionPointerType*) &cnx->hooks[egl_connection_t::GLESv2_INDEX]->gl, getProcAddress); Loading opengl/libs/EGL/Loader.h +9 −8 Original line number Diff line number Diff line Loading @@ -59,6 +59,7 @@ private: static __attribute__((noinline)) void init_api(void* dso, char const * const * api, char const * const * ref_api, __eglMustCastToProperFunctionPointerType* curr, getProcAddressType getProcAddress); }; Loading opengl/libs/EGL/egl.cpp +5 −0 Original line number Diff line number Diff line Loading @@ -252,6 +252,11 @@ char const * const gl_names[] = { NULL }; char const * const gl_names_1[] = { #include "../entries_gles1.in" nullptr }; char const * const egl_names[] = { #include "egl_entries.in" NULL Loading Loading
libs/graphicsenv/Android.bp +2 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,8 @@ cc_library_shared { cflags: ["-Wall", "-Werror"], shared_libs: [ "libbase", "libcutils", "libdl_android", "liblog", ], Loading
libs/graphicsenv/GraphicsEnv.cpp +116 −26 Original line number Diff line number Diff line Loading @@ -18,20 +18,26 @@ #define LOG_TAG "GraphicsEnv" #include <graphicsenv/GraphicsEnv.h> #include <mutex> #include <dlfcn.h> #include <android-base/file.h> #include <android-base/properties.h> #include <android-base/strings.h> #include <android/dlext.h> #include <log/log.h> #include <sys/prctl.h> #include <mutex> // TODO(b/37049319) Get this from a header once one exists extern "C" { android_namespace_t* android_get_exported_namespace(const char*); android_namespace_t* android_create_namespace(const char* name, const char* ld_library_path, const char* default_library_path, uint64_t type, android_namespace_t* android_create_namespace(const char* name, const char* ld_library_path, const char* default_library_path, uint64_t type, const char* permitted_when_isolated_path, android_namespace_t* parent); bool android_link_namespaces(android_namespace_t* from, android_namespace_t* to, const char* shared_libs_sonames); enum { ANDROID_NAMESPACE_TYPE_ISOLATED = 1, Loading @@ -41,6 +47,69 @@ extern "C" { namespace android { enum NativeLibrary { LLNDK = 0, VNDKSP = 1, }; static constexpr const char* kNativeLibrariesSystemConfigPath[] = {"/etc/llndk.libraries.txt", "/etc/vndksp.libraries.txt"}; static std::string vndkVersionStr() { #ifdef __BIONIC__ std::string version = android::base::GetProperty("ro.vndk.version", ""); if (version != "" && version != "current") { return "." + version; } #endif return ""; } static void insertVndkVersionStr(std::string* fileName) { LOG_ALWAYS_FATAL_IF(!fileName, "fileName should never be nullptr"); size_t insertPos = fileName->find_last_of("."); if (insertPos == std::string::npos) { insertPos = fileName->length(); } fileName->insert(insertPos, vndkVersionStr()); } static bool readConfig(const std::string& configFile, std::vector<std::string>* soNames) { // Read list of public native libraries from the config file. std::string fileContent; if (!base::ReadFileToString(configFile, &fileContent)) { return false; } std::vector<std::string> lines = base::Split(fileContent, "\n"); for (auto& line : lines) { auto trimmedLine = base::Trim(line); if (!trimmedLine.empty()) { soNames->push_back(trimmedLine); } } return true; } static const std::string getSystemNativeLibraries(NativeLibrary type) { static const char* androidRootEnv = getenv("ANDROID_ROOT"); static const std::string rootDir = androidRootEnv != nullptr ? androidRootEnv : "/system"; std::string nativeLibrariesSystemConfig = rootDir + kNativeLibrariesSystemConfigPath[type]; insertVndkVersionStr(&nativeLibrariesSystemConfig); std::vector<std::string> soNames; if (!readConfig(nativeLibrariesSystemConfig, &soNames)) { ALOGE("Failed to retrieve library names from %s", nativeLibrariesSystemConfig.c_str()); return ""; } return base::Join(soNames, ':'); } /*static*/ GraphicsEnv& GraphicsEnv::getInstance() { static GraphicsEnv env; return env; Loading @@ -48,8 +117,8 @@ namespace android { void GraphicsEnv::setDriverPath(const std::string path) { if (!mDriverPath.empty()) { ALOGV("ignoring attempt to change driver path from '%s' to '%s'", mDriverPath.c_str(), path.c_str()); ALOGV("ignoring attempt to change driver path from '%s' to '%s'", mDriverPath.c_str(), path.c_str()); return; } ALOGV("setting driver path to '%s'", path.c_str()); Loading Loading @@ -85,20 +154,41 @@ void GraphicsEnv::setDebugLayers(const std::string layers) { android_namespace_t* GraphicsEnv::getDriverNamespace() { static std::once_flag once; std::call_once(once, [this]() { if (mDriverPath.empty()) return; // If the sphal namespace isn't configured for a device, don't support updatable drivers. // We need a parent namespace to inherit the default search path from. auto sphalNamespace = android_get_exported_namespace("sphal"); if (!sphalNamespace) return; if (mDriverPath.empty()) return; auto vndkNamespace = android_get_exported_namespace("vndk"); if (!vndkNamespace) return; mDriverNamespace = android_create_namespace("gfx driver", nullptr, // ld_library_path mDriverPath.c_str(), // ld_library_path mDriverPath.c_str(), // default_library_path ANDROID_NAMESPACE_TYPE_SHARED | ANDROID_NAMESPACE_TYPE_ISOLATED, nullptr, // permitted_when_isolated_path sphalNamespace); nullptr); const std::string llndkLibraries = getSystemNativeLibraries(NativeLibrary::LLNDK); if (llndkLibraries.empty()) { mDriverNamespace = nullptr; return; } if (!android_link_namespaces(mDriverNamespace, nullptr, llndkLibraries.c_str())) { ALOGE("Failed to link default namespace[%s]", dlerror()); mDriverNamespace = nullptr; return; } const std::string vndkspLibraries = getSystemNativeLibraries(NativeLibrary::VNDKSP); if (vndkspLibraries.empty()) { mDriverNamespace = nullptr; return; } if (!android_link_namespaces(mDriverNamespace, vndkNamespace, vndkspLibraries.c_str())) { ALOGE("Failed to link vndk namespace[%s]", dlerror()); mDriverNamespace = nullptr; return; } }); return mDriverNamespace; } Loading
opengl/libs/EGL/Loader.cpp +13 −2 Original line number Diff line number Diff line Loading @@ -261,6 +261,7 @@ void Loader::close(void* driver) void Loader::init_api(void* dso, char const * const * api, char const * const * ref_api, __eglMustCastToProperFunctionPointerType* curr, getProcAddressType getProcAddress) { Loading @@ -270,6 +271,15 @@ void Loader::init_api(void* dso, char scrap[SIZE]; while (*api) { char const * name = *api; if (ref_api) { char const * ref_name = *ref_api; if (std::strcmp(name, ref_name) != 0) { *curr++ = nullptr; ref_api++; continue; } } __eglMustCastToProperFunctionPointerType f = (__eglMustCastToProperFunctionPointerType)dlsym(dso, name); if (f == NULL) { Loading Loading @@ -314,6 +324,7 @@ void Loader::init_api(void* dso, } *curr++ = f; api++; if (ref_api) ref_api++; } } Loading Loading @@ -525,14 +536,14 @@ void *Loader::load_driver(const char* kind, } if (mask & GLESv1_CM) { init_api(dso, gl_names, init_api(dso, gl_names_1, gl_names, (__eglMustCastToProperFunctionPointerType*) &cnx->hooks[egl_connection_t::GLESv1_INDEX]->gl, getProcAddress); } if (mask & GLESv2) { init_api(dso, gl_names, init_api(dso, gl_names, nullptr, (__eglMustCastToProperFunctionPointerType*) &cnx->hooks[egl_connection_t::GLESv2_INDEX]->gl, getProcAddress); Loading
opengl/libs/EGL/Loader.h +9 −8 Original line number Diff line number Diff line Loading @@ -59,6 +59,7 @@ private: static __attribute__((noinline)) void init_api(void* dso, char const * const * api, char const * const * ref_api, __eglMustCastToProperFunctionPointerType* curr, getProcAddressType getProcAddress); }; Loading
opengl/libs/EGL/egl.cpp +5 −0 Original line number Diff line number Diff line Loading @@ -252,6 +252,11 @@ char const * const gl_names[] = { NULL }; char const * const gl_names_1[] = { #include "../entries_gles1.in" nullptr }; char const * const egl_names[] = { #include "egl_entries.in" NULL Loading