| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 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_TAG "nativeloader" |
| 18 | |
| 19 | #include "public_libraries.h" |
| 20 | |
| 21 | #include <dirent.h> |
| 22 | |
| 23 | #include <algorithm> |
| Jooyung Han | 538f99a | 2020-03-03 00:46:50 +0900 | [diff] [blame] | 24 | #include <map> |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 25 | #include <memory> |
| 26 | |
| 27 | #include <android-base/file.h> |
| 28 | #include <android-base/logging.h> |
| 29 | #include <android-base/properties.h> |
| 30 | #include <android-base/result.h> |
| 31 | #include <android-base/strings.h> |
| 32 | #include <log/log.h> |
| 33 | |
| Nicolas Geoffray | 7ca8b67 | 2020-04-24 15:43:48 +0100 | [diff] [blame] | 34 | #if defined(ART_TARGET_ANDROID) |
| Justin Yun | 3db26d5 | 2019-12-16 14:09:39 +0900 | [diff] [blame] | 35 | #include <android/sysprop/VndkProperties.sysprop.h> |
| 36 | #endif |
| 37 | |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 38 | #include "utils.h" |
| 39 | |
| 40 | namespace android::nativeloader { |
| 41 | |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 42 | using android::base::ErrnoError; |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 43 | using android::base::Result; |
| Jeffrey Huang | 5257503 | 2020-02-11 17:33:45 -0800 | [diff] [blame] | 44 | using internal::ConfigEntry; |
| 45 | using internal::ParseConfig; |
| Jooyung Han | 538f99a | 2020-03-03 00:46:50 +0900 | [diff] [blame] | 46 | using internal::ParseJniConfig; |
| Jeffrey Huang | 5257503 | 2020-02-11 17:33:45 -0800 | [diff] [blame] | 47 | using std::literals::string_literals::operator""s; |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 48 | |
| 49 | namespace { |
| 50 | |
| 51 | constexpr const char* kDefaultPublicLibrariesFile = "/etc/public.libraries.txt"; |
| 52 | constexpr const char* kExtendedPublicLibrariesFilePrefix = "public.libraries-"; |
| 53 | constexpr const char* kExtendedPublicLibrariesFileSuffix = ".txt"; |
| Jooyung Han | 538f99a | 2020-03-03 00:46:50 +0900 | [diff] [blame] | 54 | constexpr const char* kJniConfigFile = "/linkerconfig/jni.config.txt"; |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 55 | constexpr const char* kVendorPublicLibrariesFile = "/vendor/etc/public.libraries.txt"; |
| Jooyung Han | 26f7d10 | 2020-02-22 23:39:23 +0900 | [diff] [blame] | 56 | constexpr const char* kLlndkLibrariesFile = "/apex/com.android.vndk.v{}/etc/llndk.libraries.{}.txt"; |
| 57 | constexpr const char* kVndkLibrariesFile = "/apex/com.android.vndk.v{}/etc/vndksp.libraries.{}.txt"; |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 58 | |
| 59 | const std::vector<const std::string> kArtApexPublicLibraries = { |
| vichang | 4a48775 | 2020-05-05 11:11:30 +0000 | [diff] [blame] | 60 | "libicuuc.so", |
| 61 | "libicui18n.so", |
| Orion Hodson | e33dca6 | 2020-04-28 14:07:58 +0100 | [diff] [blame] | 62 | "libnativehelper.so", |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 63 | }; |
| 64 | |
| vichang | 4a48775 | 2020-05-05 11:11:30 +0000 | [diff] [blame] | 65 | constexpr const char* kArtApexLibPath = "/apex/com.android.art/" LIB; |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 66 | |
| 67 | constexpr const char* kNeuralNetworksApexPublicLibrary = "libneuralnetworks.so"; |
| 68 | |
| Jeffrey Huang | 5257503 | 2020-02-11 17:33:45 -0800 | [diff] [blame] | 69 | constexpr const char* kStatsdApexPublicLibrary = "libstats_jni.so"; |
| 70 | |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 71 | // TODO(b/130388701): do we need this? |
| 72 | std::string root_dir() { |
| 73 | static const char* android_root_env = getenv("ANDROID_ROOT"); |
| 74 | return android_root_env != nullptr ? android_root_env : "/system"; |
| 75 | } |
| 76 | |
| 77 | bool debuggable() { |
| 78 | static bool debuggable = android::base::GetBoolProperty("ro.debuggable", false); |
| 79 | return debuggable; |
| 80 | } |
| 81 | |
| Justin Yun | 089c135 | 2020-02-06 16:53:08 +0900 | [diff] [blame] | 82 | std::string vndk_version_str(bool use_product_vndk) { |
| Jooyung Han | 26f7d10 | 2020-02-22 23:39:23 +0900 | [diff] [blame] | 83 | if (use_product_vndk) { |
| 84 | static std::string product_vndk_version = get_vndk_version(true); |
| 85 | return product_vndk_version; |
| 86 | } else { |
| 87 | static std::string vendor_vndk_version = get_vndk_version(false); |
| 88 | return vendor_vndk_version; |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 89 | } |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | // For debuggable platform builds use ANDROID_ADDITIONAL_PUBLIC_LIBRARIES environment |
| 93 | // variable to add libraries to the list. This is intended for platform tests only. |
| 94 | std::string additional_public_libraries() { |
| 95 | if (debuggable()) { |
| 96 | const char* val = getenv("ANDROID_ADDITIONAL_PUBLIC_LIBRARIES"); |
| 97 | return val ? val : ""; |
| 98 | } |
| 99 | return ""; |
| 100 | } |
| 101 | |
| Jooyung Han | 26f7d10 | 2020-02-22 23:39:23 +0900 | [diff] [blame] | 102 | // insert vndk version in every {} placeholder |
| Justin Yun | 089c135 | 2020-02-06 16:53:08 +0900 | [diff] [blame] | 103 | void InsertVndkVersionStr(std::string* file_name, bool use_product_vndk) { |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 104 | CHECK(file_name != nullptr); |
| Jooyung Han | 26f7d10 | 2020-02-22 23:39:23 +0900 | [diff] [blame] | 105 | auto version = vndk_version_str(use_product_vndk); |
| 106 | size_t pos = file_name->find("{}"); |
| 107 | while (pos != std::string::npos) { |
| 108 | file_name->replace(pos, 2, version); |
| 109 | pos = file_name->find("{}", pos + version.size()); |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 110 | } |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | const std::function<Result<bool>(const struct ConfigEntry&)> always_true = |
| 114 | [](const struct ConfigEntry&) -> Result<bool> { return true; }; |
| 115 | |
| 116 | Result<std::vector<std::string>> ReadConfig( |
| 117 | const std::string& configFile, |
| 118 | const std::function<Result<bool>(const ConfigEntry& /* entry */)>& filter_fn) { |
| 119 | std::string file_content; |
| 120 | if (!base::ReadFileToString(configFile, &file_content)) { |
| 121 | return ErrnoError(); |
| 122 | } |
| 123 | Result<std::vector<std::string>> result = ParseConfig(file_content, filter_fn); |
| Bernie Innocenti | 4bd5895 | 2020-02-06 15:43:57 +0900 | [diff] [blame] | 124 | if (!result.ok()) { |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 125 | return Errorf("Cannot parse {}: {}", configFile, result.error().message()); |
| 126 | } |
| 127 | return result; |
| 128 | } |
| 129 | |
| 130 | void ReadExtensionLibraries(const char* dirname, std::vector<std::string>* sonames) { |
| 131 | std::unique_ptr<DIR, decltype(&closedir)> dir(opendir(dirname), closedir); |
| 132 | if (dir != nullptr) { |
| 133 | // Failing to opening the dir is not an error, which can happen in |
| 134 | // webview_zygote. |
| 135 | while (struct dirent* ent = readdir(dir.get())) { |
| 136 | if (ent->d_type != DT_REG && ent->d_type != DT_LNK) { |
| 137 | continue; |
| 138 | } |
| 139 | const std::string filename(ent->d_name); |
| 140 | std::string_view fn = filename; |
| 141 | if (android::base::ConsumePrefix(&fn, kExtendedPublicLibrariesFilePrefix) && |
| 142 | android::base::ConsumeSuffix(&fn, kExtendedPublicLibrariesFileSuffix)) { |
| 143 | const std::string company_name(fn); |
| 144 | const std::string config_file_path = dirname + "/"s + filename; |
| 145 | LOG_ALWAYS_FATAL_IF( |
| 146 | company_name.empty(), |
| 147 | "Error extracting company name from public native library list file path \"%s\"", |
| 148 | config_file_path.c_str()); |
| 149 | |
| 150 | auto ret = ReadConfig( |
| 151 | config_file_path, [&company_name](const struct ConfigEntry& entry) -> Result<bool> { |
| 152 | if (android::base::StartsWith(entry.soname, "lib") && |
| 153 | android::base::EndsWith(entry.soname, "." + company_name + ".so")) { |
| 154 | return true; |
| 155 | } else { |
| 156 | return Errorf("Library name \"{}\" does not end with the company name {}.", |
| 157 | entry.soname, company_name); |
| 158 | } |
| 159 | }); |
| Bernie Innocenti | 4bd5895 | 2020-02-06 15:43:57 +0900 | [diff] [blame] | 160 | if (ret.ok()) { |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 161 | sonames->insert(sonames->end(), ret->begin(), ret->end()); |
| 162 | } else { |
| 163 | LOG_ALWAYS_FATAL("Error reading public native library list from \"%s\": %s", |
| 164 | config_file_path.c_str(), ret.error().message().c_str()); |
| 165 | } |
| 166 | } |
| 167 | } |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | static std::string InitDefaultPublicLibraries(bool for_preload) { |
| 172 | std::string config_file = root_dir() + kDefaultPublicLibrariesFile; |
| 173 | auto sonames = |
| 174 | ReadConfig(config_file, [&for_preload](const struct ConfigEntry& entry) -> Result<bool> { |
| 175 | if (for_preload) { |
| 176 | return !entry.nopreload; |
| 177 | } else { |
| 178 | return true; |
| 179 | } |
| 180 | }); |
| Bernie Innocenti | 4bd5895 | 2020-02-06 15:43:57 +0900 | [diff] [blame] | 181 | if (!sonames.ok()) { |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 182 | LOG_ALWAYS_FATAL("Error reading public native library list from \"%s\": %s", |
| 183 | config_file.c_str(), sonames.error().message().c_str()); |
| 184 | return ""; |
| 185 | } |
| 186 | |
| 187 | std::string additional_libs = additional_public_libraries(); |
| 188 | if (!additional_libs.empty()) { |
| 189 | auto vec = base::Split(additional_libs, ":"); |
| 190 | std::copy(vec.begin(), vec.end(), std::back_inserter(*sonames)); |
| 191 | } |
| 192 | |
| 193 | // If this is for preloading libs, don't remove the libs from APEXes. |
| 194 | if (for_preload) { |
| 195 | return android::base::Join(*sonames, ':'); |
| 196 | } |
| 197 | |
| vichang | 4a48775 | 2020-05-05 11:11:30 +0000 | [diff] [blame] | 198 | // Remove the public libs in the art namespace. |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 199 | // These libs are listed in public.android.txt, but we don't want the rest of android |
| 200 | // in default namespace to dlopen the libs. |
| 201 | // For example, libicuuc.so is exposed to classloader namespace from art namespace. |
| 202 | // Unfortunately, it does not have stable C symbols, and default namespace should only use |
| 203 | // stable symbols in libandroidicu.so. http://b/120786417 |
| vichang | 4a48775 | 2020-05-05 11:11:30 +0000 | [diff] [blame] | 204 | for (const std::string& lib_name : kArtApexPublicLibraries) { |
| 205 | std::string path(kArtApexLibPath); |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 206 | path.append("/").append(lib_name); |
| 207 | |
| 208 | struct stat s; |
| 209 | // Do nothing if the path in /apex does not exist. |
| 210 | // Runtime APEX must be mounted since libnativeloader is in the same APEX |
| 211 | if (stat(path.c_str(), &s) != 0) { |
| 212 | continue; |
| 213 | } |
| 214 | |
| 215 | auto it = std::find(sonames->begin(), sonames->end(), lib_name); |
| 216 | if (it != sonames->end()) { |
| 217 | sonames->erase(it); |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | // Remove the public libs in the nnapi namespace. |
| 222 | auto it = std::find(sonames->begin(), sonames->end(), kNeuralNetworksApexPublicLibrary); |
| 223 | if (it != sonames->end()) { |
| 224 | sonames->erase(it); |
| 225 | } |
| 226 | return android::base::Join(*sonames, ':'); |
| 227 | } |
| 228 | |
| 229 | static std::string InitArtPublicLibraries() { |
| Chris Wailes | 72d7e96 | 2020-04-15 09:37:38 -0700 | [diff] [blame] | 230 | CHECK_GT((int)kArtApexPublicLibraries.size(), 0); |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 231 | std::string list = android::base::Join(kArtApexPublicLibraries, ":"); |
| 232 | |
| 233 | std::string additional_libs = additional_public_libraries(); |
| 234 | if (!additional_libs.empty()) { |
| 235 | list = list + ':' + additional_libs; |
| 236 | } |
| 237 | return list; |
| 238 | } |
| 239 | |
| 240 | static std::string InitVendorPublicLibraries() { |
| 241 | // This file is optional, quietly ignore if the file does not exist. |
| 242 | auto sonames = ReadConfig(kVendorPublicLibrariesFile, always_true); |
| Bernie Innocenti | 4bd5895 | 2020-02-06 15:43:57 +0900 | [diff] [blame] | 243 | if (!sonames.ok()) { |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 244 | return ""; |
| 245 | } |
| 246 | return android::base::Join(*sonames, ':'); |
| 247 | } |
| 248 | |
| Justin Yun | 0cc4027 | 2019-12-16 16:47:40 +0900 | [diff] [blame] | 249 | // read /system/etc/public.libraries-<companyname>.txt, |
| 250 | // /system_ext/etc/public.libraries-<companyname>.txt and |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 251 | // /product/etc/public.libraries-<companyname>.txt which contain partner defined |
| 252 | // system libs that are exposed to apps. The libs in the txt files must be |
| 253 | // named as lib<name>.<companyname>.so. |
| 254 | static std::string InitExtendedPublicLibraries() { |
| 255 | std::vector<std::string> sonames; |
| 256 | ReadExtensionLibraries("/system/etc", &sonames); |
| Justin Yun | 0cc4027 | 2019-12-16 16:47:40 +0900 | [diff] [blame] | 257 | ReadExtensionLibraries("/system_ext/etc", &sonames); |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 258 | ReadExtensionLibraries("/product/etc", &sonames); |
| 259 | return android::base::Join(sonames, ':'); |
| 260 | } |
| 261 | |
| Justin Yun | 089c135 | 2020-02-06 16:53:08 +0900 | [diff] [blame] | 262 | static std::string InitLlndkLibrariesVendor() { |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 263 | std::string config_file = kLlndkLibrariesFile; |
| Justin Yun | 089c135 | 2020-02-06 16:53:08 +0900 | [diff] [blame] | 264 | InsertVndkVersionStr(&config_file, false); |
| 265 | auto sonames = ReadConfig(config_file, always_true); |
| Bernie Innocenti | c137563 | 2020-02-13 10:37:03 +0900 | [diff] [blame] | 266 | if (!sonames.ok()) { |
| Jooyung Han | 26f7d10 | 2020-02-22 23:39:23 +0900 | [diff] [blame] | 267 | LOG_ALWAYS_FATAL("%s: %s", config_file.c_str(), sonames.error().message().c_str()); |
| Justin Yun | 089c135 | 2020-02-06 16:53:08 +0900 | [diff] [blame] | 268 | return ""; |
| 269 | } |
| 270 | return android::base::Join(*sonames, ':'); |
| 271 | } |
| 272 | |
| 273 | static std::string InitLlndkLibrariesProduct() { |
| Justin Yun | 696882f | 2020-03-24 13:31:19 +0900 | [diff] [blame] | 274 | if (!is_product_vndk_version_defined()) { |
| 275 | return ""; |
| 276 | } |
| Justin Yun | 089c135 | 2020-02-06 16:53:08 +0900 | [diff] [blame] | 277 | std::string config_file = kLlndkLibrariesFile; |
| 278 | InsertVndkVersionStr(&config_file, true); |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 279 | auto sonames = ReadConfig(config_file, always_true); |
| Bernie Innocenti | 4bd5895 | 2020-02-06 15:43:57 +0900 | [diff] [blame] | 280 | if (!sonames.ok()) { |
| Jooyung Han | 26f7d10 | 2020-02-22 23:39:23 +0900 | [diff] [blame] | 281 | LOG_ALWAYS_FATAL("%s: %s", config_file.c_str(), sonames.error().message().c_str()); |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 282 | return ""; |
| 283 | } |
| 284 | return android::base::Join(*sonames, ':'); |
| 285 | } |
| 286 | |
| Justin Yun | eb4f08c | 2020-02-18 11:29:07 +0900 | [diff] [blame] | 287 | static std::string InitVndkspLibrariesVendor() { |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 288 | std::string config_file = kVndkLibrariesFile; |
| Justin Yun | 089c135 | 2020-02-06 16:53:08 +0900 | [diff] [blame] | 289 | InsertVndkVersionStr(&config_file, false); |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 290 | auto sonames = ReadConfig(config_file, always_true); |
| Bernie Innocenti | 4bd5895 | 2020-02-06 15:43:57 +0900 | [diff] [blame] | 291 | if (!sonames.ok()) { |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 292 | LOG_ALWAYS_FATAL("%s", sonames.error().message().c_str()); |
| 293 | return ""; |
| 294 | } |
| 295 | return android::base::Join(*sonames, ':'); |
| 296 | } |
| 297 | |
| Justin Yun | eb4f08c | 2020-02-18 11:29:07 +0900 | [diff] [blame] | 298 | static std::string InitVndkspLibrariesProduct() { |
| Justin Yun | 696882f | 2020-03-24 13:31:19 +0900 | [diff] [blame] | 299 | if (!is_product_vndk_version_defined()) { |
| 300 | return ""; |
| 301 | } |
| Justin Yun | eb4f08c | 2020-02-18 11:29:07 +0900 | [diff] [blame] | 302 | std::string config_file = kVndkLibrariesFile; |
| 303 | InsertVndkVersionStr(&config_file, true); |
| 304 | auto sonames = ReadConfig(config_file, always_true); |
| 305 | if (!sonames.ok()) { |
| 306 | LOG_ALWAYS_FATAL("%s", sonames.error().message().c_str()); |
| 307 | return ""; |
| 308 | } |
| 309 | return android::base::Join(*sonames, ':'); |
| 310 | } |
| 311 | |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 312 | static std::string InitNeuralNetworksPublicLibraries() { |
| 313 | return kNeuralNetworksApexPublicLibrary; |
| 314 | } |
| 315 | |
| Jeffrey Huang | 5257503 | 2020-02-11 17:33:45 -0800 | [diff] [blame] | 316 | static std::string InitStatsdPublicLibraries() { |
| 317 | return kStatsdApexPublicLibrary; |
| 318 | } |
| 319 | |
| Jooyung Han | 538f99a | 2020-03-03 00:46:50 +0900 | [diff] [blame] | 320 | static std::map<std::string, std::string> InitApexJniLibraries() { |
| 321 | std::string file_content; |
| 322 | if (!base::ReadFileToString(kJniConfigFile, &file_content)) { |
| 323 | // jni config is optional |
| 324 | return {}; |
| 325 | } |
| 326 | auto config = ParseJniConfig(file_content); |
| 327 | if (!config.ok()) { |
| 328 | LOG_ALWAYS_FATAL("%s: %s", kJniConfigFile, config.error().message().c_str()); |
| 329 | // not reach here |
| 330 | return {}; |
| 331 | } |
| 332 | return *config; |
| 333 | } |
| 334 | |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 335 | } // namespace |
| 336 | |
| 337 | const std::string& preloadable_public_libraries() { |
| 338 | static std::string list = InitDefaultPublicLibraries(/*for_preload*/ true); |
| 339 | return list; |
| 340 | } |
| 341 | |
| 342 | const std::string& default_public_libraries() { |
| 343 | static std::string list = InitDefaultPublicLibraries(/*for_preload*/ false); |
| 344 | return list; |
| 345 | } |
| 346 | |
| 347 | const std::string& art_public_libraries() { |
| 348 | static std::string list = InitArtPublicLibraries(); |
| 349 | return list; |
| 350 | } |
| 351 | |
| 352 | const std::string& vendor_public_libraries() { |
| 353 | static std::string list = InitVendorPublicLibraries(); |
| 354 | return list; |
| 355 | } |
| 356 | |
| 357 | const std::string& extended_public_libraries() { |
| 358 | static std::string list = InitExtendedPublicLibraries(); |
| 359 | return list; |
| 360 | } |
| 361 | |
| 362 | const std::string& neuralnetworks_public_libraries() { |
| 363 | static std::string list = InitNeuralNetworksPublicLibraries(); |
| 364 | return list; |
| 365 | } |
| 366 | |
| Jeffrey Huang | 5257503 | 2020-02-11 17:33:45 -0800 | [diff] [blame] | 367 | const std::string& statsd_public_libraries() { |
| 368 | static std::string list = InitStatsdPublicLibraries(); |
| 369 | return list; |
| 370 | } |
| 371 | |
| Justin Yun | 089c135 | 2020-02-06 16:53:08 +0900 | [diff] [blame] | 372 | const std::string& llndk_libraries_product() { |
| 373 | static std::string list = InitLlndkLibrariesProduct(); |
| 374 | return list; |
| 375 | } |
| 376 | |
| 377 | const std::string& llndk_libraries_vendor() { |
| 378 | static std::string list = InitLlndkLibrariesVendor(); |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 379 | return list; |
| 380 | } |
| 381 | |
| Justin Yun | eb4f08c | 2020-02-18 11:29:07 +0900 | [diff] [blame] | 382 | const std::string& vndksp_libraries_product() { |
| 383 | static std::string list = InitVndkspLibrariesProduct(); |
| 384 | return list; |
| 385 | } |
| 386 | |
| 387 | const std::string& vndksp_libraries_vendor() { |
| 388 | static std::string list = InitVndkspLibrariesVendor(); |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 389 | return list; |
| 390 | } |
| 391 | |
| Jooyung Han | 538f99a | 2020-03-03 00:46:50 +0900 | [diff] [blame] | 392 | const std::string& apex_jni_libraries(const std::string& apex_ns_name) { |
| 393 | static std::map<std::string, std::string> jni_libraries = InitApexJniLibraries(); |
| 394 | return jni_libraries[apex_ns_name]; |
| 395 | } |
| 396 | |
| Justin Yun | 3db26d5 | 2019-12-16 14:09:39 +0900 | [diff] [blame] | 397 | bool is_product_vndk_version_defined() { |
| Nicolas Geoffray | 7ca8b67 | 2020-04-24 15:43:48 +0100 | [diff] [blame] | 398 | #if defined(ART_TARGET_ANDROID) |
| Justin Yun | 3db26d5 | 2019-12-16 14:09:39 +0900 | [diff] [blame] | 399 | return android::sysprop::VndkProperties::product_vndk_version().has_value(); |
| 400 | #else |
| 401 | return false; |
| 402 | #endif |
| 403 | } |
| 404 | |
| Justin Yun | 089c135 | 2020-02-06 16:53:08 +0900 | [diff] [blame] | 405 | std::string get_vndk_version(bool is_product_vndk) { |
| Nicolas Geoffray | 7ca8b67 | 2020-04-24 15:43:48 +0100 | [diff] [blame] | 406 | #if defined(ART_TARGET_ANDROID) |
| Justin Yun | 089c135 | 2020-02-06 16:53:08 +0900 | [diff] [blame] | 407 | if (is_product_vndk) { |
| 408 | return android::sysprop::VndkProperties::product_vndk_version().value_or(""); |
| 409 | } |
| 410 | return android::sysprop::VndkProperties::vendor_vndk_version().value_or(""); |
| 411 | #else |
| 412 | if (is_product_vndk) { |
| 413 | return android::base::GetProperty("ro.product.vndk.version", ""); |
| 414 | } |
| 415 | return android::base::GetProperty("ro.vndk.version", ""); |
| 416 | #endif |
| 417 | } |
| 418 | |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 419 | namespace internal { |
| 420 | // Exported for testing |
| 421 | Result<std::vector<std::string>> ParseConfig( |
| 422 | const std::string& file_content, |
| 423 | const std::function<Result<bool>(const ConfigEntry& /* entry */)>& filter_fn) { |
| 424 | std::vector<std::string> lines = base::Split(file_content, "\n"); |
| 425 | |
| 426 | std::vector<std::string> sonames; |
| 427 | for (auto& line : lines) { |
| 428 | auto trimmed_line = base::Trim(line); |
| 429 | if (trimmed_line[0] == '#' || trimmed_line.empty()) { |
| 430 | continue; |
| 431 | } |
| 432 | |
| 433 | std::vector<std::string> tokens = android::base::Split(trimmed_line, " "); |
| 434 | if (tokens.size() < 1 || tokens.size() > 3) { |
| 435 | return Errorf("Malformed line \"{}\"", line); |
| 436 | } |
| 437 | struct ConfigEntry entry = {.soname = "", .nopreload = false, .bitness = ALL}; |
| 438 | size_t i = tokens.size(); |
| 439 | while (i-- > 0) { |
| 440 | if (tokens[i] == "nopreload") { |
| 441 | entry.nopreload = true; |
| 442 | } else if (tokens[i] == "32" || tokens[i] == "64") { |
| 443 | if (entry.bitness != ALL) { |
| 444 | return Errorf("Malformed line \"{}\": bitness can be specified only once", line); |
| 445 | } |
| 446 | entry.bitness = tokens[i] == "32" ? ONLY_32 : ONLY_64; |
| 447 | } else { |
| 448 | if (i != 0) { |
| 449 | return Errorf("Malformed line \"{}\"", line); |
| 450 | } |
| 451 | entry.soname = tokens[i]; |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | // skip 32-bit lib on 64-bit process and vice versa |
| 456 | #if defined(__LP64__) |
| 457 | if (entry.bitness == ONLY_32) continue; |
| 458 | #else |
| 459 | if (entry.bitness == ONLY_64) continue; |
| 460 | #endif |
| 461 | |
| 462 | Result<bool> ret = filter_fn(entry); |
| Bernie Innocenti | 4bd5895 | 2020-02-06 15:43:57 +0900 | [diff] [blame] | 463 | if (!ret.ok()) { |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 464 | return ret.error(); |
| 465 | } |
| 466 | if (*ret) { |
| 467 | // filter_fn has returned true. |
| 468 | sonames.push_back(entry.soname); |
| 469 | } |
| 470 | } |
| 471 | return sonames; |
| 472 | } |
| 473 | |
| Jooyung Han | 538f99a | 2020-03-03 00:46:50 +0900 | [diff] [blame] | 474 | Result<std::map<std::string, std::string>> ParseJniConfig(const std::string& file_content) { |
| 475 | std::map<std::string, std::string> entries; |
| 476 | std::vector<std::string> lines = base::Split(file_content, "\n"); |
| 477 | for (auto& line : lines) { |
| 478 | auto trimmed_line = base::Trim(line); |
| 479 | if (trimmed_line[0] == '#' || trimmed_line.empty()) { |
| 480 | continue; |
| 481 | } |
| 482 | |
| 483 | std::vector<std::string> tokens = base::Split(trimmed_line, " "); |
| 484 | if (tokens.size() < 2) { |
| 485 | return Errorf( "Malformed line \"{}\"", line); |
| 486 | } |
| 487 | entries[tokens[0]] = tokens[1]; |
| 488 | } |
| 489 | return entries; |
| 490 | } |
| 491 | |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 492 | } // namespace internal |
| 493 | |
| 494 | } // namespace android::nativeloader |