blob: cb1dd3bcf87059ac3d82c4c55229291bdf9eaf5e [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
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 */
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080025#include <sys/cdefs.h>
26#include <stddef.h>
Dan Albert4caa1f02014-08-20 09:16:57 -070027#include <stdio.h>
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080028
29__BEGIN_DECLS
30
Nick Kralevichb91791d2013-10-02 14:14:40 -070031extern 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)));
Elliott Hughes24fad012013-02-04 13:44:14 -080034extern void free(void* p);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080035
Nick Kralevichb91791d2013-10-02 14:14:40 -070036extern void* memalign(size_t alignment, size_t byte_count) __mallocfunc __wur __attribute__((alloc_size(2)));
David 'Digit' Turner25a87f72013-05-23 10:02:02 +020037extern size_t malloc_usable_size(const void* p);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080038
Ian Rogers2c344d32012-08-28 15:53:10 -070039#ifndef STRUCT_MALLINFO_DECLARED
40#define STRUCT_MALLINFO_DECLARED 1
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080041struct mallinfo {
Elliott Hughes24fad012013-02-04 13:44:14 -080042 size_t arena; /* Total number of non-mmapped bytes currently allocated from OS. */
43 size_t ordblks; /* Number of free chunks. */
44 size_t smblks; /* (Unused.) */
45 size_t hblks; /* (Unused.) */
46 size_t hblkhd; /* Total number of bytes in mmapped regions. */
47 size_t usmblks; /* Maximum total allocated space; greater than total if trimming has occurred. */
48 size_t fsmblks; /* (Unused.) */
49 size_t uordblks; /* Total allocated space (normal or mmapped.) */
50 size_t fordblks; /* Total free space. */
51 size_t keepcost; /* Upper bound on number of bytes releasable by malloc_trim. */
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080052};
Ian Rogers2c344d32012-08-28 15:53:10 -070053#endif /* STRUCT_MALLINFO_DECLARED */
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080054
Ian Rogers2c344d32012-08-28 15:53:10 -070055extern struct mallinfo mallinfo(void);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080056
Dan Albert4caa1f02014-08-20 09:16:57 -070057/*
58 * XML structure for malloc_info(3) is in the following format:
59 *
60 * <malloc version="jemalloc-1">
61 * <heap nr="INT">
62 * <allocated-large>INT</allocated-large>
63 * <allocated-huge>INT</allocated-huge>
64 * <allocated-bins>INT</allocated-bins>
65 * <bins-total>INT</bins-total>
66 * <bin nr="INT">
67 * <allocated>INT</allocated>
68 * <nmalloc>INT</nmalloc>
69 * <ndalloc>INT</ndalloc>
70 * </bin>
71 * <!-- more bins -->
72 * </heap>
73 * <!-- more heaps -->
74 * </malloc>
75 */
76extern int malloc_info(int, FILE *);
77
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080078__END_DECLS
79
Ian Rogers2c344d32012-08-28 15:53:10 -070080#endif /* LIBC_INCLUDE_MALLOC_H_ */