1 diff --git a/doc/jemalloc.xml.in b/doc/jemalloc.xml.in
2 index 0930580..d45fa3d 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 @@ -2173,4 +2184,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 c606c12..0d46d9d 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 903fb4d..d6638df 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..9c97a13
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)
201 +#define write _write
202 +#define close _close
203 +#define pthread_mutex_lock _pthread_mutex_lock
204 +#define pthread_mutex_unlock _pthread_mutex_unlock
205 diff --git a/src/jemalloc.c b/src/jemalloc.c
206 index c117685..665d98f 100644
209 @@ -8,6 +8,10 @@ malloc_tsd_data(, arenas, arena_t *, NULL)
210 malloc_tsd_data(, thread_allocated, thread_allocated_t,
211 THREAD_ALLOCATED_INITIALIZER)
213 +/* Work around <http://llvm.org/bugs/show_bug.cgi?id=12623>: */
214 +const char *__malloc_options_1_0 = NULL;
215 +__sym_compat(_malloc_options, __malloc_options_1_0, FBSD_1.0);
217 /* Runtime configuration options. */
218 const char *je_malloc_conf;
220 @@ -453,7 +457,8 @@ malloc_conf_init(void)
224 - if ((opts = getenv(envname)) != NULL) {
225 + if (issetugid() == 0 && (opts = getenv(envname)) !=
228 * Do nothing; opts is already initialized to
229 * the value of the MALLOC_CONF environment
230 diff --git a/src/mutex.c b/src/mutex.c
231 index 55e18c2..6b6f438 100644
234 @@ -66,6 +66,17 @@ pthread_create(pthread_t *__restrict thread,
235 #ifdef JEMALLOC_MUTEX_INIT_CB
236 JEMALLOC_EXPORT int _pthread_mutex_init_calloc_cb(pthread_mutex_t *mutex,
237 void *(calloc_cb)(size_t, size_t));
239 +__weak_reference(_pthread_mutex_init_calloc_cb_stub,
240 + _pthread_mutex_init_calloc_cb);
243 +_pthread_mutex_init_calloc_cb_stub(pthread_mutex_t *mutex,
244 + void *(calloc_cb)(size_t, size_t))
252 diff --git a/src/util.c b/src/util.c
253 index b3a0114..df1c5d5 100644
256 @@ -58,6 +58,22 @@ wrtmessage(void *cbopaque, const char *s)
258 JEMALLOC_EXPORT void (*je_malloc_message)(void *, const char *s);
260 +JEMALLOC_ATTR(visibility("hidden"))
262 +wrtmessage_1_0(const char *s1, const char *s2, const char *s3,
266 + wrtmessage(NULL, s1);
267 + wrtmessage(NULL, s2);
268 + wrtmessage(NULL, s3);
269 + wrtmessage(NULL, s4);
272 +void (*__malloc_message_1_0)(const char *s1, const char *s2, const char *s3,
273 + const char *s4) = wrtmessage_1_0;
274 +__sym_compat(_malloc_message, __malloc_message_1_0, FBSD_1.0);
277 * Wrapper around malloc_message() that avoids the need for
278 * je_malloc_message(...) throughout the code.