summaryrefslogtreecommitdiff
path: root/libc/include/malloc.h
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2021-01-14 13:34:20 -0800
committerElliott Hughes <enh@google.com>2021-01-14 13:34:20 -0800
commit446b4dde724ee64a336a78188c3c9a15aebca87c (patch)
tree4a91430432ee114aa75a82cc8c29e049ee7cce8b /libc/include/malloc.h
parentb4fd07297606de111c10d0f9a000fdb1e2280387 (diff)
Make "disable memory mitigations" and "set heap tagging level" more available.
These were only available internally via android_mallopt(), but they're likely to be needed by more code in future, so move them into mallopt(). This change leaves the android_mallopt() options for now, but I plan on coming back to remove them after I've switched the handful of callers over to mallopt() instead. Bug: http://b/135772972 Test: treehugger Change-Id: Ia154614069a7623c6aca85975a91e6a156f04759
Diffstat (limited to 'libc/include/malloc.h')
-rw-r--r--libc/include/malloc.h54
1 files changed, 54 insertions, 0 deletions
diff --git a/libc/include/malloc.h b/libc/include/malloc.h
index a237254b7..598a50bc5 100644
--- a/libc/include/malloc.h
+++ b/libc/include/malloc.h
@@ -204,6 +204,60 @@ int malloc_info(int __must_be_zero, FILE* __fp) __INTRODUCED_IN(23);
#define M_TSDS_COUNT_MAX (-202)
/**
+ * mallopt() option to disable heap initialization across the whole process.
+ * If the hardware supports memory tagging, this also disables memory tagging.
+ * May be called at any time, including when multiple threads are running. The
+ * value is unused but must be set to 0.
+ *
+ * Note that these memory mitigations are only implemented in scudo and
+ * therefore this will have no effect when using another allocator (such as
+ * jemalloc on Android Go devices).
+ *
+ * Available since API level 31.
+ */
+#define M_BIONIC_DISABLE_MEMORY_MITIGATIONS (-203)
+
+/**
+ * mallopt() option to change the heap tagging state. May be called at any
+ * time, including when multiple threads are running.
+ * The value must be one of the M_HEAP_TAGGING_LEVEL_ constants.
+ *
+ * Available since API level 31.
+ */
+#define M_BIONIC_SET_HEAP_TAGGING_LEVEL (-204)
+
+/**
+ * Constants for use with the M_BIONIC_SET_HEAP_TAGGING_LEVEL mallopt() option.
+ */
+enum HeapTaggingLevel {
+ /**
+ * 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,
+#define M_HEAP_TAGGING_LEVEL_NONE M_HEAP_TAGGING_LEVEL_NONE
+ /**
+ * Address-only tagging. Heap pointers have a non-zero tag in the
+ * most significant ("top") byte which is checked in free(). Memory
+ * accesses ignore the tag using arm64's Top Byte Ignore (TBI) feature.
+ */
+ M_HEAP_TAGGING_LEVEL_TBI = 1,
+#define M_HEAP_TAGGING_LEVEL_TBI M_HEAP_TAGGING_LEVEL_TBI
+ /**
+ * Enable heap tagging and asynchronous memory tag checks (if supported).
+ * Disable stack trace collection.
+ */
+ M_HEAP_TAGGING_LEVEL_ASYNC = 2,
+#define M_HEAP_TAGGING_LEVEL_ASYNC M_HEAP_TAGGING_LEVEL_ASYNC
+ /**
+ * Enable heap tagging and synchronous memory tag checks (if supported).
+ * Enable stack trace collection.
+ */
+ M_HEAP_TAGGING_LEVEL_SYNC = 3,
+#define M_HEAP_TAGGING_LEVEL_SYNC M_HEAP_TAGGING_LEVEL_SYNC
+};
+
+/**
* [mallopt(3)](http://man7.org/linux/man-pages/man3/mallopt.3.html) modifies
* heap behavior. Values of `__option` are the `M_` constants from this header.
*