1/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
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
7 *
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.
15 */
16
17#ifndef LIBC_INCLUDE_MALLOC_H_
18#define LIBC_INCLUDE_MALLOC_H_
19
20/*
21 * Declaration of malloc routines. Bionic uses dlmalloc (see
22 * upstream-dlmalloc) but doesn't directly include it here to keep the
23 * defined malloc.h interface small.
24 */
25#include <sys/cdefs.h>
26#include <stddef.h>
27
28__BEGIN_DECLS
29
30#if !defined(__clang__) || __clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ < 5)
31extern void* malloc(size_t byte_count) __mallocfunc __wur __attribute__((alloc_size(1)));
32extern void* calloc(size_t item_count, size_t item_size) __mallocfunc __wur __attribute__((alloc_size(1,2)));
33extern void* realloc(void* p, size_t byte_count) __wur __attribute__((alloc_size(2)));
34extern void* memalign(size_t alignment, size_t byte_count) __mallocfunc __wur __attribute__((alloc_size(2)));
35#else
36extern void* malloc(size_t byte_count) __mallocfunc __wur;
37extern void* calloc(size_t item_count, size_t item_size) __mallocfunc __wur;
38extern void* realloc(void* p, size_t byte_count) __wur;
39extern void* memalign(size_t alignment, size_t byte_count) __mallocfunc __wur;
40#endif
41
42extern void free(void* p);
43extern size_t malloc_usable_size(const void* p);
44
45#ifndef STRUCT_MALLINFO_DECLARED
46#define STRUCT_MALLINFO_DECLARED 1
47struct mallinfo {
48  size_t arena;    /* Total number of non-mmapped bytes currently allocated from OS. */
49  size_t ordblks;  /* Number of free chunks. */
50  size_t smblks;   /* (Unused.) */
51  size_t hblks;    /* (Unused.) */
52  size_t hblkhd;   /* Total number of bytes in mmapped regions. */
53  size_t usmblks;  /* Maximum total allocated space; greater than total if trimming has occurred. */
54  size_t fsmblks;  /* (Unused.) */
55  size_t uordblks; /* Total allocated space (normal or mmapped.) */
56  size_t fordblks; /* Total free space. */
57  size_t keepcost; /* Upper bound on number of bytes releasable by malloc_trim. */
58};
59#endif  /* STRUCT_MALLINFO_DECLARED */
60
61extern struct mallinfo mallinfo(void);
62
63__END_DECLS
64
65#endif  /* LIBC_INCLUDE_MALLOC_H_ */
66