2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include <sys/types.h>
27 #include "path_manager.h"
28 #include "plugin_manager.h"
31 static const char* __TIZEN_API_PATH_KEY = "db/dotnet/tizen_api_path";
32 static const char* __TIZEN_RID_VERSION_KEY = "db/dotnet/tizen_rid_version";
35 #define __STR(x) __XSTR(x)
36 static const char* __DEVICE_API_DIR = __STR(DEVICE_API_DIR);
37 static const char* __RUNTIME_DIR = __STR(RUNTIME_DIR);
38 static const char* __NATIVE_LIB_DIR = __STR(NATIVE_LIB_DIR);
43 #if defined (__aarch64__)
44 #define ARCHITECTURE_IDENTIFIER "arm64"
46 #elif defined (__arm__)
47 #define ARCHITECTURE_IDENTIFIER "armel"
49 #elif defined (__x86_64__)
50 #define ARCHITECTURE_IDENTIFIER "x64"
52 #elif defined (__i386__)
53 #define ARCHITECTURE_IDENTIFIER "x86"
56 #error "Unknown target"
59 // The sequence of RID_FALLBACK graphs must be:
60 // 1. Tizen + Version + Architecture
62 // 3. OS(tizen, linux, unix) + Architecture
63 // 4. OS(tizen, linux, unix)
65 static std::string getExtraNativeLibDirs(const std::string& appRoot)
67 std::vector<std::string> RID_FALLBACK_GRAPH;
68 char* tizen_rid = vconf_get_str(__TIZEN_RID_VERSION_KEY);
70 std::vector<std::string> version;
71 splitPath(tizen_rid, version);
72 std::reverse(std::begin(version), std::end(version));
73 for (unsigned int i = 0; i < version.size(); i++) {
74 RID_FALLBACK_GRAPH.push_back(std::string("tizen." + version[i] + "-" + ARCHITECTURE_IDENTIFIER));
75 RID_FALLBACK_GRAPH.push_back(std::string("tizen." + version[i]));
80 std::vector<std::string> RID_FALLBACK_OS = {"tizen", "linux", "unix"};
81 for (unsigned int i = 0; i < RID_FALLBACK_OS.size(); i++) {
82 RID_FALLBACK_GRAPH.push_back(std::string(RID_FALLBACK_OS[i] + "-" + ARCHITECTURE_IDENTIFIER));
83 RID_FALLBACK_GRAPH.push_back(std::string(RID_FALLBACK_OS[i]));
85 RID_FALLBACK_GRAPH.push_back("any");
86 RID_FALLBACK_GRAPH.push_back("base");
88 std::string candidate;
89 for (unsigned int i = 0; i < RID_FALLBACK_GRAPH.size(); i++) {
90 if (!candidate.empty()) {
93 candidate += concatPath(appRoot, "bin/runtimes/" + RID_FALLBACK_GRAPH[i] + "/native");
96 candidate = candidate + ":" + concatPath(appRoot, "lib/" ARCHITECTURE_IDENTIFIER);
97 if (!strncmp(ARCHITECTURE_IDENTIFIER, "arm64", 5)) {
98 candidate = candidate + ":" + concatPath(appRoot, "lib/aarch64");
99 } else if (!strncmp(ARCHITECTURE_IDENTIFIER, "armel", 5)) {
100 candidate = candidate + ":" + concatPath(appRoot, "lib/arm");
106 void PathManager::updateAppRelatedPath(const std::string& appRootPath)
108 std::string appBinPath = concatPath(appRootPath, "bin");
109 std::string appLibPath = concatPath(appRootPath, "lib");
111 appTacPath = concatPath(appBinPath, TAC_SYMLINK_SUB_DIR);
112 appPaths = appRootPath + ":" + appBinPath + ":" + appLibPath + ":" + appTacPath;
113 appNIPaths = concatPath(appBinPath, APP_NI_SUB_DIR) + ":" + concatPath(appLibPath, APP_NI_SUB_DIR) + ":"+ appTacPath;
114 nativeDllSearchingPaths = runtimePath + ":" + __NATIVE_LIB_DIR + ":" + getExtraNativeLibDirs(appRootPath) + ":" + appBinPath + ":" + appLibPath;
117 PathManager::PathManager() :
121 runtimePath = getAbsolutePath(__RUNTIME_DIR);
122 platformAssembliesPaths.push_back(runtimePath);
125 char* tmp = vconf_get_str(__TIZEN_API_PATH_KEY);
127 tizenfxPath = std::string(tmp);
128 _DBG("Device API Directory is set by vconf : %s", tmp);
131 tizenfxPath = getAbsolutePath(__DEVICE_API_DIR);
133 platformAssembliesPaths.push_back(tizenfxPath);
134 platformAssembliesPaths.push_back(tizenfxPath + "/ref");
136 // set temporal application root path for candidate process
137 rootFD = open("/proc/self", O_DIRECTORY);
139 _ERR("Failed to open /proc/self");
140 throw std::ios_base::failure("Fail to open /proc/self");
143 appRootPath = std::string("/proc/self/fd/") + std::to_string(rootFD);
144 updateAppRelatedPath(appRootPath);
146 _INFO("Path manager created successfully");
149 PathManager::~PathManager()
151 _INFO("Path manager destroyed");
154 // paths: ":" separated muliple path.
155 void PathManager::addPlatformAssembliesPaths(const std::string& paths, bool isHighPriority)
157 std::vector<std::string>::iterator it;
158 std::vector<std::string> pathVec;
159 splitPath(paths, pathVec);
161 for (unsigned int i = 0; i < pathVec.size(); i++) {
162 pathVec[i] = getAbsolutePath(pathVec[i]);
165 if (isHighPriority) {
166 it = platformAssembliesPaths.begin();
168 it = platformAssembliesPaths.end();
171 platformAssembliesPaths.insert(it, pathVec.begin(), pathVec.end());
174 void PathManager::setAppRootPath(const std::string& rootPath)
176 // override root path for application launch mode (candidate / standalone mode)
178 int tmpFD = open(rootPath.c_str(), O_DIRECTORY);
179 dup3(tmpFD, rootFD, O_CLOEXEC);
184 appRootPath = getAbsolutePath(rootPath);
185 updateAppRelatedPath(appRootPath);
188 const std::string& PathManager::getRuntimePath()
193 const std::string& PathManager::getTizenFXPath()
198 // return platform assembly paths
199 const std::vector<std::string>& PathManager::getPlatformAssembliesPaths()
201 return platformAssembliesPaths;
204 // return app root path
205 const std::string& PathManager::getAppRootPath()
210 // return .tac_symlink path
211 const std::string& PathManager::getAppTacPath()
216 // return dll searching paths for app
217 const std::string& PathManager::getAppPaths()
222 // return ni dll searching paths for app
223 const std::string& PathManager::getAppNIPaths()
228 // return native dll searching paths for app
229 const std::string& PathManager::getNativeDllSearchingPaths()
231 return nativeDllSearchingPaths;