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