• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <sys/cdefs.h>
21 #include <stddef.h>
22 #include <stdio.h>
23 
24 __BEGIN_DECLS
25 
26 // Remove the workaround once b/37423073 is fixed.
27 #if defined(__clang__) && !__has_attribute(alloc_size)
28 #define __BIONIC_ALLOC_SIZE(...)
29 #else
30 #define __BIONIC_ALLOC_SIZE(...) __attribute__((__alloc_size__(__VA_ARGS__)))
31 #endif
32 
33 void* malloc(size_t byte_count) __mallocfunc __BIONIC_ALLOC_SIZE(1) __wur;
34 void* calloc(size_t item_count, size_t item_size) __mallocfunc __BIONIC_ALLOC_SIZE(1,2) __wur;
35 void* realloc(void* p, size_t byte_count) __BIONIC_ALLOC_SIZE(2) __wur;
36 void free(void* p);
37 
38 void* memalign(size_t alignment, size_t byte_count) __mallocfunc __BIONIC_ALLOC_SIZE(2) __wur;
39 size_t malloc_usable_size(const void* p) __INTRODUCED_IN(17);
40 
41 #ifndef STRUCT_MALLINFO_DECLARED
42 #define STRUCT_MALLINFO_DECLARED 1
43 struct mallinfo {
44   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. */
54 };
55 #endif  /* STRUCT_MALLINFO_DECLARED */
56 
57 struct mallinfo mallinfo(void);
58 
59 /*
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  */
78 int malloc_info(int, FILE*) __INTRODUCED_IN(23);
79 
80 /* mallopt options */
81 #define M_DECAY_TIME -100
82 
83 int mallopt(int, int) __INTRODUCED_IN(26);
84 
85 __END_DECLS
86 
87 #endif  /* LIBC_INCLUDE_MALLOC_H_ */
88