]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/jemalloc/FREEBSD-diffs
Update libucl to 2014-03-03
[FreeBSD/FreeBSD.git] / contrib / jemalloc / FREEBSD-diffs
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
5 @@ -57,12 +57,23 @@
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>
9 +
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
19 +    variable).</para>
20    </refsect1>
21    <refsynopsisdiv>
22      <title>SYNOPSIS</title>
23      <funcsynopsis>
24        <funcsynopsisinfo>#include &lt;<filename class="headerfile">stdlib.h</filename>&gt;
25 -#include &lt;<filename class="headerfile">jemalloc/jemalloc.h</filename>&gt;</funcsynopsisinfo>
26 +#include &lt;<filename class="headerfile">malloc_np.h</filename>&gt;</funcsynopsisinfo>
27        <refsect2>
28          <title>Standard API</title>
29          <funcprototype>
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 (&ldquo;POSIX.1&rdquo;).</para>
33    </refsect1>
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
38 +    FreeBSD 7.0.</para>
39 +
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>
45 +
46 +    <para>The <function>*allocx<parameter/></function> functions first appeared
47 +    in FreeBSD 11.0.</para>
48 +  </refsect1>
49  </refentry>
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
54 @@ -1,5 +1,8 @@
55  #ifndef JEMALLOC_INTERNAL_H
56  #define        JEMALLOC_INTERNAL_H
57 +#include "libc_private.h"
58 +#include "namespace.h"
59 +
60  #include <math.h>
61  #ifdef _WIN32
62  #  include <windows.h>
63 @@ -65,6 +68,9 @@ typedef intptr_t ssize_t;
64  #include <valgrind/memcheck.h>
65  #endif
66  
67 +#include "un-namespace.h"
68 +#include "libc_private.h"
69 +
70  #define        JEMALLOC_NO_DEMANGLE
71  #ifdef JEMALLOC_JET
72  #  define JEMALLOC_N(n) jet_##n
73 @@ -99,13 +105,7 @@ static const bool config_fill =
74      false
75  #endif
76      ;
77 -static const bool config_lazy_lock =
78 -#ifdef JEMALLOC_LAZY_LOCK
79 -    true
80 -#else
81 -    false
82 -#endif
83 -    ;
84 +static const bool config_lazy_lock = true;
85  static const bool config_prof =
86  #ifdef JEMALLOC_PROF
87      true
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 {
93  
94  #ifdef JEMALLOC_LAZY_LOCK
95  extern bool isthreaded;
96 -#else
97 -#  undef isthreaded /* Undo private_namespace.h definition. */
98 -#  define isthreaded true
99  #endif
100  
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
107  iralloct
108  iralloct_realign
109  isalloc
110 -isthreaded
111  ivsalloc
112  ixalloc
113  jemalloc_postfork_child
114 diff --git a/include/jemalloc/jemalloc_FreeBSD.h b/include/jemalloc/jemalloc_FreeBSD.h
115 new file mode 100644
116 index 0000000..94554bc
117 --- /dev/null
118 +++ b/include/jemalloc/jemalloc_FreeBSD.h
119 @@ -0,0 +1,134 @@
120 +/*
121 + * Override settings that were generated in jemalloc_defs.h as necessary.
122 + */
123 +
124 +#undef JEMALLOC_OVERRIDE_VALLOC
125 +
126 +#ifndef MALLOC_PRODUCTION
127 +#define        JEMALLOC_DEBUG
128 +#endif
129 +
130 +/*
131 + * The following are architecture-dependent, so conditionally define them for
132 + * each supported architecture.
133 + */
134 +#undef CPU_SPINWAIT
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
141 +
142 +#ifdef __i386__
143 +#  define LG_SIZEOF_PTR                2
144 +#  define CPU_SPINWAIT         __asm__ volatile("pause")
145 +#  define JEMALLOC_TLS_MODEL   __attribute__((tls_model("initial-exec")))
146 +#endif
147 +#ifdef __ia64__
148 +#  define LG_SIZEOF_PTR                3
149 +#endif
150 +#ifdef __sparc64__
151 +#  define LG_SIZEOF_PTR                3
152 +#  define JEMALLOC_TLS_MODEL   __attribute__((tls_model("initial-exec")))
153 +#endif
154 +#ifdef __amd64__
155 +#  define LG_SIZEOF_PTR                3
156 +#  define CPU_SPINWAIT         __asm__ volatile("pause")
157 +#  define JEMALLOC_TLS_MODEL   __attribute__((tls_model("initial-exec")))
158 +#endif
159 +#ifdef __arm__
160 +#  define LG_SIZEOF_PTR                2
161 +#endif
162 +#ifdef __mips__
163 +#ifdef __mips_n64
164 +#  define LG_SIZEOF_PTR                3
165 +#else
166 +#  define LG_SIZEOF_PTR                2
167 +#endif
168 +#endif
169 +#ifdef __powerpc64__
170 +#  define LG_SIZEOF_PTR                3
171 +#elif defined(__powerpc__)
172 +#  define LG_SIZEOF_PTR                2
173 +#endif
174 +
175 +#ifndef JEMALLOC_TLS_MODEL
176 +#  define JEMALLOC_TLS_MODEL   /* Default. */
177 +#endif
178 +
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
183 +
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)
188 +
189 +/* Mangle. */
190 +#undef je_malloc
191 +#undef je_calloc
192 +#undef je_realloc
193 +#undef je_free
194 +#undef je_posix_memalign
195 +#undef je_malloc_usable_size
196 +#undef je_mallocx
197 +#undef je_rallocx
198 +#undef je_xallocx
199 +#undef je_sallocx
200 +#undef je_dallocx
201 +#undef je_nallocx
202 +#undef je_allocm
203 +#undef je_rallocm
204 +#undef je_sallocm
205 +#undef je_dallocm
206 +#undef je_nallocm
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
224 +#define        open                    _open
225 +#define        read                    _read
226 +#define        write                   _write
227 +#define        close                   _close
228 +#define        pthread_mutex_lock      _pthread_mutex_lock
229 +#define        pthread_mutex_unlock    _pthread_mutex_unlock
230 +
231 +#ifdef JEMALLOC_C_
232 +/*
233 + * Define 'weak' symbols so that an application can have its own versions
234 + * of malloc, calloc, realloc, free, et al.
235 + */
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);
253 +#endif
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
259  
260  cat <<EOF
261  #endif
262 +
263 +#include "jemalloc_FreeBSD.h"
264  EOF
265 diff --git a/src/jemalloc.c b/src/jemalloc.c
266 index 563d99f..42f97b4 100644
267 --- a/src/jemalloc.c
268 +++ b/src/jemalloc.c
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)
272  
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);
276 +
277  /* Runtime configuration options. */
278  const char     *je_malloc_conf;
279  bool   opt_abort =
280 @@ -457,7 +461,8 @@ malloc_conf_init(void)
281  #endif
282                             ;
283  
284 -                       if ((opts = getenv(envname)) != NULL) {
285 +                       if (issetugid() == 0 && (opts = getenv(envname)) !=
286 +                           NULL) {
287                                 /*
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
292 --- a/src/mutex.c
293 +++ b/src/mutex.c
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));
298 +
299 +__weak_reference(_pthread_mutex_init_calloc_cb_stub,
300 +    _pthread_mutex_init_calloc_cb);
301 +
302 +int
303 +_pthread_mutex_init_calloc_cb_stub(pthread_mutex_t *mutex,
304 +    void *(calloc_cb)(size_t, size_t))
305 +{
306 +
307 +       return (0);
308 +}
309  #endif
310  
311  bool
312 diff --git a/src/util.c b/src/util.c
313 index 93a19fd..70b3e45 100644
314 --- a/src/util.c
315 +++ b/src/util.c
316 @@ -58,6 +58,22 @@ wrtmessage(void *cbopaque, const char *s)
317  
318  JEMALLOC_EXPORT void   (*je_malloc_message)(void *, const char *s);
319  
320 +JEMALLOC_ATTR(visibility("hidden"))
321 +void
322 +wrtmessage_1_0(const char *s1, const char *s2, const char *s3,
323 +    const char *s4)
324 +{
325 +
326 +       wrtmessage(NULL, s1);
327 +       wrtmessage(NULL, s2);
328 +       wrtmessage(NULL, s3);
329 +       wrtmessage(NULL, s4);
330 +}
331 +
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);
335 +
336  /*
337   * Wrapper around malloc_message() that avoids the need for
338   * je_malloc_message(...) throughout the code.