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