xref: /freebsd/lib/libc/stdlib/malloc/jemalloc/include/jemalloc/jemalloc_FreeBSD.h (revision c43cad87172039ccf38172129c79755ea79e6102)
1 /*
2  * Override settings that were generated in jemalloc_defs.h as necessary.
3  */
4 
5 #ifndef JEMALLOC_NO_PRIVATE_NAMESPACE
6 
7 #undef JEMALLOC_OVERRIDE_VALLOC
8 
9 #ifndef MALLOC_PRODUCTION
10 #define	JEMALLOC_DEBUG
11 #endif
12 
13 #undef JEMALLOC_DSS
14 
15 #undef JEMALLOC_BACKGROUND_THREAD
16 
17 /*
18  * The following are architecture-dependent, so conditionally define them for
19  * each supported architecture.
20  */
21 #undef JEMALLOC_TLS_MODEL
22 #undef LG_PAGE
23 #undef LG_VADDR
24 #undef LG_SIZEOF_PTR
25 #undef LG_SIZEOF_INT
26 #undef LG_SIZEOF_LONG
27 #undef LG_SIZEOF_INTMAX_T
28 
29 #ifdef __i386__
30 #  define LG_VADDR		32
31 #  define LG_SIZEOF_PTR		2
32 #  define JEMALLOC_TLS_MODEL	__attribute__((tls_model("initial-exec")))
33 #endif
34 #ifdef __ia64__
35 #  define LG_VADDR		64
36 #  define LG_SIZEOF_PTR		3
37 #endif
38 #ifdef __sparc64__
39 #  define LG_VADDR		64
40 #  define LG_SIZEOF_PTR		3
41 #  define JEMALLOC_TLS_MODEL	__attribute__((tls_model("initial-exec")))
42 #endif
43 #ifdef __amd64__
44 #ifdef _USE_LG_VADDR_WIDE
45 #  define LG_VADDR		64
46 #else
47 #  define LG_VADDR		48
48 #endif
49 #  define LG_SIZEOF_PTR		3
50 #  define JEMALLOC_TLS_MODEL	__attribute__((tls_model("initial-exec")))
51 #endif
52 #ifdef __arm__
53 #  define LG_VADDR		32
54 #  define LG_SIZEOF_PTR		2
55 #endif
56 #ifdef __aarch64__
57 #  define LG_VADDR		48
58 #  define LG_SIZEOF_PTR		3
59 #endif
60 #ifdef __mips__
61 #ifdef __mips_n64
62 #  define LG_VADDR		64
63 #  define LG_SIZEOF_PTR		3
64 #else
65 #  define LG_VADDR		32
66 #  define LG_SIZEOF_PTR		2
67 #endif
68 #endif
69 #ifdef __powerpc64__
70 #  define LG_VADDR		64
71 #  define LG_SIZEOF_PTR		3
72 #  define JEMALLOC_TLS_MODEL	__attribute__((tls_model("initial-exec")))
73 #elif defined(__powerpc__)
74 #  define LG_VADDR		32
75 #  define LG_SIZEOF_PTR		2
76 #  define JEMALLOC_TLS_MODEL	__attribute__((tls_model("initial-exec")))
77 #endif
78 #ifdef __riscv
79 #  define LG_VADDR		48
80 #  define LG_SIZEOF_PTR		3
81 #endif
82 
83 #if LG_VADDR > 32
84 #  define JEMALLOC_RETAIN
85 #endif
86 
87 #ifndef JEMALLOC_TLS_MODEL
88 #  define JEMALLOC_TLS_MODEL	/* Default. */
89 #endif
90 
91 #define	LG_PAGE			PAGE_SHIFT
92 #define	LG_SIZEOF_INT		2
93 #define	LG_SIZEOF_LONG		LG_SIZEOF_PTR
94 #define	LG_SIZEOF_INTMAX_T	3
95 
96 #undef CPU_SPINWAIT
97 #include <machine/cpu.h>
98 #include <machine/cpufunc.h>
99 #define	CPU_SPINWAIT		cpu_spinwait()
100 
101 /*
102  * Disable lazy-lock machinery, redirect isthreaded to libc's flag, undo
103  * jemalloc's namespace stuff for it and adjust its type.
104  */
105 #undef JEMALLOC_LAZY_LOCK
106 #undef isthreaded
107 extern int __isthreaded;
108 #define	isthreaded		((bool)__isthreaded)
109 
110 /* Mangle. */
111 #undef je_malloc
112 #undef je_calloc
113 #undef je_posix_memalign
114 #undef je_aligned_alloc
115 #undef je_realloc
116 #undef je_free
117 #undef je_malloc_usable_size
118 #undef je_mallocx
119 #undef je_rallocx
120 #undef je_xallocx
121 #undef je_sallocx
122 #undef je_dallocx
123 #undef je_sdallocx
124 #undef je_nallocx
125 #undef je_mallctl
126 #undef je_mallctlnametomib
127 #undef je_mallctlbymib
128 #undef je_malloc_stats_print
129 #undef je_allocm
130 #undef je_rallocm
131 #undef je_dallocm
132 #undef je_nallocm
133 #define	je_malloc		__malloc
134 #define	je_calloc		__calloc
135 #define	je_posix_memalign	__posix_memalign
136 #define	je_aligned_alloc	__aligned_alloc
137 #define	je_realloc		__realloc
138 #define	je_free			__free
139 #define	je_malloc_usable_size	__malloc_usable_size
140 #define	je_mallocx		__mallocx
141 #define	je_rallocx		__rallocx
142 #define	je_xallocx		__xallocx
143 #define	je_sallocx		__sallocx
144 #define	je_dallocx		__dallocx
145 #define	je_sdallocx		__sdallocx
146 #define	je_nallocx		__nallocx
147 #define	je_mallctl		__mallctl
148 #define	je_mallctlnametomib	__mallctlnametomib
149 #define	je_mallctlbymib		__mallctlbymib
150 #define	je_malloc_stats_print	__malloc_stats_print
151 #define	open			_open
152 #define	read			_read
153 #define	write			_write
154 #define	close			_close
155 #define	pthread_join		_pthread_join
156 #define	pthread_once		_pthread_once
157 #define	pthread_self		_pthread_self
158 #define	pthread_equal		_pthread_equal
159 #define	pthread_mutex_lock	_pthread_mutex_lock
160 #define	pthread_mutex_trylock	_pthread_mutex_trylock
161 #define	pthread_mutex_unlock	_pthread_mutex_unlock
162 #define	pthread_cond_init	_pthread_cond_init
163 #define	pthread_cond_wait	_pthread_cond_wait
164 #define	pthread_cond_timedwait	_pthread_cond_timedwait
165 #define	pthread_cond_signal	_pthread_cond_signal
166 
167 #ifdef JEMALLOC_C_
168 /*
169  * Define 'weak' symbols so that an application can have its own versions
170  * of malloc, calloc, realloc, free, et al.
171  */
172 __weak_reference(__malloc, malloc);
173 __weak_reference(__calloc, calloc);
174 __weak_reference(__posix_memalign, posix_memalign);
175 __weak_reference(__aligned_alloc, aligned_alloc);
176 __weak_reference(__realloc, realloc);
177 __weak_reference(__free, free);
178 __weak_reference(__malloc_usable_size, malloc_usable_size);
179 __weak_reference(__mallocx, mallocx);
180 __weak_reference(__rallocx, rallocx);
181 __weak_reference(__xallocx, xallocx);
182 __weak_reference(__sallocx, sallocx);
183 __weak_reference(__dallocx, dallocx);
184 __weak_reference(__sdallocx, sdallocx);
185 __weak_reference(__nallocx, nallocx);
186 __weak_reference(__mallctl, mallctl);
187 __weak_reference(__mallctlnametomib, mallctlnametomib);
188 __weak_reference(__mallctlbymib, mallctlbymib);
189 __weak_reference(__malloc_stats_print, malloc_stats_print);
190 __weak_reference(je_allocm, weak_allocm);
191 __weak_reference(je_rallocm, weak_rallocm);
192 __weak_reference(je_sallocm, weak_sallocm);
193 __weak_reference(je_dallocm, weak_dallocm);
194 __weak_reference(je_nallocm, weak_nallocm);
195 __sym_compat(__allocm, je_allocm, FBSD_1.3);
196 __sym_compat(__rallocm, je_rallocm, FBSD_1.3);
197 __sym_compat(__sallocm, je_sallocm, FBSD_1.3);
198 __sym_compat(__dallocm, je_dallocm, FBSD_1.3);
199 __sym_compat(__nallocm, je_nallocm, FBSD_1.3);
200 __sym_compat(allocm, weak_allocm, FBSD_1.3);
201 __sym_compat(rallocm, weak_rallocm, FBSD_1.3);
202 __sym_compat(sallocm, weak_sallocm, FBSD_1.3);
203 __sym_compat(dallocm, weak_dallocm, FBSD_1.3);
204 __sym_compat(nallocm, weak_nallocm, FBSD_1.3);
205 #endif
206 
207 #endif
208