Bug 1447607 - Correctly init and update ElfLoader::Singleton::lastError r=glandium
MozReview-Commit-ID: r1bclXdt4V
--- a/mozglue/linker/ElfLoader.cpp
+++ b/mozglue/linker/ElfLoader.cpp
@@ -80,17 +80,21 @@ void *
if (!handle) {
ElfLoader::Singleton.lastError = "dlsym(NULL, sym) unsupported";
return nullptr;
}
if (handle != RTLD_DEFAULT && handle != RTLD_NEXT) {
LibHandle *h = reinterpret_cast<LibHandle *>(handle);
return h->GetSymbolPtr(symbol);
}
- return dlsym(handle, symbol);
+
+ void* sym = dlsym(handle, symbol);
+ ElfLoader::Singleton.lastError = dlerror();
+
+ return sym;
}
int
__wrap_dlclose(void *handle)
{
if (!handle) {
ElfLoader::Singleton.lastError = "No handle given to dlclose()";
return -1;
@@ -351,16 +355,17 @@ LibHandle::MappableMUnmap(void *addr, si
*/
already_AddRefed<LibHandle>
SystemElf::Load(const char *path, int flags)
{
/* The Android linker returns a handle when the file name matches an
* already loaded library, even when the full path doesn't exist */
if (path && path[0] == '/' && (access(path, F_OK) == -1)){
DEBUG_LOG("dlopen(\"%s\", 0x%x) = %p", path, flags, (void *)nullptr);
+ ElfLoader::Singleton.lastError = "Specified file does not exist";
return nullptr;
}
void *handle = dlopen(path, flags);
DEBUG_LOG("dlopen(\"%s\", 0x%x) = %p", path, flags, handle);
ElfLoader::Singleton.lastError = dlerror();
if (handle) {
SystemElf *elf = new SystemElf(path, handle);
--- a/mozglue/linker/ElfLoader.h
+++ b/mozglue/linker/ElfLoader.h
@@ -449,17 +449,17 @@ protected:
/* Last error. Used for dlerror() */
friend class SystemElf;
friend const char *__wrap_dlerror(void);
friend void *__wrap_dlsym(void *handle, const char *symbol);
friend int __wrap_dlclose(void *handle);
const char *lastError;
private:
- ElfLoader() : expect_shutdown(true)
+ ElfLoader() : expect_shutdown(true), lastError(nullptr)
{
pthread_mutex_init(&handlesMutex, nullptr);
}
~ElfLoader();
/* Initialization code that can't run during static initialization. */
void Init();