Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 493aea74 authored by Mitch Phillips's avatar Mitch Phillips Committed by Automerger Merge Worker
Browse files

Merge "[MTE] Add SYNC compat feature & disable for system apps." am: 284195e7 am: 6d521a4b

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1548867

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: Ibba6138e7e5d0dcfdb6fdd3fab9d9cb8ee8f8b0a
parents 66a873b5 6d521a4b
Loading
Loading
Loading
Loading
+26 −15
Original line number Diff line number Diff line
@@ -110,7 +110,6 @@ import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.app.ProcessMap;
import com.android.internal.app.procstats.ProcessStats;
import com.android.internal.os.RuntimeInit;
import com.android.internal.os.Zygote;
import com.android.internal.util.ArrayUtils;
import com.android.internal.util.FrameworkStatsLog;
@@ -349,12 +348,23 @@ public final class ProcessList {
    private static final long NATIVE_HEAP_POINTER_TAGGING = 135754954; // This is a bug id.

    /**
     * Enable memory tag checks in non-system apps. This flag will only have an effect on
     * hardware supporting the ARM Memory Tagging Extension (MTE).
     * Enable asynchronous (ASYNC) memory tag checking in this process. This
     * flag will only have an effect on hardware supporting the ARM Memory
     * Tagging Extension (MTE).
     */
    @ChangeId
    @Disabled
    private static final long NATIVE_MEMORY_TAGGING = 135772972; // This is a bug id.
    private static final long NATIVE_MEMTAG_ASYNC = 135772972; // This is a bug id.

    /**
     * Enable synchronous (SYNC) memory tag checking in this process. This flag
     * will only have an effect on hardware supporting the ARM Memory Tagging
     * Extension (MTE). If both NATIVE_MEMTAG_ASYNC and this option is selected,
     * this option takes preference and MTE is enabled in SYNC mode.
     */
    @ChangeId
    @Disabled
    private static final long NATIVE_MEMTAG_SYNC = 177438394; // This is a bug id.

    /**
     * Enable sampled memory bug detection in the app.
@@ -1677,23 +1687,23 @@ public final class ProcessList {
        return gidArray;
    }

    private boolean shouldEnableMemoryTagging(ProcessRecord app) {
    // Returns the memory tagging level to be enabled. If memory tagging isn't
    // requested, returns zero.
    private int getMemtagLevel(ProcessRecord app) {
        // Ensure the hardware + kernel actually supports MTE.
        if (!Zygote.nativeSupportsMemoryTagging()) {
            return false;
            return 0;
        }

        // Enable MTE for system apps if supported.
        if ((app.info.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
            return true;
        if (mPlatformCompat.isChangeEnabled(NATIVE_MEMTAG_SYNC, app.info)) {
            return Zygote.MEMORY_TAG_LEVEL_SYNC;
        }

        // Enable MTE if the compat feature is enabled.
        if (mPlatformCompat.isChangeEnabled(NATIVE_MEMORY_TAGGING, app.info)) {
            return true;
        if (mPlatformCompat.isChangeEnabled(NATIVE_MEMTAG_ASYNC, app.info)) {
            return Zygote.MEMORY_TAG_LEVEL_ASYNC;
        }

        return false;
        return 0;
    }

    private boolean shouldEnableTaggedPointers(ProcessRecord app) {
@@ -1717,8 +1727,9 @@ public final class ProcessList {

    private int decideTaggingLevel(ProcessRecord app) {
        // Check MTE support first, as it should take precedence over TBI.
        if (shouldEnableMemoryTagging(app)) {
            return Zygote.MEMORY_TAG_LEVEL_ASYNC;
        int memtagLevel = getMemtagLevel(app);
        if (memtagLevel != 0) {
            return memtagLevel;
        }

        if (shouldEnableTaggedPointers(app)) {