Load library using file handle.

* This patch enables dlopen by file descriptor
   instead of path/name.

Bug: 15984217
Change-Id: Ib39051e00567fb97070bf96d8ce63993877c0a01
This commit is contained in:
Dmitriy Ivanov
2014-07-01 14:10:16 -07:00
parent 4d299a2cf7
commit 04dc91ae76
7 changed files with 122 additions and 9 deletions

View File

@@ -45,6 +45,11 @@ typedef int (*fn)(void);
#define LIBNAME_NORELRO "libdlext_test_norelro.so"
#define LIBSIZE 1024*1024 // how much address space to reserve for it
#if defined(__LP64__)
#define LIBPATH "%s/nativetest64/libdlext_test_fd/libdlext_test_fd.so"
#else
#define LIBPATH "%s/nativetest/libdlext_test_fd/libdlext_test_fd.so"
#endif
class DlExtTest : public ::testing::Test {
protected:
@@ -83,6 +88,23 @@ TEST_F(DlExtTest, ExtInfoNoFlags) {
EXPECT_EQ(4, f());
}
TEST_F(DlExtTest, ExtInfoUseFd) {
const char* android_data = getenv("ANDROID_DATA");
ASSERT_TRUE(android_data != NULL);
char lib_path[PATH_MAX];
snprintf(lib_path, sizeof(lib_path), LIBPATH, android_data);
android_dlextinfo extinfo;
extinfo.flags = ANDROID_DLEXT_USE_LIBRARY_FD;
extinfo.library_fd = TEMP_FAILURE_RETRY(open(lib_path, O_RDONLY | O_CLOEXEC));
ASSERT_TRUE(extinfo.library_fd != -1);
handle_ = android_dlopen_ext(lib_path, RTLD_NOW, &extinfo);
ASSERT_DL_NOTNULL(handle_);
fn f = reinterpret_cast<fn>(dlsym(handle_, "getRandomNumber"));
ASSERT_DL_NOTNULL(f);
EXPECT_EQ(4, f());
}
TEST_F(DlExtTest, Reserved) {
void* start = mmap(NULL, LIBSIZE, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS,
-1, 0);