The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 1 | /* |
Ian Rogers | 2c344d3 | 2012-08-28 15:53:10 -0700 | [diff] [blame] | 2 | * Copyright (C) 2012 The Android Open Source Project |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 3 | * |
Ian Rogers | 2c344d3 | 2012-08-28 15:53:10 -0700 | [diff] [blame] | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 7 | * |
Ian Rogers | 2c344d3 | 2012-08-28 15:53:10 -0700 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 15 | */ |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 16 | |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 17 | #pragma once |
| 18 | |
| 19 | /** |
| 20 | * @file malloc.h |
| 21 | * @brief Heap memory allocation. |
| 22 | * |
| 23 | * [Debugging Native Memory Use](https://source.android.com/devices/tech/debug/native-memory) |
| 24 | * is the canonical source for documentation on Android's heap debugging |
| 25 | * features. |
| 26 | */ |
Ian Rogers | 2c344d3 | 2012-08-28 15:53:10 -0700 | [diff] [blame] | 27 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 28 | #include <sys/cdefs.h> |
| 29 | #include <stddef.h> |
Dan Albert | 4caa1f0 | 2014-08-20 09:16:57 -0700 | [diff] [blame] | 30 | #include <stdio.h> |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 31 | |
| 32 | __BEGIN_DECLS |
| 33 | |
Elliott Hughes | 36a88e8 | 2016-07-30 09:58:15 -0700 | [diff] [blame] | 34 | #define __BIONIC_ALLOC_SIZE(...) __attribute__((__alloc_size__(__VA_ARGS__))) |
Elliott Hughes | 36a88e8 | 2016-07-30 09:58:15 -0700 | [diff] [blame] | 35 | |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 36 | /** |
| 37 | * [malloc(3)](http://man7.org/linux/man-pages/man3/malloc.3.html) allocates |
| 38 | * memory on the heap. |
| 39 | * |
| 40 | * Returns a pointer to the allocated memory on success and returns a null |
| 41 | * pointer and sets `errno` on failure. |
Elliott Hughes | 0a94e15 | 2023-06-26 19:03:41 +0000 | [diff] [blame^] | 42 | * |
| 43 | * Note that Android (like most Unix systems) allows "overcommit". This |
| 44 | * allows processes to allocate more memory than the system has, provided |
| 45 | * they don't use it all. This works because only "dirty" pages that have |
| 46 | * been written to actually require physical memory. In practice, this |
| 47 | * means that it's rare to see memory allocation functions return a null |
| 48 | * pointer, and that a non-null pointer does not mean that you actually |
| 49 | * have all of the memory you asked for. |
| 50 | * |
| 51 | * Note also that the Linux Out Of Memory (OOM) killer behaves differently |
| 52 | * for code run via `adb shell`. The assumption is that if you ran |
| 53 | * something via `adb shell` you're a developer who actually wants the |
| 54 | * device to do what you're asking it to do _even if_ that means killing |
| 55 | * other processes. Obviously this is not the case for apps, which will |
| 56 | * be killed in preference to killing other processes. |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 57 | */ |
zijunzhao | 1a49058 | 2022-12-14 02:15:40 +0000 | [diff] [blame] | 58 | void* _Nullable malloc(size_t __byte_count) __mallocfunc __BIONIC_ALLOC_SIZE(1) __wur; |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 59 | |
| 60 | /** |
| 61 | * [calloc(3)](http://man7.org/linux/man-pages/man3/calloc.3.html) allocates |
| 62 | * and clears memory on the heap. |
| 63 | * |
| 64 | * Returns a pointer to the allocated memory on success and returns a null |
Elliott Hughes | 0a94e15 | 2023-06-26 19:03:41 +0000 | [diff] [blame^] | 65 | * pointer and sets `errno` on failure (but see the notes for malloc()). |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 66 | */ |
zijunzhao | 1a49058 | 2022-12-14 02:15:40 +0000 | [diff] [blame] | 67 | void* _Nullable calloc(size_t __item_count, size_t __item_size) __mallocfunc __BIONIC_ALLOC_SIZE(1,2) __wur; |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 68 | |
| 69 | /** |
| 70 | * [realloc(3)](http://man7.org/linux/man-pages/man3/realloc.3.html) resizes |
| 71 | * allocated memory on the heap. |
| 72 | * |
| 73 | * Returns a pointer (which may be different from `__ptr`) to the resized |
Elliott Hughes | 0a94e15 | 2023-06-26 19:03:41 +0000 | [diff] [blame^] | 74 | * memory on success and returns a null pointer and sets `errno` on failure |
| 75 | * (but see the notes for malloc()). |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 76 | */ |
zijunzhao | 1a49058 | 2022-12-14 02:15:40 +0000 | [diff] [blame] | 77 | void* _Nullable realloc(void* _Nullable __ptr, size_t __byte_count) __BIONIC_ALLOC_SIZE(2) __wur; |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 78 | |
| 79 | /** |
Elliott Hughes | b177085 | 2018-09-18 12:52:42 -0700 | [diff] [blame] | 80 | * [reallocarray(3)](http://man7.org/linux/man-pages/man3/realloc.3.html) resizes |
| 81 | * allocated memory on the heap. |
| 82 | * |
| 83 | * Equivalent to `realloc(__ptr, __item_count * __item_size)` but fails if the |
| 84 | * multiplication overflows. |
| 85 | * |
| 86 | * Returns a pointer (which may be different from `__ptr`) to the resized |
Elliott Hughes | 0a94e15 | 2023-06-26 19:03:41 +0000 | [diff] [blame^] | 87 | * memory on success and returns a null pointer and sets `errno` on failure |
| 88 | * (but see the notes for malloc()). |
Elliott Hughes | b177085 | 2018-09-18 12:52:42 -0700 | [diff] [blame] | 89 | */ |
zijunzhao | 1a49058 | 2022-12-14 02:15:40 +0000 | [diff] [blame] | 90 | void* _Nullable reallocarray(void* _Nullable __ptr, size_t __item_count, size_t __item_size) __BIONIC_ALLOC_SIZE(2, 3) __wur __INTRODUCED_IN(29); |
Elliott Hughes | b177085 | 2018-09-18 12:52:42 -0700 | [diff] [blame] | 91 | |
| 92 | /** |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 93 | * [free(3)](http://man7.org/linux/man-pages/man3/free.3.html) deallocates |
| 94 | * memory on the heap. |
| 95 | */ |
zijunzhao | 1a49058 | 2022-12-14 02:15:40 +0000 | [diff] [blame] | 96 | void free(void* _Nullable __ptr); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 97 | |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 98 | /** |
| 99 | * [memalign(3)](http://man7.org/linux/man-pages/man3/memalign.3.html) allocates |
| 100 | * memory on the heap with the required alignment. |
| 101 | * |
| 102 | * Returns a pointer to the allocated memory on success and returns a null |
Elliott Hughes | 0a94e15 | 2023-06-26 19:03:41 +0000 | [diff] [blame^] | 103 | * pointer and sets `errno` on failure (but see the notes for malloc()). |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 104 | * |
| 105 | * See also posix_memalign(). |
| 106 | */ |
zijunzhao | 1a49058 | 2022-12-14 02:15:40 +0000 | [diff] [blame] | 107 | void* _Nullable memalign(size_t __alignment, size_t __byte_count) __mallocfunc __BIONIC_ALLOC_SIZE(2) __wur; |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 108 | |
| 109 | /** |
| 110 | * [malloc_usable_size(3)](http://man7.org/linux/man-pages/man3/malloc_usable_size.3.html) |
| 111 | * returns the actual size of the given heap block. |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 112 | */ |
Elliott Hughes | 655e430 | 2023-06-16 12:39:33 -0700 | [diff] [blame] | 113 | size_t malloc_usable_size(const void* _Nullable __ptr); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 114 | |
Christopher Ferris | 8248e62 | 2021-12-03 13:55:57 -0800 | [diff] [blame] | 115 | #define __MALLINFO_BODY \ |
| 116 | /** Total number of non-mmapped bytes currently allocated from OS. */ \ |
| 117 | size_t arena; \ |
| 118 | /** Number of free chunks. */ \ |
| 119 | size_t ordblks; \ |
| 120 | /** (Unused.) */ \ |
| 121 | size_t smblks; \ |
| 122 | /** (Unused.) */ \ |
| 123 | size_t hblks; \ |
| 124 | /** Total number of bytes in mmapped regions. */ \ |
| 125 | size_t hblkhd; \ |
| 126 | /** Maximum total allocated space; greater than total if trimming has occurred. */ \ |
| 127 | size_t usmblks; \ |
| 128 | /** (Unused.) */ \ |
| 129 | size_t fsmblks; \ |
| 130 | /** Total allocated space (normal or mmapped.) */ \ |
| 131 | size_t uordblks; \ |
| 132 | /** Total free space. */ \ |
| 133 | size_t fordblks; \ |
| 134 | /** Upper bound on number of bytes releasable by a trim operation. */ \ |
| 135 | size_t keepcost; |
| 136 | |
Ian Rogers | 2c344d3 | 2012-08-28 15:53:10 -0700 | [diff] [blame] | 137 | #ifndef STRUCT_MALLINFO_DECLARED |
| 138 | #define STRUCT_MALLINFO_DECLARED 1 |
Christopher Ferris | 8248e62 | 2021-12-03 13:55:57 -0800 | [diff] [blame] | 139 | struct mallinfo { __MALLINFO_BODY }; |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 140 | #endif |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 141 | |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 142 | /** |
| 143 | * [mallinfo(3)](http://man7.org/linux/man-pages/man3/mallinfo.3.html) returns |
Elliott Hughes | 4fa9b8c | 2019-04-30 12:39:46 -0700 | [diff] [blame] | 144 | * information about the current state of the heap. Note that mallinfo() is |
| 145 | * inherently unreliable and consider using malloc_info() instead. |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 146 | */ |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 147 | struct mallinfo mallinfo(void); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 148 | |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 149 | /** |
Christopher Ferris | 8248e62 | 2021-12-03 13:55:57 -0800 | [diff] [blame] | 150 | * On Android the struct mallinfo and struct mallinfo2 are the same. |
| 151 | */ |
| 152 | struct mallinfo2 { __MALLINFO_BODY }; |
| 153 | |
| 154 | /** |
| 155 | * [mallinfo2(3)](http://man7.org/linux/man-pages/man3/mallinfo2.3.html) returns |
| 156 | * information about the current state of the heap. Note that mallinfo2() is |
| 157 | * inherently unreliable and consider using malloc_info() instead. |
| 158 | */ |
| 159 | struct mallinfo2 mallinfo2(void) __RENAME(mallinfo); |
| 160 | |
| 161 | /** |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 162 | * [malloc_info(3)](http://man7.org/linux/man-pages/man3/malloc_info.3.html) |
| 163 | * writes information about the current state of the heap to the given stream. |
Dan Albert | 4caa1f0 | 2014-08-20 09:16:57 -0700 | [diff] [blame] | 164 | * |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 165 | * The XML structure for malloc_info() is as follows: |
| 166 | * ``` |
Dan Albert | 4caa1f0 | 2014-08-20 09:16:57 -0700 | [diff] [blame] | 167 | * <malloc version="jemalloc-1"> |
| 168 | * <heap nr="INT"> |
| 169 | * <allocated-large>INT</allocated-large> |
| 170 | * <allocated-huge>INT</allocated-huge> |
| 171 | * <allocated-bins>INT</allocated-bins> |
| 172 | * <bins-total>INT</bins-total> |
| 173 | * <bin nr="INT"> |
| 174 | * <allocated>INT</allocated> |
| 175 | * <nmalloc>INT</nmalloc> |
| 176 | * <ndalloc>INT</ndalloc> |
| 177 | * </bin> |
| 178 | * <!-- more bins --> |
| 179 | * </heap> |
| 180 | * <!-- more heaps --> |
| 181 | * </malloc> |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 182 | * ``` |
| 183 | * |
| 184 | * Available since API level 23. |
Dan Albert | 4caa1f0 | 2014-08-20 09:16:57 -0700 | [diff] [blame] | 185 | */ |
zijunzhao | 1a49058 | 2022-12-14 02:15:40 +0000 | [diff] [blame] | 186 | int malloc_info(int __must_be_zero, FILE* _Nonnull __fp) __INTRODUCED_IN(23); |
Dan Albert | 4caa1f0 | 2014-08-20 09:16:57 -0700 | [diff] [blame] | 187 | |
Christopher Ferris | 8daea55 | 2018-10-23 11:17:24 -0700 | [diff] [blame] | 188 | /** |
| 189 | * mallopt() option to set the decay time. Valid values are 0 and 1. |
| 190 | * |
| 191 | * Available since API level 27. |
| 192 | */ |
Chih-Hung Hsieh | fa658eb | 2020-03-04 11:14:42 -0800 | [diff] [blame] | 193 | #define M_DECAY_TIME (-100) |
Christopher Ferris | 8daea55 | 2018-10-23 11:17:24 -0700 | [diff] [blame] | 194 | /** |
| 195 | * mallopt() option to immediately purge any memory not in use. This |
| 196 | * will release the memory back to the kernel. The value is ignored. |
| 197 | * |
| 198 | * Available since API level 28. |
| 199 | */ |
Chih-Hung Hsieh | fa658eb | 2020-03-04 11:14:42 -0800 | [diff] [blame] | 200 | #define M_PURGE (-101) |
Christopher Ferris | d86eb86 | 2023-02-28 12:45:54 -0800 | [diff] [blame] | 201 | /** |
| 202 | * mallopt() option to immediately purge all possible memory back to |
| 203 | * the kernel. This call can take longer than a normal purge since it |
| 204 | * examines everything. In some cases, it can take more than twice the |
| 205 | * time of a M_PURGE call. The value is ignored. |
| 206 | * |
| 207 | * Available since API level 34. |
| 208 | */ |
| 209 | #define M_PURGE_ALL (-104) |
Evgenii Stepanov | d8d561c | 2021-06-22 10:18:12 -0700 | [diff] [blame] | 210 | |
| 211 | /** |
| 212 | * mallopt() option to tune the allocator's choice of memory tags to |
| 213 | * make it more likely that a certain class of memory errors will be |
| 214 | * detected. This is only relevant if MTE is enabled in this process |
| 215 | * and ignored otherwise. The value argument should be one of the |
| 216 | * M_MEMTAG_TUNING_* flags. |
| 217 | * NOTE: This is only available in scudo. |
| 218 | * |
| 219 | * Available since API level 31. |
| 220 | */ |
| 221 | #define M_MEMTAG_TUNING (-102) |
| 222 | |
| 223 | /** |
| 224 | * When passed as a value of M_MEMTAG_TUNING mallopt() call, enables |
| 225 | * deterministic detection of linear buffer overflow and underflow |
| 226 | * bugs by assigning distinct tag values to adjacent allocations. This |
| 227 | * mode has a slightly reduced chance to detect use-after-free bugs |
| 228 | * because only half of the possible tag values are available for each |
| 229 | * memory location. |
| 230 | * |
| 231 | * Please keep in mind that MTE can not detect overflow within the |
| 232 | * same tag granule (16-byte aligned chunk), and can miss small |
| 233 | * overflows even in this mode. Such overflow can not be the cause of |
| 234 | * a memory corruption, because the memory within one granule is never |
| 235 | * used for multiple allocations. |
| 236 | */ |
| 237 | #define M_MEMTAG_TUNING_BUFFER_OVERFLOW 0 |
| 238 | |
| 239 | /** |
| 240 | * When passed as a value of M_MEMTAG_TUNING mallopt() call, enables |
| 241 | * independently randomized tags for uniform ~93% probability of |
| 242 | * detecting both spatial (buffer overflow) and temporal (use after |
| 243 | * free) bugs. |
| 244 | */ |
| 245 | #define M_MEMTAG_TUNING_UAF 1 |
| 246 | |
| 247 | /** |
Peter Collingbourne | 978eb16 | 2020-09-21 15:26:02 -0700 | [diff] [blame] | 248 | * mallopt() option for per-thread memory initialization tuning. |
| 249 | * The value argument should be one of: |
Christopher Ferris | e28867c | 2023-04-27 17:03:59 -0700 | [diff] [blame] | 250 | * 1: Disable automatic heap initialization on this thread only. |
| 251 | * If memory tagging is enabled, disable as much as possible of the |
| 252 | * memory tagging initialization for this thread. |
Peter Collingbourne | 978eb16 | 2020-09-21 15:26:02 -0700 | [diff] [blame] | 253 | * 0: Normal behavior. |
| 254 | * |
| 255 | * Available since API level 31. |
| 256 | */ |
| 257 | #define M_THREAD_DISABLE_MEM_INIT (-103) |
Christopher Ferris | 8844879 | 2020-07-28 14:15:31 -0700 | [diff] [blame] | 258 | /** |
| 259 | * mallopt() option to set the maximum number of items in the secondary |
| 260 | * cache of the scudo allocator. |
| 261 | * |
| 262 | * Available since API level 31. |
| 263 | */ |
| 264 | #define M_CACHE_COUNT_MAX (-200) |
| 265 | /** |
| 266 | * mallopt() option to set the maximum size in bytes of a cacheable item in |
| 267 | * the secondary cache of the scudo allocator. |
| 268 | * |
| 269 | * Available since API level 31. |
| 270 | */ |
| 271 | #define M_CACHE_SIZE_MAX (-201) |
| 272 | /** |
| 273 | * mallopt() option to increase the maximum number of shared thread-specific |
| 274 | * data structures that can be created. This number cannot be decreased, |
| 275 | * only increased and only applies to the scudo allocator. |
| 276 | * |
| 277 | * Available since API level 31. |
| 278 | */ |
| 279 | #define M_TSDS_COUNT_MAX (-202) |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 280 | |
| 281 | /** |
Mitch Phillips | 9cad842 | 2021-01-20 16:03:27 -0800 | [diff] [blame] | 282 | * mallopt() option to decide whether heap memory is zero-initialized on |
| 283 | * allocation across the whole process. May be called at any time, including |
| 284 | * when multiple threads are running. An argument of zero indicates memory |
| 285 | * should not be zero-initialized, any other value indicates to initialize heap |
| 286 | * memory to zero. |
Elliott Hughes | 446b4dd | 2021-01-14 13:34:20 -0800 | [diff] [blame] | 287 | * |
Evgenii Stepanov | d8d561c | 2021-06-22 10:18:12 -0700 | [diff] [blame] | 288 | * Note that this memory mitigation is only implemented in scudo and therefore |
Mitch Phillips | 9cad842 | 2021-01-20 16:03:27 -0800 | [diff] [blame] | 289 | * this will have no effect when using another allocator (such as jemalloc on |
| 290 | * Android Go devices). |
Elliott Hughes | 446b4dd | 2021-01-14 13:34:20 -0800 | [diff] [blame] | 291 | * |
| 292 | * Available since API level 31. |
| 293 | */ |
Mitch Phillips | 9cad842 | 2021-01-20 16:03:27 -0800 | [diff] [blame] | 294 | #define M_BIONIC_ZERO_INIT (-203) |
Elliott Hughes | 446b4dd | 2021-01-14 13:34:20 -0800 | [diff] [blame] | 295 | |
| 296 | /** |
| 297 | * mallopt() option to change the heap tagging state. May be called at any |
| 298 | * time, including when multiple threads are running. |
| 299 | * The value must be one of the M_HEAP_TAGGING_LEVEL_ constants. |
Evgenii Stepanov | d8d561c | 2021-06-22 10:18:12 -0700 | [diff] [blame] | 300 | * NOTE: This is only available in scudo. |
Elliott Hughes | 446b4dd | 2021-01-14 13:34:20 -0800 | [diff] [blame] | 301 | * |
| 302 | * Available since API level 31. |
| 303 | */ |
| 304 | #define M_BIONIC_SET_HEAP_TAGGING_LEVEL (-204) |
| 305 | |
| 306 | /** |
| 307 | * Constants for use with the M_BIONIC_SET_HEAP_TAGGING_LEVEL mallopt() option. |
| 308 | */ |
| 309 | enum HeapTaggingLevel { |
| 310 | /** |
| 311 | * Disable heap tagging and memory tag checks (if supported). |
| 312 | * Heap tagging may not be re-enabled after being disabled. |
| 313 | */ |
| 314 | M_HEAP_TAGGING_LEVEL_NONE = 0, |
| 315 | #define M_HEAP_TAGGING_LEVEL_NONE M_HEAP_TAGGING_LEVEL_NONE |
| 316 | /** |
| 317 | * Address-only tagging. Heap pointers have a non-zero tag in the |
| 318 | * most significant ("top") byte which is checked in free(). Memory |
| 319 | * accesses ignore the tag using arm64's Top Byte Ignore (TBI) feature. |
| 320 | */ |
| 321 | M_HEAP_TAGGING_LEVEL_TBI = 1, |
| 322 | #define M_HEAP_TAGGING_LEVEL_TBI M_HEAP_TAGGING_LEVEL_TBI |
| 323 | /** |
| 324 | * Enable heap tagging and asynchronous memory tag checks (if supported). |
| 325 | * Disable stack trace collection. |
| 326 | */ |
| 327 | M_HEAP_TAGGING_LEVEL_ASYNC = 2, |
| 328 | #define M_HEAP_TAGGING_LEVEL_ASYNC M_HEAP_TAGGING_LEVEL_ASYNC |
| 329 | /** |
| 330 | * Enable heap tagging and synchronous memory tag checks (if supported). |
| 331 | * Enable stack trace collection. |
| 332 | */ |
| 333 | M_HEAP_TAGGING_LEVEL_SYNC = 3, |
| 334 | #define M_HEAP_TAGGING_LEVEL_SYNC M_HEAP_TAGGING_LEVEL_SYNC |
| 335 | }; |
| 336 | |
| 337 | /** |
Christopher Ferris | e9a7b81 | 2023-05-11 15:36:27 -0700 | [diff] [blame] | 338 | * mallopt() option to print human readable statistics about the memory |
| 339 | * allocator to the log. There is no format for this data, each allocator |
| 340 | * can use a different format, and the data that is printed can |
| 341 | * change at any time. This is expected to be used as a debugging aid. |
| 342 | * |
| 343 | * Available since API level 35. |
| 344 | */ |
| 345 | #define M_LOG_STATS (-205) |
| 346 | |
| 347 | /** |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 348 | * [mallopt(3)](http://man7.org/linux/man-pages/man3/mallopt.3.html) modifies |
| 349 | * heap behavior. Values of `__option` are the `M_` constants from this header. |
| 350 | * |
| 351 | * Returns 1 on success, 0 on error. |
| 352 | * |
| 353 | * Available since API level 26. |
| 354 | */ |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 355 | int mallopt(int __option, int __value) __INTRODUCED_IN(26); |
Christopher Ferris | a1c0d2f | 2017-05-15 15:50:19 -0700 | [diff] [blame] | 356 | |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 357 | /** |
| 358 | * [__malloc_hook(3)](http://man7.org/linux/man-pages/man3/__malloc_hook.3.html) |
| 359 | * is called to implement malloc(). By default this points to the system's |
| 360 | * implementation. |
| 361 | * |
| 362 | * Available since API level 28. |
| 363 | * |
| 364 | * See also: [extra documentation](https://android.googlesource.com/platform/bionic/+/master/libc/malloc_hooks/README.md) |
Christopher Ferris | db478a6 | 2018-02-07 18:42:14 -0800 | [diff] [blame] | 365 | */ |
zijunzhao | 1a49058 | 2022-12-14 02:15:40 +0000 | [diff] [blame] | 366 | extern void* _Nonnull (*volatile _Nonnull __malloc_hook)(size_t __byte_count, const void* _Nonnull __caller) __INTRODUCED_IN(28); |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 367 | |
| 368 | /** |
| 369 | * [__realloc_hook(3)](http://man7.org/linux/man-pages/man3/__realloc_hook.3.html) |
| 370 | * is called to implement realloc(). By default this points to the system's |
| 371 | * implementation. |
| 372 | * |
| 373 | * Available since API level 28. |
| 374 | * |
| 375 | * See also: [extra documentation](https://android.googlesource.com/platform/bionic/+/master/libc/malloc_hooks/README.md) |
| 376 | */ |
zijunzhao | 1a49058 | 2022-12-14 02:15:40 +0000 | [diff] [blame] | 377 | extern void* _Nonnull (*volatile _Nonnull __realloc_hook)(void* _Nullable __ptr, size_t __byte_count, const void* _Nonnull __caller) __INTRODUCED_IN(28); |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 378 | |
| 379 | /** |
| 380 | * [__free_hook(3)](http://man7.org/linux/man-pages/man3/__free_hook.3.html) |
| 381 | * is called to implement free(). By default this points to the system's |
| 382 | * implementation. |
| 383 | * |
| 384 | * Available since API level 28. |
| 385 | * |
| 386 | * See also: [extra documentation](https://android.googlesource.com/platform/bionic/+/master/libc/malloc_hooks/README.md) |
| 387 | */ |
zijunzhao | 1a49058 | 2022-12-14 02:15:40 +0000 | [diff] [blame] | 388 | extern void (*volatile _Nonnull __free_hook)(void* _Nullable __ptr, const void* _Nonnull __caller) __INTRODUCED_IN(28); |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 389 | |
| 390 | /** |
| 391 | * [__memalign_hook(3)](http://man7.org/linux/man-pages/man3/__memalign_hook.3.html) |
| 392 | * is called to implement memalign(). By default this points to the system's |
| 393 | * implementation. |
| 394 | * |
| 395 | * Available since API level 28. |
| 396 | * |
| 397 | * See also: [extra documentation](https://android.googlesource.com/platform/bionic/+/master/libc/malloc_hooks/README.md) |
| 398 | */ |
zijunzhao | 1a49058 | 2022-12-14 02:15:40 +0000 | [diff] [blame] | 399 | extern void* _Nonnull (*volatile _Nonnull __memalign_hook)(size_t __alignment, size_t __byte_count, const void* _Nonnull __caller) __INTRODUCED_IN(28); |
Christopher Ferris | db478a6 | 2018-02-07 18:42:14 -0800 | [diff] [blame] | 400 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 401 | __END_DECLS |