1 diff --git a/doc/jemalloc.xml.in b/doc/jemalloc.xml.in
2 index abd5e6f..1d7491a 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 @@ -2180,4 +2191,16 @@ 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>
47 diff --git a/include/jemalloc/internal/jemalloc_internal.h.in b/include/jemalloc/internal/jemalloc_internal.h.in
48 index e46ac54..527449d 100644
49 --- a/include/jemalloc/internal/jemalloc_internal.h.in
50 +++ b/include/jemalloc/internal/jemalloc_internal.h.in
52 #ifndef JEMALLOC_INTERNAL_H
53 #define JEMALLOC_INTERNAL_H
54 +#include "libc_private.h"
55 +#include "namespace.h"
60 @@ -54,6 +57,9 @@ typedef intptr_t ssize_t;
64 +#include "un-namespace.h"
65 +#include "libc_private.h"
67 #define JEMALLOC_NO_DEMANGLE
68 #include "../jemalloc@install_suffix@.h"
70 @@ -95,13 +101,7 @@ static const bool config_fill =
74 -static const bool config_lazy_lock =
75 -#ifdef JEMALLOC_LAZY_LOCK
81 +static const bool config_lazy_lock = true;
82 static const bool config_prof =
85 diff --git a/include/jemalloc/internal/mutex.h b/include/jemalloc/internal/mutex.h
86 index de44e14..564d604 100644
87 --- a/include/jemalloc/internal/mutex.h
88 +++ b/include/jemalloc/internal/mutex.h
89 @@ -43,9 +43,6 @@ struct malloc_mutex_s {
91 #ifdef JEMALLOC_LAZY_LOCK
92 extern bool isthreaded;
94 -# undef isthreaded /* Undo private_namespace.h definition. */
95 -# define isthreaded true
98 bool malloc_mutex_init(malloc_mutex_t *mutex);
99 diff --git a/include/jemalloc/internal/private_namespace.h b/include/jemalloc/internal/private_namespace.h
100 index 65de316..366676b 100644
101 --- a/include/jemalloc/internal/private_namespace.h
102 +++ b/include/jemalloc/internal/private_namespace.h
104 #define iralloc JEMALLOC_N(iralloc)
105 #define irallocx JEMALLOC_N(irallocx)
106 #define isalloc JEMALLOC_N(isalloc)
107 -#define isthreaded JEMALLOC_N(isthreaded)
108 #define ivsalloc JEMALLOC_N(ivsalloc)
109 #define jemalloc_postfork_child JEMALLOC_N(jemalloc_postfork_child)
110 #define jemalloc_postfork_parent JEMALLOC_N(jemalloc_postfork_parent)
111 diff --git a/include/jemalloc/jemalloc.h.in b/include/jemalloc/jemalloc.h.in
112 index 31b1304..c3ef2f5 100644
113 --- a/include/jemalloc/jemalloc.h.in
114 +++ b/include/jemalloc/jemalloc.h.in
115 @@ -15,6 +15,7 @@ extern "C" {
116 #define JEMALLOC_VERSION_GID "@jemalloc_version_gid@"
118 #include "jemalloc_defs@install_suffix@.h"
119 +#include "jemalloc_FreeBSD.h"
121 #ifdef JEMALLOC_EXPERIMENTAL
122 #define ALLOCM_LG_ALIGN(la) (la)
123 diff --git a/include/jemalloc/jemalloc_FreeBSD.h b/include/jemalloc/jemalloc_FreeBSD.h
125 index 0000000..e6c8407
127 +++ b/include/jemalloc/jemalloc_FreeBSD.h
130 + * Override settings that were generated in jemalloc_defs.h as necessary.
133 +#undef JEMALLOC_OVERRIDE_VALLOC
135 +#ifndef MALLOC_PRODUCTION
136 +#define JEMALLOC_DEBUG
140 + * The following are architecture-dependent, so conditionally define them for
141 + * each supported architecture.
144 +#undef JEMALLOC_TLS_MODEL
145 +#undef STATIC_PAGE_SHIFT
146 +#undef LG_SIZEOF_PTR
147 +#undef LG_SIZEOF_INT
148 +#undef LG_SIZEOF_LONG
149 +#undef LG_SIZEOF_INTMAX_T
152 +# define LG_SIZEOF_PTR 2
153 +# define CPU_SPINWAIT __asm__ volatile("pause")
154 +# define JEMALLOC_TLS_MODEL __attribute__((tls_model("initial-exec")))
157 +# define LG_SIZEOF_PTR 3
160 +# define LG_SIZEOF_PTR 3
161 +# define JEMALLOC_TLS_MODEL __attribute__((tls_model("initial-exec")))
164 +# define LG_SIZEOF_PTR 3
165 +# define CPU_SPINWAIT __asm__ volatile("pause")
166 +# define JEMALLOC_TLS_MODEL __attribute__((tls_model("initial-exec")))
169 +# define LG_SIZEOF_PTR 2
173 +# define LG_SIZEOF_PTR 3
175 +# define LG_SIZEOF_PTR 2
178 +#ifdef __powerpc64__
179 +# define LG_SIZEOF_PTR 3
180 +#elif defined(__powerpc__)
181 +# define LG_SIZEOF_PTR 2
184 +#ifndef JEMALLOC_TLS_MODEL
185 +# define JEMALLOC_TLS_MODEL /* Default. */
188 +#define STATIC_PAGE_SHIFT PAGE_SHIFT
189 +#define LG_SIZEOF_INT 2
190 +#define LG_SIZEOF_LONG LG_SIZEOF_PTR
191 +#define LG_SIZEOF_INTMAX_T 3
193 +/* Disable lazy-lock machinery, mangle isthreaded, and adjust its type. */
194 +#undef JEMALLOC_LAZY_LOCK
195 +extern int __isthreaded;
196 +#define isthreaded ((bool)__isthreaded)
203 +#undef je_posix_memalign
204 +#undef je_malloc_usable_size
210 +#define je_malloc __malloc
211 +#define je_calloc __calloc
212 +#define je_realloc __realloc
213 +#define je_free __free
214 +#define je_posix_memalign __posix_memalign
215 +#define je_malloc_usable_size __malloc_usable_size
216 +#define je_allocm __allocm
217 +#define je_rallocm __rallocm
218 +#define je_sallocm __sallocm
219 +#define je_dallocm __dallocm
220 +#define je_nallocm __nallocm
223 +#define write _write
224 +#define close _close
225 +#define pthread_mutex_lock _pthread_mutex_lock
226 +#define pthread_mutex_unlock _pthread_mutex_unlock
230 + * Define 'weak' symbols so that an application can have its own versions
231 + * of malloc, calloc, realloc, free, et al.
233 +__weak_reference(__malloc, malloc);
234 +__weak_reference(__calloc, calloc);
235 +__weak_reference(__realloc, realloc);
236 +__weak_reference(__free, free);
237 +__weak_reference(__posix_memalign, posix_memalign);
238 +__weak_reference(__malloc_usable_size, malloc_usable_size);
239 +__weak_reference(__allocm, allocm);
240 +__weak_reference(__rallocm, rallocm);
241 +__weak_reference(__sallocm, sallocm);
242 +__weak_reference(__dallocm, dallocm);
243 +__weak_reference(__nallocm, nallocm);
246 diff --git a/src/jemalloc.c b/src/jemalloc.c
247 index bc350ed..352c98e 100644
250 @@ -8,6 +8,10 @@ malloc_tsd_data(, arenas, arena_t *, NULL)
251 malloc_tsd_data(, thread_allocated, thread_allocated_t,
252 THREAD_ALLOCATED_INITIALIZER)
254 +/* Work around <http://llvm.org/bugs/show_bug.cgi?id=12623>: */
255 +const char *__malloc_options_1_0 = NULL;
256 +__sym_compat(_malloc_options, __malloc_options_1_0, FBSD_1.0);
258 /* Runtime configuration options. */
259 const char *je_malloc_conf;
261 @@ -471,7 +475,8 @@ malloc_conf_init(void)
265 - if ((opts = getenv(envname)) != NULL) {
266 + if (issetugid() == 0 && (opts = getenv(envname)) !=
269 * Do nothing; opts is already initialized to
270 * the value of the MALLOC_CONF environment
271 diff --git a/src/mutex.c b/src/mutex.c
272 index 55e18c2..6b6f438 100644
275 @@ -66,6 +66,17 @@ pthread_create(pthread_t *__restrict thread,
276 #ifdef JEMALLOC_MUTEX_INIT_CB
277 JEMALLOC_EXPORT int _pthread_mutex_init_calloc_cb(pthread_mutex_t *mutex,
278 void *(calloc_cb)(size_t, size_t));
280 +__weak_reference(_pthread_mutex_init_calloc_cb_stub,
281 + _pthread_mutex_init_calloc_cb);
284 +_pthread_mutex_init_calloc_cb_stub(pthread_mutex_t *mutex,
285 + void *(calloc_cb)(size_t, size_t))
293 diff --git a/src/util.c b/src/util.c
294 index b3a0114..df1c5d5 100644
297 @@ -58,6 +58,22 @@ wrtmessage(void *cbopaque, const char *s)
299 JEMALLOC_EXPORT void (*je_malloc_message)(void *, const char *s);
301 +JEMALLOC_ATTR(visibility("hidden"))
303 +wrtmessage_1_0(const char *s1, const char *s2, const char *s3,
307 + wrtmessage(NULL, s1);
308 + wrtmessage(NULL, s2);
309 + wrtmessage(NULL, s3);
310 + wrtmessage(NULL, s4);
313 +void (*__malloc_message_1_0)(const char *s1, const char *s2, const char *s3,
314 + const char *s4) = wrtmessage_1_0;
315 +__sym_compat(_malloc_message, __malloc_message_1_0, FBSD_1.0);
318 * Wrapper around malloc_message() that avoids the need for
319 * je_malloc_message(...) throughout the code.