1 diff --git a/doc/jemalloc.xml.in b/doc/jemalloc.xml.in
2 index c7e2e87..2bd59f0 100644
3 --- a/doc/jemalloc.xml.in
4 +++ b/doc/jemalloc.xml.in
6 <para>This manual describes jemalloc @jemalloc_version@. More information
7 can be found at the <ulink
8 url="http://www.canonware.com/jemalloc/">jemalloc website</ulink>.</para>
10 + <para>The following configuration options are enabled in libc's built-in
11 + jemalloc: <option>--enable-dss</option>,
12 + <option>--enable-experimental</option>, <option>--enable-fill</option>,
13 + <option>--enable-lazy-lock</option>, <option>--enable-munmap</option>,
14 + <option>--enable-stats</option>, <option>--enable-tcache</option>,
15 + <option>--enable-tls</option>, <option>--enable-utrace</option>, and
16 + <option>--enable-xmalloc</option>. Additionally,
17 + <option>--enable-debug</option> is enabled in development versions of
18 + FreeBSD (controlled by the <constant>MALLOC_PRODUCTION</constant> make
22 <title>SYNOPSIS</title>
24 <funcsynopsisinfo>#include <<filename class="headerfile">stdlib.h</filename>>
25 -#include <<filename class="headerfile">jemalloc/jemalloc.h</filename>></funcsynopsisinfo>
26 +#include <<filename class="headerfile">malloc_np.h</filename>></funcsynopsisinfo>
28 <title>Standard API</title>
30 @@ -2338,4 +2349,19 @@ malloc_conf = "lg_chunk:24";]]></programlisting></para>
31 <para>The <function>posix_memalign<parameter/></function> function conforms
32 to IEEE Std 1003.1-2001 (“POSIX.1”).</para>
34 + <refsect1 id="history">
35 + <title>HISTORY</title>
36 + <para>The <function>malloc_usable_size<parameter/></function> and
37 + <function>posix_memalign<parameter/></function> functions first appeared in
40 + <para>The <function>aligned_alloc<parameter/></function>,
41 + <function>malloc_stats_print<parameter/></function>,
42 + <function>mallctl*<parameter/></function>, and
43 + <function>*allocm<parameter/></function> functions first appeared in
44 + FreeBSD 10.0.</para>
46 + <para>The <function>*allocx<parameter/></function> functions first appeared
47 + in FreeBSD 11.0.</para>
50 diff --git a/include/jemalloc/internal/jemalloc_internal.h.in b/include/jemalloc/internal/jemalloc_internal.h.in
51 index d24a1fe..d101c3d 100644
52 --- a/include/jemalloc/internal/jemalloc_internal.h.in
53 +++ b/include/jemalloc/internal/jemalloc_internal.h.in
55 #ifndef JEMALLOC_INTERNAL_H
56 #define JEMALLOC_INTERNAL_H
57 +#include "libc_private.h"
58 +#include "namespace.h"
63 @@ -65,6 +68,9 @@ typedef intptr_t ssize_t;
64 #include <valgrind/memcheck.h>
67 +#include "un-namespace.h"
68 +#include "libc_private.h"
70 #define JEMALLOC_NO_DEMANGLE
72 # define JEMALLOC_N(n) jet_##n
73 @@ -99,13 +105,7 @@ static const bool config_fill =
77 -static const bool config_lazy_lock =
78 -#ifdef JEMALLOC_LAZY_LOCK
84 +static const bool config_lazy_lock = true;
85 static const bool config_prof =
88 diff --git a/include/jemalloc/internal/mutex.h b/include/jemalloc/internal/mutex.h
89 index de44e14..564d604 100644
90 --- a/include/jemalloc/internal/mutex.h
91 +++ b/include/jemalloc/internal/mutex.h
92 @@ -43,9 +43,6 @@ struct malloc_mutex_s {
94 #ifdef JEMALLOC_LAZY_LOCK
95 extern bool isthreaded;
97 -# undef isthreaded /* Undo private_namespace.h definition. */
98 -# define isthreaded true
101 bool malloc_mutex_init(malloc_mutex_t *mutex);
102 diff --git a/include/jemalloc/internal/private_symbols.txt b/include/jemalloc/internal/private_symbols.txt
103 index 1e64ed5..29ddba3 100644
104 --- a/include/jemalloc/internal/private_symbols.txt
105 +++ b/include/jemalloc/internal/private_symbols.txt
106 @@ -225,7 +225,6 @@ iralloc
113 jemalloc_postfork_child
114 diff --git a/include/jemalloc/jemalloc_FreeBSD.h b/include/jemalloc/jemalloc_FreeBSD.h
116 index 0000000..94554bc
118 +++ b/include/jemalloc/jemalloc_FreeBSD.h
121 + * Override settings that were generated in jemalloc_defs.h as necessary.
124 +#undef JEMALLOC_OVERRIDE_VALLOC
126 +#ifndef MALLOC_PRODUCTION
127 +#define JEMALLOC_DEBUG
131 + * The following are architecture-dependent, so conditionally define them for
132 + * each supported architecture.
135 +#undef JEMALLOC_TLS_MODEL
136 +#undef STATIC_PAGE_SHIFT
137 +#undef LG_SIZEOF_PTR
138 +#undef LG_SIZEOF_INT
139 +#undef LG_SIZEOF_LONG
140 +#undef LG_SIZEOF_INTMAX_T
143 +# define LG_SIZEOF_PTR 2
144 +# define CPU_SPINWAIT __asm__ volatile("pause")
145 +# define JEMALLOC_TLS_MODEL __attribute__((tls_model("initial-exec")))
148 +# define LG_SIZEOF_PTR 3
151 +# define LG_SIZEOF_PTR 3
152 +# define JEMALLOC_TLS_MODEL __attribute__((tls_model("initial-exec")))
155 +# define LG_SIZEOF_PTR 3
156 +# define CPU_SPINWAIT __asm__ volatile("pause")
157 +# define JEMALLOC_TLS_MODEL __attribute__((tls_model("initial-exec")))
160 +# define LG_SIZEOF_PTR 2
164 +# define LG_SIZEOF_PTR 3
166 +# define LG_SIZEOF_PTR 2
169 +#ifdef __powerpc64__
170 +# define LG_SIZEOF_PTR 3
171 +#elif defined(__powerpc__)
172 +# define LG_SIZEOF_PTR 2
175 +#ifndef JEMALLOC_TLS_MODEL
176 +# define JEMALLOC_TLS_MODEL /* Default. */
179 +#define STATIC_PAGE_SHIFT PAGE_SHIFT
180 +#define LG_SIZEOF_INT 2
181 +#define LG_SIZEOF_LONG LG_SIZEOF_PTR
182 +#define LG_SIZEOF_INTMAX_T 3
184 +/* Disable lazy-lock machinery, mangle isthreaded, and adjust its type. */
185 +#undef JEMALLOC_LAZY_LOCK
186 +extern int __isthreaded;
187 +#define isthreaded ((bool)__isthreaded)
194 +#undef je_posix_memalign
195 +#undef je_malloc_usable_size
207 +#define je_malloc __malloc
208 +#define je_calloc __calloc
209 +#define je_realloc __realloc
210 +#define je_free __free
211 +#define je_posix_memalign __posix_memalign
212 +#define je_malloc_usable_size __malloc_usable_size
213 +#define je_mallocx __mallocx
214 +#define je_rallocx __rallocx
215 +#define je_xallocx __xallocx
216 +#define je_sallocx __sallocx
217 +#define je_dallocx __dallocx
218 +#define je_nallocx __nallocx
219 +#define je_allocm __allocm
220 +#define je_rallocm __rallocm
221 +#define je_sallocm __sallocm
222 +#define je_dallocm __dallocm
223 +#define je_nallocm __nallocm
226 +#define write _write
227 +#define close _close
228 +#define pthread_mutex_lock _pthread_mutex_lock
229 +#define pthread_mutex_unlock _pthread_mutex_unlock
233 + * Define 'weak' symbols so that an application can have its own versions
234 + * of malloc, calloc, realloc, free, et al.
236 +__weak_reference(__malloc, malloc);
237 +__weak_reference(__calloc, calloc);
238 +__weak_reference(__realloc, realloc);
239 +__weak_reference(__free, free);
240 +__weak_reference(__posix_memalign, posix_memalign);
241 +__weak_reference(__malloc_usable_size, malloc_usable_size);
242 +__weak_reference(__mallocx, mallocx);
243 +__weak_reference(__rallocx, rallocx);
244 +__weak_reference(__xallocx, xallocx);
245 +__weak_reference(__sallocx, sallocx);
246 +__weak_reference(__dallocx, dallocx);
247 +__weak_reference(__nallocx, nallocx);
248 +__weak_reference(__allocm, allocm);
249 +__weak_reference(__rallocm, rallocm);
250 +__weak_reference(__sallocm, sallocm);
251 +__weak_reference(__dallocm, dallocm);
252 +__weak_reference(__nallocm, nallocm);
254 diff --git a/include/jemalloc/jemalloc_rename.sh b/include/jemalloc/jemalloc_rename.sh
255 index f943891..47d032c 100755
256 --- a/include/jemalloc/jemalloc_rename.sh
257 +++ b/include/jemalloc/jemalloc_rename.sh
258 @@ -19,4 +19,6 @@ done
263 +#include "jemalloc_FreeBSD.h"
265 diff --git a/src/jemalloc.c b/src/jemalloc.c
266 index 563d99f..42f97b4 100644
269 @@ -8,6 +8,10 @@ malloc_tsd_data(, arenas, arena_t *, NULL)
270 malloc_tsd_data(, thread_allocated, thread_allocated_t,
271 THREAD_ALLOCATED_INITIALIZER)
273 +/* Work around <http://llvm.org/bugs/show_bug.cgi?id=12623>: */
274 +const char *__malloc_options_1_0 = NULL;
275 +__sym_compat(_malloc_options, __malloc_options_1_0, FBSD_1.0);
277 /* Runtime configuration options. */
278 const char *je_malloc_conf;
280 @@ -457,7 +461,8 @@ malloc_conf_init(void)
284 - if ((opts = getenv(envname)) != NULL) {
285 + if (issetugid() == 0 && (opts = getenv(envname)) !=
288 * Do nothing; opts is already initialized to
289 * the value of the MALLOC_CONF environment
290 diff --git a/src/mutex.c b/src/mutex.c
291 index 788eca3..6f5954e 100644
294 @@ -66,6 +66,17 @@ pthread_create(pthread_t *__restrict thread,
295 #ifdef JEMALLOC_MUTEX_INIT_CB
296 JEMALLOC_EXPORT int _pthread_mutex_init_calloc_cb(pthread_mutex_t *mutex,
297 void *(calloc_cb)(size_t, size_t));
299 +__weak_reference(_pthread_mutex_init_calloc_cb_stub,
300 + _pthread_mutex_init_calloc_cb);
303 +_pthread_mutex_init_calloc_cb_stub(pthread_mutex_t *mutex,
304 + void *(calloc_cb)(size_t, size_t))
312 diff --git a/src/util.c b/src/util.c
313 index 93a19fd..70b3e45 100644
316 @@ -58,6 +58,22 @@ wrtmessage(void *cbopaque, const char *s)
318 JEMALLOC_EXPORT void (*je_malloc_message)(void *, const char *s);
320 +JEMALLOC_ATTR(visibility("hidden"))
322 +wrtmessage_1_0(const char *s1, const char *s2, const char *s3,
326 + wrtmessage(NULL, s1);
327 + wrtmessage(NULL, s2);
328 + wrtmessage(NULL, s3);
329 + wrtmessage(NULL, s4);
332 +void (*__malloc_message_1_0)(const char *s1, const char *s2, const char *s3,
333 + const char *s4) = wrtmessage_1_0;
334 +__sym_compat(_malloc_message, __malloc_message_1_0, FBSD_1.0);
337 * Wrapper around malloc_message() that avoids the need for
338 * je_malloc_message(...) throughout the code.