Merge "Refactor NativeHeapTagging compat feature."
This commit is contained in:
@@ -19,8 +19,6 @@ package com.android.internal.os;
|
|||||||
import android.app.ActivityManager;
|
import android.app.ActivityManager;
|
||||||
import android.app.ActivityThread;
|
import android.app.ActivityThread;
|
||||||
import android.app.ApplicationErrorReport;
|
import android.app.ApplicationErrorReport;
|
||||||
import android.compat.annotation.ChangeId;
|
|
||||||
import android.compat.annotation.EnabledAfter;
|
|
||||||
import android.compat.annotation.UnsupportedAppUsage;
|
import android.compat.annotation.UnsupportedAppUsage;
|
||||||
import android.content.type.DefaultMimeMapFactory;
|
import android.content.type.DefaultMimeMapFactory;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
@@ -36,7 +34,6 @@ import android.util.Slog;
|
|||||||
import com.android.internal.logging.AndroidConfig;
|
import com.android.internal.logging.AndroidConfig;
|
||||||
import com.android.server.NetworkManagementSocketTagger;
|
import com.android.server.NetworkManagementSocketTagger;
|
||||||
|
|
||||||
import dalvik.annotation.compat.VersionCodes;
|
|
||||||
import dalvik.system.RuntimeHooks;
|
import dalvik.system.RuntimeHooks;
|
||||||
import dalvik.system.ThreadPrioritySetter;
|
import dalvik.system.ThreadPrioritySetter;
|
||||||
import dalvik.system.VMRuntime;
|
import dalvik.system.VMRuntime;
|
||||||
@@ -67,18 +64,8 @@ public class RuntimeInit {
|
|||||||
|
|
||||||
private static volatile boolean mCrashing = false;
|
private static volatile boolean mCrashing = false;
|
||||||
|
|
||||||
/**
|
|
||||||
* Native heap allocations will now have a non-zero tag in the most significant byte.
|
|
||||||
* See
|
|
||||||
* <a href="https://source.android.com/devices/tech/debug/tagged-pointers">https://source.android.com/devices/tech/debug/tagged-pointers</a>.
|
|
||||||
*/
|
|
||||||
@ChangeId
|
|
||||||
@EnabledAfter(targetSdkVersion = VersionCodes.Q)
|
|
||||||
private static final long NATIVE_HEAP_POINTER_TAGGING = 135754954; // This is a bug id.
|
|
||||||
|
|
||||||
private static final native void nativeFinishInit();
|
private static final native void nativeFinishInit();
|
||||||
private static final native void nativeSetExitWithoutCleanup(boolean exitWithoutCleanup);
|
private static final native void nativeSetExitWithoutCleanup(boolean exitWithoutCleanup);
|
||||||
private static native void nativeDisableHeapPointerTagging();
|
|
||||||
|
|
||||||
private static int Clog_e(String tag, String msg, Throwable tr) {
|
private static int Clog_e(String tag, String msg, Throwable tr) {
|
||||||
return Log.printlns(Log.LOG_ID_CRASH, Log.ERROR, tag, msg, tr);
|
return Log.printlns(Log.LOG_ID_CRASH, Log.ERROR, tag, msg, tr);
|
||||||
@@ -411,20 +398,6 @@ public class RuntimeInit {
|
|||||||
if (DEBUG) Slog.d(TAG, "Leaving RuntimeInit!");
|
if (DEBUG) Slog.d(TAG, "Leaving RuntimeInit!");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void maybeDisableHeapPointerTagging(long[] disabledCompatChanges) {
|
|
||||||
// Heap tagging needs to be disabled before any additional threads are created, but the
|
|
||||||
// AppCompat framework is not initialized enough at this point.
|
|
||||||
// Check if the change is enabled manually.
|
|
||||||
if (disabledCompatChanges != null) {
|
|
||||||
for (int i = 0; i < disabledCompatChanges.length; i++) {
|
|
||||||
if (disabledCompatChanges[i] == NATIVE_HEAP_POINTER_TAGGING) {
|
|
||||||
nativeDisableHeapPointerTagging();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static Runnable applicationInit(int targetSdkVersion, long[] disabledCompatChanges,
|
protected static Runnable applicationInit(int targetSdkVersion, long[] disabledCompatChanges,
|
||||||
String[] argv, ClassLoader classLoader) {
|
String[] argv, ClassLoader classLoader) {
|
||||||
// If the application calls System.exit(), terminate the process
|
// If the application calls System.exit(), terminate the process
|
||||||
@@ -437,8 +410,6 @@ public class RuntimeInit {
|
|||||||
VMRuntime.getRuntime().setTargetSdkVersion(targetSdkVersion);
|
VMRuntime.getRuntime().setTargetSdkVersion(targetSdkVersion);
|
||||||
VMRuntime.getRuntime().setDisabledCompatChanges(disabledCompatChanges);
|
VMRuntime.getRuntime().setDisabledCompatChanges(disabledCompatChanges);
|
||||||
|
|
||||||
maybeDisableHeapPointerTagging(disabledCompatChanges);
|
|
||||||
|
|
||||||
final Arguments args = new Arguments(argv);
|
final Arguments args = new Arguments(argv);
|
||||||
|
|
||||||
// The end of of the RuntimeInit event (see #zygoteInit).
|
// The end of of the RuntimeInit event (see #zygoteInit).
|
||||||
|
|||||||
@@ -121,6 +121,25 @@ public final class Zygote {
|
|||||||
*/
|
*/
|
||||||
public static final int DISABLE_TEST_API_ENFORCEMENT_POLICY = 1 << 18;
|
public static final int DISABLE_TEST_API_ENFORCEMENT_POLICY = 1 << 18;
|
||||||
|
|
||||||
|
public static final int MEMORY_TAG_LEVEL_MASK = (1 << 19) | (1 << 20);
|
||||||
|
/**
|
||||||
|
* Enable pointer tagging in this process.
|
||||||
|
* Tags are checked during memory deallocation, but not on access.
|
||||||
|
* TBI stands for Top-Byte-Ignore, an ARM CPU feature.
|
||||||
|
* {@link https://developer.arm.com/docs/den0024/latest/the-memory-management-unit/translation-table-configuration/virtual-address-tagging}
|
||||||
|
*/
|
||||||
|
public static final int MEMORY_TAG_LEVEL_TBI = 1 << 19;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable asynchronous memory tag checks in this process.
|
||||||
|
*/
|
||||||
|
public static final int MEMORY_TAG_LEVEL_ASYNC = 2 << 19;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable synchronous memory tag checks in this process.
|
||||||
|
*/
|
||||||
|
public static final int MEMORY_TAG_LEVEL_SYNC = 3 << 19;
|
||||||
|
|
||||||
/** No external storage should be mounted. */
|
/** No external storage should be mounted. */
|
||||||
public static final int MOUNT_EXTERNAL_NONE = IVold.REMOUNT_MODE_NONE;
|
public static final int MOUNT_EXTERNAL_NONE = IVold.REMOUNT_MODE_NONE;
|
||||||
/** Default external storage should be mounted. */
|
/** Default external storage should be mounted. */
|
||||||
|
|||||||
@@ -781,6 +781,10 @@ public class ZygoteInit {
|
|||||||
Zygote.applyDebuggerSystemProperty(parsedArgs);
|
Zygote.applyDebuggerSystemProperty(parsedArgs);
|
||||||
Zygote.applyInvokeWithSystemProperty(parsedArgs);
|
Zygote.applyInvokeWithSystemProperty(parsedArgs);
|
||||||
|
|
||||||
|
/* Enable pointer tagging in the system server unconditionally. Hardware support for
|
||||||
|
* this is present in all ARMv8 CPUs; this flag has no effect on other platforms. */
|
||||||
|
parsedArgs.mRuntimeFlags |= Zygote.MEMORY_TAG_LEVEL_TBI;
|
||||||
|
|
||||||
if (shouldProfileSystemServer()) {
|
if (shouldProfileSystemServer()) {
|
||||||
parsedArgs.mRuntimeFlags |= Zygote.PROFILE_SYSTEM_SERVER;
|
parsedArgs.mRuntimeFlags |= Zygote.PROFILE_SYSTEM_SERVER;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -282,14 +282,6 @@ static void com_android_internal_os_RuntimeInit_nativeSetExitWithoutCleanup(JNIE
|
|||||||
gCurRuntime->setExitWithoutCleanup(exitWithoutCleanup);
|
gCurRuntime->setExitWithoutCleanup(exitWithoutCleanup);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void com_android_internal_os_RuntimeInit_nativeDisableHeapPointerTagging(
|
|
||||||
JNIEnv* env, jobject clazz) {
|
|
||||||
HeapTaggingLevel tag_level = M_HEAP_TAGGING_LEVEL_NONE;
|
|
||||||
if (!android_mallopt(M_SET_HEAP_TAGGING_LEVEL, &tag_level, sizeof(tag_level))) {
|
|
||||||
ALOGE("ERROR: could not disable heap pointer tagging\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* JNI registration.
|
* JNI registration.
|
||||||
*/
|
*/
|
||||||
@@ -301,8 +293,6 @@ int register_com_android_internal_os_RuntimeInit(JNIEnv* env)
|
|||||||
(void*)com_android_internal_os_RuntimeInit_nativeFinishInit},
|
(void*)com_android_internal_os_RuntimeInit_nativeFinishInit},
|
||||||
{"nativeSetExitWithoutCleanup", "(Z)V",
|
{"nativeSetExitWithoutCleanup", "(Z)V",
|
||||||
(void*)com_android_internal_os_RuntimeInit_nativeSetExitWithoutCleanup},
|
(void*)com_android_internal_os_RuntimeInit_nativeSetExitWithoutCleanup},
|
||||||
{"nativeDisableHeapPointerTagging", "()V",
|
|
||||||
(void*)com_android_internal_os_RuntimeInit_nativeDisableHeapPointerTagging},
|
|
||||||
};
|
};
|
||||||
return jniRegisterNativeMethods(env, "com/android/internal/os/RuntimeInit",
|
return jniRegisterNativeMethods(env, "com/android/internal/os/RuntimeInit",
|
||||||
methods, NELEM(methods));
|
methods, NELEM(methods));
|
||||||
|
|||||||
@@ -315,6 +315,8 @@ enum MountExternalKind {
|
|||||||
enum RuntimeFlags : uint32_t {
|
enum RuntimeFlags : uint32_t {
|
||||||
DEBUG_ENABLE_JDWP = 1,
|
DEBUG_ENABLE_JDWP = 1,
|
||||||
PROFILE_FROM_SHELL = 1 << 15,
|
PROFILE_FROM_SHELL = 1 << 15,
|
||||||
|
MEMORY_TAG_LEVEL_MASK = (1 << 19) | (1 << 20),
|
||||||
|
MEMORY_TAG_LEVEL_TBI = 1 << 19,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum UnsolicitedZygoteMessageTypes : uint32_t {
|
enum UnsolicitedZygoteMessageTypes : uint32_t {
|
||||||
@@ -1153,6 +1155,16 @@ static void SpecializeCommon(JNIEnv* env, uid_t uid, gid_t gid, jintArray gids,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HeapTaggingLevel heap_tagging_level;
|
||||||
|
switch (runtime_flags & RuntimeFlags::MEMORY_TAG_LEVEL_MASK) {
|
||||||
|
case RuntimeFlags::MEMORY_TAG_LEVEL_TBI:
|
||||||
|
heap_tagging_level = M_HEAP_TAGGING_LEVEL_TBI;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
heap_tagging_level = M_HEAP_TAGGING_LEVEL_NONE;
|
||||||
|
}
|
||||||
|
android_mallopt(M_SET_HEAP_TAGGING_LEVEL, &heap_tagging_level, sizeof(heap_tagging_level));
|
||||||
|
|
||||||
if (NeedsNoRandomizeWorkaround()) {
|
if (NeedsNoRandomizeWorkaround()) {
|
||||||
// Work around ARM kernel ASLR lossage (http://b/5817320).
|
// Work around ARM kernel ASLR lossage (http://b/5817320).
|
||||||
int old_personality = personality(0xffffffff);
|
int old_personality = personality(0xffffffff);
|
||||||
|
|||||||
@@ -51,6 +51,9 @@ import android.app.ActivityThread;
|
|||||||
import android.app.AppGlobals;
|
import android.app.AppGlobals;
|
||||||
import android.app.AppProtoEnums;
|
import android.app.AppProtoEnums;
|
||||||
import android.app.IApplicationThread;
|
import android.app.IApplicationThread;
|
||||||
|
import android.app.IUidObserver;
|
||||||
|
import android.compat.annotation.ChangeId;
|
||||||
|
import android.compat.annotation.EnabledAfter;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@@ -103,6 +106,7 @@ import com.android.server.pm.dex.DexManager;
|
|||||||
import com.android.server.wm.ActivityServiceConnectionsHolder;
|
import com.android.server.wm.ActivityServiceConnectionsHolder;
|
||||||
import com.android.server.wm.WindowManagerService;
|
import com.android.server.wm.WindowManagerService;
|
||||||
|
|
||||||
|
import dalvik.annotation.compat.VersionCodes;
|
||||||
import dalvik.system.VMRuntime;
|
import dalvik.system.VMRuntime;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -280,6 +284,15 @@ public final class ProcessList {
|
|||||||
// lmkd reconnect delay in msecs
|
// lmkd reconnect delay in msecs
|
||||||
private static final long LMKD_RECONNECT_DELAY_MS = 1000;
|
private static final long LMKD_RECONNECT_DELAY_MS = 1000;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Native heap allocations will now have a non-zero tag in the most significant byte.
|
||||||
|
* @see <a href="https://source.android.com/devices/tech/debug/tagged-pointers">Tagged
|
||||||
|
* Pointers</a>
|
||||||
|
*/
|
||||||
|
@ChangeId
|
||||||
|
@EnabledAfter(targetSdkVersion = VersionCodes.Q)
|
||||||
|
private static final long NATIVE_HEAP_POINTER_TAGGING = 135754954; // This is a bug id.
|
||||||
|
|
||||||
ActivityManagerService mService = null;
|
ActivityManagerService mService = null;
|
||||||
|
|
||||||
// To kill process groups asynchronously
|
// To kill process groups asynchronously
|
||||||
@@ -1653,6 +1666,10 @@ public final class ProcessList {
|
|||||||
runtimeFlags |= Zygote.USE_APP_IMAGE_STARTUP_CACHE;
|
runtimeFlags |= Zygote.USE_APP_IMAGE_STARTUP_CACHE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mPlatformCompat.isChangeEnabled(NATIVE_HEAP_POINTER_TAGGING, app.info)) {
|
||||||
|
runtimeFlags |= Zygote.MEMORY_TAG_LEVEL_TBI;
|
||||||
|
}
|
||||||
|
|
||||||
String invokeWith = null;
|
String invokeWith = null;
|
||||||
if ((app.info.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
|
if ((app.info.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
|
||||||
// Debuggable apps may include a wrapper script with their library directory.
|
// Debuggable apps may include a wrapper script with their library directory.
|
||||||
|
|||||||
Reference in New Issue
Block a user