Change the android_mallopt(M_SET_HEAP_TAGGING_LEVEL) API.
- Make it apply to every thread, and thus remove the restriction
that it must be called while the program is single threaded.
- Make it change TCF0 itself (on all threads), instead of requiring
callers to do it themselves, which can be error prone.
And update all of the call sites.
Change the implementation of
android_mallopt(M_DISABLE_MEMORY_MITIGATIONS) to call
android_mallopt(M_SET_HEAP_TAGGING_LEVEL) internally. This avoids
crashes during startup that were observed when the two mallopts
updated TCF0 unaware of each other.
I wouldn't expect there to be any out-of-tree callers at this point,
but it's worth noting that the new interface is backwards compatible
with the old one because it strictly expands the set of situations in
which the API can be used (i.e. situations where there are multiple
threads running or where TCF0 hadn't been updated beforehand).
Bug: 135772972
Change-Id: I7746707898ff31ef2e0af01c4f55ba90b72bef51
diff --git a/libc/platform/bionic/malloc.h b/libc/platform/bionic/malloc.h
index 16ef3a0..56badf0 100644
--- a/libc/platform/bionic/malloc.h
+++ b/libc/platform/bionic/malloc.h
@@ -85,8 +85,8 @@
// arg_size = sizeof(android_mallopt_leak_info_t)
M_FREE_MALLOC_LEAK_INFO = 7,
#define M_FREE_MALLOC_LEAK_INFO M_FREE_MALLOC_LEAK_INFO
- // Change the heap tagging state. The program must be single threaded at the point when the
- // android_mallopt function is called.
+ // Change the heap tagging state. May be called at any time including when
+ // multiple threads are running.
// arg = HeapTaggingLevel*
// arg_size = sizeof(HeapTaggingLevel)
M_SET_HEAP_TAGGING_LEVEL = 8,
@@ -115,15 +115,17 @@
};
enum HeapTaggingLevel {
- // Disable heap tagging. The program must use prctl(PR_SET_TAGGED_ADDR_CTRL) to disable memory tag
- // checks before disabling heap tagging. Heap tagging may not be re-enabled after being disabled.
+ // Disable heap tagging and memory tag checks if supported. Heap tagging may not be re-enabled
+ // after being disabled.
M_HEAP_TAGGING_LEVEL_NONE = 0,
// Address-only tagging. Heap pointers have a non-zero tag in the most significant byte which is
// checked in free(). Memory accesses ignore the tag.
M_HEAP_TAGGING_LEVEL_TBI = 1,
- // Enable heap tagging if supported, at a level appropriate for asynchronous memory tag checks.
+ // Enable heap tagging and asynchronous memory tag checks if supported. Disable stack trace
+ // collection.
M_HEAP_TAGGING_LEVEL_ASYNC = 2,
- // Enable heap tagging if supported, at a level appropriate for synchronous memory tag checks.
+ // Enable heap tagging and synchronous memory tag checks if supported. Enable stack trace
+ // collection.
M_HEAP_TAGGING_LEVEL_SYNC = 3,
};