diff options
author | Dmitriy Ivanov <dimitry@google.com> | 2014-07-01 14:10:16 -0700 |
---|---|---|
committer | Dmitriy Ivanov <dimitry@google.com> | 2014-07-02 13:20:47 -0700 |
commit | 04dc91ae763adc403a14c88b4c46f77b3d2d71a3 (patch) | |
tree | aa8c5774929f43e2a13e308f93df4c65744f777d /linker | |
parent | 4d299a2cf7880789e658f427196d1ca9fe02a9bc (diff) | |
download | bionic-04dc91ae763adc403a14c88b4c46f77b3d2d71a3.zip bionic-04dc91ae763adc403a14c88b4c46f77b3d2d71a3.tar.gz bionic-04dc91ae763adc403a14c88b4c46f77b3d2d71a3.tar.bz2 |
Load library using file handle.
* This patch enables dlopen by file descriptor
instead of path/name.
Bug: 15984217
Change-Id: Ib39051e00567fb97070bf96d8ce63993877c0a01
Diffstat (limited to 'linker')
-rw-r--r-- | linker/linker.cpp | 20 | ||||
-rw-r--r-- | linker/linker_phdr.cpp | 3 |
2 files changed, 15 insertions, 8 deletions
diff --git a/linker/linker.cpp b/linker/linker.cpp index bf923c1..2065231 100644 --- a/linker/linker.cpp +++ b/linker/linker.cpp @@ -42,6 +42,7 @@ #include "private/bionic_tls.h" #include "private/KernelArgumentBlock.h" #include "private/ScopedPthreadMutexLocker.h" +#include "private/ScopedFd.h" #include "linker.h" #include "linker_debug.h" @@ -696,11 +697,20 @@ static int open_library(const char* name) { } static soinfo* load_library(const char* name, int dlflags, const android_dlextinfo* extinfo) { - // Open the file. - int fd = open_library(name); - if (fd == -1) { + int fd = -1; + ScopedFd file_guard(-1); + + if (extinfo != NULL && (extinfo->flags & ANDROID_DLEXT_USE_LIBRARY_FD) != 0) { + fd = extinfo->library_fd; + } else { + // Open the file. + fd = open_library(name); + if (fd == -1) { DL_ERR("library \"%s\" not found", name); return NULL; + } + + file_guard.reset(fd); } ElfReader elf_reader(name, fd); @@ -744,7 +754,7 @@ static soinfo* load_library(const char* name, int dlflags, const android_dlextin // At this point we know that whatever is loaded @ base is a valid ELF // shared library whose segments are properly mapped in. - TRACE("[ find_library_internal base=%p size=%zu name='%s' ]", + TRACE("[ load_library base=%p size=%zu name='%s' ]", reinterpret_cast<void*>(si->base), si->size, si->name); if (!soinfo_link_image(si, extinfo)) { @@ -847,7 +857,7 @@ soinfo* do_dlopen(const char* name, int flags, const android_dlextinfo* extinfo) return NULL; } if (extinfo != NULL && ((extinfo->flags & ~(ANDROID_DLEXT_VALID_FLAG_BITS)) != 0)) { - DL_ERR("invalid extended flags to android_dlopen_ext: %x", extinfo->flags); + DL_ERR("invalid extended flags to android_dlopen_ext: %llx", extinfo->flags); return NULL; } protect_data(PROT_READ | PROT_WRITE); diff --git a/linker/linker_phdr.cpp b/linker/linker_phdr.cpp index 12e9779..11585af 100644 --- a/linker/linker_phdr.cpp +++ b/linker/linker_phdr.cpp @@ -127,9 +127,6 @@ ElfReader::ElfReader(const char* name, int fd) } ElfReader::~ElfReader() { - if (fd_ != -1) { - close(fd_); - } if (phdr_mmap_ != NULL) { munmap(phdr_mmap_, phdr_size_); } |