зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1291377 - Don't use custom linker on Android 6.0+ r=glandium
We still need it for Android < 6.0 (API 23) because otherwise we don't have a way to hook up mozalloc. Differential Revision: https://phabricator.services.mozilla.com/D66993 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
6fa26b1439
Коммит
2ef4e466f8
|
@ -23,6 +23,9 @@
|
|||
# if defined(MOZ_LINKER)
|
||||
# include <dlfcn.h>
|
||||
# include "mozilla/Types.h"
|
||||
# if defined(ANDROID)
|
||||
# include <sys/system_properties.h>
|
||||
# endif
|
||||
// FIXME move these out of mozglue/linker/ElfLoader.h into their
|
||||
// own header, so as to avoid conflicts arising from two definitions
|
||||
// of Array
|
||||
|
@ -96,6 +99,22 @@ bool AutoObjectMapperPOSIX::Map(/*OUT*/ void** start, /*OUT*/ size_t* length,
|
|||
}
|
||||
|
||||
# if defined(MOZ_LINKER)
|
||||
# if defined(ANDROID)
|
||||
static int GetAndroidSDKVersion() {
|
||||
static int version = 0;
|
||||
if (version) {
|
||||
return version;
|
||||
}
|
||||
|
||||
char version_string[PROP_VALUE_MAX] = {'\0'};
|
||||
int len = __system_property_get("ro.build.version.sdk", version_string);
|
||||
if (len) {
|
||||
version = static_cast<int>(strtol(version_string, nullptr, 10));
|
||||
}
|
||||
return version;
|
||||
}
|
||||
# endif
|
||||
|
||||
AutoObjectMapperFaultyLib::AutoObjectMapperFaultyLib(void (*aLog)(const char*))
|
||||
: AutoObjectMapperPOSIX(aLog), mHdl(nullptr) {}
|
||||
|
||||
|
@ -122,6 +141,13 @@ bool AutoObjectMapperFaultyLib::Map(/*OUT*/ void** start,
|
|||
/*OUT*/ size_t* length,
|
||||
std::string fileName) {
|
||||
MOZ_ASSERT(!mHdl);
|
||||
|
||||
# if defined(ANDROID)
|
||||
if (GetAndroidSDKVersion() >= 23) {
|
||||
return AutoObjectMapperPOSIX::Map(start, length, fileName);
|
||||
}
|
||||
# endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,24 @@ mozilla::Atomic<size_t, mozilla::ReleaseAcquire> gPageSize;
|
|||
# include <math.h>
|
||||
|
||||
# include <android/api-level.h>
|
||||
|
||||
/**
|
||||
* Return the current Android version, or 0 on failure.
|
||||
*/
|
||||
static int GetAndroidSDKVersion() {
|
||||
static int version = 0;
|
||||
if (version) {
|
||||
return version;
|
||||
}
|
||||
|
||||
char version_string[PROP_VALUE_MAX] = {'\0'};
|
||||
int len = __system_property_get("ro.build.version.sdk", version_string);
|
||||
if (len) {
|
||||
version = static_cast<int>(strtol(version_string, nullptr, 10));
|
||||
}
|
||||
return version;
|
||||
}
|
||||
|
||||
# if __ANDROID_API__ < 8
|
||||
/* Android API < 8 doesn't provide sigaltstack */
|
||||
|
||||
|
@ -61,12 +79,20 @@ extern "C" Elf::Dyn _DYNAMIC[];
|
|||
*/
|
||||
|
||||
void* __wrap_dlopen(const char* path, int flags) {
|
||||
if (GetAndroidSDKVersion() >= 23) {
|
||||
return dlopen(path, flags);
|
||||
}
|
||||
|
||||
RefPtr<LibHandle> handle = ElfLoader::Singleton.Load(path, flags);
|
||||
if (handle) handle->AddDirectRef();
|
||||
return handle;
|
||||
}
|
||||
|
||||
const char* __wrap_dlerror(void) {
|
||||
if (GetAndroidSDKVersion() >= 23) {
|
||||
return dlerror();
|
||||
}
|
||||
|
||||
const char* error = ElfLoader::Singleton.lastError.exchange(nullptr);
|
||||
if (error) {
|
||||
// Return a custom error if available.
|
||||
|
@ -77,6 +103,10 @@ const char* __wrap_dlerror(void) {
|
|||
}
|
||||
|
||||
void* __wrap_dlsym(void* handle, const char* symbol) {
|
||||
if (GetAndroidSDKVersion() >= 23) {
|
||||
return dlsym(handle, symbol);
|
||||
}
|
||||
|
||||
if (!handle) {
|
||||
ElfLoader::Singleton.lastError = "dlsym(NULL, sym) unsupported";
|
||||
return nullptr;
|
||||
|
@ -91,6 +121,10 @@ void* __wrap_dlsym(void* handle, const char* symbol) {
|
|||
}
|
||||
|
||||
int __wrap_dlclose(void* handle) {
|
||||
if (GetAndroidSDKVersion() >= 23) {
|
||||
return dlclose(handle);
|
||||
}
|
||||
|
||||
if (!handle) {
|
||||
ElfLoader::Singleton.lastError = "No handle given to dlclose()";
|
||||
return -1;
|
||||
|
@ -100,6 +134,10 @@ int __wrap_dlclose(void* handle) {
|
|||
}
|
||||
|
||||
int __wrap_dladdr(void* addr, Dl_info* info) {
|
||||
if (GetAndroidSDKVersion() >= 23) {
|
||||
return dladdr(addr, info);
|
||||
}
|
||||
|
||||
RefPtr<LibHandle> handle = ElfLoader::Singleton.GetHandleByPtr(addr);
|
||||
if (!handle) {
|
||||
return dladdr(addr, info);
|
||||
|
@ -197,6 +235,10 @@ int DlIteratePhdrHelper::fill_and_call(dl_phdr_cb callback, const void* l_addr,
|
|||
}
|
||||
|
||||
int __wrap_dl_iterate_phdr(dl_phdr_cb callback, void* data) {
|
||||
if (GetAndroidSDKVersion() >= 23) {
|
||||
return dl_iterate_phdr(callback, data);
|
||||
}
|
||||
|
||||
DlIteratePhdrHelper helper;
|
||||
AutoLock lock(&ElfLoader::Singleton.handlesMutex);
|
||||
|
||||
|
@ -275,25 +317,6 @@ const char* LeafName(const char* path) {
|
|||
return path;
|
||||
}
|
||||
|
||||
#if defined(ANDROID)
|
||||
/**
|
||||
* Return the current Android version, or 0 on failure.
|
||||
*/
|
||||
int GetAndroidSDKVersion() {
|
||||
static int version = 0;
|
||||
if (version) {
|
||||
return version;
|
||||
}
|
||||
|
||||
char version_string[PROP_VALUE_MAX] = {'\0'};
|
||||
int len = __system_property_get("ro.build.version.sdk", version_string);
|
||||
if (len) {
|
||||
version = static_cast<int>(strtol(version_string, nullptr, 10));
|
||||
}
|
||||
return version;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Run the given lambda while holding the internal lock of the system linker.
|
||||
* To take the lock, we call the system dl_iterate_phdr and invoke the lambda
|
||||
|
|
|
@ -19,6 +19,10 @@
|
|||
#if defined(MOZ_LINKER)
|
||||
# include <dlfcn.h>
|
||||
# include "mozilla/Types.h"
|
||||
# if defined(ANDROID)
|
||||
# include <sys/system_properties.h>
|
||||
# endif
|
||||
|
||||
// FIXME move these out of mozglue/linker/ElfLoader.h into their
|
||||
// own header, so as to avoid conflicts arising from two definitions
|
||||
// of Array
|
||||
|
@ -140,11 +144,33 @@ AutoObjectMapperFaultyLib::~AutoObjectMapperFaultyLib() {
|
|||
// either by faulty.lib or by the parent class, but not by both.
|
||||
}
|
||||
|
||||
# if defined(ANDROID)
|
||||
static int GetAndroidSDKVersion() {
|
||||
static int version = 0;
|
||||
if (version) {
|
||||
return version;
|
||||
}
|
||||
|
||||
char version_string[PROP_VALUE_MAX] = {'\0'};
|
||||
int len = __system_property_get("ro.build.version.sdk", version_string);
|
||||
if (len) {
|
||||
version = static_cast<int>(strtol(version_string, nullptr, 10));
|
||||
}
|
||||
return version;
|
||||
}
|
||||
# endif
|
||||
|
||||
bool AutoObjectMapperFaultyLib::Map(/*OUT*/ void** start,
|
||||
/*OUT*/ size_t* length,
|
||||
std::string fileName) {
|
||||
MOZ_ASSERT(!mHdl);
|
||||
|
||||
# if defined(ANDROID)
|
||||
if (GetAndroidSDKVersion() >= 23) {
|
||||
return AutoObjectMapperPOSIX::Map(start, length, fileName);
|
||||
}
|
||||
# endif
|
||||
|
||||
if (fileName == "libmozglue.so") {
|
||||
// Do (2) in the comment above.
|
||||
char* libdir = get_installation_lib_dir();
|
||||
|
|
Загрузка…
Ссылка в новой задаче