summaryrefslogtreecommitdiff
path: root/runtime/native/java_lang_Runtime.cc
diff options
context:
space:
mode:
author Dmitriy Ivanov <dimitry@google.com> 2015-11-11 14:18:55 -0800
committer Dimitry Ivanov <dimitry@google.com> 2015-12-10 17:25:14 -0800
commitf5a3099c509cf9b8a4ce9c3073a4db47e14a23bc (patch)
tree5f07f3ea531240643f4f637c9d3abbad6feafa52 /runtime/native/java_lang_Runtime.cc
parent748047de833061466e230baf374480a147568f73 (diff)
Use isolated namespaces for app native libs
Linker namespaces provide necessary level of isolation for application native libraries. The native libraries will no longer be able to mistakenly depend on platform private libraries like /system/lib/libssl.so This change creates one namespace for each instance of class-loader and uses it when loading native libraries. For backwards compatibility with older apps we keep using default namespace and LD_LIBRARY_PATH if target sdk version is <= 23. (currently set to 0 for testing) Bug: http://b/22548808 Change-Id: I64e97af7450fbf7e3740ccddda96bb2f7c52e03b
Diffstat (limited to 'runtime/native/java_lang_Runtime.cc')
-rw-r--r--runtime/native/java_lang_Runtime.cc24
1 files changed, 16 insertions, 8 deletions
diff --git a/runtime/native/java_lang_Runtime.cc b/runtime/native/java_lang_Runtime.cc
index 856a3e7d01..ff82772171 100644
--- a/runtime/native/java_lang_Runtime.cc
+++ b/runtime/native/java_lang_Runtime.cc
@@ -52,10 +52,10 @@ NO_RETURN static void Runtime_nativeExit(JNIEnv*, jclass, jint status) {
exit(status);
}
-static void SetLdLibraryPath(JNIEnv* env, jstring javaLdLibraryPathJstr) {
+static void SetLdLibraryPath(JNIEnv* env, jstring javaLdLibraryPath) {
#ifdef __ANDROID__
- if (javaLdLibraryPathJstr != nullptr) {
- ScopedUtfChars ldLibraryPath(env, javaLdLibraryPathJstr);
+ if (javaLdLibraryPath != nullptr) {
+ ScopedUtfChars ldLibraryPath(env, javaLdLibraryPath);
if (ldLibraryPath.c_str() != nullptr) {
android_update_LD_LIBRARY_PATH(ldLibraryPath.c_str());
}
@@ -63,23 +63,31 @@ static void SetLdLibraryPath(JNIEnv* env, jstring javaLdLibraryPathJstr) {
#else
LOG(WARNING) << "android_update_LD_LIBRARY_PATH not found; .so dependencies will not work!";
- UNUSED(javaLdLibraryPathJstr, env);
+ UNUSED(javaLdLibraryPath, env);
#endif
}
static jstring Runtime_nativeLoad(JNIEnv* env, jclass, jstring javaFilename, jobject javaLoader,
- jstring javaLdLibraryPathJstr) {
+ jstring javaLdLibraryPath, jstring javaIsolationPath) {
ScopedUtfChars filename(env, javaFilename);
if (filename.c_str() == nullptr) {
return nullptr;
}
- SetLdLibraryPath(env, javaLdLibraryPathJstr);
+ int32_t target_sdk_version = Runtime::Current()->GetTargetSdkVersion();
+
+ // Starting with N nativeLoad uses classloader local
+ // linker namespace instead of global LD_LIBRARY_PATH
+ // (23 is Marshmallow)
+ if (target_sdk_version == 0) {
+ SetLdLibraryPath(env, javaLdLibraryPath);
+ }
std::string error_msg;
{
JavaVMExt* vm = Runtime::Current()->GetJavaVM();
- bool success = vm->LoadNativeLibrary(env, filename.c_str(), javaLoader, &error_msg);
+ bool success = vm->LoadNativeLibrary(env, filename.c_str(), javaLoader,
+ javaLdLibraryPath, javaIsolationPath, &error_msg);
if (success) {
return nullptr;
}
@@ -107,7 +115,7 @@ static JNINativeMethod gMethods[] = {
NATIVE_METHOD(Runtime, gc, "()V"),
NATIVE_METHOD(Runtime, maxMemory, "!()J"),
NATIVE_METHOD(Runtime, nativeExit, "(I)V"),
- NATIVE_METHOD(Runtime, nativeLoad, "(Ljava/lang/String;Ljava/lang/ClassLoader;Ljava/lang/String;)Ljava/lang/String;"),
+ NATIVE_METHOD(Runtime, nativeLoad, "(Ljava/lang/String;Ljava/lang/ClassLoader;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;"),
NATIVE_METHOD(Runtime, totalMemory, "!()J"),
};