blob: 987f5892953820c6e6f3ac030f44575bde39cd18 [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
Dan Albertd407e5e2024-11-08 19:45:35 +000079// The reallocarray polyfill is only available when in weak API mode to avoid
80// collisions with existing polyfills. The only known conflict is in libconfuse,
81// so if that's ever fixed upstream the guard could probably be removed.
82// https://github.com/android/ndk/issues/2081
83
Elliott Hughes462e90c2018-08-21 16:10:48 -070084/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +000085 * [reallocarray(3)](https://man7.org/linux/man-pages/man3/realloc.3.html) resizes
Elliott Hughesb1770852018-09-18 12:52:42 -070086 * allocated memory on the heap.
87 *
88 * Equivalent to `realloc(__ptr, __item_count * __item_size)` but fails if the
89 * multiplication overflows.
90 *
91 * Returns a pointer (which may be different from `__ptr`) to the resized
Elliott Hughes0a94e152023-06-26 19:03:41 +000092 * memory on success and returns a null pointer and sets `errno` on failure
93 * (but see the notes for malloc()).
Elliott Hughesb1770852018-09-18 12:52:42 -070094 */
Elliott Hughesf93af262024-09-05 13:02:21 +000095#if __ANDROID_API__ >= 29
Elliott Hughesb19df892024-09-06 14:27:41 +000096__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 +000097#elif defined(__ANDROID_UNAVAILABLE_SYMBOLS_ARE_WEAK__)
Elliott Hughesf93af262024-09-05 13:02:21 +000098#include <errno.h>
Elliott Hughesb19df892024-09-06 14:27:41 +000099static __inline __nodiscard void* _Nullable reallocarray(void* _Nullable __ptr, size_t __item_count, size_t __item_size) {
Elliott Hughesf93af262024-09-05 13:02:21 +0000100 size_t __new_size;
101 if (__builtin_mul_overflow(__item_count, __item_size, &__new_size)) {
102 errno = ENOMEM;
103 return NULL;
104 }
105 return realloc(__ptr, __new_size);
106}
Dan Albertcce54372024-08-22 18:24:30 +0000107#endif
Elliott Hughesb1770852018-09-18 12:52:42 -0700108
109/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +0000110 * [free(3)](https://man7.org/linux/man-pages/man3/free.3.html) deallocates
Elliott Hughes462e90c2018-08-21 16:10:48 -0700111 * memory on the heap.
112 */
zijunzhao1a490582022-12-14 02:15:40 +0000113void free(void* _Nullable __ptr);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800114
Elliott Hughes462e90c2018-08-21 16:10:48 -0700115/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +0000116 * [memalign(3)](https://man7.org/linux/man-pages/man3/memalign.3.html) allocates
Elliott Hughes462e90c2018-08-21 16:10:48 -0700117 * memory on the heap with the required alignment.
118 *
119 * Returns a pointer to the allocated memory on success and returns a null
Elliott Hughes0a94e152023-06-26 19:03:41 +0000120 * pointer and sets `errno` on failure (but see the notes for malloc()).
Elliott Hughes462e90c2018-08-21 16:10:48 -0700121 *
122 * See also posix_memalign().
123 */
Elliott Hughesb19df892024-09-06 14:27:41 +0000124__nodiscard void* _Nullable memalign(size_t __alignment, size_t __byte_count) __mallocfunc __BIONIC_ALLOC_SIZE(2);
Elliott Hughes462e90c2018-08-21 16:10:48 -0700125
126/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +0000127 * [malloc_usable_size(3)](https://man7.org/linux/man-pages/man3/malloc_usable_size.3.html)
Elliott Hughes462e90c2018-08-21 16:10:48 -0700128 * returns the actual size of the given heap block.
Elliott Hughes462e90c2018-08-21 16:10:48 -0700129 */
Elliott Hughesb19df892024-09-06 14:27:41 +0000130__nodiscard size_t malloc_usable_size(const void* _Nullable __ptr);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800131
Christopher Ferris8248e622021-12-03 13:55:57 -0800132#define __MALLINFO_BODY \
133 /** Total number of non-mmapped bytes currently allocated from OS. */ \
134 size_t arena; \
135 /** Number of free chunks. */ \
136 size_t ordblks; \
137 /** (Unused.) */ \
138 size_t smblks; \
139 /** (Unused.) */ \
140 size_t hblks; \
141 /** Total number of bytes in mmapped regions. */ \
142 size_t hblkhd; \
143 /** Maximum total allocated space; greater than total if trimming has occurred. */ \
144 size_t usmblks; \
145 /** (Unused.) */ \
146 size_t fsmblks; \
147 /** Total allocated space (normal or mmapped.) */ \
148 size_t uordblks; \
149 /** Total free space. */ \
150 size_t fordblks; \
151 /** Upper bound on number of bytes releasable by a trim operation. */ \
152 size_t keepcost;
153
Ian Rogers2c344d32012-08-28 15:53:10 -0700154#ifndef STRUCT_MALLINFO_DECLARED
155#define STRUCT_MALLINFO_DECLARED 1
Christopher Ferris8248e622021-12-03 13:55:57 -0800156struct mallinfo { __MALLINFO_BODY };
Elliott Hughes462e90c2018-08-21 16:10:48 -0700157#endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800158
Elliott Hughes462e90c2018-08-21 16:10:48 -0700159/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +0000160 * [mallinfo(3)](https://man7.org/linux/man-pages/man3/mallinfo.3.html) returns
Elliott Hughes4fa9b8c2019-04-30 12:39:46 -0700161 * information about the current state of the heap. Note that mallinfo() is
162 * inherently unreliable and consider using malloc_info() instead.
Elliott Hughes462e90c2018-08-21 16:10:48 -0700163 */
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700164struct mallinfo mallinfo(void);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800165
Elliott Hughes462e90c2018-08-21 16:10:48 -0700166/**
Christopher Ferris8248e622021-12-03 13:55:57 -0800167 * On Android the struct mallinfo and struct mallinfo2 are the same.
168 */
169struct mallinfo2 { __MALLINFO_BODY };
170
171/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +0000172 * [mallinfo2(3)](https://man7.org/linux/man-pages/man3/mallinfo2.3.html) returns
Christopher Ferris8248e622021-12-03 13:55:57 -0800173 * information about the current state of the heap. Note that mallinfo2() is
174 * inherently unreliable and consider using malloc_info() instead.
175 */
176struct mallinfo2 mallinfo2(void) __RENAME(mallinfo);
177
178/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +0000179 * [malloc_info(3)](https://man7.org/linux/man-pages/man3/malloc_info.3.html)
Elliott Hughes462e90c2018-08-21 16:10:48 -0700180 * writes information about the current state of the heap to the given stream.
Dan Albert4caa1f02014-08-20 09:16:57 -0700181 *
Elliott Hughes462e90c2018-08-21 16:10:48 -0700182 * The XML structure for malloc_info() is as follows:
183 * ```
Dan Albert4caa1f02014-08-20 09:16:57 -0700184 * <malloc version="jemalloc-1">
185 * <heap nr="INT">
186 * <allocated-large>INT</allocated-large>
187 * <allocated-huge>INT</allocated-huge>
188 * <allocated-bins>INT</allocated-bins>
189 * <bins-total>INT</bins-total>
190 * <bin nr="INT">
191 * <allocated>INT</allocated>
192 * <nmalloc>INT</nmalloc>
193 * <ndalloc>INT</ndalloc>
194 * </bin>
195 * <!-- more bins -->
196 * </heap>
197 * <!-- more heaps -->
198 * </malloc>
Elliott Hughes462e90c2018-08-21 16:10:48 -0700199 * ```
200 *
201 * Available since API level 23.
Dan Albert4caa1f02014-08-20 09:16:57 -0700202 */
Dan Albert02ce4012024-10-25 19:13:49 +0000203
204#if __BIONIC_AVAILABILITY_GUARD(23)
zijunzhao1a490582022-12-14 02:15:40 +0000205int malloc_info(int __must_be_zero, FILE* _Nonnull __fp) __INTRODUCED_IN(23);
Dan Albert02ce4012024-10-25 19:13:49 +0000206#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
207
Dan Albert4caa1f02014-08-20 09:16:57 -0700208
Christopher Ferris8daea552018-10-23 11:17:24 -0700209/**
Chia-hung Duan6abb4062024-04-17 19:08:48 -0700210 * mallopt() option to set the decay time. Valid values are -1, 0 and 1.
211 * -1 : Disable the releasing of unused pages. This value is available since
212 * API level 35.
213 * 0 : Release the unused pages immediately.
214 * 1 : Release the unused pages at a device-specific interval.
Christopher Ferris8daea552018-10-23 11:17:24 -0700215 *
216 * Available since API level 27.
217 */
Chih-Hung Hsiehfa658eb2020-03-04 11:14:42 -0800218#define M_DECAY_TIME (-100)
Christopher Ferris8daea552018-10-23 11:17:24 -0700219/**
220 * mallopt() option to immediately purge any memory not in use. This
221 * will release the memory back to the kernel. The value is ignored.
222 *
223 * Available since API level 28.
224 */
Chih-Hung Hsiehfa658eb2020-03-04 11:14:42 -0800225#define M_PURGE (-101)
Christopher Ferrisd86eb862023-02-28 12:45:54 -0800226/**
227 * mallopt() option to immediately purge all possible memory back to
228 * the kernel. This call can take longer than a normal purge since it
229 * examines everything. In some cases, it can take more than twice the
230 * time of a M_PURGE call. The value is ignored.
231 *
232 * Available since API level 34.
233 */
234#define M_PURGE_ALL (-104)
Evgenii Stepanovd8d561c2021-06-22 10:18:12 -0700235
236/**
237 * mallopt() option to tune the allocator's choice of memory tags to
238 * make it more likely that a certain class of memory errors will be
239 * detected. This is only relevant if MTE is enabled in this process
240 * and ignored otherwise. The value argument should be one of the
241 * M_MEMTAG_TUNING_* flags.
242 * NOTE: This is only available in scudo.
243 *
244 * Available since API level 31.
245 */
246#define M_MEMTAG_TUNING (-102)
247
248/**
249 * When passed as a value of M_MEMTAG_TUNING mallopt() call, enables
250 * deterministic detection of linear buffer overflow and underflow
251 * bugs by assigning distinct tag values to adjacent allocations. This
252 * mode has a slightly reduced chance to detect use-after-free bugs
253 * because only half of the possible tag values are available for each
254 * memory location.
255 *
256 * Please keep in mind that MTE can not detect overflow within the
257 * same tag granule (16-byte aligned chunk), and can miss small
258 * overflows even in this mode. Such overflow can not be the cause of
259 * a memory corruption, because the memory within one granule is never
260 * used for multiple allocations.
261 */
262#define M_MEMTAG_TUNING_BUFFER_OVERFLOW 0
263
264/**
265 * When passed as a value of M_MEMTAG_TUNING mallopt() call, enables
266 * independently randomized tags for uniform ~93% probability of
267 * detecting both spatial (buffer overflow) and temporal (use after
268 * free) bugs.
269 */
270#define M_MEMTAG_TUNING_UAF 1
271
272/**
Peter Collingbourne978eb162020-09-21 15:26:02 -0700273 * mallopt() option for per-thread memory initialization tuning.
274 * The value argument should be one of:
Christopher Ferrise28867c2023-04-27 17:03:59 -0700275 * 1: Disable automatic heap initialization on this thread only.
276 * If memory tagging is enabled, disable as much as possible of the
277 * memory tagging initialization for this thread.
Peter Collingbourne978eb162020-09-21 15:26:02 -0700278 * 0: Normal behavior.
279 *
280 * Available since API level 31.
281 */
282#define M_THREAD_DISABLE_MEM_INIT (-103)
Christopher Ferris88448792020-07-28 14:15:31 -0700283/**
284 * mallopt() option to set the maximum number of items in the secondary
285 * cache of the scudo allocator.
286 *
287 * Available since API level 31.
288 */
289#define M_CACHE_COUNT_MAX (-200)
290/**
291 * mallopt() option to set the maximum size in bytes of a cacheable item in
292 * the secondary cache of the scudo allocator.
293 *
294 * Available since API level 31.
295 */
296#define M_CACHE_SIZE_MAX (-201)
297/**
298 * mallopt() option to increase the maximum number of shared thread-specific
299 * data structures that can be created. This number cannot be decreased,
300 * only increased and only applies to the scudo allocator.
301 *
302 * Available since API level 31.
303 */
304#define M_TSDS_COUNT_MAX (-202)
Elliott Hughes462e90c2018-08-21 16:10:48 -0700305
306/**
Mitch Phillips9cad8422021-01-20 16:03:27 -0800307 * mallopt() option to decide whether heap memory is zero-initialized on
308 * allocation across the whole process. May be called at any time, including
309 * when multiple threads are running. An argument of zero indicates memory
310 * should not be zero-initialized, any other value indicates to initialize heap
311 * memory to zero.
Elliott Hughes446b4dd2021-01-14 13:34:20 -0800312 *
Evgenii Stepanovd8d561c2021-06-22 10:18:12 -0700313 * Note that this memory mitigation is only implemented in scudo and therefore
Mitch Phillips9cad8422021-01-20 16:03:27 -0800314 * this will have no effect when using another allocator (such as jemalloc on
315 * Android Go devices).
Elliott Hughes446b4dd2021-01-14 13:34:20 -0800316 *
317 * Available since API level 31.
318 */
Mitch Phillips9cad8422021-01-20 16:03:27 -0800319#define M_BIONIC_ZERO_INIT (-203)
Elliott Hughes446b4dd2021-01-14 13:34:20 -0800320
321/**
322 * mallopt() option to change the heap tagging state. May be called at any
323 * time, including when multiple threads are running.
324 * The value must be one of the M_HEAP_TAGGING_LEVEL_ constants.
Evgenii Stepanovd8d561c2021-06-22 10:18:12 -0700325 * NOTE: This is only available in scudo.
Elliott Hughes446b4dd2021-01-14 13:34:20 -0800326 *
327 * Available since API level 31.
328 */
329#define M_BIONIC_SET_HEAP_TAGGING_LEVEL (-204)
330
331/**
332 * Constants for use with the M_BIONIC_SET_HEAP_TAGGING_LEVEL mallopt() option.
333 */
334enum HeapTaggingLevel {
335 /**
336 * Disable heap tagging and memory tag checks (if supported).
337 * Heap tagging may not be re-enabled after being disabled.
338 */
339 M_HEAP_TAGGING_LEVEL_NONE = 0,
340#define M_HEAP_TAGGING_LEVEL_NONE M_HEAP_TAGGING_LEVEL_NONE
341 /**
342 * Address-only tagging. Heap pointers have a non-zero tag in the
343 * most significant ("top") byte which is checked in free(). Memory
344 * accesses ignore the tag using arm64's Top Byte Ignore (TBI) feature.
345 */
346 M_HEAP_TAGGING_LEVEL_TBI = 1,
347#define M_HEAP_TAGGING_LEVEL_TBI M_HEAP_TAGGING_LEVEL_TBI
348 /**
349 * Enable heap tagging and asynchronous memory tag checks (if supported).
350 * Disable stack trace collection.
351 */
352 M_HEAP_TAGGING_LEVEL_ASYNC = 2,
353#define M_HEAP_TAGGING_LEVEL_ASYNC M_HEAP_TAGGING_LEVEL_ASYNC
354 /**
355 * Enable heap tagging and synchronous memory tag checks (if supported).
356 * Enable stack trace collection.
357 */
358 M_HEAP_TAGGING_LEVEL_SYNC = 3,
359#define M_HEAP_TAGGING_LEVEL_SYNC M_HEAP_TAGGING_LEVEL_SYNC
360};
361
362/**
Christopher Ferrise9a7b812023-05-11 15:36:27 -0700363 * mallopt() option to print human readable statistics about the memory
364 * allocator to the log. There is no format for this data, each allocator
365 * can use a different format, and the data that is printed can
366 * change at any time. This is expected to be used as a debugging aid.
367 *
368 * Available since API level 35.
369 */
370#define M_LOG_STATS (-205)
371
372/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +0000373 * [mallopt(3)](https://man7.org/linux/man-pages/man3/mallopt.3.html) modifies
Elliott Hughes462e90c2018-08-21 16:10:48 -0700374 * heap behavior. Values of `__option` are the `M_` constants from this header.
375 *
376 * Returns 1 on success, 0 on error.
377 *
378 * Available since API level 26.
379 */
Dan Albert02ce4012024-10-25 19:13:49 +0000380
381#if __BIONIC_AVAILABILITY_GUARD(26)
Elliott Hughesfaa74342017-08-11 17:34:44 -0700382int mallopt(int __option, int __value) __INTRODUCED_IN(26);
Dan Albert02ce4012024-10-25 19:13:49 +0000383#endif /* __BIONIC_AVAILABILITY_GUARD(26) */
384
Christopher Ferrisa1c0d2f2017-05-15 15:50:19 -0700385
Elliott Hughes462e90c2018-08-21 16:10:48 -0700386/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +0000387 * [__malloc_hook(3)](https://man7.org/linux/man-pages/man3/__malloc_hook.3.html)
Elliott Hughes462e90c2018-08-21 16:10:48 -0700388 * is called to implement malloc(). By default this points to the system's
389 * implementation.
390 *
391 * Available since API level 28.
392 *
Elliott Hughes9c06d162023-10-04 23:36:14 +0000393 * See also: [extra documentation](https://android.googlesource.com/platform/bionic/+/main/libc/malloc_hooks/README.md)
Christopher Ferrisdb478a62018-02-07 18:42:14 -0800394 */
Dan Albert02ce4012024-10-25 19:13:49 +0000395
396#if __BIONIC_AVAILABILITY_GUARD(28)
zijunzhao1a490582022-12-14 02:15:40 +0000397extern void* _Nonnull (*volatile _Nonnull __malloc_hook)(size_t __byte_count, const void* _Nonnull __caller) __INTRODUCED_IN(28);
Elliott Hughes462e90c2018-08-21 16:10:48 -0700398
399/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +0000400 * [__realloc_hook(3)](https://man7.org/linux/man-pages/man3/__realloc_hook.3.html)
Elliott Hughes462e90c2018-08-21 16:10:48 -0700401 * is called to implement realloc(). By default this points to the system's
402 * implementation.
403 *
404 * Available since API level 28.
405 *
Elliott Hughes9c06d162023-10-04 23:36:14 +0000406 * See also: [extra documentation](https://android.googlesource.com/platform/bionic/+/main/libc/malloc_hooks/README.md)
Elliott Hughes462e90c2018-08-21 16:10:48 -0700407 */
zijunzhao1a490582022-12-14 02:15:40 +0000408extern void* _Nonnull (*volatile _Nonnull __realloc_hook)(void* _Nullable __ptr, size_t __byte_count, const void* _Nonnull __caller) __INTRODUCED_IN(28);
Elliott Hughes462e90c2018-08-21 16:10:48 -0700409
410/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +0000411 * [__free_hook(3)](https://man7.org/linux/man-pages/man3/__free_hook.3.html)
Elliott Hughes462e90c2018-08-21 16:10:48 -0700412 * is called to implement free(). By default this points to the system's
413 * implementation.
414 *
415 * Available since API level 28.
416 *
Elliott Hughes9c06d162023-10-04 23:36:14 +0000417 * See also: [extra documentation](https://android.googlesource.com/platform/bionic/+/main/libc/malloc_hooks/README.md)
Elliott Hughes462e90c2018-08-21 16:10:48 -0700418 */
zijunzhao1a490582022-12-14 02:15:40 +0000419extern void (*volatile _Nonnull __free_hook)(void* _Nullable __ptr, const void* _Nonnull __caller) __INTRODUCED_IN(28);
Elliott Hughes462e90c2018-08-21 16:10:48 -0700420
421/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +0000422 * [__memalign_hook(3)](https://man7.org/linux/man-pages/man3/__memalign_hook.3.html)
Elliott Hughes462e90c2018-08-21 16:10:48 -0700423 * is called to implement memalign(). By default this points to the system's
424 * implementation.
425 *
426 * Available since API level 28.
427 *
Elliott Hughes9c06d162023-10-04 23:36:14 +0000428 * See also: [extra documentation](https://android.googlesource.com/platform/bionic/+/main/libc/malloc_hooks/README.md)
Elliott Hughes462e90c2018-08-21 16:10:48 -0700429 */
zijunzhao1a490582022-12-14 02:15:40 +0000430extern 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 +0000431#endif /* __BIONIC_AVAILABILITY_GUARD(28) */
432
Christopher Ferrisdb478a62018-02-07 18:42:14 -0800433
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800434__END_DECLS