Merge "Revert "Revert "Allow dlopen("/system/lib/<soname>") for pre-Q"""
This commit is contained in:
commit
1d3c56bc30
|
@ -91,19 +91,21 @@ static const char* const kLdConfigFilePath = "/system/etc/ld.config.txt";
|
|||
static const char* const kLdConfigVndkLiteFilePath = "/system/etc/ld.config.vndk_lite.txt";
|
||||
|
||||
#if defined(__LP64__)
|
||||
static const char* const kSystemLibDir = "/system/lib64";
|
||||
static const char* const kOdmLibDir = "/odm/lib64";
|
||||
static const char* const kVendorLibDir = "/vendor/lib64";
|
||||
static const char* const kAsanSystemLibDir = "/data/asan/system/lib64";
|
||||
static const char* const kAsanOdmLibDir = "/data/asan/odm/lib64";
|
||||
static const char* const kAsanVendorLibDir = "/data/asan/vendor/lib64";
|
||||
static const char* const kSystemLibDir = "/system/lib64";
|
||||
static const char* const kOdmLibDir = "/odm/lib64";
|
||||
static const char* const kVendorLibDir = "/vendor/lib64";
|
||||
static const char* const kAsanSystemLibDir = "/data/asan/system/lib64";
|
||||
static const char* const kAsanOdmLibDir = "/data/asan/odm/lib64";
|
||||
static const char* const kAsanVendorLibDir = "/data/asan/vendor/lib64";
|
||||
static const char* const kRuntimeApexLibDir = "/apex/com.android.runtime/lib64";
|
||||
#else
|
||||
static const char* const kSystemLibDir = "/system/lib";
|
||||
static const char* const kOdmLibDir = "/odm/lib";
|
||||
static const char* const kVendorLibDir = "/vendor/lib";
|
||||
static const char* const kAsanSystemLibDir = "/data/asan/system/lib";
|
||||
static const char* const kAsanOdmLibDir = "/data/asan/odm/lib";
|
||||
static const char* const kAsanVendorLibDir = "/data/asan/vendor/lib";
|
||||
static const char* const kSystemLibDir = "/system/lib";
|
||||
static const char* const kOdmLibDir = "/odm/lib";
|
||||
static const char* const kVendorLibDir = "/vendor/lib";
|
||||
static const char* const kAsanSystemLibDir = "/data/asan/system/lib";
|
||||
static const char* const kAsanOdmLibDir = "/data/asan/odm/lib";
|
||||
static const char* const kAsanVendorLibDir = "/data/asan/vendor/lib";
|
||||
static const char* const kRuntimeApexLibDir = "/apex/com.android.runtime/lib";
|
||||
#endif
|
||||
|
||||
static const char* const kAsanLibDirPrefix = "/data/asan";
|
||||
|
@ -228,6 +230,44 @@ static bool is_greylisted(android_namespace_t* ns, const char* name, const soinf
|
|||
}
|
||||
// END OF WORKAROUND
|
||||
|
||||
// Workaround for dlopen(/system/lib(64)/<soname>) when .so is in /apex. http://b/121248172
|
||||
/**
|
||||
* Translate /system path to /apex path if needed
|
||||
* The workaround should work only when targetSdkVersion < Q.
|
||||
*
|
||||
* param out_name_to_apex pointing to /apex path
|
||||
* return true if translation is needed
|
||||
*/
|
||||
static bool translateSystemPathToApexPath(const char* name, std::string* out_name_to_apex) {
|
||||
static const char* const kSystemToRuntimeApexLibs[] = {
|
||||
"libicuuc.so",
|
||||
"libicui18n.so",
|
||||
};
|
||||
// New mapping for new apex should be added below
|
||||
|
||||
// Nothing to do if target sdk version is Q or above
|
||||
if (get_application_target_sdk_version() >= __ANDROID_API_Q__) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If the path isn't /system/lib, there's nothing to do.
|
||||
if (name == nullptr || dirname(name) != kSystemLibDir) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const char* base_name = basename(name);
|
||||
|
||||
for (const char* soname : kSystemToRuntimeApexLibs) {
|
||||
if (strcmp(base_name, soname) == 0) {
|
||||
*out_name_to_apex = std::string(kRuntimeApexLibDir) + "/" + base_name;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
// End Workaround for dlopen(/system/lib/<soname>) when .so is in /apex.
|
||||
|
||||
static std::vector<std::string> g_ld_preload_names;
|
||||
|
||||
static bool g_anonymous_namespace_initialized;
|
||||
|
@ -2074,13 +2114,14 @@ void* do_dlopen(const char* name, int flags,
|
|||
android_namespace_t* ns = get_caller_namespace(caller);
|
||||
|
||||
LD_LOG(kLogDlopen,
|
||||
"dlopen(name=\"%s\", flags=0x%x, extinfo=%s, caller=\"%s\", caller_ns=%s@%p) ...",
|
||||
"dlopen(name=\"%s\", flags=0x%x, extinfo=%s, caller=\"%s\", caller_ns=%s@%p, targetSdkVersion=%i) ...",
|
||||
name,
|
||||
flags,
|
||||
android_dlextinfo_to_string(extinfo).c_str(),
|
||||
caller == nullptr ? "(null)" : caller->get_realpath(),
|
||||
ns == nullptr ? "(null)" : ns->get_name(),
|
||||
ns);
|
||||
ns,
|
||||
get_application_target_sdk_version());
|
||||
|
||||
auto purge_guard = android::base::make_scope_guard([&]() { purge_unused_memory(); });
|
||||
|
||||
|
@ -2114,6 +2155,28 @@ void* do_dlopen(const char* name, int flags,
|
|||
}
|
||||
}
|
||||
|
||||
// Workaround for dlopen(/system/lib/<soname>) when .so is in /apex. http://b/121248172
|
||||
// The workaround works only when targetSdkVersion < Q.
|
||||
std::string name_to_apex;
|
||||
if (translateSystemPathToApexPath(name, &name_to_apex)) {
|
||||
const char* new_name = name_to_apex.c_str();
|
||||
LD_LOG(kLogDlopen, "dlopen considering translation from %s to APEX path %s",
|
||||
name,
|
||||
new_name);
|
||||
// Some APEXs could be optionally disabled. Only translate the path
|
||||
// when the old file is absent and the new file exists.
|
||||
if (file_exists(name)) {
|
||||
LD_LOG(kLogDlopen, "dlopen %s exists, not translating", name);
|
||||
} else if (!file_exists(new_name)) {
|
||||
LD_LOG(kLogDlopen, "dlopen %s does not exist, not translating",
|
||||
new_name);
|
||||
} else {
|
||||
LD_LOG(kLogDlopen, "dlopen translation accepted: using %s", new_name);
|
||||
name = new_name;
|
||||
}
|
||||
}
|
||||
// End Workaround for dlopen(/system/lib/<soname>) when .so is in /apex.
|
||||
|
||||
std::string asan_name_holder;
|
||||
|
||||
const char* translated_name = name;
|
||||
|
|
|
@ -232,6 +232,12 @@ TEST(dlext, android_dlopen_ext_force_load_soname_exception) {
|
|||
dlclose(handle);
|
||||
}
|
||||
|
||||
TEST(dlfcn, dlopen_from_nullptr_android_api_level) {
|
||||
// Regression test for http://b/123972211. Testing dlopen(nullptr) when target sdk is P
|
||||
android_set_application_target_sdk_version(__ANDROID_API_P__);
|
||||
ASSERT_TRUE(dlopen(nullptr, RTLD_NOW) != nullptr);
|
||||
}
|
||||
|
||||
TEST(dlfcn, dlopen_from_zip_absolute_path) {
|
||||
const std::string lib_zip_path = "/libdlext_test_zip/libdlext_test_zip_zipaligned.zip";
|
||||
const std::string lib_path = GetTestlibRoot() + lib_zip_path;
|
||||
|
|
Loading…
Reference in New Issue