Merge "Create linker-namespace for the classloader" into nyc-dev
am: 1a2cb453fa
* commit '1a2cb453fa8204db84d92fd2de92b0ed1e546a03':
Create linker-namespace for the classloader
This commit is contained in:
@@ -20,16 +20,14 @@ import android.os.Trace;
|
|||||||
import android.util.ArrayMap;
|
import android.util.ArrayMap;
|
||||||
import dalvik.system.PathClassLoader;
|
import dalvik.system.PathClassLoader;
|
||||||
|
|
||||||
class ApplicationLoaders
|
class ApplicationLoaders {
|
||||||
{
|
public static ApplicationLoaders getDefault() {
|
||||||
public static ApplicationLoaders getDefault()
|
|
||||||
{
|
|
||||||
return gApplicationLoaders;
|
return gApplicationLoaders;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ClassLoader getClassLoader(String zip, boolean isBundled, String librarySearchPath,
|
public ClassLoader getClassLoader(String zip, int targetSdkVersion, boolean isBundled,
|
||||||
String libraryPermittedPath, ClassLoader parent)
|
String librarySearchPath, String libraryPermittedPath,
|
||||||
{
|
ClassLoader parent) {
|
||||||
/*
|
/*
|
||||||
* This is the parent we use if they pass "null" in. In theory
|
* This is the parent we use if they pass "null" in. In theory
|
||||||
* this should be the "system" class loader; in practice we
|
* this should be the "system" class loader; in practice we
|
||||||
@@ -55,11 +53,22 @@ class ApplicationLoaders
|
|||||||
}
|
}
|
||||||
|
|
||||||
Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, zip);
|
Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, zip);
|
||||||
|
|
||||||
PathClassLoader pathClassloader =
|
PathClassLoader pathClassloader =
|
||||||
new PathClassLoader(zip, isBundled, librarySearchPath,
|
new PathClassLoader(zip, librarySearchPath, parent);
|
||||||
libraryPermittedPath, parent);
|
|
||||||
|
String errorMessage = createClassloaderNamespace(pathClassloader,
|
||||||
|
targetSdkVersion,
|
||||||
|
librarySearchPath,
|
||||||
|
libraryPermittedPath,
|
||||||
|
isBundled);
|
||||||
Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
|
Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
|
||||||
|
|
||||||
|
if (errorMessage != null) {
|
||||||
|
throw new UnsatisfiedLinkError("Unable to create namespace for the classloader " +
|
||||||
|
pathClassloader + ": " + errorMessage);
|
||||||
|
}
|
||||||
|
|
||||||
mLoaders.put(zip, pathClassloader);
|
mLoaders.put(zip, pathClassloader);
|
||||||
return pathClassloader;
|
return pathClassloader;
|
||||||
}
|
}
|
||||||
@@ -71,6 +80,12 @@ class ApplicationLoaders
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static native String createClassloaderNamespace(ClassLoader classLoader,
|
||||||
|
int targetSdkVersion,
|
||||||
|
String librarySearchPath,
|
||||||
|
String libraryPermittedPath,
|
||||||
|
boolean isShared);
|
||||||
|
|
||||||
private final ArrayMap<String, ClassLoader> mLoaders = new ArrayMap<String, ClassLoader>();
|
private final ArrayMap<String, ClassLoader> mLoaders = new ArrayMap<String, ClassLoader>();
|
||||||
|
|
||||||
private static final ApplicationLoaders gApplicationLoaders
|
private static final ApplicationLoaders gApplicationLoaders
|
||||||
|
|||||||
@@ -413,8 +413,9 @@ public final class LoadedApk {
|
|||||||
// as this is early and necessary.
|
// as this is early and necessary.
|
||||||
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
|
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
|
||||||
|
|
||||||
mClassLoader = ApplicationLoaders.getDefault().getClassLoader(zip, isBundledApp,
|
mClassLoader = ApplicationLoaders.getDefault().getClassLoader(zip,
|
||||||
librarySearchPath, libraryPermittedPath, mBaseClassLoader);
|
mApplicationInfo.targetSdkVersion, isBundledApp, librarySearchPath,
|
||||||
|
libraryPermittedPath, mBaseClassLoader);
|
||||||
|
|
||||||
StrictMode.setThreadPolicy(oldPolicy);
|
StrictMode.setThreadPolicy(oldPolicy);
|
||||||
return mClassLoader;
|
return mClassLoader;
|
||||||
|
|||||||
@@ -87,8 +87,7 @@ public class NativeActivity extends Activity implements SurfaceHolder.Callback2,
|
|||||||
|
|
||||||
private native long loadNativeCode(String path, String funcname, MessageQueue queue,
|
private native long loadNativeCode(String path, String funcname, MessageQueue queue,
|
||||||
String internalDataPath, String obbPath, String externalDataPath, int sdkVersion,
|
String internalDataPath, String obbPath, String externalDataPath, int sdkVersion,
|
||||||
AssetManager assetMgr, byte[] savedState, ClassLoader classLoader, String libraryPath,
|
AssetManager assetMgr, byte[] savedState, ClassLoader classLoader, String libraryPath);
|
||||||
String isolationPath);
|
|
||||||
private native String getDlError();
|
private native String getDlError();
|
||||||
private native void unloadNativeCode(long handle);
|
private native void unloadNativeCode(long handle);
|
||||||
private native void onStartNative(long handle);
|
private native void onStartNative(long handle);
|
||||||
@@ -169,8 +168,7 @@ public class NativeActivity extends Activity implements SurfaceHolder.Callback2,
|
|||||||
getAbsolutePath(getFilesDir()), getAbsolutePath(getObbDir()),
|
getAbsolutePath(getFilesDir()), getAbsolutePath(getObbDir()),
|
||||||
getAbsolutePath(getExternalFilesDir(null)),
|
getAbsolutePath(getExternalFilesDir(null)),
|
||||||
Build.VERSION.SDK_INT, getAssets(), nativeSavedState,
|
Build.VERSION.SDK_INT, getAssets(), nativeSavedState,
|
||||||
classLoader, classLoader.getLdLibraryPath(),
|
classLoader, classLoader.getLdLibraryPath());
|
||||||
classLoader.getLibraryPermittedPath());
|
|
||||||
|
|
||||||
if (mNativeHandle == 0) {
|
if (mNativeHandle == 0) {
|
||||||
throw new UnsatisfiedLinkError(
|
throw new UnsatisfiedLinkError(
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ LOCAL_SRC_FILES:= \
|
|||||||
com_android_internal_content_NativeLibraryHelper.cpp \
|
com_android_internal_content_NativeLibraryHelper.cpp \
|
||||||
com_google_android_gles_jni_EGLImpl.cpp \
|
com_google_android_gles_jni_EGLImpl.cpp \
|
||||||
com_google_android_gles_jni_GLImpl.cpp.arm \
|
com_google_android_gles_jni_GLImpl.cpp.arm \
|
||||||
|
android_app_ApplicationLoaders.cpp \
|
||||||
android_app_NativeActivity.cpp \
|
android_app_NativeActivity.cpp \
|
||||||
android_auditing_SecurityLog.cpp \
|
android_auditing_SecurityLog.cpp \
|
||||||
android_opengl_EGL14.cpp \
|
android_opengl_EGL14.cpp \
|
||||||
|
|||||||
@@ -177,6 +177,7 @@ extern int register_android_backup_BackupDataOutput(JNIEnv *env);
|
|||||||
extern int register_android_backup_FileBackupHelperBase(JNIEnv *env);
|
extern int register_android_backup_FileBackupHelperBase(JNIEnv *env);
|
||||||
extern int register_android_backup_BackupHelperDispatcher(JNIEnv *env);
|
extern int register_android_backup_BackupHelperDispatcher(JNIEnv *env);
|
||||||
extern int register_android_app_backup_FullBackup(JNIEnv *env);
|
extern int register_android_app_backup_FullBackup(JNIEnv *env);
|
||||||
|
extern int register_android_app_ApplicationLoaders(JNIEnv* env);
|
||||||
extern int register_android_app_ActivityThread(JNIEnv *env);
|
extern int register_android_app_ActivityThread(JNIEnv *env);
|
||||||
extern int register_android_app_NativeActivity(JNIEnv *env);
|
extern int register_android_app_NativeActivity(JNIEnv *env);
|
||||||
extern int register_android_media_RemoteDisplay(JNIEnv *env);
|
extern int register_android_media_RemoteDisplay(JNIEnv *env);
|
||||||
@@ -1371,6 +1372,7 @@ static const RegJNIRec gRegJNI[] = {
|
|||||||
REG_JNI(register_android_backup_FileBackupHelperBase),
|
REG_JNI(register_android_backup_FileBackupHelperBase),
|
||||||
REG_JNI(register_android_backup_BackupHelperDispatcher),
|
REG_JNI(register_android_backup_BackupHelperDispatcher),
|
||||||
REG_JNI(register_android_app_backup_FullBackup),
|
REG_JNI(register_android_app_backup_FullBackup),
|
||||||
|
REG_JNI(register_android_app_ApplicationLoaders),
|
||||||
REG_JNI(register_android_app_ActivityThread),
|
REG_JNI(register_android_app_ActivityThread),
|
||||||
REG_JNI(register_android_app_NativeActivity),
|
REG_JNI(register_android_app_NativeActivity),
|
||||||
REG_JNI(register_android_util_jar_StrictJarFile),
|
REG_JNI(register_android_util_jar_StrictJarFile),
|
||||||
|
|||||||
51
core/jni/android_app_ApplicationLoaders.cpp
Normal file
51
core/jni/android_app_ApplicationLoaders.cpp
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016 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 <string>
|
||||||
|
|
||||||
|
#include "nativeloader/native_loader.h"
|
||||||
|
|
||||||
|
#include "core_jni_helpers.h"
|
||||||
|
|
||||||
|
|
||||||
|
static jstring createClassloaderNamespace_native(JNIEnv* env,
|
||||||
|
jobject clazz,
|
||||||
|
jobject classLoader,
|
||||||
|
jint targetSdkVersion,
|
||||||
|
jstring librarySearchPath,
|
||||||
|
jstring libraryPermittedPath,
|
||||||
|
jboolean isShared) {
|
||||||
|
return android::CreateClassLoaderNamespace(env, targetSdkVersion,
|
||||||
|
classLoader, isShared == JNI_TRUE,
|
||||||
|
librarySearchPath, libraryPermittedPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
static const JNINativeMethod g_methods[] = {
|
||||||
|
{ "createClassloaderNamespace",
|
||||||
|
"(Ljava/lang/ClassLoader;ILjava/lang/String;Ljava/lang/String;Z)Ljava/lang/String;",
|
||||||
|
reinterpret_cast<void*>(createClassloaderNamespace_native) },
|
||||||
|
};
|
||||||
|
|
||||||
|
static const char* const kApplicationLoadersPathName = "android/app/ApplicationLoaders";
|
||||||
|
|
||||||
|
namespace android
|
||||||
|
{
|
||||||
|
|
||||||
|
int register_android_app_ApplicationLoaders(JNIEnv* env) {
|
||||||
|
return RegisterMethodsOrDie(env, kApplicationLoadersPathName, g_methods, NELEM(g_methods));
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace android
|
||||||
@@ -259,8 +259,7 @@ static jlong
|
|||||||
loadNativeCode_native(JNIEnv* env, jobject clazz, jstring path, jstring funcName,
|
loadNativeCode_native(JNIEnv* env, jobject clazz, jstring path, jstring funcName,
|
||||||
jobject messageQueue, jstring internalDataDir, jstring obbDir,
|
jobject messageQueue, jstring internalDataDir, jstring obbDir,
|
||||||
jstring externalDataDir, jint sdkVersion, jobject jAssetMgr,
|
jstring externalDataDir, jint sdkVersion, jobject jAssetMgr,
|
||||||
jbyteArray savedState, jobject classLoader, jstring libraryPath,
|
jbyteArray savedState, jobject classLoader, jstring libraryPath) {
|
||||||
jstring isolationPath) {
|
|
||||||
if (kLogTrace) {
|
if (kLogTrace) {
|
||||||
ALOGD("loadNativeCode_native");
|
ALOGD("loadNativeCode_native");
|
||||||
}
|
}
|
||||||
@@ -269,8 +268,7 @@ loadNativeCode_native(JNIEnv* env, jobject clazz, jstring path, jstring funcName
|
|||||||
std::unique_ptr<NativeCode> code;
|
std::unique_ptr<NativeCode> code;
|
||||||
bool needNativeBridge = false;
|
bool needNativeBridge = false;
|
||||||
|
|
||||||
void* handle = OpenNativeLibrary(env, sdkVersion, pathStr, classLoader,
|
void* handle = OpenNativeLibrary(env, sdkVersion, pathStr, classLoader, libraryPath);
|
||||||
false, libraryPath, isolationPath);
|
|
||||||
if (handle == NULL) {
|
if (handle == NULL) {
|
||||||
if (NativeBridgeIsSupported(pathStr)) {
|
if (NativeBridgeIsSupported(pathStr)) {
|
||||||
handle = NativeBridgeLoadLibrary(pathStr, RTLD_LAZY);
|
handle = NativeBridgeLoadLibrary(pathStr, RTLD_LAZY);
|
||||||
@@ -656,7 +654,7 @@ onContentRectChanged_native(JNIEnv* env, jobject clazz, jlong handle,
|
|||||||
|
|
||||||
static const JNINativeMethod g_methods[] = {
|
static const JNINativeMethod g_methods[] = {
|
||||||
{ "loadNativeCode",
|
{ "loadNativeCode",
|
||||||
"(Ljava/lang/String;Ljava/lang/String;Landroid/os/MessageQueue;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILandroid/content/res/AssetManager;[BLjava/lang/ClassLoader;Ljava/lang/String;Ljava/lang/String;)J",
|
"(Ljava/lang/String;Ljava/lang/String;Landroid/os/MessageQueue;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILandroid/content/res/AssetManager;[BLjava/lang/ClassLoader;Ljava/lang/String;)J",
|
||||||
(void*)loadNativeCode_native },
|
(void*)loadNativeCode_native },
|
||||||
{ "getDlError", "()Ljava/lang/String;", (void*) getDlError_native },
|
{ "getDlError", "()Ljava/lang/String;", (void*) getDlError_native },
|
||||||
{ "unloadNativeCode", "(J)V", (void*)unloadNativeCode_native },
|
{ "unloadNativeCode", "(J)V", (void*)unloadNativeCode_native },
|
||||||
|
|||||||
Reference in New Issue
Block a user