blob: 7452e535f6abbfc1f9cd4e10c8ac40fffad015d2 [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
Elliott Hughes36a88e82016-07-30 09:58:15 -070026#if defined(__clang__)
27#define __BIONIC_ALLOC_SIZE(...) /* clang doesn't support attribute alloc_size. */
28#else
29#define __BIONIC_ALLOC_SIZE(...) __attribute__((__alloc_size__(__VA_ARGS__)))
30#endif
31
32void* malloc(size_t byte_count) __mallocfunc __BIONIC_ALLOC_SIZE(1) __wur;
33void* calloc(size_t item_count, size_t item_size) __mallocfunc __BIONIC_ALLOC_SIZE(1,2) __wur;
34void* realloc(void* p, size_t byte_count) __BIONIC_ALLOC_SIZE(2) __wur;
Elliott Hughes3b2096a2016-07-22 18:57:12 -070035void free(void* p);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080036
Elliott Hughes36a88e82016-07-30 09:58:15 -070037void* memalign(size_t alignment, size_t byte_count) __mallocfunc __BIONIC_ALLOC_SIZE(2) __wur;
Elliott Hughes3b2096a2016-07-22 18:57:12 -070038size_t malloc_usable_size(const void* p) __INTRODUCED_IN(17);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080039
Ian Rogers2c344d32012-08-28 15:53:10 -070040#ifndef STRUCT_MALLINFO_DECLARED
41#define STRUCT_MALLINFO_DECLARED 1
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080042struct mallinfo {
Elliott Hughes24fad012013-02-04 13:44:14 -080043 size_t arena; /* Total number of non-mmapped bytes currently allocated from OS. */
44 size_t ordblks; /* Number of free chunks. */
45 size_t smblks; /* (Unused.) */
46 size_t hblks; /* (Unused.) */
47 size_t hblkhd; /* Total number of bytes in mmapped regions. */
48 size_t usmblks; /* Maximum total allocated space; greater than total if trimming has occurred. */
49 size_t fsmblks; /* (Unused.) */
50 size_t uordblks; /* Total allocated space (normal or mmapped.) */
51 size_t fordblks; /* Total free space. */
52 size_t keepcost; /* Upper bound on number of bytes releasable by malloc_trim. */
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080053};
Ian Rogers2c344d32012-08-28 15:53:10 -070054#endif /* STRUCT_MALLINFO_DECLARED */
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080055
Elliott Hughes3b2096a2016-07-22 18:57:12 -070056struct mallinfo mallinfo(void);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080057
Dan Albert4caa1f02014-08-20 09:16:57 -070058/*
59 * XML structure for malloc_info(3) is in the following format:
60 *
61 * <malloc version="jemalloc-1">
62 * <heap nr="INT">
63 * <allocated-large>INT</allocated-large>
64 * <allocated-huge>INT</allocated-huge>
65 * <allocated-bins>INT</allocated-bins>
66 * <bins-total>INT</bins-total>
67 * <bin nr="INT">
68 * <allocated>INT</allocated>
69 * <nmalloc>INT</nmalloc>
70 * <ndalloc>INT</ndalloc>
71 * </bin>
72 * <!-- more bins -->
73 * </heap>
74 * <!-- more heaps -->
75 * </malloc>
76 */
Elliott Hughes3b2096a2016-07-22 18:57:12 -070077int malloc_info(int, FILE*) __INTRODUCED_IN(23);
Dan Albert4caa1f02014-08-20 09:16:57 -070078
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080079__END_DECLS
80
Ian Rogers2c344d32012-08-28 15:53:10 -070081#endif /* LIBC_INCLUDE_MALLOC_H_ */