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