xref: /freebsd/contrib/jemalloc/include/jemalloc/jemalloc_macros.h.in (revision 8ebb3de0c9dfb1a15bf24dcb0ca65cc91e7ad0e8)
1#include <stdlib.h>
2#include <stdbool.h>
3#include <stdint.h>
4#include <limits.h>
5#include <strings.h>
6
7#define JEMALLOC_VERSION "@jemalloc_version@"
8#define JEMALLOC_VERSION_MAJOR @jemalloc_version_major@
9#define JEMALLOC_VERSION_MINOR @jemalloc_version_minor@
10#define JEMALLOC_VERSION_BUGFIX @jemalloc_version_bugfix@
11#define JEMALLOC_VERSION_NREV @jemalloc_version_nrev@
12#define JEMALLOC_VERSION_GID "@jemalloc_version_gid@"
13#define JEMALLOC_VERSION_GID_IDENT @jemalloc_version_gid@
14
15#define MALLOCX_LG_ALIGN(la)	((int)(la))
16#if LG_SIZEOF_PTR == 2
17#  define MALLOCX_ALIGN(a)	((int)(ffs((int)(a))-1))
18#else
19#  define MALLOCX_ALIGN(a)						\
20     ((int)(((size_t)(a) < (size_t)INT_MAX) ? ffs((int)(a))-1 :	\
21     ffs((int)(((size_t)(a))>>32))+31))
22#endif
23#define MALLOCX_ZERO	((int)0x40)
24/*
25 * Bias tcache index bits so that 0 encodes "automatic tcache management", and 1
26 * encodes MALLOCX_TCACHE_NONE.
27 */
28#define MALLOCX_TCACHE(tc)	((int)(((tc)+2) << 8))
29#define MALLOCX_TCACHE_NONE	MALLOCX_TCACHE(-1)
30/*
31 * Bias arena index bits so that 0 encodes "use an automatically chosen arena".
32 */
33#define MALLOCX_ARENA(a)	((((int)(a))+1) << 20)
34
35/*
36 * Use as arena index in "arena.<i>.{purge,decay,dss}" and
37 * "stats.arenas.<i>.*" mallctl interfaces to select all arenas.  This
38 * definition is intentionally specified in raw decimal format to support
39 * cpp-based string concatenation, e.g.
40 *
41 *   #define STRINGIFY_HELPER(x) #x
42 *   #define STRINGIFY(x) STRINGIFY_HELPER(x)
43 *
44 *   mallctl("arena." STRINGIFY(MALLCTL_ARENAS_ALL) ".purge", NULL, NULL, NULL,
45 *       0);
46 */
47#define MALLCTL_ARENAS_ALL	4096
48/*
49 * Use as arena index in "stats.arenas.<i>.*" mallctl interfaces to select
50 * destroyed arenas.
51 */
52#define MALLCTL_ARENAS_DESTROYED	4097
53
54#if defined(__cplusplus) && defined(JEMALLOC_USE_CXX_THROW)
55#  define JEMALLOC_CXX_THROW throw()
56#else
57#  define JEMALLOC_CXX_THROW
58#endif
59
60#if defined(_MSC_VER)
61#  define JEMALLOC_ATTR(s)
62#  define JEMALLOC_ALIGNED(s) __declspec(align(s))
63#  define JEMALLOC_ALLOC_SIZE(s)
64#  define JEMALLOC_ALLOC_SIZE2(s1, s2)
65#  ifndef JEMALLOC_EXPORT
66#    ifdef DLLEXPORT
67#      define JEMALLOC_EXPORT __declspec(dllexport)
68#    else
69#      define JEMALLOC_EXPORT __declspec(dllimport)
70#    endif
71#  endif
72#  define JEMALLOC_FORMAT_ARG(i)
73#  define JEMALLOC_FORMAT_PRINTF(s, i)
74#  define JEMALLOC_FALLTHROUGH
75#  define JEMALLOC_NOINLINE __declspec(noinline)
76#  ifdef __cplusplus
77#    define JEMALLOC_NOTHROW __declspec(nothrow)
78#  else
79#    define JEMALLOC_NOTHROW
80#  endif
81#  define JEMALLOC_SECTION(s) __declspec(allocate(s))
82#  define JEMALLOC_RESTRICT_RETURN __declspec(restrict)
83#  if _MSC_VER >= 1900 && !defined(__EDG__)
84#    define JEMALLOC_ALLOCATOR __declspec(allocator)
85#  else
86#    define JEMALLOC_ALLOCATOR
87#  endif
88#  define JEMALLOC_COLD
89#elif defined(JEMALLOC_HAVE_ATTR)
90#  define JEMALLOC_ATTR(s) __attribute__((s))
91#  define JEMALLOC_ALIGNED(s) JEMALLOC_ATTR(aligned(s))
92#  ifdef JEMALLOC_HAVE_ATTR_ALLOC_SIZE
93#    define JEMALLOC_ALLOC_SIZE(s) JEMALLOC_ATTR(alloc_size(s))
94#    define JEMALLOC_ALLOC_SIZE2(s1, s2) JEMALLOC_ATTR(alloc_size(s1, s2))
95#  else
96#    define JEMALLOC_ALLOC_SIZE(s)
97#    define JEMALLOC_ALLOC_SIZE2(s1, s2)
98#  endif
99#  ifndef JEMALLOC_EXPORT
100#    define JEMALLOC_EXPORT JEMALLOC_ATTR(visibility("default"))
101#  endif
102#  ifdef JEMALLOC_HAVE_ATTR_FORMAT_ARG
103#    define JEMALLOC_FORMAT_ARG(i) JEMALLOC_ATTR(__format_arg__(3))
104#  else
105#    define JEMALLOC_FORMAT_ARG(i)
106#  endif
107#  ifdef JEMALLOC_HAVE_ATTR_FORMAT_GNU_PRINTF
108#    define JEMALLOC_FORMAT_PRINTF(s, i) JEMALLOC_ATTR(format(gnu_printf, s, i))
109#  elif defined(JEMALLOC_HAVE_ATTR_FORMAT_PRINTF)
110#    define JEMALLOC_FORMAT_PRINTF(s, i) JEMALLOC_ATTR(format(printf, s, i))
111#  else
112#    define JEMALLOC_FORMAT_PRINTF(s, i)
113#  endif
114#  ifdef JEMALLOC_HAVE_ATTR_FALLTHROUGH
115#    define JEMALLOC_FALLTHROUGH JEMALLOC_ATTR(fallthrough)
116#  else
117#    define JEMALLOC_FALLTHROUGH
118#  endif
119#  define JEMALLOC_NOINLINE JEMALLOC_ATTR(noinline)
120#  define JEMALLOC_NOTHROW JEMALLOC_ATTR(nothrow)
121#  define JEMALLOC_SECTION(s) JEMALLOC_ATTR(section(s))
122#  define JEMALLOC_RESTRICT_RETURN
123#  define JEMALLOC_ALLOCATOR
124#  ifdef JEMALLOC_HAVE_ATTR_COLD
125#    define JEMALLOC_COLD JEMALLOC_ATTR(__cold__)
126#  else
127#    define JEMALLOC_COLD
128#  endif
129#else
130#  define JEMALLOC_ATTR(s)
131#  define JEMALLOC_ALIGNED(s)
132#  define JEMALLOC_ALLOC_SIZE(s)
133#  define JEMALLOC_ALLOC_SIZE2(s1, s2)
134#  define JEMALLOC_EXPORT
135#  define JEMALLOC_FORMAT_PRINTF(s, i)
136#  define JEMALLOC_FALLTHROUGH
137#  define JEMALLOC_NOINLINE
138#  define JEMALLOC_NOTHROW
139#  define JEMALLOC_SECTION(s)
140#  define JEMALLOC_RESTRICT_RETURN
141#  define JEMALLOC_ALLOCATOR
142#  define JEMALLOC_COLD
143#endif
144
145#if (defined(__APPLE__) || defined(__FreeBSD__)) && !defined(JEMALLOC_NO_RENAME)
146#  define JEMALLOC_SYS_NOTHROW
147#else
148#  define JEMALLOC_SYS_NOTHROW JEMALLOC_NOTHROW
149#endif
150