blob: 3a678a94e7e8f35e0b40787c990ffa65e74218d9 [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
Ian Rogers2c344d32012-08-28 15:53:10 -070017#ifndef LIBC_INCLUDE_MALLOC_H_
18#define LIBC_INCLUDE_MALLOC_H_
19
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080020#include <sys/cdefs.h>
21#include <stddef.h>
Dan Albert4caa1f02014-08-20 09:16:57 -070022#include <stdio.h>
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080023
24__BEGIN_DECLS
25
Yi Kong06be3452017-04-20 14:27:28 -070026// Remove the workaround once b/37423073 is fixed.
27#if defined(__clang__) && !__has_attribute(alloc_size)
George Burgess IV7cc779f2017-02-09 00:00:31 -080028#define __BIONIC_ALLOC_SIZE(...)
Elliott Hughes36a88e82016-07-30 09:58:15 -070029#else
30#define __BIONIC_ALLOC_SIZE(...) __attribute__((__alloc_size__(__VA_ARGS__)))
31#endif
32
Elliott Hughesfaa74342017-08-11 17:34:44 -070033void* malloc(size_t __byte_count) __mallocfunc __BIONIC_ALLOC_SIZE(1) __wur;
34void* calloc(size_t __item_count, size_t __item_size) __mallocfunc __BIONIC_ALLOC_SIZE(1,2) __wur;
35void* realloc(void* __ptr, size_t __byte_count) __BIONIC_ALLOC_SIZE(2) __wur;
36void free(void* __ptr);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080037
Elliott Hughesfaa74342017-08-11 17:34:44 -070038void* memalign(size_t __alignment, size_t __byte_count) __mallocfunc __BIONIC_ALLOC_SIZE(2) __wur;
39size_t malloc_usable_size(const void* __ptr) __INTRODUCED_IN(17);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080040
Ian Rogers2c344d32012-08-28 15:53:10 -070041#ifndef STRUCT_MALLINFO_DECLARED
42#define STRUCT_MALLINFO_DECLARED 1
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080043struct mallinfo {
Elliott Hughes24fad012013-02-04 13:44:14 -080044 size_t arena; /* Total number of non-mmapped bytes currently allocated from OS. */
45 size_t ordblks; /* Number of free chunks. */
46 size_t smblks; /* (Unused.) */
47 size_t hblks; /* (Unused.) */
48 size_t hblkhd; /* Total number of bytes in mmapped regions. */
49 size_t usmblks; /* Maximum total allocated space; greater than total if trimming has occurred. */
50 size_t fsmblks; /* (Unused.) */
51 size_t uordblks; /* Total allocated space (normal or mmapped.) */
52 size_t fordblks; /* Total free space. */
53 size_t keepcost; /* Upper bound on number of bytes releasable by malloc_trim. */
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080054};
Ian Rogers2c344d32012-08-28 15:53:10 -070055#endif /* STRUCT_MALLINFO_DECLARED */
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080056
Elliott Hughes3b2096a2016-07-22 18:57:12 -070057struct mallinfo mallinfo(void);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080058
Dan Albert4caa1f02014-08-20 09:16:57 -070059/*
60 * XML structure for malloc_info(3) is in the following format:
61 *
62 * <malloc version="jemalloc-1">
63 * <heap nr="INT">
64 * <allocated-large>INT</allocated-large>
65 * <allocated-huge>INT</allocated-huge>
66 * <allocated-bins>INT</allocated-bins>
67 * <bins-total>INT</bins-total>
68 * <bin nr="INT">
69 * <allocated>INT</allocated>
70 * <nmalloc>INT</nmalloc>
71 * <ndalloc>INT</ndalloc>
72 * </bin>
73 * <!-- more bins -->
74 * </heap>
75 * <!-- more heaps -->
76 * </malloc>
77 */
Elliott Hughesfaa74342017-08-11 17:34:44 -070078int malloc_info(int __must_be_zero, FILE* __fp) __INTRODUCED_IN(23);
Dan Albert4caa1f02014-08-20 09:16:57 -070079
Christopher Ferrisa1c0d2f2017-05-15 15:50:19 -070080/* mallopt options */
81#define M_DECAY_TIME -100
Elliott Hughesfaa74342017-08-11 17:34:44 -070082int mallopt(int __option, int __value) __INTRODUCED_IN(26);
Christopher Ferrisa1c0d2f2017-05-15 15:50:19 -070083
Christopher Ferrisdb478a62018-02-07 18:42:14 -080084/*
85 * Memory Allocation Hooks
86 */
87extern void* (*volatile __malloc_hook)(size_t, const void*) __INTRODUCED_IN(28);
88extern void* (*volatile __realloc_hook)(void*, size_t, const void*) __INTRODUCED_IN(28);
89extern void (*volatile __free_hook)(void*, const void*) __INTRODUCED_IN(28);
90extern void* (*volatile __memalign_hook)(size_t, size_t, const void*) __INTRODUCED_IN(28);
91
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080092__END_DECLS
93
Ian Rogers2c344d32012-08-28 15:53:10 -070094#endif /* LIBC_INCLUDE_MALLOC_H_ */