xref: /freebsd/contrib/jemalloc/FREEBSD-diffs (revision f921d10f4871e24cf637772c2ea9b83dc8e2cf93)
1a4bd5210SJason Evansdiff --git a/doc/jemalloc.xml.in b/doc/jemalloc.xml.in
2*f921d10fSJason Evansindex c7e2e87..2bd59f0 100644
3a4bd5210SJason Evans--- a/doc/jemalloc.xml.in
4a4bd5210SJason Evans+++ b/doc/jemalloc.xml.in
5*f921d10fSJason Evans@@ -57,12 +57,23 @@
6a4bd5210SJason Evans     <para>This manual describes jemalloc @jemalloc_version@.  More information
7a4bd5210SJason Evans     can be found at the <ulink
8a4bd5210SJason Evans     url="http://www.canonware.com/jemalloc/">jemalloc website</ulink>.</para>
9a4bd5210SJason Evans+
10a4bd5210SJason Evans+    <para>The following configuration options are enabled in libc's built-in
11a4bd5210SJason Evans+    jemalloc: <option>--enable-dss</option>,
12a4bd5210SJason Evans+    <option>--enable-experimental</option>, <option>--enable-fill</option>,
13a4bd5210SJason Evans+    <option>--enable-lazy-lock</option>, <option>--enable-munmap</option>,
14a4bd5210SJason Evans+    <option>--enable-stats</option>, <option>--enable-tcache</option>,
15a4bd5210SJason Evans+    <option>--enable-tls</option>, <option>--enable-utrace</option>, and
16a4bd5210SJason Evans+    <option>--enable-xmalloc</option>.  Additionally,
17a4bd5210SJason Evans+    <option>--enable-debug</option> is enabled in development versions of
18a4bd5210SJason Evans+    FreeBSD (controlled by the <constant>MALLOC_PRODUCTION</constant> make
19a4bd5210SJason Evans+    variable).</para>
20a4bd5210SJason Evans   </refsect1>
21a4bd5210SJason Evans   <refsynopsisdiv>
22a4bd5210SJason Evans     <title>SYNOPSIS</title>
23a4bd5210SJason Evans     <funcsynopsis>
24a4bd5210SJason Evans       <funcsynopsisinfo>#include &lt;<filename class="headerfile">stdlib.h</filename>&gt;
25a4bd5210SJason Evans-#include &lt;<filename class="headerfile">jemalloc/jemalloc.h</filename>&gt;</funcsynopsisinfo>
26a4bd5210SJason Evans+#include &lt;<filename class="headerfile">malloc_np.h</filename>&gt;</funcsynopsisinfo>
27a4bd5210SJason Evans       <refsect2>
28a4bd5210SJason Evans         <title>Standard API</title>
29a4bd5210SJason Evans         <funcprototype>
30*f921d10fSJason Evans@@ -2338,4 +2349,19 @@ malloc_conf = "lg_chunk:24";]]></programlisting></para>
31a4bd5210SJason Evans     <para>The <function>posix_memalign<parameter/></function> function conforms
32a4bd5210SJason Evans     to IEEE Std 1003.1-2001 (&ldquo;POSIX.1&rdquo;).</para>
33a4bd5210SJason Evans   </refsect1>
34a4bd5210SJason Evans+  <refsect1 id="history">
35a4bd5210SJason Evans+    <title>HISTORY</title>
36a4bd5210SJason Evans+    <para>The <function>malloc_usable_size<parameter/></function> and
37a4bd5210SJason Evans+    <function>posix_memalign<parameter/></function> functions first appeared in
38a4bd5210SJason Evans+    FreeBSD 7.0.</para>
39a4bd5210SJason Evans+
40a4bd5210SJason Evans+    <para>The <function>aligned_alloc<parameter/></function>,
41a4bd5210SJason Evans+    <function>malloc_stats_print<parameter/></function>,
42a4bd5210SJason Evans+    <function>mallctl*<parameter/></function>, and
43a4bd5210SJason Evans+    <function>*allocm<parameter/></function> functions first appeared in
44a4bd5210SJason Evans+    FreeBSD 10.0.</para>
45*f921d10fSJason Evans+
46*f921d10fSJason Evans+    <para>The <function>*allocx<parameter/></function> functions first appeared
47*f921d10fSJason Evans+    in FreeBSD 11.0.</para>
48a4bd5210SJason Evans+  </refsect1>
49a4bd5210SJason Evans </refentry>
50a4bd5210SJason Evansdiff --git a/include/jemalloc/internal/jemalloc_internal.h.in b/include/jemalloc/internal/jemalloc_internal.h.in
51*f921d10fSJason Evansindex d24a1fe..d101c3d 100644
52a4bd5210SJason Evans--- a/include/jemalloc/internal/jemalloc_internal.h.in
53a4bd5210SJason Evans+++ b/include/jemalloc/internal/jemalloc_internal.h.in
54c92c6224SJason Evans@@ -1,5 +1,8 @@
55c92c6224SJason Evans #ifndef JEMALLOC_INTERNAL_H
56c92c6224SJason Evans #define	JEMALLOC_INTERNAL_H
57a4bd5210SJason Evans+#include "libc_private.h"
58a4bd5210SJason Evans+#include "namespace.h"
59a4bd5210SJason Evans+
60a4bd5210SJason Evans #include <math.h>
61e722f8f8SJason Evans #ifdef _WIN32
62e722f8f8SJason Evans #  include <windows.h>
63*f921d10fSJason Evans@@ -65,6 +68,9 @@ typedef intptr_t ssize_t;
64*f921d10fSJason Evans #include <valgrind/memcheck.h>
65e722f8f8SJason Evans #endif
66a4bd5210SJason Evans
67a4bd5210SJason Evans+#include "un-namespace.h"
68a4bd5210SJason Evans+#include "libc_private.h"
69a4bd5210SJason Evans+
70a4bd5210SJason Evans #define	JEMALLOC_NO_DEMANGLE
71*f921d10fSJason Evans #ifdef JEMALLOC_JET
72*f921d10fSJason Evans #  define JEMALLOC_N(n) jet_##n
73*f921d10fSJason Evans@@ -99,13 +105,7 @@ static const bool config_fill =
74edaa25bdSJason Evans     false
75edaa25bdSJason Evans #endif
76edaa25bdSJason Evans     ;
77edaa25bdSJason Evans-static const bool config_lazy_lock =
78edaa25bdSJason Evans-#ifdef JEMALLOC_LAZY_LOCK
79edaa25bdSJason Evans-    true
80edaa25bdSJason Evans-#else
81edaa25bdSJason Evans-    false
82edaa25bdSJason Evans-#endif
83edaa25bdSJason Evans-    ;
84edaa25bdSJason Evans+static const bool config_lazy_lock = true;
85edaa25bdSJason Evans static const bool config_prof =
86edaa25bdSJason Evans #ifdef JEMALLOC_PROF
87edaa25bdSJason Evans     true
88a4bd5210SJason Evansdiff --git a/include/jemalloc/internal/mutex.h b/include/jemalloc/internal/mutex.h
89e722f8f8SJason Evansindex de44e14..564d604 100644
90a4bd5210SJason Evans--- a/include/jemalloc/internal/mutex.h
91a4bd5210SJason Evans+++ b/include/jemalloc/internal/mutex.h
92e722f8f8SJason Evans@@ -43,9 +43,6 @@ struct malloc_mutex_s {
93a4bd5210SJason Evans
94a4bd5210SJason Evans #ifdef JEMALLOC_LAZY_LOCK
95a4bd5210SJason Evans extern bool isthreaded;
96a4bd5210SJason Evans-#else
978ed34ab0SJason Evans-#  undef isthreaded /* Undo private_namespace.h definition. */
98a4bd5210SJason Evans-#  define isthreaded true
99a4bd5210SJason Evans #endif
100a4bd5210SJason Evans
101a4bd5210SJason Evans bool	malloc_mutex_init(malloc_mutex_t *mutex);
102*f921d10fSJason Evansdiff --git a/include/jemalloc/internal/private_symbols.txt b/include/jemalloc/internal/private_symbols.txt
103*f921d10fSJason Evansindex 1e64ed5..29ddba3 100644
104*f921d10fSJason Evans--- a/include/jemalloc/internal/private_symbols.txt
105*f921d10fSJason Evans+++ b/include/jemalloc/internal/private_symbols.txt
106*f921d10fSJason Evans@@ -225,7 +225,6 @@ iralloc
107*f921d10fSJason Evans iralloct
108*f921d10fSJason Evans iralloct_realign
109*f921d10fSJason Evans isalloc
110*f921d10fSJason Evans-isthreaded
111*f921d10fSJason Evans ivsalloc
112*f921d10fSJason Evans ixalloc
113*f921d10fSJason Evans jemalloc_postfork_child
114a4bd5210SJason Evansdiff --git a/include/jemalloc/jemalloc_FreeBSD.h b/include/jemalloc/jemalloc_FreeBSD.h
115a4bd5210SJason Evansnew file mode 100644
116*f921d10fSJason Evansindex 0000000..94554bc
117a4bd5210SJason Evans--- /dev/null
118a4bd5210SJason Evans+++ b/include/jemalloc/jemalloc_FreeBSD.h
119*f921d10fSJason Evans@@ -0,0 +1,134 @@
120a4bd5210SJason Evans+/*
121a4bd5210SJason Evans+ * Override settings that were generated in jemalloc_defs.h as necessary.
122a4bd5210SJason Evans+ */
123a4bd5210SJason Evans+
124a4bd5210SJason Evans+#undef JEMALLOC_OVERRIDE_VALLOC
125a4bd5210SJason Evans+
126a4bd5210SJason Evans+#ifndef MALLOC_PRODUCTION
127a4bd5210SJason Evans+#define	JEMALLOC_DEBUG
128a4bd5210SJason Evans+#endif
129a4bd5210SJason Evans+
130a4bd5210SJason Evans+/*
131a4bd5210SJason Evans+ * The following are architecture-dependent, so conditionally define them for
132a4bd5210SJason Evans+ * each supported architecture.
133a4bd5210SJason Evans+ */
134a4bd5210SJason Evans+#undef CPU_SPINWAIT
135a4bd5210SJason Evans+#undef JEMALLOC_TLS_MODEL
136a4bd5210SJason Evans+#undef STATIC_PAGE_SHIFT
137a4bd5210SJason Evans+#undef LG_SIZEOF_PTR
138a4bd5210SJason Evans+#undef LG_SIZEOF_INT
139a4bd5210SJason Evans+#undef LG_SIZEOF_LONG
140a4bd5210SJason Evans+#undef LG_SIZEOF_INTMAX_T
141a4bd5210SJason Evans+
142a4bd5210SJason Evans+#ifdef __i386__
143a4bd5210SJason Evans+#  define LG_SIZEOF_PTR		2
144a4bd5210SJason Evans+#  define CPU_SPINWAIT		__asm__ volatile("pause")
145a4bd5210SJason Evans+#  define JEMALLOC_TLS_MODEL	__attribute__((tls_model("initial-exec")))
146a4bd5210SJason Evans+#endif
147a4bd5210SJason Evans+#ifdef __ia64__
148a4bd5210SJason Evans+#  define LG_SIZEOF_PTR		3
149a4bd5210SJason Evans+#endif
150a4bd5210SJason Evans+#ifdef __sparc64__
151a4bd5210SJason Evans+#  define LG_SIZEOF_PTR		3
152a4bd5210SJason Evans+#  define JEMALLOC_TLS_MODEL	__attribute__((tls_model("initial-exec")))
153a4bd5210SJason Evans+#endif
154a4bd5210SJason Evans+#ifdef __amd64__
155a4bd5210SJason Evans+#  define LG_SIZEOF_PTR		3
156a4bd5210SJason Evans+#  define CPU_SPINWAIT		__asm__ volatile("pause")
157a4bd5210SJason Evans+#  define JEMALLOC_TLS_MODEL	__attribute__((tls_model("initial-exec")))
158a4bd5210SJason Evans+#endif
159a4bd5210SJason Evans+#ifdef __arm__
160a4bd5210SJason Evans+#  define LG_SIZEOF_PTR		2
161a4bd5210SJason Evans+#endif
162a4bd5210SJason Evans+#ifdef __mips__
163e722f8f8SJason Evans+#ifdef __mips_n64
164e722f8f8SJason Evans+#  define LG_SIZEOF_PTR		3
165e722f8f8SJason Evans+#else
166a4bd5210SJason Evans+#  define LG_SIZEOF_PTR		2
167a4bd5210SJason Evans+#endif
168e722f8f8SJason Evans+#endif
169a4bd5210SJason Evans+#ifdef __powerpc64__
170a4bd5210SJason Evans+#  define LG_SIZEOF_PTR		3
171a4bd5210SJason Evans+#elif defined(__powerpc__)
172a4bd5210SJason Evans+#  define LG_SIZEOF_PTR		2
173a4bd5210SJason Evans+#endif
174a4bd5210SJason Evans+
175a4bd5210SJason Evans+#ifndef JEMALLOC_TLS_MODEL
176a4bd5210SJason Evans+#  define JEMALLOC_TLS_MODEL	/* Default. */
177a4bd5210SJason Evans+#endif
178a4bd5210SJason Evans+
179a4bd5210SJason Evans+#define	STATIC_PAGE_SHIFT	PAGE_SHIFT
180a4bd5210SJason Evans+#define	LG_SIZEOF_INT		2
181a4bd5210SJason Evans+#define	LG_SIZEOF_LONG		LG_SIZEOF_PTR
182a4bd5210SJason Evans+#define	LG_SIZEOF_INTMAX_T	3
183a4bd5210SJason Evans+
184a4bd5210SJason Evans+/* Disable lazy-lock machinery, mangle isthreaded, and adjust its type. */
185a4bd5210SJason Evans+#undef JEMALLOC_LAZY_LOCK
186a4bd5210SJason Evans+extern int __isthreaded;
187a4bd5210SJason Evans+#define	isthreaded		((bool)__isthreaded)
188a4bd5210SJason Evans+
189a4bd5210SJason Evans+/* Mangle. */
190f8ca2db1SJason Evans+#undef je_malloc
191f8ca2db1SJason Evans+#undef je_calloc
192f8ca2db1SJason Evans+#undef je_realloc
193f8ca2db1SJason Evans+#undef je_free
194f8ca2db1SJason Evans+#undef je_posix_memalign
195f8ca2db1SJason Evans+#undef je_malloc_usable_size
196*f921d10fSJason Evans+#undef je_mallocx
197*f921d10fSJason Evans+#undef je_rallocx
198*f921d10fSJason Evans+#undef je_xallocx
199*f921d10fSJason Evans+#undef je_sallocx
200*f921d10fSJason Evans+#undef je_dallocx
201*f921d10fSJason Evans+#undef je_nallocx
202f8ca2db1SJason Evans+#undef je_allocm
203f8ca2db1SJason Evans+#undef je_rallocm
204f8ca2db1SJason Evans+#undef je_sallocm
205f8ca2db1SJason Evans+#undef je_dallocm
206f8ca2db1SJason Evans+#undef je_nallocm
207f8ca2db1SJason Evans+#define	je_malloc		__malloc
208f8ca2db1SJason Evans+#define	je_calloc		__calloc
209f8ca2db1SJason Evans+#define	je_realloc		__realloc
210f8ca2db1SJason Evans+#define	je_free			__free
211f8ca2db1SJason Evans+#define	je_posix_memalign	__posix_memalign
212f8ca2db1SJason Evans+#define	je_malloc_usable_size	__malloc_usable_size
213*f921d10fSJason Evans+#define	je_mallocx		__mallocx
214*f921d10fSJason Evans+#define	je_rallocx		__rallocx
215*f921d10fSJason Evans+#define	je_xallocx		__xallocx
216*f921d10fSJason Evans+#define	je_sallocx		__sallocx
217*f921d10fSJason Evans+#define	je_dallocx		__dallocx
218*f921d10fSJason Evans+#define	je_nallocx		__nallocx
219f8ca2db1SJason Evans+#define	je_allocm		__allocm
220f8ca2db1SJason Evans+#define	je_rallocm		__rallocm
221f8ca2db1SJason Evans+#define	je_sallocm		__sallocm
222f8ca2db1SJason Evans+#define	je_dallocm		__dallocm
223f8ca2db1SJason Evans+#define	je_nallocm		__nallocm
224a4bd5210SJason Evans+#define	open			_open
225a4bd5210SJason Evans+#define	read			_read
226a4bd5210SJason Evans+#define	write			_write
227a4bd5210SJason Evans+#define	close			_close
228a4bd5210SJason Evans+#define	pthread_mutex_lock	_pthread_mutex_lock
229a4bd5210SJason Evans+#define	pthread_mutex_unlock	_pthread_mutex_unlock
230f8ca2db1SJason Evans+
231f8ca2db1SJason Evans+#ifdef JEMALLOC_C_
232f8ca2db1SJason Evans+/*
233f8ca2db1SJason Evans+ * Define 'weak' symbols so that an application can have its own versions
234f8ca2db1SJason Evans+ * of malloc, calloc, realloc, free, et al.
235f8ca2db1SJason Evans+ */
236f8ca2db1SJason Evans+__weak_reference(__malloc, malloc);
237f8ca2db1SJason Evans+__weak_reference(__calloc, calloc);
238f8ca2db1SJason Evans+__weak_reference(__realloc, realloc);
239f8ca2db1SJason Evans+__weak_reference(__free, free);
240f8ca2db1SJason Evans+__weak_reference(__posix_memalign, posix_memalign);
241f8ca2db1SJason Evans+__weak_reference(__malloc_usable_size, malloc_usable_size);
242*f921d10fSJason Evans+__weak_reference(__mallocx, mallocx);
243*f921d10fSJason Evans+__weak_reference(__rallocx, rallocx);
244*f921d10fSJason Evans+__weak_reference(__xallocx, xallocx);
245*f921d10fSJason Evans+__weak_reference(__sallocx, sallocx);
246*f921d10fSJason Evans+__weak_reference(__dallocx, dallocx);
247*f921d10fSJason Evans+__weak_reference(__nallocx, nallocx);
248f8ca2db1SJason Evans+__weak_reference(__allocm, allocm);
249f8ca2db1SJason Evans+__weak_reference(__rallocm, rallocm);
250f8ca2db1SJason Evans+__weak_reference(__sallocm, sallocm);
251f8ca2db1SJason Evans+__weak_reference(__dallocm, dallocm);
252f8ca2db1SJason Evans+__weak_reference(__nallocm, nallocm);
253f8ca2db1SJason Evans+#endif
254*f921d10fSJason Evansdiff --git a/include/jemalloc/jemalloc_rename.sh b/include/jemalloc/jemalloc_rename.sh
255*f921d10fSJason Evansindex f943891..47d032c 100755
256*f921d10fSJason Evans--- a/include/jemalloc/jemalloc_rename.sh
257*f921d10fSJason Evans+++ b/include/jemalloc/jemalloc_rename.sh
258*f921d10fSJason Evans@@ -19,4 +19,6 @@ done
259*f921d10fSJason Evans
260*f921d10fSJason Evans cat <<EOF
261*f921d10fSJason Evans #endif
262f8ca2db1SJason Evans+
263*f921d10fSJason Evans+#include "jemalloc_FreeBSD.h"
264*f921d10fSJason Evans EOF
265a4bd5210SJason Evansdiff --git a/src/jemalloc.c b/src/jemalloc.c
266*f921d10fSJason Evansindex 563d99f..42f97b4 100644
267a4bd5210SJason Evans--- a/src/jemalloc.c
268a4bd5210SJason Evans+++ b/src/jemalloc.c
269e722f8f8SJason Evans@@ -8,6 +8,10 @@ malloc_tsd_data(, arenas, arena_t *, NULL)
270a4bd5210SJason Evans malloc_tsd_data(, thread_allocated, thread_allocated_t,
271a4bd5210SJason Evans     THREAD_ALLOCATED_INITIALIZER)
272a4bd5210SJason Evans
273e722f8f8SJason Evans+/* Work around <http://llvm.org/bugs/show_bug.cgi?id=12623>: */
274e722f8f8SJason Evans+const char	*__malloc_options_1_0 = NULL;
275a4bd5210SJason Evans+__sym_compat(_malloc_options, __malloc_options_1_0, FBSD_1.0);
276a4bd5210SJason Evans+
277a4bd5210SJason Evans /* Runtime configuration options. */
278e722f8f8SJason Evans const char	*je_malloc_conf;
27988ad2f8dSJason Evans bool	opt_abort =
280*f921d10fSJason Evans@@ -457,7 +461,8 @@ malloc_conf_init(void)
281a4bd5210SJason Evans #endif
282a4bd5210SJason Evans 			    ;
283a4bd5210SJason Evans
284a4bd5210SJason Evans-			if ((opts = getenv(envname)) != NULL) {
285a4bd5210SJason Evans+			if (issetugid() == 0 && (opts = getenv(envname)) !=
286a4bd5210SJason Evans+			    NULL) {
287a4bd5210SJason Evans 				/*
288a4bd5210SJason Evans 				 * Do nothing; opts is already initialized to
289a4bd5210SJason Evans 				 * the value of the MALLOC_CONF environment
290a4bd5210SJason Evansdiff --git a/src/mutex.c b/src/mutex.c
291*f921d10fSJason Evansindex 788eca3..6f5954e 100644
292a4bd5210SJason Evans--- a/src/mutex.c
293a4bd5210SJason Evans+++ b/src/mutex.c
294e722f8f8SJason Evans@@ -66,6 +66,17 @@ pthread_create(pthread_t *__restrict thread,
295a4bd5210SJason Evans #ifdef JEMALLOC_MUTEX_INIT_CB
29682872ac0SJason Evans JEMALLOC_EXPORT int	_pthread_mutex_init_calloc_cb(pthread_mutex_t *mutex,
297a4bd5210SJason Evans     void *(calloc_cb)(size_t, size_t));
298a4bd5210SJason Evans+
299a4bd5210SJason Evans+__weak_reference(_pthread_mutex_init_calloc_cb_stub,
300a4bd5210SJason Evans+    _pthread_mutex_init_calloc_cb);
301a4bd5210SJason Evans+
302a4bd5210SJason Evans+int
303a4bd5210SJason Evans+_pthread_mutex_init_calloc_cb_stub(pthread_mutex_t *mutex,
304a4bd5210SJason Evans+    void *(calloc_cb)(size_t, size_t))
305a4bd5210SJason Evans+{
306a4bd5210SJason Evans+
307a4bd5210SJason Evans+	return (0);
308a4bd5210SJason Evans+}
309a4bd5210SJason Evans #endif
310a4bd5210SJason Evans
311a4bd5210SJason Evans bool
312a4bd5210SJason Evansdiff --git a/src/util.c b/src/util.c
313*f921d10fSJason Evansindex 93a19fd..70b3e45 100644
314a4bd5210SJason Evans--- a/src/util.c
315a4bd5210SJason Evans+++ b/src/util.c
316e722f8f8SJason Evans@@ -58,6 +58,22 @@ wrtmessage(void *cbopaque, const char *s)
317a4bd5210SJason Evans
318e722f8f8SJason Evans JEMALLOC_EXPORT void	(*je_malloc_message)(void *, const char *s);
319e722f8f8SJason Evans
320e722f8f8SJason Evans+JEMALLOC_ATTR(visibility("hidden"))
321a4bd5210SJason Evans+void
322a4bd5210SJason Evans+wrtmessage_1_0(const char *s1, const char *s2, const char *s3,
323a4bd5210SJason Evans+    const char *s4)
324a4bd5210SJason Evans+{
325a4bd5210SJason Evans+
326a4bd5210SJason Evans+	wrtmessage(NULL, s1);
327a4bd5210SJason Evans+	wrtmessage(NULL, s2);
328a4bd5210SJason Evans+	wrtmessage(NULL, s3);
329a4bd5210SJason Evans+	wrtmessage(NULL, s4);
330a4bd5210SJason Evans+}
331a4bd5210SJason Evans+
332a4bd5210SJason Evans+void	(*__malloc_message_1_0)(const char *s1, const char *s2, const char *s3,
333a4bd5210SJason Evans+    const char *s4) = wrtmessage_1_0;
334a4bd5210SJason Evans+__sym_compat(_malloc_message, __malloc_message_1_0, FBSD_1.0);
335a4bd5210SJason Evans+
336a4bd5210SJason Evans /*
337e722f8f8SJason Evans  * Wrapper around malloc_message() that avoids the need for
338e722f8f8SJason Evans  * je_malloc_message(...) throughout the code.
339