diff options
author | Evgenii Stepanov <eugenis@google.com> | 2021-01-15 14:11:47 -0800 |
---|---|---|
committer | Evgenii Stepanov <eugenis@google.com> | 2021-02-25 23:38:33 +0000 |
commit | 15cce113f7232e117b091770c220ebc1b55f41d2 (patch) | |
tree | 04573488d956131135f487cd63d2d0b4ec4d2331 /core/jni | |
parent | 5c9ebe31abcb0ab531032caf610e5ccd247c7582 (diff) |
Implement memtagMode and nativeHeapZeroInit manifest attrs.
memtagMode allows an app to opt in to MTE in either sync or async mode.
nativeHeapZeroInit enables automatic initialization of heap memory.
Both attributes default to off and can be specified at either
application or process level.
Bug: 135772972
Bug: 177438394
Bug: 178038272
Test: CtsTaggingHostTestCases
Change-Id: I6a481a9d2363997bf954f248d08224c79f0c2afb
Merged-In: I6a481a9d2363997bf954f248d08224c79f0c2afb
Diffstat (limited to 'core/jni')
-rw-r--r-- | core/jni/com_android_internal_os_Zygote.cpp | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/core/jni/com_android_internal_os_Zygote.cpp b/core/jni/com_android_internal_os_Zygote.cpp index 4cef2b099589..bcd203b6ca77 100644 --- a/core/jni/com_android_internal_os_Zygote.cpp +++ b/core/jni/com_android_internal_os_Zygote.cpp @@ -344,6 +344,7 @@ enum RuntimeFlags : uint32_t { GWP_ASAN_LEVEL_NEVER = 0 << 21, GWP_ASAN_LEVEL_LOTTERY = 1 << 21, GWP_ASAN_LEVEL_ALWAYS = 2 << 21, + NATIVE_HEAP_ZERO_INIT = 1 << 23, }; enum UnsolicitedZygoteMessageTypes : uint32_t { @@ -1682,15 +1683,20 @@ static void SpecializeCommon(JNIEnv* env, uid_t uid, gid_t gid, jintArray gids, } mallopt(M_BIONIC_SET_HEAP_TAGGING_LEVEL, heap_tagging_level); + // Now that we've used the flag, clear it so that we don't pass unknown flags to the ART runtime. + runtime_flags &= ~RuntimeFlags::MEMORY_TAG_LEVEL_MASK; + // Avoid heap zero initialization for applications without MTE. Zero init may // cause app compat problems, use more memory, or reduce performance. While it // would be nice to have them for apps, we will have to wait until they are // proven out, have more efficient hardware, and/or apply them only to new // applications. - mallopt(M_BIONIC_ZERO_INIT, 0); + if (!(runtime_flags & RuntimeFlags::NATIVE_HEAP_ZERO_INIT)) { + mallopt(M_BIONIC_ZERO_INIT, 0); + } // Now that we've used the flag, clear it so that we don't pass unknown flags to the ART runtime. - runtime_flags &= ~RuntimeFlags::MEMORY_TAG_LEVEL_MASK; + runtime_flags &= ~RuntimeFlags::NATIVE_HEAP_ZERO_INIT; bool forceEnableGwpAsan = false; switch (runtime_flags & RuntimeFlags::GWP_ASAN_LEVEL_MASK) { |