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/* Defined if alloc_size attribute is supported. */
11/* #undef	JEMALLOC_HAVE_ATTR_ALLOC_SIZE */
12
13/* Defined if format(gnu_printf, ...) attribute is supported. */
14#if !defined(__clang__)
15#define	JEMALLOC_HAVE_ATTR_FORMAT_GNU_PRINTF
16#endif
17
18/* Defined if format(printf, ...) attribute is supported. */
19#define	JEMALLOC_HAVE_ATTR_FORMAT_PRINTF
20
21/*
22 * Define overrides for non-standard allocator-related functions if they are
23 * present on the system.
24 */
25#define	JEMALLOC_OVERRIDE_MEMALIGN
26#ifndef __LP64__
27#define JEMALLOC_OVERRIDE_VALLOC
28#endif
29
30/*
31 * At least Linux omits the "const" in:
32 *
33 *   size_t malloc_usable_size(const void *ptr);
34 *
35 * Match the operating system's prototype.
36 */
37#define	JEMALLOC_USABLE_SIZE_CONST const
38
39/*
40 * If defined, specify throw() for the public function prototypes when compiling
41 * with C++.  The only justification for this is to match the prototypes that
42 * glibc defines.
43 */
44/* #undef	JEMALLOC_USE_CXX_THROW */
45
46#ifdef _MSC_VER
47#  ifdef _WIN64
48#    define LG_SIZEOF_PTR_WIN 3
49#  else
50#    define LG_SIZEOF_PTR_WIN 2
51#  endif
52#endif
53
54/* sizeof(void *) == 2^LG_SIZEOF_PTR. */
55#ifdef __LP64__
56#define	LG_SIZEOF_PTR 3
57#else
58#define	LG_SIZEOF_PTR 2
59#endif
60
61/*
62 * Name mangling for public symbols is controlled by --with-mangling and
63 * --with-jemalloc-prefix.  With default settings the je_ prefix is stripped by
64 * these macro definitions.
65 */
66#ifndef JEMALLOC_NO_RENAME
67#  define je_malloc_conf je_malloc_conf
68#  define je_malloc_message je_malloc_message
69#  define je_malloc je_malloc
70#  define je_calloc je_calloc
71#  define je_posix_memalign je_posix_memalign
72#  define je_aligned_alloc je_aligned_alloc
73#  define je_realloc je_realloc
74#  define je_free je_free
75#  define je_mallocx je_mallocx
76#  define je_rallocx je_rallocx
77#  define je_xallocx je_xallocx
78#  define je_sallocx je_sallocx
79#  define je_dallocx je_dallocx
80#  define je_sdallocx je_sdallocx
81#  define je_nallocx je_nallocx
82#  define je_mallctl je_mallctl
83#  define je_mallctlnametomib je_mallctlnametomib
84#  define je_mallctlbymib je_mallctlbymib
85#  define je_malloc_stats_print je_malloc_stats_print
86#  define je_malloc_usable_size je_malloc_usable_size
87#  define je_memalign je_memalign
88#  define je_valloc je_valloc
89#endif
90
91#include <stdlib.h>
92#include <stdbool.h>
93#include <stdint.h>
94#include <limits.h>
95#include <strings.h>
96
97#define	JEMALLOC_VERSION "4.1.0-4-g33184bf69813087bf1885b0993685f9d03320c69"
98#define	JEMALLOC_VERSION_MAJOR 4
99#define	JEMALLOC_VERSION_MINOR 1
100#define	JEMALLOC_VERSION_BUGFIX 0
101#define	JEMALLOC_VERSION_NREV 4
102#define	JEMALLOC_VERSION_GID "33184bf69813087bf1885b0993685f9d03320c69"
103
104#  define MALLOCX_LG_ALIGN(la)	((int)(la))
105#  if LG_SIZEOF_PTR == 2
106#    define MALLOCX_ALIGN(a)	((int)(ffs(a)-1))
107#  else
108#    define MALLOCX_ALIGN(a)						\
109       ((int)(((a) < (size_t)INT_MAX) ? ffs((int)(a))-1 :		\
110       ffs((int)((a)>>32))+31))
111#  endif
112#  define MALLOCX_ZERO	((int)0x40)
113/*
114 * Bias tcache index bits so that 0 encodes "automatic tcache management", and 1
115 * encodes MALLOCX_TCACHE_NONE.
116 */
117#  define MALLOCX_TCACHE(tc)	((int)(((tc)+2) << 8))
118#  define MALLOCX_TCACHE_NONE	MALLOCX_TCACHE(-1)
119/*
120 * Bias arena index bits so that 0 encodes "use an automatically chosen arena".
121 */
122#  define MALLOCX_ARENA(a)	((int)(((a)+1) << 20))
123
124#if defined(__cplusplus) && defined(JEMALLOC_USE_CXX_THROW)
125#  define JEMALLOC_CXX_THROW throw()
126#else
127#  define JEMALLOC_CXX_THROW
128#endif
129
130#if _MSC_VER
131#  define JEMALLOC_ATTR(s)
132#  define JEMALLOC_ALIGNED(s) __declspec(align(s))
133#  define JEMALLOC_ALLOC_SIZE(s)
134#  define JEMALLOC_ALLOC_SIZE2(s1, s2)
135#  ifndef JEMALLOC_EXPORT
136#    ifdef DLLEXPORT
137#      define JEMALLOC_EXPORT __declspec(dllexport)
138#    else
139#      define JEMALLOC_EXPORT __declspec(dllimport)
140#    endif
141#  endif
142#  define JEMALLOC_FORMAT_PRINTF(s, i)
143#  define JEMALLOC_NOINLINE __declspec(noinline)
144#  ifdef __cplusplus
145#    define JEMALLOC_NOTHROW __declspec(nothrow)
146#  else
147#    define JEMALLOC_NOTHROW
148#  endif
149#  define JEMALLOC_SECTION(s) __declspec(allocate(s))
150#  define JEMALLOC_RESTRICT_RETURN __declspec(restrict)
151#  if _MSC_VER >= 1900 && !defined(__EDG__)
152#    define JEMALLOC_ALLOCATOR __declspec(allocator)
153#  else
154#    define JEMALLOC_ALLOCATOR
155#  endif
156#elif defined(JEMALLOC_HAVE_ATTR)
157#  define JEMALLOC_ATTR(s) __attribute__((s))
158#  define JEMALLOC_ALIGNED(s) JEMALLOC_ATTR(aligned(s))
159#  ifdef JEMALLOC_HAVE_ATTR_ALLOC_SIZE
160#    define JEMALLOC_ALLOC_SIZE(s) JEMALLOC_ATTR(alloc_size(s))
161#    define JEMALLOC_ALLOC_SIZE2(s1, s2) JEMALLOC_ATTR(alloc_size(s1, s2))
162#  else
163#    define JEMALLOC_ALLOC_SIZE(s)
164#    define JEMALLOC_ALLOC_SIZE2(s1, s2)
165#  endif
166#  ifndef JEMALLOC_EXPORT
167#    define JEMALLOC_EXPORT JEMALLOC_ATTR(visibility("default"))
168#  endif
169#  ifdef JEMALLOC_HAVE_ATTR_FORMAT_GNU_PRINTF
170#    define JEMALLOC_FORMAT_PRINTF(s, i) JEMALLOC_ATTR(format(gnu_printf, s, i))
171#  elif defined(JEMALLOC_HAVE_ATTR_FORMAT_PRINTF)
172#    define JEMALLOC_FORMAT_PRINTF(s, i) JEMALLOC_ATTR(format(printf, s, i))
173#  else
174#    define JEMALLOC_FORMAT_PRINTF(s, i)
175#  endif
176#  define JEMALLOC_NOINLINE JEMALLOC_ATTR(noinline)
177#  define JEMALLOC_NOTHROW JEMALLOC_ATTR(nothrow)
178#  define JEMALLOC_SECTION(s) JEMALLOC_ATTR(section(s))
179#  define JEMALLOC_RESTRICT_RETURN
180#  define JEMALLOC_ALLOCATOR
181#else
182#  define JEMALLOC_ATTR(s)
183#  define JEMALLOC_ALIGNED(s)
184#  define JEMALLOC_ALLOC_SIZE(s)
185#  define JEMALLOC_ALLOC_SIZE2(s1, s2)
186#  define JEMALLOC_EXPORT
187#  define JEMALLOC_FORMAT_PRINTF(s, i)
188#  define JEMALLOC_NOINLINE
189#  define JEMALLOC_NOTHROW
190#  define JEMALLOC_SECTION(s)
191#  define JEMALLOC_RESTRICT_RETURN
192#  define JEMALLOC_ALLOCATOR
193#endif
194
195/*
196 * The je_ prefix on the following public symbol declarations is an artifact
197 * of namespace management, and should be omitted in application code unless
198 * JEMALLOC_NO_DEMANGLE is defined (see jemalloc_mangle.h).
199 */
200extern JEMALLOC_EXPORT const char	*je_malloc_conf;
201extern JEMALLOC_EXPORT void		(*je_malloc_message)(void *cbopaque,
202    const char *s);
203
204JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN
205    void JEMALLOC_NOTHROW	*je_malloc(size_t size)
206    JEMALLOC_CXX_THROW JEMALLOC_ATTR(malloc) JEMALLOC_ALLOC_SIZE(1);
207JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN
208    void JEMALLOC_NOTHROW	*je_calloc(size_t num, size_t size)
209    JEMALLOC_CXX_THROW JEMALLOC_ATTR(malloc) JEMALLOC_ALLOC_SIZE2(1, 2);
210JEMALLOC_EXPORT int JEMALLOC_NOTHROW	je_posix_memalign(void **memptr,
211    size_t alignment, size_t size) JEMALLOC_CXX_THROW JEMALLOC_ATTR(nonnull(1));
212JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN
213    void JEMALLOC_NOTHROW	*je_aligned_alloc(size_t alignment,
214    size_t size) JEMALLOC_CXX_THROW JEMALLOC_ATTR(malloc)
215    JEMALLOC_ALLOC_SIZE(2);
216JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN
217    void JEMALLOC_NOTHROW	*je_realloc(void *ptr, size_t size)
218    JEMALLOC_CXX_THROW JEMALLOC_ALLOC_SIZE(2);
219JEMALLOC_EXPORT void JEMALLOC_NOTHROW	je_free(void *ptr)
220    JEMALLOC_CXX_THROW;
221
222JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN
223    void JEMALLOC_NOTHROW	*je_mallocx(size_t size, int flags)
224    JEMALLOC_ATTR(malloc) JEMALLOC_ALLOC_SIZE(1);
225JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN
226    void JEMALLOC_NOTHROW	*je_rallocx(void *ptr, size_t size,
227    int flags) JEMALLOC_ALLOC_SIZE(2);
228JEMALLOC_EXPORT size_t JEMALLOC_NOTHROW	je_xallocx(void *ptr, size_t size,
229    size_t extra, int flags);
230JEMALLOC_EXPORT size_t JEMALLOC_NOTHROW	je_sallocx(const void *ptr,
231    int flags) JEMALLOC_ATTR(pure);
232JEMALLOC_EXPORT void JEMALLOC_NOTHROW	je_dallocx(void *ptr, int flags);
233JEMALLOC_EXPORT void JEMALLOC_NOTHROW	je_sdallocx(void *ptr, size_t size,
234    int flags);
235JEMALLOC_EXPORT size_t JEMALLOC_NOTHROW	je_nallocx(size_t size, int flags)
236    JEMALLOC_ATTR(pure);
237
238JEMALLOC_EXPORT int JEMALLOC_NOTHROW	je_mallctl(const char *name,
239    void *oldp, size_t *oldlenp, void *newp, size_t newlen);
240JEMALLOC_EXPORT int JEMALLOC_NOTHROW	je_mallctlnametomib(const char *name,
241    size_t *mibp, size_t *miblenp);
242JEMALLOC_EXPORT int JEMALLOC_NOTHROW	je_mallctlbymib(const size_t *mib,
243    size_t miblen, void *oldp, size_t *oldlenp, void *newp, size_t newlen);
244JEMALLOC_EXPORT void JEMALLOC_NOTHROW	je_malloc_stats_print(
245    void (*write_cb)(void *, const char *), void *je_cbopaque,
246    const char *opts);
247JEMALLOC_EXPORT size_t JEMALLOC_NOTHROW	je_malloc_usable_size(
248    JEMALLOC_USABLE_SIZE_CONST void *ptr) JEMALLOC_CXX_THROW;
249
250#ifdef JEMALLOC_OVERRIDE_MEMALIGN
251JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN
252    void JEMALLOC_NOTHROW	*je_memalign(size_t alignment, size_t size)
253    JEMALLOC_CXX_THROW JEMALLOC_ATTR(malloc);
254#endif
255
256#ifdef JEMALLOC_OVERRIDE_VALLOC
257JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN
258    void JEMALLOC_NOTHROW	*je_valloc(size_t size) JEMALLOC_CXX_THROW
259    JEMALLOC_ATTR(malloc);
260#endif
261
262/*
263 * void *
264 * chunk_alloc(void *new_addr, size_t size, size_t alignment, bool *zero,
265 *     bool *commit, unsigned arena_ind);
266 */
267typedef void *(chunk_alloc_t)(void *, size_t, size_t, bool *, bool *, unsigned);
268
269/*
270 * bool
271 * chunk_dalloc(void *chunk, size_t size, bool committed, unsigned arena_ind);
272 */
273typedef bool (chunk_dalloc_t)(void *, size_t, bool, unsigned);
274
275/*
276 * bool
277 * chunk_commit(void *chunk, size_t size, size_t offset, size_t length,
278 *     unsigned arena_ind);
279 */
280typedef bool (chunk_commit_t)(void *, size_t, size_t, size_t, unsigned);
281
282/*
283 * bool
284 * chunk_decommit(void *chunk, size_t size, size_t offset, size_t length,
285 *     unsigned arena_ind);
286 */
287typedef bool (chunk_decommit_t)(void *, size_t, size_t, size_t, unsigned);
288
289/*
290 * bool
291 * chunk_purge(void *chunk, size_t size, size_t offset, size_t length,
292 *     unsigned arena_ind);
293 */
294typedef bool (chunk_purge_t)(void *, size_t, size_t, size_t, unsigned);
295
296/*
297 * bool
298 * chunk_split(void *chunk, size_t size, size_t size_a, size_t size_b,
299 *     bool committed, unsigned arena_ind);
300 */
301typedef bool (chunk_split_t)(void *, size_t, size_t, size_t, bool, unsigned);
302
303/*
304 * bool
305 * chunk_merge(void *chunk_a, size_t size_a, void *chunk_b, size_t size_b,
306 *     bool committed, unsigned arena_ind);
307 */
308typedef bool (chunk_merge_t)(void *, size_t, void *, size_t, bool, unsigned);
309
310typedef struct {
311	chunk_alloc_t		*alloc;
312	chunk_dalloc_t		*dalloc;
313	chunk_commit_t		*commit;
314	chunk_decommit_t	*decommit;
315	chunk_purge_t		*purge;
316	chunk_split_t		*split;
317	chunk_merge_t		*merge;
318} chunk_hooks_t;
319
320/*
321 * By default application code must explicitly refer to mangled symbol names,
322 * so that it is possible to use jemalloc in conjunction with another allocator
323 * in the same application.  Define JEMALLOC_MANGLE in order to cause automatic
324 * name mangling that matches the API prefixing that happened as a result of
325 * --with-mangling and/or --with-jemalloc-prefix configuration settings.
326 */
327#ifdef JEMALLOC_MANGLE
328#  ifndef JEMALLOC_NO_DEMANGLE
329#    define JEMALLOC_NO_DEMANGLE
330#  endif
331#  define malloc_conf je_malloc_conf
332#  define malloc_message je_malloc_message
333#  define malloc je_malloc
334#  define calloc je_calloc
335#  define posix_memalign je_posix_memalign
336#  define aligned_alloc je_aligned_alloc
337#  define realloc je_realloc
338#  define free je_free
339#  define mallocx je_mallocx
340#  define rallocx je_rallocx
341#  define xallocx je_xallocx
342#  define sallocx je_sallocx
343#  define dallocx je_dallocx
344#  define sdallocx je_sdallocx
345#  define nallocx je_nallocx
346#  define mallctl je_mallctl
347#  define mallctlnametomib je_mallctlnametomib
348#  define mallctlbymib je_mallctlbymib
349#  define malloc_stats_print je_malloc_stats_print
350#  define malloc_usable_size je_malloc_usable_size
351#  define memalign je_memalign
352#  define valloc je_valloc
353#endif
354
355/*
356 * The je_* macros can be used as stable alternative names for the
357 * public jemalloc API if JEMALLOC_NO_DEMANGLE is defined.  This is primarily
358 * meant for use in jemalloc itself, but it can be used by application code to
359 * provide isolation from the name mangling specified via --with-mangling
360 * and/or --with-jemalloc-prefix.
361 */
362#ifndef JEMALLOC_NO_DEMANGLE
363#  undef je_malloc_conf
364#  undef je_malloc_message
365#  undef je_malloc
366#  undef je_calloc
367#  undef je_posix_memalign
368#  undef je_aligned_alloc
369#  undef je_realloc
370#  undef je_free
371#  undef je_mallocx
372#  undef je_rallocx
373#  undef je_xallocx
374#  undef je_sallocx
375#  undef je_dallocx
376#  undef je_sdallocx
377#  undef je_nallocx
378#  undef je_mallctl
379#  undef je_mallctlnametomib
380#  undef je_mallctlbymib
381#  undef je_malloc_stats_print
382#  undef je_malloc_usable_size
383#  undef je_memalign
384#  undef je_valloc
385#endif
386
387#ifdef __cplusplus
388}
389#endif
390#endif /* JEMALLOC_H_ */
391