1#ifndef JEMALLOC_H_
2#define	JEMALLOC_H_
3#ifdef __cplusplus
4extern "C" {
5#endif
6
7/* Defined if __attribute__((...)) syntax is supported. */
8#define	JEMALLOC_HAVE_ATTR
9
10/*
11 * Define overrides for non-standard allocator-related functions if they are
12 * present on the system.
13 */
14#define	JEMALLOC_OVERRIDE_MEMALIGN
15#define	JEMALLOC_OVERRIDE_VALLOC
16
17/*
18 * At least Linux omits the "const" in:
19 *
20 *   size_t malloc_usable_size(const void *ptr);
21 *
22 * Match the operating system's prototype.
23 */
24#define	JEMALLOC_USABLE_SIZE_CONST const
25
26/* sizeof(void *) == 2^LG_SIZEOF_PTR. */
27#ifdef __LP64__
28#define	LG_SIZEOF_PTR 3
29#else
30#define	LG_SIZEOF_PTR 2
31#endif
32
33/*
34 * Name mangling for public symbols is controlled by --with-mangling and
35 * --with-jemalloc-prefix.  With default settings the je_ prefix is stripped by
36 * these macro definitions.
37 */
38#ifndef JEMALLOC_NO_RENAME
39#  define je_malloc_conf je_malloc_conf
40#  define je_malloc_message je_malloc_message
41#  define je_malloc je_malloc
42#  define je_calloc je_calloc
43#  define je_posix_memalign je_posix_memalign
44#  define je_aligned_alloc je_aligned_alloc
45#  define je_realloc je_realloc
46#  define je_free je_free
47#  define je_mallocx je_mallocx
48#  define je_rallocx je_rallocx
49#  define je_xallocx je_xallocx
50#  define je_sallocx je_sallocx
51#  define je_dallocx je_dallocx
52#  define je_nallocx je_nallocx
53#  define je_mallctl je_mallctl
54#  define je_mallctlnametomib je_mallctlnametomib
55#  define je_mallctlbymib je_mallctlbymib
56#  define je_malloc_stats_print je_malloc_stats_print
57#  define je_malloc_usable_size je_malloc_usable_size
58#  define je_memalign je_memalign
59#  define je_valloc je_valloc
60#endif
61
62#include <limits.h>
63#include <strings.h>
64
65#define	JEMALLOC_VERSION ""
66#define	JEMALLOC_VERSION_MAJOR
67#define	JEMALLOC_VERSION_MINOR
68#define	JEMALLOC_VERSION_BUGFIX
69#define	JEMALLOC_VERSION_NREV
70#define	JEMALLOC_VERSION_GID ""
71
72#  define MALLOCX_LG_ALIGN(la)	(la)
73#  if LG_SIZEOF_PTR == 2
74#    define MALLOCX_ALIGN(a)	(ffs(a)-1)
75#  else
76#    define MALLOCX_ALIGN(a)						\
77	 ((a < (size_t)INT_MAX) ? ffs(a)-1 : ffs(a>>32)+31)
78#  endif
79#  define MALLOCX_ZERO	((int)0x40)
80/* Bias arena index bits so that 0 encodes "MALLOCX_ARENA() unspecified". */
81#  define MALLOCX_ARENA(a)	((int)(((a)+1) << 8))
82
83#ifdef JEMALLOC_HAVE_ATTR
84#  define JEMALLOC_ATTR(s) __attribute__((s))
85#  if defined(__ANDROID__)
86/* None of these functions should be public on ANDROID. */
87#    define JEMALLOC_EXPORT
88#  else
89#    define JEMALLOC_EXPORT JEMALLOC_ATTR(visibility("default"))
90#  endif
91#  define JEMALLOC_ALIGNED(s) JEMALLOC_ATTR(aligned(s))
92#  define JEMALLOC_SECTION(s) JEMALLOC_ATTR(section(s))
93#  define JEMALLOC_NOINLINE JEMALLOC_ATTR(noinline)
94#elif _MSC_VER
95#  define JEMALLOC_ATTR(s)
96#  ifdef DLLEXPORT
97#    define JEMALLOC_EXPORT __declspec(dllexport)
98#  else
99#    define JEMALLOC_EXPORT __declspec(dllimport)
100#  endif
101#  define JEMALLOC_ALIGNED(s) __declspec(align(s))
102#  define JEMALLOC_SECTION(s) __declspec(allocate(s))
103#  define JEMALLOC_NOINLINE __declspec(noinline)
104#else
105#  define JEMALLOC_ATTR(s)
106#  define JEMALLOC_EXPORT
107#  define JEMALLOC_ALIGNED(s)
108#  define JEMALLOC_SECTION(s)
109#  define JEMALLOC_NOINLINE
110#endif
111
112/*
113 * The je_ prefix on the following public symbol declarations is an artifact
114 * of namespace management, and should be omitted in application code unless
115 * JEMALLOC_NO_DEMANGLE is defined (see jemalloc_mangle.h).
116 */
117extern JEMALLOC_EXPORT const char	*je_malloc_conf;
118extern JEMALLOC_EXPORT void		(*je_malloc_message)(void *cbopaque,
119    const char *s);
120
121JEMALLOC_EXPORT void	*je_malloc(size_t size) JEMALLOC_ATTR(malloc);
122JEMALLOC_EXPORT void	*je_calloc(size_t num, size_t size)
123    JEMALLOC_ATTR(malloc);
124JEMALLOC_EXPORT int	je_posix_memalign(void **memptr, size_t alignment,
125    size_t size) JEMALLOC_ATTR(nonnull(1));
126JEMALLOC_EXPORT void	*je_aligned_alloc(size_t alignment, size_t size)
127    JEMALLOC_ATTR(malloc);
128JEMALLOC_EXPORT void	*je_realloc(void *ptr, size_t size);
129JEMALLOC_EXPORT void	je_free(void *ptr);
130
131JEMALLOC_EXPORT void	*je_mallocx(size_t size, int flags);
132JEMALLOC_EXPORT void	*je_rallocx(void *ptr, size_t size, int flags);
133JEMALLOC_EXPORT size_t	je_xallocx(void *ptr, size_t size, size_t extra,
134    int flags);
135JEMALLOC_EXPORT size_t	je_sallocx(const void *ptr, int flags);
136JEMALLOC_EXPORT void	je_dallocx(void *ptr, int flags);
137JEMALLOC_EXPORT size_t	je_nallocx(size_t size, int flags);
138
139JEMALLOC_EXPORT int	je_mallctl(const char *name, void *oldp,
140    size_t *oldlenp, void *newp, size_t newlen);
141JEMALLOC_EXPORT int	je_mallctlnametomib(const char *name, size_t *mibp,
142    size_t *miblenp);
143JEMALLOC_EXPORT int	je_mallctlbymib(const size_t *mib, size_t miblen,
144    void *oldp, size_t *oldlenp, void *newp, size_t newlen);
145JEMALLOC_EXPORT void	je_malloc_stats_print(void (*write_cb)(void *,
146    const char *), void *je_cbopaque, const char *opts);
147JEMALLOC_EXPORT size_t	je_malloc_usable_size(
148    JEMALLOC_USABLE_SIZE_CONST void *ptr);
149
150#ifdef JEMALLOC_OVERRIDE_MEMALIGN
151JEMALLOC_EXPORT void *	je_memalign(size_t alignment, size_t size)
152    JEMALLOC_ATTR(malloc);
153#endif
154
155#ifdef JEMALLOC_OVERRIDE_VALLOC
156JEMALLOC_EXPORT void *	je_valloc(size_t size) JEMALLOC_ATTR(malloc);
157#endif
158
159typedef void *(chunk_alloc_t)(size_t, size_t, bool *, unsigned);
160typedef bool (chunk_dalloc_t)(void *, size_t, unsigned);
161
162/*
163 * By default application code must explicitly refer to mangled symbol names,
164 * so that it is possible to use jemalloc in conjunction with another allocator
165 * in the same application.  Define JEMALLOC_MANGLE in order to cause automatic
166 * name mangling that matches the API prefixing that happened as a result of
167 * --with-mangling and/or --with-jemalloc-prefix configuration settings.
168 */
169#ifdef JEMALLOC_MANGLE
170#  ifndef JEMALLOC_NO_DEMANGLE
171#    define JEMALLOC_NO_DEMANGLE
172#  endif
173#  define malloc_conf je_malloc_conf
174#  define malloc_message je_malloc_message
175#  define malloc je_malloc
176#  define calloc je_calloc
177#  define posix_memalign je_posix_memalign
178#  define aligned_alloc je_aligned_alloc
179#  define realloc je_realloc
180#  define free je_free
181#  define mallocx je_mallocx
182#  define rallocx je_rallocx
183#  define xallocx je_xallocx
184#  define sallocx je_sallocx
185#  define dallocx je_dallocx
186#  define nallocx je_nallocx
187#  define mallctl je_mallctl
188#  define mallctlnametomib je_mallctlnametomib
189#  define mallctlbymib je_mallctlbymib
190#  define malloc_stats_print je_malloc_stats_print
191#  define malloc_usable_size je_malloc_usable_size
192#  define memalign je_memalign
193#  define valloc je_valloc
194#endif
195
196/*
197 * The je_* macros can be used as stable alternative names for the
198 * public jemalloc API if JEMALLOC_NO_DEMANGLE is defined.  This is primarily
199 * meant for use in jemalloc itself, but it can be used by application code to
200 * provide isolation from the name mangling specified via --with-mangling
201 * and/or --with-jemalloc-prefix.
202 */
203#ifndef JEMALLOC_NO_DEMANGLE
204#  undef je_malloc_conf
205#  undef je_malloc_message
206#  undef je_malloc
207#  undef je_calloc
208#  undef je_posix_memalign
209#  undef je_aligned_alloc
210#  undef je_realloc
211#  undef je_free
212#  undef je_mallocx
213#  undef je_rallocx
214#  undef je_xallocx
215#  undef je_sallocx
216#  undef je_dallocx
217#  undef je_nallocx
218#  undef je_mallctl
219#  undef je_mallctlnametomib
220#  undef je_mallctlbymib
221#  undef je_malloc_stats_print
222#  undef je_malloc_usable_size
223#  undef je_memalign
224#  undef je_valloc
225#endif
226
227#ifdef __cplusplus
228};
229#endif
230#endif /* JEMALLOC_H_ */
231