1 diff --git a/doc/jemalloc.xml.in b/doc/jemalloc.xml.in
2 index e8a5722..cec85b5 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 @@ -2091,4 +2102,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 b61abe8..edbb437 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"
58 #include <sys/param.h>
59 #include <sys/syscall.h>
64 +#include "un-namespace.h"
65 +#include "libc_private.h"
67 #define JEMALLOC_NO_DEMANGLE
68 #include "../jemalloc@install_suffix@.h"
70 diff --git a/include/jemalloc/internal/mutex.h b/include/jemalloc/internal/mutex.h
71 index 8837ef5..d7133f4 100644
72 --- a/include/jemalloc/internal/mutex.h
73 +++ b/include/jemalloc/internal/mutex.h
74 @@ -39,9 +39,6 @@ struct malloc_mutex_s {
76 #ifdef JEMALLOC_LAZY_LOCK
77 extern bool isthreaded;
79 -# undef isthreaded /* Undo private_namespace.h definition. */
80 -# define isthreaded true
83 bool malloc_mutex_init(malloc_mutex_t *mutex);
84 diff --git a/include/jemalloc/internal/private_namespace.h b/include/jemalloc/internal/private_namespace.h
85 index bb1b63e..00eb169 100644
86 --- a/include/jemalloc/internal/private_namespace.h
87 +++ b/include/jemalloc/internal/private_namespace.h
89 #define iqalloc JEMALLOC_N(iqalloc)
90 #define iralloc JEMALLOC_N(iralloc)
91 #define isalloc JEMALLOC_N(isalloc)
92 -#define isthreaded JEMALLOC_N(isthreaded)
93 #define ivsalloc JEMALLOC_N(ivsalloc)
94 #define jemalloc_postfork_child JEMALLOC_N(jemalloc_postfork_child)
95 #define jemalloc_postfork_parent JEMALLOC_N(jemalloc_postfork_parent)
96 diff --git a/include/jemalloc/jemalloc.h.in b/include/jemalloc/jemalloc.h.in
97 index f0581db..f26d8bc 100644
98 --- a/include/jemalloc/jemalloc.h.in
99 +++ b/include/jemalloc/jemalloc.h.in
100 @@ -15,6 +15,7 @@ extern "C" {
101 #define JEMALLOC_VERSION_GID "@jemalloc_version_gid@"
103 #include "jemalloc_defs@install_suffix@.h"
104 +#include "jemalloc_FreeBSD.h"
106 #ifdef JEMALLOC_EXPERIMENTAL
107 #define ALLOCM_LG_ALIGN(la) (la)
108 diff --git a/include/jemalloc/jemalloc_FreeBSD.h b/include/jemalloc/jemalloc_FreeBSD.h
110 index 0000000..2c5797f
112 +++ b/include/jemalloc/jemalloc_FreeBSD.h
115 + * Override settings that were generated in jemalloc_defs.h as necessary.
118 +#undef JEMALLOC_OVERRIDE_VALLOC
120 +#ifndef MALLOC_PRODUCTION
121 +#define JEMALLOC_DEBUG
125 + * The following are architecture-dependent, so conditionally define them for
126 + * each supported architecture.
129 +#undef JEMALLOC_TLS_MODEL
130 +#undef STATIC_PAGE_SHIFT
131 +#undef LG_SIZEOF_PTR
132 +#undef LG_SIZEOF_INT
133 +#undef LG_SIZEOF_LONG
134 +#undef LG_SIZEOF_INTMAX_T
137 +# define LG_SIZEOF_PTR 2
138 +# define CPU_SPINWAIT __asm__ volatile("pause")
139 +# define JEMALLOC_TLS_MODEL __attribute__((tls_model("initial-exec")))
142 +# define LG_SIZEOF_PTR 3
145 +# define LG_SIZEOF_PTR 3
146 +# define JEMALLOC_TLS_MODEL __attribute__((tls_model("initial-exec")))
149 +# define LG_SIZEOF_PTR 3
150 +# define CPU_SPINWAIT __asm__ volatile("pause")
151 +# define JEMALLOC_TLS_MODEL __attribute__((tls_model("initial-exec")))
154 +# define LG_SIZEOF_PTR 2
157 +# define LG_SIZEOF_PTR 2
159 +#ifdef __powerpc64__
160 +# define LG_SIZEOF_PTR 3
161 +#elif defined(__powerpc__)
162 +# define LG_SIZEOF_PTR 2
165 +#ifndef JEMALLOC_TLS_MODEL
166 +# define JEMALLOC_TLS_MODEL /* Default. */
169 +# undef JEMALLOC_TLS_MODEL
170 +# define JEMALLOC_TLS_MODEL /* clang does not support tls_model yet. */
173 +#define STATIC_PAGE_SHIFT PAGE_SHIFT
174 +#define LG_SIZEOF_INT 2
175 +#define LG_SIZEOF_LONG LG_SIZEOF_PTR
176 +#define LG_SIZEOF_INTMAX_T 3
178 +/* Disable lazy-lock machinery, mangle isthreaded, and adjust its type. */
179 +#undef JEMALLOC_LAZY_LOCK
180 +extern int __isthreaded;
181 +#define isthreaded ((bool)__isthreaded)
186 +#define write _write
187 +#define close _close
188 +#define pthread_mutex_lock _pthread_mutex_lock
189 +#define pthread_mutex_unlock _pthread_mutex_unlock
190 diff --git a/src/jemalloc.c b/src/jemalloc.c
191 index f9c8916..8e24a5a 100644
194 @@ -8,6 +8,9 @@ malloc_tsd_data(, arenas, arena_t *, NULL)
195 malloc_tsd_data(, thread_allocated, thread_allocated_t,
196 THREAD_ALLOCATED_INITIALIZER)
198 +const char *__malloc_options_1_0;
199 +__sym_compat(_malloc_options, __malloc_options_1_0, FBSD_1.0);
201 /* Runtime configuration options. */
202 const char *je_malloc_conf JEMALLOC_ATTR(visibility("default"));
203 #ifdef JEMALLOC_DEBUG
204 @@ -401,7 +404,8 @@ malloc_conf_init(void)
208 - if ((opts = getenv(envname)) != NULL) {
209 + if (issetugid() == 0 && (opts = getenv(envname)) !=
212 * Do nothing; opts is already initialized to
213 * the value of the MALLOC_CONF environment
214 diff --git a/src/mutex.c b/src/mutex.c
215 index 4b8ce57..7be5fc9 100644
218 @@ -63,6 +63,17 @@ pthread_create(pthread_t *__restrict thread,
219 #ifdef JEMALLOC_MUTEX_INIT_CB
220 int _pthread_mutex_init_calloc_cb(pthread_mutex_t *mutex,
221 void *(calloc_cb)(size_t, size_t));
223 +__weak_reference(_pthread_mutex_init_calloc_cb_stub,
224 + _pthread_mutex_init_calloc_cb);
227 +_pthread_mutex_init_calloc_cb_stub(pthread_mutex_t *mutex,
228 + void *(calloc_cb)(size_t, size_t))
236 diff --git a/src/util.c b/src/util.c
237 index 99ae26d..b80676c 100644
240 @@ -60,6 +60,22 @@ wrtmessage(void *cbopaque, const char *s)
241 void (*je_malloc_message)(void *, const char *s)
242 JEMALLOC_ATTR(visibility("default")) = wrtmessage;
244 +JEMALLOC_CATTR(visibility("hidden"), static)
246 +wrtmessage_1_0(const char *s1, const char *s2, const char *s3,
250 + wrtmessage(NULL, s1);
251 + wrtmessage(NULL, s2);
252 + wrtmessage(NULL, s3);
253 + wrtmessage(NULL, s4);
256 +void (*__malloc_message_1_0)(const char *s1, const char *s2, const char *s3,
257 + const char *s4) = wrtmessage_1_0;
258 +__sym_compat(_malloc_message, __malloc_message_1_0, FBSD_1.0);
261 * glibc provides a non-standard strerror_r() when _GNU_SOURCE is defined, so