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