using ::android::base::ErrnoError; using ::android::base::Error; using ::android::base::Result;
// The allow-listed libraries. Standalone tests can assume that the ART module // is from the same build as the test(*), but not the platform nor any other // module. Hence all dynamic libraries listed here must satisfy at least one of // these conditions: // // - Have a stable ABI and be available since the APEX min_sdk_version (31). // This includes NDK and system APIs. // - Be loaded from the ART APEX itself(*). Note that linker namespaces aren't // set up to allow this for libraries that aren't exported, so in practice it // is restricted to them. // - Always be pushed to device together with the test. // - Be a runtime instrumentation library or similar, e.g. for sanitizer test // builds, where everything is always built from source - platform, module, // and tests. // // *) (Non-MCTS) CTS tests is an exception - they must work with any future // version of the module and hence restrict themselves to the exported module // APIs.
constexpr constchar* kAllowedDynamicLibDeps[] = { // LLVM "libclang_rt.hwasan-aarch64-android.so", // Bionic "libc.so", "libdl.so", "libdl_android.so", "libm.so", // Platform "heapprofd_client_api.so", "libbinder_ndk.so", "liblog.so", "libselinux.so", "libz.so", // Other modules "libstatspull.so", "libstatssocket.so", // ART exported "libdexfile.so", "libnativebridge.so", "libnativehelper.so", "libnativeloader.so",
};
Result<std::string> GetCurrentElfObjectPath() {
Dl_info info; if (dladdr(reinterpret_cast<void*>(GetCurrentElfObjectPath), &info) == 0) { return Error() << "dladdr failed to map own address to a shared object.";
} return info.dli_fname;
}
Elf* elf = elf_begin(fd.get(), ELF_C_READ, /*ref=*/nullptr); if (elf == nullptr) { return Errorf("Error creating ELF object for {}: {}", filename, elf_errmsg(-1));
} auto elf_cleanup = android::base::make_scope_guard([&]() { elf_end(elf); });
std::vector<std::string> libs;
// Find the dynamic section. for (Elf_Scn* dyn_scn = nullptr; (dyn_scn = elf_nextscn(elf, dyn_scn)) != nullptr;) {
GElf_Shdr scn_hdr; if (gelf_getshdr(dyn_scn, &scn_hdr) != &scn_hdr) { return Errorf("Failed to retrieve ELF section header in {}: {}", filename, elf_errmsg(-1));
}
if (scn_hdr.sh_type == SHT_DYNAMIC) {
Elf_Data* data = elf_getdata(dyn_scn, /*data=*/nullptr);
// Iterate through dynamic section entries. for (int i = 0; i < scn_hdr.sh_size / scn_hdr.sh_entsize; i++) {
GElf_Dyn dyn_entry; if (gelf_getdyn(data, i, &dyn_entry) != &dyn_entry) { return Errorf("Failed to get entry {} in ELF dynamic section of {}: {}",
i,
filename,
elf_errmsg(-1));
}
if (dyn_entry.d_tag == DT_NEEDED) { constchar* lib_name = elf_strptr(elf, scn_hdr.sh_link, dyn_entry.d_un.d_val); if (lib_name == nullptr) { return Errorf("Failed to get string from entry {} in ELF dynamic section of {}: {}",
i,
filename,
elf_errmsg(-1));
}
libs.push_back(lib_name);
}
} break; // Found the dynamic section, no need to continue.
}
}
// Allow .so files in the same directory as the test binary, for shared libs // pushed with the test using `data_libs`.
std::filesystem::path self_dir = std::filesystem::path(path_to_self.value()).parent_path();
std::vector<std::string> test_libs; for (const std::filesystem::directory_entry& entry :
std::filesystem::directory_iterator(self_dir)) { if (entry.is_regular_file() && entry.path().extension() == ".so") {
test_libs.push_back(entry.path().filename());
}
}
std::vector<std::string> disallowed_libs; for (const std::string& dyn_lib_dep : dyn_lib_deps.value()) { if (std::find(std::begin(kAllowedDynamicLibDeps),
std::end(kAllowedDynamicLibDeps),
dyn_lib_dep) != std::end(kAllowedDynamicLibDeps)) { continue;
} if (art::ContainsElement(test_libs, dyn_lib_dep)) { continue;
}
disallowed_libs.push_back(dyn_lib_dep);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.