Bug 1447607 - Correctly init and update ElfLoader::Singleton::lastError r=glandium draft
authorJames Willcox <snorp@snorp.net>
Fri, 30 Mar 2018 09:57:43 -0500
changeset 775200 ceffcf19af30a8a1b70aaf5df548f440da3743df
parent 775199 e70f70a71f59cdb3f32bc07f6f288d70c858f528
push id104647
push userbmo:snorp@snorp.net
push dateFri, 30 Mar 2018 14:58:30 +0000
reviewersglandium
bugs1447607
milestone61.0a1
Bug 1447607 - Correctly init and update ElfLoader::Singleton::lastError r=glandium MozReview-Commit-ID: r1bclXdt4V
mozglue/linker/ElfLoader.cpp
mozglue/linker/ElfLoader.h
--- 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();