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