xref: /freebsd/contrib/jemalloc/FREEBSD-diffs (revision f8ca2db1f82e3a08c25740c7c3f99323794e6ca7)
1a4bd5210SJason Evansdiff --git a/doc/jemalloc.xml.in b/doc/jemalloc.xml.in
2*f8ca2db1SJason Evansindex abd5e6f..1d7491a 100644
3a4bd5210SJason Evans--- a/doc/jemalloc.xml.in
4a4bd5210SJason Evans+++ b/doc/jemalloc.xml.in
5a4bd5210SJason Evans@@ -51,12 +51,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*f8ca2db1SJason Evans@@ -2180,4 +2191,16 @@ 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>
45a4bd5210SJason Evans+  </refsect1>
46a4bd5210SJason Evans </refentry>
47a4bd5210SJason Evansdiff --git a/include/jemalloc/internal/jemalloc_internal.h.in b/include/jemalloc/internal/jemalloc_internal.h.in
48*f8ca2db1SJason Evansindex e46ac54..527449d 100644
49a4bd5210SJason Evans--- a/include/jemalloc/internal/jemalloc_internal.h.in
50a4bd5210SJason Evans+++ b/include/jemalloc/internal/jemalloc_internal.h.in
51c92c6224SJason Evans@@ -1,5 +1,8 @@
52c92c6224SJason Evans #ifndef JEMALLOC_INTERNAL_H
53c92c6224SJason Evans #define JEMALLOC_INTERNAL_H
54a4bd5210SJason Evans+#include "libc_private.h"
55a4bd5210SJason Evans+#include "namespace.h"
56a4bd5210SJason Evans+
57a4bd5210SJason Evans #include <math.h>
58e722f8f8SJason Evans #ifdef _WIN32
59e722f8f8SJason Evans #  include <windows.h>
60e722f8f8SJason Evans@@ -54,6 +57,9 @@ typedef intptr_t ssize_t;
61e722f8f8SJason Evans #endif
62e722f8f8SJason Evans #include <fcntl.h>
63a4bd5210SJason Evans
64a4bd5210SJason Evans+#include "un-namespace.h"
65a4bd5210SJason Evans+#include "libc_private.h"
66a4bd5210SJason Evans+
67a4bd5210SJason Evans #define	JEMALLOC_NO_DEMANGLE
68a4bd5210SJason Evans #include "../jemalloc@install_suffix@.h"
69a4bd5210SJason Evans
70edaa25bdSJason Evans@@ -95,13 +101,7 @@ static const bool config_fill =
71edaa25bdSJason Evans     false
72edaa25bdSJason Evans #endif
73edaa25bdSJason Evans     ;
74edaa25bdSJason Evans-static const bool config_lazy_lock =
75edaa25bdSJason Evans-#ifdef JEMALLOC_LAZY_LOCK
76edaa25bdSJason Evans-    true
77edaa25bdSJason Evans-#else
78edaa25bdSJason Evans-    false
79edaa25bdSJason Evans-#endif
80edaa25bdSJason Evans-    ;
81edaa25bdSJason Evans+static const bool config_lazy_lock = true;
82edaa25bdSJason Evans static const bool config_prof =
83edaa25bdSJason Evans #ifdef JEMALLOC_PROF
84edaa25bdSJason Evans     true
85a4bd5210SJason Evansdiff --git a/include/jemalloc/internal/mutex.h b/include/jemalloc/internal/mutex.h
86e722f8f8SJason Evansindex de44e14..564d604 100644
87a4bd5210SJason Evans--- a/include/jemalloc/internal/mutex.h
88a4bd5210SJason Evans+++ b/include/jemalloc/internal/mutex.h
89e722f8f8SJason Evans@@ -43,9 +43,6 @@ struct malloc_mutex_s {
90a4bd5210SJason Evans
91a4bd5210SJason Evans #ifdef JEMALLOC_LAZY_LOCK
92a4bd5210SJason Evans extern bool isthreaded;
93a4bd5210SJason Evans-#else
948ed34ab0SJason Evans-#  undef isthreaded /* Undo private_namespace.h definition. */
95a4bd5210SJason Evans-#  define isthreaded true
96a4bd5210SJason Evans #endif
97a4bd5210SJason Evans
98a4bd5210SJason Evans bool	malloc_mutex_init(malloc_mutex_t *mutex);
998ed34ab0SJason Evansdiff --git a/include/jemalloc/internal/private_namespace.h b/include/jemalloc/internal/private_namespace.h
100*f8ca2db1SJason Evansindex 65de316..366676b 100644
1018ed34ab0SJason Evans--- a/include/jemalloc/internal/private_namespace.h
1028ed34ab0SJason Evans+++ b/include/jemalloc/internal/private_namespace.h
10388ad2f8dSJason Evans@@ -216,7 +216,6 @@
1048ed34ab0SJason Evans #define	iralloc JEMALLOC_N(iralloc)
10582872ac0SJason Evans #define	irallocx JEMALLOC_N(irallocx)
1068ed34ab0SJason Evans #define	isalloc JEMALLOC_N(isalloc)
1078ed34ab0SJason Evans-#define	isthreaded JEMALLOC_N(isthreaded)
1088ed34ab0SJason Evans #define	ivsalloc JEMALLOC_N(ivsalloc)
1098ed34ab0SJason Evans #define	jemalloc_postfork_child JEMALLOC_N(jemalloc_postfork_child)
1108ed34ab0SJason Evans #define	jemalloc_postfork_parent JEMALLOC_N(jemalloc_postfork_parent)
111a4bd5210SJason Evansdiff --git a/include/jemalloc/jemalloc.h.in b/include/jemalloc/jemalloc.h.in
11282872ac0SJason Evansindex 31b1304..c3ef2f5 100644
113a4bd5210SJason Evans--- a/include/jemalloc/jemalloc.h.in
114a4bd5210SJason Evans+++ b/include/jemalloc/jemalloc.h.in
115a4bd5210SJason Evans@@ -15,6 +15,7 @@ extern "C" {
116a4bd5210SJason Evans #define	JEMALLOC_VERSION_GID "@jemalloc_version_gid@"
117a4bd5210SJason Evans
118a4bd5210SJason Evans #include "jemalloc_defs@install_suffix@.h"
119a4bd5210SJason Evans+#include "jemalloc_FreeBSD.h"
120a4bd5210SJason Evans
121a4bd5210SJason Evans #ifdef JEMALLOC_EXPERIMENTAL
122a4bd5210SJason Evans #define	ALLOCM_LG_ALIGN(la)	(la)
123a4bd5210SJason Evansdiff --git a/include/jemalloc/jemalloc_FreeBSD.h b/include/jemalloc/jemalloc_FreeBSD.h
124a4bd5210SJason Evansnew file mode 100644
125*f8ca2db1SJason Evansindex 0000000..e6c8407
126a4bd5210SJason Evans--- /dev/null
127a4bd5210SJason Evans+++ b/include/jemalloc/jemalloc_FreeBSD.h
128*f8ca2db1SJason Evans@@ -0,0 +1,117 @@
129a4bd5210SJason Evans+/*
130a4bd5210SJason Evans+ * Override settings that were generated in jemalloc_defs.h as necessary.
131a4bd5210SJason Evans+ */
132a4bd5210SJason Evans+
133a4bd5210SJason Evans+#undef JEMALLOC_OVERRIDE_VALLOC
134a4bd5210SJason Evans+
135a4bd5210SJason Evans+#ifndef MALLOC_PRODUCTION
136a4bd5210SJason Evans+#define	JEMALLOC_DEBUG
137a4bd5210SJason Evans+#endif
138a4bd5210SJason Evans+
139a4bd5210SJason Evans+/*
140a4bd5210SJason Evans+ * The following are architecture-dependent, so conditionally define them for
141a4bd5210SJason Evans+ * each supported architecture.
142a4bd5210SJason Evans+ */
143a4bd5210SJason Evans+#undef CPU_SPINWAIT
144a4bd5210SJason Evans+#undef JEMALLOC_TLS_MODEL
145a4bd5210SJason Evans+#undef STATIC_PAGE_SHIFT
146a4bd5210SJason Evans+#undef LG_SIZEOF_PTR
147a4bd5210SJason Evans+#undef LG_SIZEOF_INT
148a4bd5210SJason Evans+#undef LG_SIZEOF_LONG
149a4bd5210SJason Evans+#undef LG_SIZEOF_INTMAX_T
150a4bd5210SJason Evans+
151a4bd5210SJason Evans+#ifdef __i386__
152a4bd5210SJason Evans+#  define LG_SIZEOF_PTR		2
153a4bd5210SJason Evans+#  define CPU_SPINWAIT		__asm__ volatile("pause")
154a4bd5210SJason Evans+#  define JEMALLOC_TLS_MODEL	__attribute__((tls_model("initial-exec")))
155a4bd5210SJason Evans+#endif
156a4bd5210SJason Evans+#ifdef __ia64__
157a4bd5210SJason Evans+#  define LG_SIZEOF_PTR		3
158a4bd5210SJason Evans+#endif
159a4bd5210SJason Evans+#ifdef __sparc64__
160a4bd5210SJason Evans+#  define LG_SIZEOF_PTR		3
161a4bd5210SJason Evans+#  define JEMALLOC_TLS_MODEL	__attribute__((tls_model("initial-exec")))
162a4bd5210SJason Evans+#endif
163a4bd5210SJason Evans+#ifdef __amd64__
164a4bd5210SJason Evans+#  define LG_SIZEOF_PTR		3
165a4bd5210SJason Evans+#  define CPU_SPINWAIT		__asm__ volatile("pause")
166a4bd5210SJason Evans+#  define JEMALLOC_TLS_MODEL	__attribute__((tls_model("initial-exec")))
167a4bd5210SJason Evans+#endif
168a4bd5210SJason Evans+#ifdef __arm__
169a4bd5210SJason Evans+#  define LG_SIZEOF_PTR		2
170a4bd5210SJason Evans+#endif
171a4bd5210SJason Evans+#ifdef __mips__
172e722f8f8SJason Evans+#ifdef __mips_n64
173e722f8f8SJason Evans+#  define LG_SIZEOF_PTR		3
174e722f8f8SJason Evans+#else
175a4bd5210SJason Evans+#  define LG_SIZEOF_PTR		2
176a4bd5210SJason Evans+#endif
177e722f8f8SJason Evans+#endif
178a4bd5210SJason Evans+#ifdef __powerpc64__
179a4bd5210SJason Evans+#  define LG_SIZEOF_PTR		3
180a4bd5210SJason Evans+#elif defined(__powerpc__)
181a4bd5210SJason Evans+#  define LG_SIZEOF_PTR		2
182a4bd5210SJason Evans+#endif
183a4bd5210SJason Evans+
184a4bd5210SJason Evans+#ifndef JEMALLOC_TLS_MODEL
185a4bd5210SJason Evans+#  define JEMALLOC_TLS_MODEL	/* Default. */
186a4bd5210SJason Evans+#endif
187a4bd5210SJason Evans+
188a4bd5210SJason Evans+#define	STATIC_PAGE_SHIFT	PAGE_SHIFT
189a4bd5210SJason Evans+#define	LG_SIZEOF_INT		2
190a4bd5210SJason Evans+#define	LG_SIZEOF_LONG		LG_SIZEOF_PTR
191a4bd5210SJason Evans+#define	LG_SIZEOF_INTMAX_T	3
192a4bd5210SJason Evans+
193a4bd5210SJason Evans+/* Disable lazy-lock machinery, mangle isthreaded, and adjust its type. */
194a4bd5210SJason Evans+#undef JEMALLOC_LAZY_LOCK
195a4bd5210SJason Evans+extern int __isthreaded;
196a4bd5210SJason Evans+#define	isthreaded		((bool)__isthreaded)
197a4bd5210SJason Evans+
198a4bd5210SJason Evans+/* Mangle. */
199*f8ca2db1SJason Evans+#undef je_malloc
200*f8ca2db1SJason Evans+#undef je_calloc
201*f8ca2db1SJason Evans+#undef je_realloc
202*f8ca2db1SJason Evans+#undef je_free
203*f8ca2db1SJason Evans+#undef je_posix_memalign
204*f8ca2db1SJason Evans+#undef je_malloc_usable_size
205*f8ca2db1SJason Evans+#undef je_allocm
206*f8ca2db1SJason Evans+#undef je_rallocm
207*f8ca2db1SJason Evans+#undef je_sallocm
208*f8ca2db1SJason Evans+#undef je_dallocm
209*f8ca2db1SJason Evans+#undef je_nallocm
210*f8ca2db1SJason Evans+#define	je_malloc		__malloc
211*f8ca2db1SJason Evans+#define	je_calloc		__calloc
212*f8ca2db1SJason Evans+#define	je_realloc		__realloc
213*f8ca2db1SJason Evans+#define	je_free			__free
214*f8ca2db1SJason Evans+#define	je_posix_memalign	__posix_memalign
215*f8ca2db1SJason Evans+#define	je_malloc_usable_size	__malloc_usable_size
216*f8ca2db1SJason Evans+#define	je_allocm		__allocm
217*f8ca2db1SJason Evans+#define	je_rallocm		__rallocm
218*f8ca2db1SJason Evans+#define	je_sallocm		__sallocm
219*f8ca2db1SJason Evans+#define	je_dallocm		__dallocm
220*f8ca2db1SJason Evans+#define	je_nallocm		__nallocm
221a4bd5210SJason Evans+#define	open			_open
222a4bd5210SJason Evans+#define	read			_read
223a4bd5210SJason Evans+#define	write			_write
224a4bd5210SJason Evans+#define	close			_close
225a4bd5210SJason Evans+#define	pthread_mutex_lock	_pthread_mutex_lock
226a4bd5210SJason Evans+#define	pthread_mutex_unlock	_pthread_mutex_unlock
227*f8ca2db1SJason Evans+
228*f8ca2db1SJason Evans+#ifdef JEMALLOC_C_
229*f8ca2db1SJason Evans+/*
230*f8ca2db1SJason Evans+ * Define 'weak' symbols so that an application can have its own versions
231*f8ca2db1SJason Evans+ * of malloc, calloc, realloc, free, et al.
232*f8ca2db1SJason Evans+ */
233*f8ca2db1SJason Evans+__weak_reference(__malloc, malloc);
234*f8ca2db1SJason Evans+__weak_reference(__calloc, calloc);
235*f8ca2db1SJason Evans+__weak_reference(__realloc, realloc);
236*f8ca2db1SJason Evans+__weak_reference(__free, free);
237*f8ca2db1SJason Evans+__weak_reference(__posix_memalign, posix_memalign);
238*f8ca2db1SJason Evans+__weak_reference(__malloc_usable_size, malloc_usable_size);
239*f8ca2db1SJason Evans+__weak_reference(__allocm, allocm);
240*f8ca2db1SJason Evans+__weak_reference(__rallocm, rallocm);
241*f8ca2db1SJason Evans+__weak_reference(__sallocm, sallocm);
242*f8ca2db1SJason Evans+__weak_reference(__dallocm, dallocm);
243*f8ca2db1SJason Evans+__weak_reference(__nallocm, nallocm);
244*f8ca2db1SJason Evans+#endif
245*f8ca2db1SJason Evans+
246a4bd5210SJason Evansdiff --git a/src/jemalloc.c b/src/jemalloc.c
247*f8ca2db1SJason Evansindex bc350ed..352c98e 100644
248a4bd5210SJason Evans--- a/src/jemalloc.c
249a4bd5210SJason Evans+++ b/src/jemalloc.c
250e722f8f8SJason Evans@@ -8,6 +8,10 @@ malloc_tsd_data(, arenas, arena_t *, NULL)
251a4bd5210SJason Evans malloc_tsd_data(, thread_allocated, thread_allocated_t,
252a4bd5210SJason Evans     THREAD_ALLOCATED_INITIALIZER)
253a4bd5210SJason Evans
254e722f8f8SJason Evans+/* Work around <http://llvm.org/bugs/show_bug.cgi?id=12623>: */
255e722f8f8SJason Evans+const char	*__malloc_options_1_0 = NULL;
256a4bd5210SJason Evans+__sym_compat(_malloc_options, __malloc_options_1_0, FBSD_1.0);
257a4bd5210SJason Evans+
258a4bd5210SJason Evans /* Runtime configuration options. */
259e722f8f8SJason Evans const char	*je_malloc_conf;
26088ad2f8dSJason Evans bool	opt_abort =
261*f8ca2db1SJason Evans@@ -471,7 +475,8 @@ malloc_conf_init(void)
262a4bd5210SJason Evans #endif
263a4bd5210SJason Evans 			    ;
264a4bd5210SJason Evans
265a4bd5210SJason Evans-			if ((opts = getenv(envname)) != NULL) {
266a4bd5210SJason Evans+			if (issetugid() == 0 && (opts = getenv(envname)) !=
267a4bd5210SJason Evans+			    NULL) {
268a4bd5210SJason Evans 				/*
269a4bd5210SJason Evans 				 * Do nothing; opts is already initialized to
270a4bd5210SJason Evans 				 * the value of the MALLOC_CONF environment
271a4bd5210SJason Evansdiff --git a/src/mutex.c b/src/mutex.c
27282872ac0SJason Evansindex 55e18c2..6b6f438 100644
273a4bd5210SJason Evans--- a/src/mutex.c
274a4bd5210SJason Evans+++ b/src/mutex.c
275e722f8f8SJason Evans@@ -66,6 +66,17 @@ pthread_create(pthread_t *__restrict thread,
276a4bd5210SJason Evans #ifdef JEMALLOC_MUTEX_INIT_CB
27782872ac0SJason Evans JEMALLOC_EXPORT int	_pthread_mutex_init_calloc_cb(pthread_mutex_t *mutex,
278a4bd5210SJason Evans     void *(calloc_cb)(size_t, size_t));
279a4bd5210SJason Evans+
280a4bd5210SJason Evans+__weak_reference(_pthread_mutex_init_calloc_cb_stub,
281a4bd5210SJason Evans+    _pthread_mutex_init_calloc_cb);
282a4bd5210SJason Evans+
283a4bd5210SJason Evans+int
284a4bd5210SJason Evans+_pthread_mutex_init_calloc_cb_stub(pthread_mutex_t *mutex,
285a4bd5210SJason Evans+    void *(calloc_cb)(size_t, size_t))
286a4bd5210SJason Evans+{
287a4bd5210SJason Evans+
288a4bd5210SJason Evans+	return (0);
289a4bd5210SJason Evans+}
290a4bd5210SJason Evans #endif
291a4bd5210SJason Evans
292a4bd5210SJason Evans bool
293a4bd5210SJason Evansdiff --git a/src/util.c b/src/util.c
29482872ac0SJason Evansindex b3a0114..df1c5d5 100644
295a4bd5210SJason Evans--- a/src/util.c
296a4bd5210SJason Evans+++ b/src/util.c
297e722f8f8SJason Evans@@ -58,6 +58,22 @@ wrtmessage(void *cbopaque, const char *s)
298a4bd5210SJason Evans
299e722f8f8SJason Evans JEMALLOC_EXPORT void	(*je_malloc_message)(void *, const char *s);
300e722f8f8SJason Evans
301e722f8f8SJason Evans+JEMALLOC_ATTR(visibility("hidden"))
302a4bd5210SJason Evans+void
303a4bd5210SJason Evans+wrtmessage_1_0(const char *s1, const char *s2, const char *s3,
304a4bd5210SJason Evans+    const char *s4)
305a4bd5210SJason Evans+{
306a4bd5210SJason Evans+
307a4bd5210SJason Evans+	wrtmessage(NULL, s1);
308a4bd5210SJason Evans+	wrtmessage(NULL, s2);
309a4bd5210SJason Evans+	wrtmessage(NULL, s3);
310a4bd5210SJason Evans+	wrtmessage(NULL, s4);
311a4bd5210SJason Evans+}
312a4bd5210SJason Evans+
313a4bd5210SJason Evans+void	(*__malloc_message_1_0)(const char *s1, const char *s2, const char *s3,
314a4bd5210SJason Evans+    const char *s4) = wrtmessage_1_0;
315a4bd5210SJason Evans+__sym_compat(_malloc_message, __malloc_message_1_0, FBSD_1.0);
316a4bd5210SJason Evans+
317a4bd5210SJason Evans /*
318e722f8f8SJason Evans  * Wrapper around malloc_message() that avoids the need for
319e722f8f8SJason Evans  * je_malloc_message(...) throughout the code.
320