blob: 02760081febce0aea38e7c956192190231989515 [file] [log] [blame]
Jesse Hall90b25ed2016-12-12 12:56:46 -08001/*
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 Park27c39e12017-05-08 13:00:02 +090019#include <graphicsenv/GraphicsEnv.h>
Jesse Hall90b25ed2016-12-12 12:56:46 -080020
Jesse Hall53457db2016-12-14 16:54:06 -080021#include <mutex>
22
Jesse Hall90b25ed2016-12-12 12:56:46 -080023#include <log/log.h>
Jesse Hall53457db2016-12-14 16:54:06 -080024#include <nativeloader/dlext_namespaces.h>
Jesse Hall90b25ed2016-12-12 12:56:46 -080025
26namespace android {
27
28/*static*/ GraphicsEnv& GraphicsEnv::getInstance() {
29 static GraphicsEnv env;
30 return env;
31}
32
33void GraphicsEnv::setDriverPath(const std::string path) {
34 if (!mDriverPath.empty()) {
35 ALOGV("ignoring attempt to change driver path from '%s' to '%s'",
36 mDriverPath.c_str(), path.c_str());
37 return;
38 }
39 ALOGV("setting driver path to '%s'", path.c_str());
40 mDriverPath = path;
41}
42
Jesse Hall53457db2016-12-14 16:54:06 -080043android_namespace_t* GraphicsEnv::getDriverNamespace() {
44 static std::once_flag once;
45 std::call_once(once, [this]() {
46 // TODO; In the next version of Android, all graphics drivers will be
47 // loaded into a custom namespace. To minimize risk for this release,
48 // only updated drivers use a custom namespace.
49 //
50 // Additionally, the custom namespace will be
51 // ANDROID_NAMESPACE_TYPE_ISOLATED, and will only have access to a
52 // subset of the system.
53 if (mDriverPath.empty())
54 return;
55
56 char defaultPath[PATH_MAX];
57 android_get_LD_LIBRARY_PATH(defaultPath, sizeof(defaultPath));
58 size_t defaultPathLen = strlen(defaultPath);
59
60 std::string path;
61 path.reserve(mDriverPath.size() + 1 + defaultPathLen);
62 path.append(mDriverPath);
63 path.push_back(':');
64 path.append(defaultPath, defaultPathLen);
65
66 mDriverNamespace = android_create_namespace(
67 "gfx driver",
68 nullptr, // ld_library_path
69 path.c_str(), // default_library_path
70 ANDROID_NAMESPACE_TYPE_SHARED,
71 nullptr, // permitted_when_isolated_path
72 nullptr); // parent
73 });
74 return mDriverNamespace;
75}
76
Jesse Hall90b25ed2016-12-12 12:56:46 -080077} // namespace android
Jesse Hall7a8d83e2016-12-20 15:24:28 -080078
79extern "C" android_namespace_t* android_getDriverNamespace() {
80 return android::GraphicsEnv::getInstance().getDriverNamespace();
81}