blob: 6fb12a2cc25b79b84d26982518fa3028ca417e2e [file] [log] [blame]
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08001/*
Ian Rogers2c344d32012-08-28 15:53:10 -07002 * Copyright (C) 2012 The Android Open Source Project
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08003 *
Ian Rogers2c344d32012-08-28 15:53:10 -07004 * 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 Project1dc9e472009-03-03 19:28:35 -08007 *
Ian Rogers2c344d32012-08-28 15:53:10 -07008 * 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 Project1dc9e472009-03-03 19:28:35 -080015 */
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080016
Elliott Hughes462e90c2018-08-21 16:10:48 -070017#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 Rogers2c344d32012-08-28 15:53:10 -070027
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080028#include <sys/cdefs.h>
29#include <stddef.h>
Dan Albert4caa1f02014-08-20 09:16:57 -070030#include <stdio.h>
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080031
32__BEGIN_DECLS
33
Elliott Hughes36a88e82016-07-30 09:58:15 -070034#define __BIONIC_ALLOC_SIZE(...) __attribute__((__alloc_size__(__VA_ARGS__)))
Elliott Hughes36a88e82016-07-30 09:58:15 -070035
Elliott Hughes462e90c2018-08-21 16:10:48 -070036/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +000037 * [malloc(3)](https://man7.org/linux/man-pages/man3/malloc.3.html) allocates
Elliott Hughes462e90c2018-08-21 16:10:48 -070038 * 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 Hughes0a94e152023-06-26 19:03:41 +000042 *
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 Hughes462e90c2018-08-21 16:10:48 -070057 */
Elliott Hughesb19df892024-09-06 14:27:41 +000058__nodiscard void* _Nullable malloc(size_t __byte_count) __mallocfunc __BIONIC_ALLOC_SIZE(1);
Elliott Hughes462e90c2018-08-21 16:10:48 -070059
60/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +000061 * [calloc(3)](https://man7.org/linux/man-pages/man3/calloc.3.html) allocates
Elliott Hughes462e90c2018-08-21 16:10:48 -070062 * and clears memory on the heap.
63 *
64 * Returns a pointer to the allocated memory on success and returns a null
Elliott Hughes0a94e152023-06-26 19:03:41 +000065 * pointer and sets `errno` on failure (but see the notes for malloc()).
Elliott Hughes462e90c2018-08-21 16:10:48 -070066 */
Elliott Hughesb19df892024-09-06 14:27:41 +000067__nodiscard void* _Nullable calloc(size_t __item_count, size_t __item_size) __mallocfunc __BIONIC_ALLOC_SIZE(1,2);
Elliott Hughes462e90c2018-08-21 16:10:48 -070068
69/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +000070 * [realloc(3)](https://man7.org/linux/man-pages/man3/realloc.3.html) resizes
Elliott Hughes462e90c2018-08-21 16:10:48 -070071 * allocated memory on the heap.
72 *
73 * Returns a pointer (which may be different from `__ptr`) to the resized
Elliott Hughes0a94e152023-06-26 19:03:41 +000074 * memory on success and returns a null pointer and sets `errno` on failure
75 * (but see the notes for malloc()).
Elliott Hughes462e90c2018-08-21 16:10:48 -070076 */
Elliott Hughesb19df892024-09-06 14:27:41 +000077__nodiscard void* _Nullable realloc(void* _Nullable __ptr, size_t __byte_count) __BIONIC_ALLOC_SIZE(2);
Elliott Hughes462e90c2018-08-21 16:10:48 -070078
79/**
Elliott Hughes7fb8d582025-01-06 15:57:38 +000080 * [reallocarray(3)](https://man7.org/linux/man-pages/man3/reallocarray.3.html)
81 * resizes allocated memory on the heap.
Elliott Hughesb1770852018-09-18 12:52:42 -070082 *
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 Hughes0a94e152023-06-26 19:03:41 +000087 * memory on success and returns a null pointer and sets `errno` on failure
88 * (but see the notes for malloc()).
Elliott Hughesb1770852018-09-18 12:52:42 -070089 */
Elliott Hughesf93af262024-09-05 13:02:21 +000090#if __ANDROID_API__ >= 29
Elliott Hughesb19df892024-09-06 14:27:41 +000091__nodiscard void* _Nullable reallocarray(void* _Nullable __ptr, size_t __item_count, size_t __item_size) __BIONIC_ALLOC_SIZE(2, 3) __INTRODUCED_IN(29);
Dan Albertd407e5e2024-11-08 19:45:35 +000092#elif defined(__ANDROID_UNAVAILABLE_SYMBOLS_ARE_WEAK__)
Elliott Hughesf93af262024-09-05 13:02:21 +000093#include <errno.h>
Dan Albert1f8c2252024-11-08 19:46:12 +000094static __inline __nodiscard void* _Nullable reallocarray(void* _Nullable __ptr, size_t __item_count, size_t __item_size) __BIONIC_ALLOC_SIZE(2, 3) {
Elliott Hughesf93af262024-09-05 13:02:21 +000095 size_t __new_size;
96 if (__builtin_mul_overflow(__item_count, __item_size, &__new_size)) {
97 errno = ENOMEM;
98 return NULL;
99 }
100 return realloc(__ptr, __new_size);
101}
Dan Albertcce54372024-08-22 18:24:30 +0000102#endif
Elliott Hughesb1770852018-09-18 12:52:42 -0700103
104/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +0000105 * [free(3)](https://man7.org/linux/man-pages/man3/free.3.html) deallocates
Elliott Hughes462e90c2018-08-21 16:10:48 -0700106 * memory on the heap.
107 */
zijunzhao1a490582022-12-14 02:15:40 +0000108void free(void* _Nullable __ptr);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800109
Elliott Hughes462e90c2018-08-21 16:10:48 -0700110/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +0000111 * [memalign(3)](https://man7.org/linux/man-pages/man3/memalign.3.html) allocates
Elliott Hughes462e90c2018-08-21 16:10:48 -0700112 * memory on the heap with the required alignment.
113 *
114 * Returns a pointer to the allocated memory on success and returns a null
Elliott Hughes0a94e152023-06-26 19:03:41 +0000115 * pointer and sets `errno` on failure (but see the notes for malloc()).
Elliott Hughes462e90c2018-08-21 16:10:48 -0700116 *
117 * See also posix_memalign().
118 */
Elliott Hughesb19df892024-09-06 14:27:41 +0000119__nodiscard void* _Nullable memalign(size_t __alignment, size_t __byte_count) __mallocfunc __BIONIC_ALLOC_SIZE(2);
Elliott Hughes462e90c2018-08-21 16:10:48 -0700120
121/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +0000122 * [malloc_usable_size(3)](https://man7.org/linux/man-pages/man3/malloc_usable_size.3.html)
Elliott Hughes462e90c2018-08-21 16:10:48 -0700123 * returns the actual size of the given heap block.
Sharjeel Khanaac2db22025-03-20 21:10:32 +0000124 *
Sharjeel Khan5654c1f2025-05-07 17:03:27 +0000125 * malloc_usable_size() and _FORTIFY_SOURCE>=3 are incompatible if you are using more of the
Sharjeel Khanaac2db22025-03-20 21:10:32 +0000126 * allocation than originally requested. However, malloc_usable_size() can be used to keep track
127 * of allocation/deallocation byte counts and this is an exception to the incompatible rule. In this
128 * case, you can define __BIONIC_DISABLE_MALLOC_USABLE_SIZE_FORTIFY_WARNINGS to disable the
129 * compiler error.
Elliott Hughes462e90c2018-08-21 16:10:48 -0700130 */
Elliott Hughes17d46c12025-03-12 08:43:28 -0700131__nodiscard size_t malloc_usable_size(const void* _Nullable __ptr)
Sharjeel Khanaac2db22025-03-20 21:10:32 +0000132#if defined(_FORTIFY_SOURCE) && !defined(__BIONIC_DISABLE_MALLOC_USABLE_SIZE_FORTIFY_WARNINGS)
Sharjeel Khan5654c1f2025-05-07 17:03:27 +0000133 __clang_error_if(_FORTIFY_SOURCE >= 3,
134 "malloc_usable_size() and _FORTIFY_SOURCE>=3 are incompatible: see malloc_usable_size() documentation")
Elliott Hughes17d46c12025-03-12 08:43:28 -0700135#endif
136;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800137
Christopher Ferris8248e622021-12-03 13:55:57 -0800138#define __MALLINFO_BODY \
139 /** Total number of non-mmapped bytes currently allocated from OS. */ \
140 size_t arena; \
141 /** Number of free chunks. */ \
142 size_t ordblks; \
143 /** (Unused.) */ \
144 size_t smblks; \
145 /** (Unused.) */ \
146 size_t hblks; \
147 /** Total number of bytes in mmapped regions. */ \
148 size_t hblkhd; \
149 /** Maximum total allocated space; greater than total if trimming has occurred. */ \
150 size_t usmblks; \
151 /** (Unused.) */ \
152 size_t fsmblks; \
153 /** Total allocated space (normal or mmapped.) */ \
154 size_t uordblks; \
155 /** Total free space. */ \
156 size_t fordblks; \
157 /** Upper bound on number of bytes releasable by a trim operation. */ \
158 size_t keepcost;
159
Ian Rogers2c344d32012-08-28 15:53:10 -0700160#ifndef STRUCT_MALLINFO_DECLARED
161#define STRUCT_MALLINFO_DECLARED 1
Christopher Ferris8248e622021-12-03 13:55:57 -0800162struct mallinfo { __MALLINFO_BODY };
Elliott Hughes462e90c2018-08-21 16:10:48 -0700163#endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800164
Elliott Hughes462e90c2018-08-21 16:10:48 -0700165/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +0000166 * [mallinfo(3)](https://man7.org/linux/man-pages/man3/mallinfo.3.html) returns
Elliott Hughes4fa9b8c2019-04-30 12:39:46 -0700167 * information about the current state of the heap. Note that mallinfo() is
168 * inherently unreliable and consider using malloc_info() instead.
Elliott Hughes462e90c2018-08-21 16:10:48 -0700169 */
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700170struct mallinfo mallinfo(void);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800171
Elliott Hughes462e90c2018-08-21 16:10:48 -0700172/**
Christopher Ferris8248e622021-12-03 13:55:57 -0800173 * On Android the struct mallinfo and struct mallinfo2 are the same.
174 */
175struct mallinfo2 { __MALLINFO_BODY };
176
177/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +0000178 * [mallinfo2(3)](https://man7.org/linux/man-pages/man3/mallinfo2.3.html) returns
Christopher Ferris8248e622021-12-03 13:55:57 -0800179 * information about the current state of the heap. Note that mallinfo2() is
180 * inherently unreliable and consider using malloc_info() instead.
181 */
182struct mallinfo2 mallinfo2(void) __RENAME(mallinfo);
183
184/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +0000185 * [malloc_info(3)](https://man7.org/linux/man-pages/man3/malloc_info.3.html)
Elliott Hughes462e90c2018-08-21 16:10:48 -0700186 * writes information about the current state of the heap to the given stream.
Dan Albert4caa1f02014-08-20 09:16:57 -0700187 *
Elliott Hughes462e90c2018-08-21 16:10:48 -0700188 * The XML structure for malloc_info() is as follows:
189 * ```
Dan Albert4caa1f02014-08-20 09:16:57 -0700190 * <malloc version="jemalloc-1">
191 * <heap nr="INT">
192 * <allocated-large>INT</allocated-large>
193 * <allocated-huge>INT</allocated-huge>
194 * <allocated-bins>INT</allocated-bins>
195 * <bins-total>INT</bins-total>
196 * <bin nr="INT">
197 * <allocated>INT</allocated>
198 * <nmalloc>INT</nmalloc>
199 * <ndalloc>INT</ndalloc>
200 * </bin>
201 * <!-- more bins -->
202 * </heap>
203 * <!-- more heaps -->
204 * </malloc>
Elliott Hughes462e90c2018-08-21 16:10:48 -0700205 * ```
206 *
207 * Available since API level 23.
Dan Albert4caa1f02014-08-20 09:16:57 -0700208 */
Dan Albert02ce4012024-10-25 19:13:49 +0000209#if __BIONIC_AVAILABILITY_GUARD(23)
zijunzhao1a490582022-12-14 02:15:40 +0000210int malloc_info(int __must_be_zero, FILE* _Nonnull __fp) __INTRODUCED_IN(23);
Dan Albert02ce4012024-10-25 19:13:49 +0000211#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
212
Dan Albert4caa1f02014-08-20 09:16:57 -0700213
Christopher Ferris8daea552018-10-23 11:17:24 -0700214/**
Chia-hung Duan6abb4062024-04-17 19:08:48 -0700215 * mallopt() option to set the decay time. Valid values are -1, 0 and 1.
216 * -1 : Disable the releasing of unused pages. This value is available since
217 * API level 35.
218 * 0 : Release the unused pages immediately.
219 * 1 : Release the unused pages at a device-specific interval.
Christopher Ferris8daea552018-10-23 11:17:24 -0700220 *
221 * Available since API level 27.
222 */
Chih-Hung Hsiehfa658eb2020-03-04 11:14:42 -0800223#define M_DECAY_TIME (-100)
Christopher Ferris8daea552018-10-23 11:17:24 -0700224/**
225 * mallopt() option to immediately purge any memory not in use. This
226 * will release the memory back to the kernel. The value is ignored.
227 *
228 * Available since API level 28.
229 */
Chih-Hung Hsiehfa658eb2020-03-04 11:14:42 -0800230#define M_PURGE (-101)
Christopher Ferrisd86eb862023-02-28 12:45:54 -0800231/**
232 * mallopt() option to immediately purge all possible memory back to
233 * the kernel. This call can take longer than a normal purge since it
234 * examines everything. In some cases, it can take more than twice the
235 * time of a M_PURGE call. The value is ignored.
236 *
237 * Available since API level 34.
238 */
239#define M_PURGE_ALL (-104)
Evgenii Stepanovd8d561c2021-06-22 10:18:12 -0700240
241/**
242 * mallopt() option to tune the allocator's choice of memory tags to
243 * make it more likely that a certain class of memory errors will be
244 * detected. This is only relevant if MTE is enabled in this process
245 * and ignored otherwise. The value argument should be one of the
246 * M_MEMTAG_TUNING_* flags.
247 * NOTE: This is only available in scudo.
248 *
249 * Available since API level 31.
250 */
251#define M_MEMTAG_TUNING (-102)
252
253/**
254 * When passed as a value of M_MEMTAG_TUNING mallopt() call, enables
255 * deterministic detection of linear buffer overflow and underflow
256 * bugs by assigning distinct tag values to adjacent allocations. This
257 * mode has a slightly reduced chance to detect use-after-free bugs
258 * because only half of the possible tag values are available for each
259 * memory location.
260 *
261 * Please keep in mind that MTE can not detect overflow within the
262 * same tag granule (16-byte aligned chunk), and can miss small
263 * overflows even in this mode. Such overflow can not be the cause of
264 * a memory corruption, because the memory within one granule is never
265 * used for multiple allocations.
266 */
267#define M_MEMTAG_TUNING_BUFFER_OVERFLOW 0
268
269/**
270 * When passed as a value of M_MEMTAG_TUNING mallopt() call, enables
271 * independently randomized tags for uniform ~93% probability of
272 * detecting both spatial (buffer overflow) and temporal (use after
273 * free) bugs.
274 */
275#define M_MEMTAG_TUNING_UAF 1
276
277/**
Peter Collingbourne978eb162020-09-21 15:26:02 -0700278 * mallopt() option for per-thread memory initialization tuning.
279 * The value argument should be one of:
Christopher Ferrise28867c2023-04-27 17:03:59 -0700280 * 1: Disable automatic heap initialization on this thread only.
281 * If memory tagging is enabled, disable as much as possible of the
282 * memory tagging initialization for this thread.
Peter Collingbourne978eb162020-09-21 15:26:02 -0700283 * 0: Normal behavior.
284 *
285 * Available since API level 31.
286 */
287#define M_THREAD_DISABLE_MEM_INIT (-103)
Christopher Ferris88448792020-07-28 14:15:31 -0700288/**
289 * mallopt() option to set the maximum number of items in the secondary
290 * cache of the scudo allocator.
291 *
292 * Available since API level 31.
293 */
294#define M_CACHE_COUNT_MAX (-200)
295/**
296 * mallopt() option to set the maximum size in bytes of a cacheable item in
297 * the secondary cache of the scudo allocator.
298 *
299 * Available since API level 31.
300 */
301#define M_CACHE_SIZE_MAX (-201)
302/**
303 * mallopt() option to increase the maximum number of shared thread-specific
304 * data structures that can be created. This number cannot be decreased,
305 * only increased and only applies to the scudo allocator.
306 *
307 * Available since API level 31.
308 */
309#define M_TSDS_COUNT_MAX (-202)
Elliott Hughes462e90c2018-08-21 16:10:48 -0700310
311/**
Mitch Phillips9cad8422021-01-20 16:03:27 -0800312 * mallopt() option to decide whether heap memory is zero-initialized on
313 * allocation across the whole process. May be called at any time, including
314 * when multiple threads are running. An argument of zero indicates memory
315 * should not be zero-initialized, any other value indicates to initialize heap
316 * memory to zero.
Elliott Hughes446b4dd2021-01-14 13:34:20 -0800317 *
Evgenii Stepanovd8d561c2021-06-22 10:18:12 -0700318 * Note that this memory mitigation is only implemented in scudo and therefore
Mitch Phillips9cad8422021-01-20 16:03:27 -0800319 * this will have no effect when using another allocator (such as jemalloc on
320 * Android Go devices).
Elliott Hughes446b4dd2021-01-14 13:34:20 -0800321 *
322 * Available since API level 31.
323 */
Mitch Phillips9cad8422021-01-20 16:03:27 -0800324#define M_BIONIC_ZERO_INIT (-203)
Elliott Hughes446b4dd2021-01-14 13:34:20 -0800325
326/**
327 * mallopt() option to change the heap tagging state. May be called at any
328 * time, including when multiple threads are running.
329 * The value must be one of the M_HEAP_TAGGING_LEVEL_ constants.
Evgenii Stepanovd8d561c2021-06-22 10:18:12 -0700330 * NOTE: This is only available in scudo.
Elliott Hughes446b4dd2021-01-14 13:34:20 -0800331 *
332 * Available since API level 31.
333 */
334#define M_BIONIC_SET_HEAP_TAGGING_LEVEL (-204)
335
336/**
337 * Constants for use with the M_BIONIC_SET_HEAP_TAGGING_LEVEL mallopt() option.
338 */
339enum HeapTaggingLevel {
340 /**
341 * Disable heap tagging and memory tag checks (if supported).
342 * Heap tagging may not be re-enabled after being disabled.
343 */
344 M_HEAP_TAGGING_LEVEL_NONE = 0,
345#define M_HEAP_TAGGING_LEVEL_NONE M_HEAP_TAGGING_LEVEL_NONE
346 /**
347 * Address-only tagging. Heap pointers have a non-zero tag in the
348 * most significant ("top") byte which is checked in free(). Memory
349 * accesses ignore the tag using arm64's Top Byte Ignore (TBI) feature.
350 */
351 M_HEAP_TAGGING_LEVEL_TBI = 1,
352#define M_HEAP_TAGGING_LEVEL_TBI M_HEAP_TAGGING_LEVEL_TBI
353 /**
354 * Enable heap tagging and asynchronous memory tag checks (if supported).
355 * Disable stack trace collection.
356 */
357 M_HEAP_TAGGING_LEVEL_ASYNC = 2,
358#define M_HEAP_TAGGING_LEVEL_ASYNC M_HEAP_TAGGING_LEVEL_ASYNC
359 /**
360 * Enable heap tagging and synchronous memory tag checks (if supported).
361 * Enable stack trace collection.
362 */
363 M_HEAP_TAGGING_LEVEL_SYNC = 3,
364#define M_HEAP_TAGGING_LEVEL_SYNC M_HEAP_TAGGING_LEVEL_SYNC
365};
366
367/**
Christopher Ferrise9a7b812023-05-11 15:36:27 -0700368 * mallopt() option to print human readable statistics about the memory
369 * allocator to the log. There is no format for this data, each allocator
370 * can use a different format, and the data that is printed can
371 * change at any time. This is expected to be used as a debugging aid.
372 *
373 * Available since API level 35.
374 */
375#define M_LOG_STATS (-205)
376
377/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +0000378 * [mallopt(3)](https://man7.org/linux/man-pages/man3/mallopt.3.html) modifies
Elliott Hughes462e90c2018-08-21 16:10:48 -0700379 * heap behavior. Values of `__option` are the `M_` constants from this header.
380 *
381 * Returns 1 on success, 0 on error.
382 *
383 * Available since API level 26.
384 */
Dan Albert02ce4012024-10-25 19:13:49 +0000385#if __BIONIC_AVAILABILITY_GUARD(26)
Elliott Hughesfaa74342017-08-11 17:34:44 -0700386int mallopt(int __option, int __value) __INTRODUCED_IN(26);
Dan Albert02ce4012024-10-25 19:13:49 +0000387#endif /* __BIONIC_AVAILABILITY_GUARD(26) */
388
Christopher Ferrisa1c0d2f2017-05-15 15:50:19 -0700389
Elliott Hughes462e90c2018-08-21 16:10:48 -0700390/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +0000391 * [__malloc_hook(3)](https://man7.org/linux/man-pages/man3/__malloc_hook.3.html)
Elliott Hughes462e90c2018-08-21 16:10:48 -0700392 * is called to implement malloc(). By default this points to the system's
393 * implementation.
394 *
395 * Available since API level 28.
396 *
Elliott Hughes9c06d162023-10-04 23:36:14 +0000397 * See also: [extra documentation](https://android.googlesource.com/platform/bionic/+/main/libc/malloc_hooks/README.md)
Christopher Ferrisdb478a62018-02-07 18:42:14 -0800398 */
Dan Albert02ce4012024-10-25 19:13:49 +0000399#if __BIONIC_AVAILABILITY_GUARD(28)
zijunzhao1a490582022-12-14 02:15:40 +0000400extern void* _Nonnull (*volatile _Nonnull __malloc_hook)(size_t __byte_count, const void* _Nonnull __caller) __INTRODUCED_IN(28);
Elliott Hughes216f3ad2025-03-31 13:36:43 -0700401#endif /* __BIONIC_AVAILABILITY_GUARD(28) */
Elliott Hughes462e90c2018-08-21 16:10:48 -0700402
403/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +0000404 * [__realloc_hook(3)](https://man7.org/linux/man-pages/man3/__realloc_hook.3.html)
Elliott Hughes462e90c2018-08-21 16:10:48 -0700405 * is called to implement realloc(). By default this points to the system's
406 * implementation.
407 *
408 * Available since API level 28.
409 *
Elliott Hughes9c06d162023-10-04 23:36:14 +0000410 * See also: [extra documentation](https://android.googlesource.com/platform/bionic/+/main/libc/malloc_hooks/README.md)
Elliott Hughes462e90c2018-08-21 16:10:48 -0700411 */
Elliott Hughes216f3ad2025-03-31 13:36:43 -0700412#if __BIONIC_AVAILABILITY_GUARD(28)
zijunzhao1a490582022-12-14 02:15:40 +0000413extern void* _Nonnull (*volatile _Nonnull __realloc_hook)(void* _Nullable __ptr, size_t __byte_count, const void* _Nonnull __caller) __INTRODUCED_IN(28);
Elliott Hughes216f3ad2025-03-31 13:36:43 -0700414#endif /* __BIONIC_AVAILABILITY_GUARD(28) */
Elliott Hughes462e90c2018-08-21 16:10:48 -0700415
416/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +0000417 * [__free_hook(3)](https://man7.org/linux/man-pages/man3/__free_hook.3.html)
Elliott Hughes462e90c2018-08-21 16:10:48 -0700418 * is called to implement free(). By default this points to the system's
419 * implementation.
420 *
421 * Available since API level 28.
422 *
Elliott Hughes9c06d162023-10-04 23:36:14 +0000423 * See also: [extra documentation](https://android.googlesource.com/platform/bionic/+/main/libc/malloc_hooks/README.md)
Elliott Hughes462e90c2018-08-21 16:10:48 -0700424 */
Elliott Hughes216f3ad2025-03-31 13:36:43 -0700425#if __BIONIC_AVAILABILITY_GUARD(28)
zijunzhao1a490582022-12-14 02:15:40 +0000426extern void (*volatile _Nonnull __free_hook)(void* _Nullable __ptr, const void* _Nonnull __caller) __INTRODUCED_IN(28);
Elliott Hughes216f3ad2025-03-31 13:36:43 -0700427#endif /* __BIONIC_AVAILABILITY_GUARD(28) */
Elliott Hughes462e90c2018-08-21 16:10:48 -0700428
429/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +0000430 * [__memalign_hook(3)](https://man7.org/linux/man-pages/man3/__memalign_hook.3.html)
Elliott Hughes462e90c2018-08-21 16:10:48 -0700431 * is called to implement memalign(). By default this points to the system's
432 * implementation.
433 *
434 * Available since API level 28.
435 *
Elliott Hughes9c06d162023-10-04 23:36:14 +0000436 * See also: [extra documentation](https://android.googlesource.com/platform/bionic/+/main/libc/malloc_hooks/README.md)
Elliott Hughes462e90c2018-08-21 16:10:48 -0700437 */
Elliott Hughes216f3ad2025-03-31 13:36:43 -0700438#if __BIONIC_AVAILABILITY_GUARD(28)
zijunzhao1a490582022-12-14 02:15:40 +0000439extern void* _Nonnull (*volatile _Nonnull __memalign_hook)(size_t __alignment, size_t __byte_count, const void* _Nonnull __caller) __INTRODUCED_IN(28);
Dan Albert02ce4012024-10-25 19:13:49 +0000440#endif /* __BIONIC_AVAILABILITY_GUARD(28) */
441
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800442__END_DECLS