Merge "Minimize calls to mprotect"

This commit is contained in:
Dmitriy Ivanov
2015-01-24 00:41:52 +00:00
committed by Gerrit Code Review
4 changed files with 106 additions and 23 deletions

View File

@@ -850,3 +850,17 @@ TEST(dlfcn, dlopen_symlink) {
dlclose(handle1);
dlclose(handle2);
}
// libtest_dlopen_from_ctor_main.so depends on
// libtest_dlopen_from_ctor.so which has a constructor
// that calls dlopen(libc...). This is to test the situation
// described in b/7941716.
TEST(dlfcn, dlopen_dlopen_from_ctor) {
#if defined(__BIONIC__)
void* handle = dlopen("libtest_dlopen_from_ctor_main.so", RTLD_NOW);
ASSERT_TRUE(handle != nullptr) << dlerror();
dlclose(handle);
#else
GTEST_LOG_(INFO) << "This test is disabled for glibc (glibc segfaults if you try to call dlopen from a constructor).\n";
#endif
}

View File

@@ -367,3 +367,29 @@ libtest_dlopen_weak_undefined_func_src_files := \
module := libtest_dlopen_weak_undefined_func
include $(LOCAL_PATH)/Android.build.testlib.mk
# -----------------------------------------------------------------------------
# Library with constructor that calls dlopen() b/7941716
# -----------------------------------------------------------------------------
libtest_dlopen_from_ctor_src_files := \
dlopen_testlib_dlopen_from_ctor.cpp
module := libtest_dlopen_from_ctor
build_target := SHARED_LIBRARY
build_type := host
include $(TEST_PATH)/Android.build.mk
libtest_dlopen_from_ctor_shared_libraries := libdl
build_type := target
include $(TEST_PATH)/Android.build.mk
# -----------------------------------------------------------------------------
# Library that depends on the library with constructor that calls dlopen() b/7941716
# -----------------------------------------------------------------------------
libtest_dlopen_from_ctor_main_src_files := empty.cpp
libtest_dlopen_from_ctor_main_shared_libraries := libtest_dlopen_from_ctor
module := libtest_dlopen_from_ctor_main
include $(LOCAL_PATH)/Android.build.testlib.mk

View File

@@ -0,0 +1,23 @@
/*
* Copyright (C) 2015 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <dlfcn.h>
static void __attribute__((constructor)) call_dlopen_from_ctor() {
void* handle = dlopen("libc.so", RTLD_NOW);
dlclose(handle);
}