Jesse Hall | 90b25ed | 2016-12-12 12:56:46 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | //#define LOG_NDEBUG 1 |
| 18 | #define LOG_TAG "GraphicsEnv" |
Jiyong Park | 27c39e1 | 2017-05-08 13:00:02 +0900 | [diff] [blame] | 19 | #include <graphicsenv/GraphicsEnv.h> |
Jesse Hall | 90b25ed | 2016-12-12 12:56:46 -0800 | [diff] [blame] | 20 | |
Yiwei Zhang | 64d8921 | 2018-11-27 19:58:29 -0800 | [diff] [blame] | 21 | #include <dlfcn.h> |
Tim Van Patten | 5f744f1 | 2018-12-12 11:46:21 -0700 | [diff] [blame] | 22 | #include <unistd.h> |
Yiwei Zhang | 64d8921 | 2018-11-27 19:58:29 -0800 | [diff] [blame] | 23 | |
| 24 | #include <android-base/file.h> |
| 25 | #include <android-base/properties.h> |
| 26 | #include <android-base/strings.h> |
| 27 | #include <android/dlext.h> |
| 28 | #include <cutils/properties.h> |
| 29 | #include <log/log.h> |
Cody Northrop | 629ce4e | 2018-10-15 07:22:09 -0600 | [diff] [blame] | 30 | #include <sys/prctl.h> |
| 31 | |
Tim Van Patten | 5f744f1 | 2018-12-12 11:46:21 -0700 | [diff] [blame] | 32 | #include <memory> |
Tim Van Patten | 5f744f1 | 2018-12-12 11:46:21 -0700 | [diff] [blame] | 33 | #include <string> |
| 34 | |
| 35 | #include <dlfcn.h> |
Jesse Hall | 53457db | 2016-12-14 16:54:06 -0800 | [diff] [blame] | 36 | |
Jesse Hall | 57de0ff | 2017-05-05 16:41:35 -0700 | [diff] [blame] | 37 | // TODO(b/37049319) Get this from a header once one exists |
| 38 | extern "C" { |
Yiwei Zhang | 64d8921 | 2018-11-27 19:58:29 -0800 | [diff] [blame] | 39 | android_namespace_t* android_get_exported_namespace(const char*); |
| 40 | android_namespace_t* android_create_namespace(const char* name, const char* ld_library_path, |
| 41 | const char* default_library_path, uint64_t type, |
| 42 | const char* permitted_when_isolated_path, |
| 43 | android_namespace_t* parent); |
| 44 | bool android_link_namespaces(android_namespace_t* from, android_namespace_t* to, |
| 45 | const char* shared_libs_sonames); |
Jiyong Park | 9b816a8 | 2018-01-02 17:37:37 +0900 | [diff] [blame] | 46 | |
Yiwei Zhang | 64d8921 | 2018-11-27 19:58:29 -0800 | [diff] [blame] | 47 | enum { |
| 48 | ANDROID_NAMESPACE_TYPE_ISOLATED = 1, |
| 49 | ANDROID_NAMESPACE_TYPE_SHARED = 2, |
| 50 | }; |
Jesse Hall | 57de0ff | 2017-05-05 16:41:35 -0700 | [diff] [blame] | 51 | } |
| 52 | |
Tim Van Patten | 5f744f1 | 2018-12-12 11:46:21 -0700 | [diff] [blame] | 53 | // TODO(ianelliott@): Get the following from an ANGLE header: |
| 54 | #define CURRENT_ANGLE_API_VERSION 2 // Current API verion we are targetting |
| 55 | // Version-2 API: |
| 56 | typedef bool (*fpANGLEGetFeatureSupportUtilAPIVersion)(unsigned int* versionToUse); |
| 57 | typedef bool (*fpANGLEAndroidParseRulesString)(const char* rulesString, void** rulesHandle, |
| 58 | int* rulesVersion); |
| 59 | typedef bool (*fpANGLEGetSystemInfo)(void** handle); |
| 60 | typedef bool (*fpANGLEAddDeviceInfoToSystemInfo)(const char* deviceMfr, const char* deviceModel, |
| 61 | void* handle); |
| 62 | typedef bool (*fpANGLEShouldBeUsedForApplication)(void* rulesHandle, int rulesVersion, |
| 63 | void* systemInfoHandle, const char* appName); |
| 64 | typedef bool (*fpANGLEFreeRulesHandle)(void* handle); |
| 65 | typedef bool (*fpANGLEFreeSystemInfoHandle)(void* handle); |
| 66 | |
Jesse Hall | 90b25ed | 2016-12-12 12:56:46 -0800 | [diff] [blame] | 67 | namespace android { |
| 68 | |
Yiwei Zhang | 64d8921 | 2018-11-27 19:58:29 -0800 | [diff] [blame] | 69 | enum NativeLibrary { |
| 70 | LLNDK = 0, |
| 71 | VNDKSP = 1, |
| 72 | }; |
| 73 | |
| 74 | static constexpr const char* kNativeLibrariesSystemConfigPath[] = {"/etc/llndk.libraries.txt", |
| 75 | "/etc/vndksp.libraries.txt"}; |
| 76 | |
| 77 | static std::string vndkVersionStr() { |
| 78 | #ifdef __BIONIC__ |
| 79 | std::string version = android::base::GetProperty("ro.vndk.version", ""); |
| 80 | if (version != "" && version != "current") { |
| 81 | return "." + version; |
| 82 | } |
| 83 | #endif |
| 84 | return ""; |
| 85 | } |
| 86 | |
| 87 | static void insertVndkVersionStr(std::string* fileName) { |
| 88 | LOG_ALWAYS_FATAL_IF(!fileName, "fileName should never be nullptr"); |
| 89 | size_t insertPos = fileName->find_last_of("."); |
| 90 | if (insertPos == std::string::npos) { |
| 91 | insertPos = fileName->length(); |
| 92 | } |
| 93 | fileName->insert(insertPos, vndkVersionStr()); |
| 94 | } |
| 95 | |
| 96 | static bool readConfig(const std::string& configFile, std::vector<std::string>* soNames) { |
| 97 | // Read list of public native libraries from the config file. |
| 98 | std::string fileContent; |
| 99 | if (!base::ReadFileToString(configFile, &fileContent)) { |
| 100 | return false; |
| 101 | } |
| 102 | |
| 103 | std::vector<std::string> lines = base::Split(fileContent, "\n"); |
| 104 | |
| 105 | for (auto& line : lines) { |
| 106 | auto trimmedLine = base::Trim(line); |
| 107 | if (!trimmedLine.empty()) { |
| 108 | soNames->push_back(trimmedLine); |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | return true; |
| 113 | } |
| 114 | |
| 115 | static const std::string getSystemNativeLibraries(NativeLibrary type) { |
| 116 | static const char* androidRootEnv = getenv("ANDROID_ROOT"); |
| 117 | static const std::string rootDir = androidRootEnv != nullptr ? androidRootEnv : "/system"; |
| 118 | |
| 119 | std::string nativeLibrariesSystemConfig = rootDir + kNativeLibrariesSystemConfigPath[type]; |
| 120 | |
| 121 | insertVndkVersionStr(&nativeLibrariesSystemConfig); |
| 122 | |
| 123 | std::vector<std::string> soNames; |
| 124 | if (!readConfig(nativeLibrariesSystemConfig, &soNames)) { |
| 125 | ALOGE("Failed to retrieve library names from %s", nativeLibrariesSystemConfig.c_str()); |
| 126 | return ""; |
| 127 | } |
| 128 | |
| 129 | return base::Join(soNames, ':'); |
| 130 | } |
| 131 | |
Jesse Hall | 90b25ed | 2016-12-12 12:56:46 -0800 | [diff] [blame] | 132 | /*static*/ GraphicsEnv& GraphicsEnv::getInstance() { |
| 133 | static GraphicsEnv env; |
| 134 | return env; |
| 135 | } |
| 136 | |
Cody Northrop | 629ce4e | 2018-10-15 07:22:09 -0600 | [diff] [blame] | 137 | int GraphicsEnv::getCanLoadSystemLibraries() { |
| 138 | if (property_get_bool("ro.debuggable", false) && prctl(PR_GET_DUMPABLE, 0, 0, 0, 0)) { |
| 139 | // Return an integer value since this crosses library boundaries |
| 140 | return 1; |
| 141 | } |
| 142 | return 0; |
| 143 | } |
| 144 | |
Jesse Hall | 90b25ed | 2016-12-12 12:56:46 -0800 | [diff] [blame] | 145 | void GraphicsEnv::setDriverPath(const std::string path) { |
| 146 | if (!mDriverPath.empty()) { |
Yiwei Zhang | 64d8921 | 2018-11-27 19:58:29 -0800 | [diff] [blame] | 147 | ALOGV("ignoring attempt to change driver path from '%s' to '%s'", mDriverPath.c_str(), |
| 148 | path.c_str()); |
Jesse Hall | 90b25ed | 2016-12-12 12:56:46 -0800 | [diff] [blame] | 149 | return; |
| 150 | } |
| 151 | ALOGV("setting driver path to '%s'", path.c_str()); |
| 152 | mDriverPath = path; |
| 153 | } |
| 154 | |
Tim Van Patten | 5f744f1 | 2018-12-12 11:46:21 -0700 | [diff] [blame] | 155 | void* GraphicsEnv::loadLibrary(std::string name) { |
| 156 | const android_dlextinfo dlextinfo = { |
| 157 | .flags = ANDROID_DLEXT_USE_NAMESPACE, |
| 158 | .library_namespace = getAngleNamespace(), |
| 159 | }; |
| 160 | |
| 161 | std::string libName = std::string("lib") + name + "_angle.so"; |
| 162 | |
| 163 | void* so = android_dlopen_ext(libName.c_str(), RTLD_LOCAL | RTLD_NOW, &dlextinfo); |
| 164 | |
| 165 | if (so) { |
| 166 | ALOGD("dlopen_ext from APK (%s) success at %p", libName.c_str(), so); |
| 167 | return so; |
| 168 | } else { |
| 169 | ALOGE("dlopen_ext(\"%s\") failed: %s", libName.c_str(), dlerror()); |
| 170 | } |
| 171 | |
| 172 | return nullptr; |
| 173 | } |
| 174 | |
| 175 | bool GraphicsEnv::checkAngleRules(void* so) { |
| 176 | char manufacturer[PROPERTY_VALUE_MAX]; |
| 177 | char model[PROPERTY_VALUE_MAX]; |
| 178 | property_get("ro.product.manufacturer", manufacturer, "UNSET"); |
| 179 | property_get("ro.product.model", model, "UNSET"); |
| 180 | |
| 181 | auto ANGLEGetFeatureSupportUtilAPIVersion = |
| 182 | (fpANGLEGetFeatureSupportUtilAPIVersion)dlsym(so, |
| 183 | "ANGLEGetFeatureSupportUtilAPIVersion"); |
| 184 | |
| 185 | if (!ANGLEGetFeatureSupportUtilAPIVersion) { |
| 186 | ALOGW("Cannot find ANGLEGetFeatureSupportUtilAPIVersion function"); |
| 187 | return false; |
| 188 | } |
| 189 | |
| 190 | // Negotiate the interface version by requesting most recent known to the platform |
| 191 | unsigned int versionToUse = CURRENT_ANGLE_API_VERSION; |
| 192 | if (!(ANGLEGetFeatureSupportUtilAPIVersion)(&versionToUse)) { |
| 193 | ALOGW("Cannot use ANGLE feature-support library, it is older than supported by EGL, " |
| 194 | "requested version %u", |
| 195 | versionToUse); |
| 196 | return false; |
| 197 | } |
| 198 | |
| 199 | // Add and remove versions below as needed |
| 200 | bool useAngle = false; |
| 201 | switch (versionToUse) { |
| 202 | case 2: { |
| 203 | ALOGV("Using version %d of ANGLE feature-support library", versionToUse); |
| 204 | void* rulesHandle = nullptr; |
| 205 | int rulesVersion = 0; |
| 206 | void* systemInfoHandle = nullptr; |
| 207 | |
| 208 | // Get the symbols for the feature-support-utility library: |
| 209 | #define GET_SYMBOL(symbol) \ |
| 210 | fp##symbol symbol = (fp##symbol)dlsym(so, #symbol); \ |
| 211 | if (!symbol) { \ |
| 212 | ALOGW("Cannot find " #symbol " in ANGLE feature-support library"); \ |
| 213 | break; \ |
| 214 | } |
| 215 | GET_SYMBOL(ANGLEAndroidParseRulesString); |
| 216 | GET_SYMBOL(ANGLEGetSystemInfo); |
| 217 | GET_SYMBOL(ANGLEAddDeviceInfoToSystemInfo); |
| 218 | GET_SYMBOL(ANGLEShouldBeUsedForApplication); |
| 219 | GET_SYMBOL(ANGLEFreeRulesHandle); |
| 220 | GET_SYMBOL(ANGLEFreeSystemInfoHandle); |
| 221 | |
| 222 | // Parse the rules, obtain the SystemInfo, and evaluate the |
| 223 | // application against the rules: |
| 224 | if (!(ANGLEAndroidParseRulesString)(mRulesBuffer.data(), &rulesHandle, &rulesVersion)) { |
| 225 | ALOGW("ANGLE feature-support library cannot parse rules file"); |
| 226 | break; |
| 227 | } |
| 228 | if (!(ANGLEGetSystemInfo)(&systemInfoHandle)) { |
| 229 | ALOGW("ANGLE feature-support library cannot obtain SystemInfo"); |
| 230 | break; |
| 231 | } |
| 232 | if (!(ANGLEAddDeviceInfoToSystemInfo)(manufacturer, model, systemInfoHandle)) { |
| 233 | ALOGW("ANGLE feature-support library cannot add device info to SystemInfo"); |
| 234 | break; |
| 235 | } |
| 236 | useAngle = (ANGLEShouldBeUsedForApplication)(rulesHandle, rulesVersion, |
| 237 | systemInfoHandle, mAngleAppName.c_str()); |
| 238 | (ANGLEFreeRulesHandle)(rulesHandle); |
| 239 | (ANGLEFreeSystemInfoHandle)(systemInfoHandle); |
| 240 | } break; |
| 241 | |
| 242 | default: |
| 243 | ALOGW("Version %u of ANGLE feature-support library is NOT supported.", versionToUse); |
| 244 | } |
| 245 | |
| 246 | ALOGV("Close temporarily-loaded ANGLE opt-in/out logic"); |
| 247 | return useAngle; |
| 248 | } |
| 249 | |
| 250 | bool GraphicsEnv::shouldUseAngle(std::string appName) { |
| 251 | if (appName != mAngleAppName) { |
| 252 | // Make sure we are checking the app we were init'ed for |
| 253 | ALOGE("App name does not match: expected '%s', got '%s'", mAngleAppName.c_str(), |
| 254 | appName.c_str()); |
| 255 | return false; |
| 256 | } |
| 257 | |
| 258 | return shouldUseAngle(); |
| 259 | } |
| 260 | |
| 261 | bool GraphicsEnv::shouldUseAngle() { |
| 262 | // Make sure we are init'ed |
| 263 | if (mAngleAppName.empty()) { |
Cody Northrop | 2d7af74 | 2019-01-24 16:55:03 -0700 | [diff] [blame] | 264 | ALOGV("App name is empty. setAngleInfo() has not been called to enable ANGLE."); |
Tim Van Patten | 5f744f1 | 2018-12-12 11:46:21 -0700 | [diff] [blame] | 265 | return false; |
| 266 | } |
| 267 | |
| 268 | return mUseAngle; |
| 269 | } |
| 270 | |
| 271 | void GraphicsEnv::updateUseAngle() { |
| 272 | mUseAngle = false; |
| 273 | |
| 274 | const char* ANGLE_PREFER_ANGLE = "angle"; |
| 275 | const char* ANGLE_PREFER_NATIVE = "native"; |
| 276 | |
| 277 | if (mAngleDeveloperOptIn == ANGLE_PREFER_ANGLE) { |
| 278 | ALOGV("User set \"Developer Options\" to force the use of ANGLE"); |
| 279 | mUseAngle = true; |
| 280 | } else if (mAngleDeveloperOptIn == ANGLE_PREFER_NATIVE) { |
| 281 | ALOGV("User set \"Developer Options\" to force the use of Native"); |
| 282 | mUseAngle = false; |
| 283 | } else { |
| 284 | // The "Developer Options" value wasn't set to force the use of ANGLE. Need to temporarily |
| 285 | // load ANGLE and call the updatable opt-in/out logic: |
Cody Northrop | c15d382 | 2019-01-17 10:26:47 -0700 | [diff] [blame] | 286 | void* featureSo = loadLibrary("feature_support"); |
Tim Van Patten | 5f744f1 | 2018-12-12 11:46:21 -0700 | [diff] [blame] | 287 | if (featureSo) { |
| 288 | ALOGV("loaded ANGLE's opt-in/out logic from namespace"); |
| 289 | mUseAngle = checkAngleRules(featureSo); |
| 290 | dlclose(featureSo); |
| 291 | featureSo = nullptr; |
| 292 | } else { |
| 293 | ALOGV("Could not load the ANGLE opt-in/out logic, cannot use ANGLE."); |
| 294 | } |
| 295 | } |
| 296 | } |
| 297 | |
Courtney Goeltzenleuchter | d41ef25 | 2018-09-26 14:37:42 -0600 | [diff] [blame] | 298 | void GraphicsEnv::setAngleInfo(const std::string path, const std::string appName, |
Tim Van Patten | a2a60a0 | 2018-11-09 16:51:15 -0700 | [diff] [blame] | 299 | const std::string developerOptIn, const int rulesFd, |
| 300 | const long rulesOffset, const long rulesLength) { |
Tim Van Patten | 5f744f1 | 2018-12-12 11:46:21 -0700 | [diff] [blame] | 301 | ALOGV("setting ANGLE path to '%s'", path.c_str()); |
| 302 | mAnglePath = path; |
| 303 | ALOGV("setting ANGLE app name to '%s'", appName.c_str()); |
| 304 | mAngleAppName = appName; |
| 305 | ALOGV("setting ANGLE application opt-in to '%s'", developerOptIn.c_str()); |
| 306 | mAngleDeveloperOptIn = developerOptIn; |
Courtney Goeltzenleuchter | d41ef25 | 2018-09-26 14:37:42 -0600 | [diff] [blame] | 307 | |
Tim Van Patten | 5f744f1 | 2018-12-12 11:46:21 -0700 | [diff] [blame] | 308 | lseek(rulesFd, rulesOffset, SEEK_SET); |
| 309 | mRulesBuffer = std::vector<char>(rulesLength + 1); |
| 310 | ssize_t numBytesRead = read(rulesFd, mRulesBuffer.data(), rulesLength); |
| 311 | if (numBytesRead < 0) { |
| 312 | ALOGE("Cannot read rules file: numBytesRead = %zd", numBytesRead); |
| 313 | numBytesRead = 0; |
| 314 | } else if (numBytesRead == 0) { |
| 315 | ALOGW("Empty rules file"); |
Courtney Goeltzenleuchter | d41ef25 | 2018-09-26 14:37:42 -0600 | [diff] [blame] | 316 | } |
Tim Van Patten | 5f744f1 | 2018-12-12 11:46:21 -0700 | [diff] [blame] | 317 | if (numBytesRead != rulesLength) { |
| 318 | ALOGW("Did not read all of the necessary bytes from the rules file." |
| 319 | "expected: %ld, got: %zd", |
| 320 | rulesLength, numBytesRead); |
Tim Van Patten | a2a60a0 | 2018-11-09 16:51:15 -0700 | [diff] [blame] | 321 | } |
Tim Van Patten | 5f744f1 | 2018-12-12 11:46:21 -0700 | [diff] [blame] | 322 | mRulesBuffer[numBytesRead] = '\0'; |
Cody Northrop | 04e7043 | 2018-09-06 10:34:58 -0600 | [diff] [blame] | 323 | |
Tim Van Patten | 5f744f1 | 2018-12-12 11:46:21 -0700 | [diff] [blame] | 324 | // Update the current status of whether we should use ANGLE or not |
| 325 | updateUseAngle(); |
Cody Northrop | 1f00e17 | 2018-04-02 11:23:31 -0600 | [diff] [blame] | 326 | } |
| 327 | |
Victor Khimenko | 4819b52 | 2018-07-13 17:24:18 +0200 | [diff] [blame] | 328 | void GraphicsEnv::setLayerPaths(NativeLoaderNamespace* appNamespace, const std::string layerPaths) { |
Cody Northrop | d2aa3ab | 2017-10-20 09:01:53 -0600 | [diff] [blame] | 329 | if (mLayerPaths.empty()) { |
| 330 | mLayerPaths = layerPaths; |
| 331 | mAppNamespace = appNamespace; |
| 332 | } else { |
| 333 | ALOGV("Vulkan layer search path already set, not clobbering with '%s' for namespace %p'", |
Yiwei Zhang | 64d8921 | 2018-11-27 19:58:29 -0800 | [diff] [blame] | 334 | layerPaths.c_str(), appNamespace); |
Cody Northrop | d2aa3ab | 2017-10-20 09:01:53 -0600 | [diff] [blame] | 335 | } |
| 336 | } |
| 337 | |
Victor Khimenko | 4819b52 | 2018-07-13 17:24:18 +0200 | [diff] [blame] | 338 | NativeLoaderNamespace* GraphicsEnv::getAppNamespace() { |
Cody Northrop | d2aa3ab | 2017-10-20 09:01:53 -0600 | [diff] [blame] | 339 | return mAppNamespace; |
| 340 | } |
| 341 | |
Tim Van Patten | 5f744f1 | 2018-12-12 11:46:21 -0700 | [diff] [blame] | 342 | std::string& GraphicsEnv::getAngleAppName() { |
| 343 | return mAngleAppName; |
Cody Northrop | 04e7043 | 2018-09-06 10:34:58 -0600 | [diff] [blame] | 344 | } |
| 345 | |
Courtney Goeltzenleuchter | 30ad2ab | 2018-10-30 08:20:44 -0600 | [diff] [blame] | 346 | const std::string& GraphicsEnv::getLayerPaths() { |
Cody Northrop | d2aa3ab | 2017-10-20 09:01:53 -0600 | [diff] [blame] | 347 | return mLayerPaths; |
| 348 | } |
| 349 | |
Courtney Goeltzenleuchter | 30ad2ab | 2018-10-30 08:20:44 -0600 | [diff] [blame] | 350 | const std::string& GraphicsEnv::getDebugLayers() { |
Cody Northrop | d2aa3ab | 2017-10-20 09:01:53 -0600 | [diff] [blame] | 351 | return mDebugLayers; |
| 352 | } |
| 353 | |
Cody Northrop | b9b01b6 | 2018-10-23 13:13:10 -0600 | [diff] [blame] | 354 | const std::string& GraphicsEnv::getDebugLayersGLES() { |
| 355 | return mDebugLayersGLES; |
| 356 | } |
| 357 | |
Cody Northrop | d2aa3ab | 2017-10-20 09:01:53 -0600 | [diff] [blame] | 358 | void GraphicsEnv::setDebugLayers(const std::string layers) { |
| 359 | mDebugLayers = layers; |
| 360 | } |
| 361 | |
Cody Northrop | b9b01b6 | 2018-10-23 13:13:10 -0600 | [diff] [blame] | 362 | void GraphicsEnv::setDebugLayersGLES(const std::string layers) { |
| 363 | mDebugLayersGLES = layers; |
| 364 | } |
| 365 | |
Jesse Hall | 53457db | 2016-12-14 16:54:06 -0800 | [diff] [blame] | 366 | android_namespace_t* GraphicsEnv::getDriverNamespace() { |
| 367 | static std::once_flag once; |
| 368 | std::call_once(once, [this]() { |
Yiwei Zhang | 64d8921 | 2018-11-27 19:58:29 -0800 | [diff] [blame] | 369 | if (mDriverPath.empty()) return; |
| 370 | |
| 371 | auto vndkNamespace = android_get_exported_namespace("vndk"); |
| 372 | if (!vndkNamespace) return; |
| 373 | |
Jesse Hall | 57de0ff | 2017-05-05 16:41:35 -0700 | [diff] [blame] | 374 | mDriverNamespace = android_create_namespace("gfx driver", |
Peiyong Lin | 2e9c74c | 2018-10-24 11:18:07 -0700 | [diff] [blame] | 375 | mDriverPath.c_str(), // ld_library_path |
Jesse Hall | 57de0ff | 2017-05-05 16:41:35 -0700 | [diff] [blame] | 376 | mDriverPath.c_str(), // default_library_path |
Yiwei Zhang | 64d8921 | 2018-11-27 19:58:29 -0800 | [diff] [blame] | 377 | ANDROID_NAMESPACE_TYPE_ISOLATED, |
Jesse Hall | 57de0ff | 2017-05-05 16:41:35 -0700 | [diff] [blame] | 378 | nullptr, // permitted_when_isolated_path |
Yiwei Zhang | 64d8921 | 2018-11-27 19:58:29 -0800 | [diff] [blame] | 379 | nullptr); |
| 380 | |
| 381 | const std::string llndkLibraries = getSystemNativeLibraries(NativeLibrary::LLNDK); |
| 382 | if (llndkLibraries.empty()) { |
| 383 | mDriverNamespace = nullptr; |
| 384 | return; |
| 385 | } |
| 386 | if (!android_link_namespaces(mDriverNamespace, nullptr, llndkLibraries.c_str())) { |
| 387 | ALOGE("Failed to link default namespace[%s]", dlerror()); |
| 388 | mDriverNamespace = nullptr; |
| 389 | return; |
| 390 | } |
| 391 | |
| 392 | const std::string vndkspLibraries = getSystemNativeLibraries(NativeLibrary::VNDKSP); |
| 393 | if (vndkspLibraries.empty()) { |
| 394 | mDriverNamespace = nullptr; |
| 395 | return; |
| 396 | } |
| 397 | if (!android_link_namespaces(mDriverNamespace, vndkNamespace, vndkspLibraries.c_str())) { |
| 398 | ALOGE("Failed to link vndk namespace[%s]", dlerror()); |
| 399 | mDriverNamespace = nullptr; |
| 400 | return; |
| 401 | } |
Jesse Hall | 53457db | 2016-12-14 16:54:06 -0800 | [diff] [blame] | 402 | }); |
Yiwei Zhang | 64d8921 | 2018-11-27 19:58:29 -0800 | [diff] [blame] | 403 | |
Jesse Hall | 53457db | 2016-12-14 16:54:06 -0800 | [diff] [blame] | 404 | return mDriverNamespace; |
| 405 | } |
| 406 | |
Cody Northrop | 1f00e17 | 2018-04-02 11:23:31 -0600 | [diff] [blame] | 407 | android_namespace_t* GraphicsEnv::getAngleNamespace() { |
Cody Northrop | 3892cfa | 2019-01-30 10:03:12 -0700 | [diff] [blame^] | 408 | std::lock_guard<std::mutex> lock(mNamespaceMutex); |
Cody Northrop | 1f00e17 | 2018-04-02 11:23:31 -0600 | [diff] [blame] | 409 | |
Cody Northrop | 3892cfa | 2019-01-30 10:03:12 -0700 | [diff] [blame^] | 410 | if (mAngleNamespace) { |
| 411 | return mAngleNamespace; |
| 412 | } |
| 413 | |
| 414 | if (mAnglePath.empty()) { |
| 415 | ALOGV("mAnglePath is empty, not creating ANGLE namespace"); |
| 416 | return nullptr; |
| 417 | } |
| 418 | |
| 419 | mAngleNamespace = android_create_namespace("ANGLE", |
| 420 | nullptr, // ld_library_path |
| 421 | mAnglePath.c_str(), // default_library_path |
| 422 | ANDROID_NAMESPACE_TYPE_SHARED | |
| 423 | ANDROID_NAMESPACE_TYPE_ISOLATED, |
| 424 | nullptr, // permitted_when_isolated_path |
| 425 | nullptr); |
| 426 | |
| 427 | ALOGD_IF(!mAngleNamespace, "Could not create ANGLE namespace from default"); |
Cody Northrop | 1f00e17 | 2018-04-02 11:23:31 -0600 | [diff] [blame] | 428 | |
| 429 | return mAngleNamespace; |
| 430 | } |
| 431 | |
Jesse Hall | 90b25ed | 2016-12-12 12:56:46 -0800 | [diff] [blame] | 432 | } // namespace android |