]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/jemalloc/FREEBSD-diffs
Import jemalloc a8f8d7540d66ddee7337db80c92890916e1063ca (dev branch,
[FreeBSD/FreeBSD.git] / contrib / jemalloc / FREEBSD-diffs
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
5 @@ -51,12 +51,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 @@ -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 (&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 +  </refsect1>
46  </refentry>
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
51 @@ -1,5 +1,8 @@
52  #ifndef JEMALLOC_INTERNAL_H
53  #define JEMALLOC_INTERNAL_H
54 +#include "libc_private.h"
55 +#include "namespace.h"
56 +
57  #include <sys/mman.h>
58  #include <sys/param.h>
59  #include <sys/syscall.h>
60 @@ -35,6 +38,9 @@
61  #include <pthread.h>
62  #include <math.h>
63  
64 +#include "un-namespace.h"
65 +#include "libc_private.h"
66 +
67  #define        JEMALLOC_NO_DEMANGLE
68  #include "../jemalloc@install_suffix@.h"
69  
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 {
75  
76  #ifdef JEMALLOC_LAZY_LOCK
77  extern bool isthreaded;
78 -#else
79 -#  undef isthreaded /* Undo private_namespace.h definition. */
80 -#  define isthreaded true
81  #endif
82  
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
88 @@ -165,7 +165,6 @@
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@"
102  
103  #include "jemalloc_defs@install_suffix@.h"
104 +#include "jemalloc_FreeBSD.h"
105  
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
109 new file mode 100644
110 index 0000000..2c5797f
111 --- /dev/null
112 +++ b/include/jemalloc/jemalloc_FreeBSD.h
113 @@ -0,0 +1,76 @@
114 +/*
115 + * Override settings that were generated in jemalloc_defs.h as necessary.
116 + */
117 +
118 +#undef JEMALLOC_OVERRIDE_VALLOC
119 +
120 +#ifndef MALLOC_PRODUCTION
121 +#define        JEMALLOC_DEBUG
122 +#endif
123 +
124 +/*
125 + * The following are architecture-dependent, so conditionally define them for
126 + * each supported architecture.
127 + */
128 +#undef CPU_SPINWAIT
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
135 +
136 +#ifdef __i386__
137 +#  define LG_SIZEOF_PTR                2
138 +#  define CPU_SPINWAIT         __asm__ volatile("pause")
139 +#  define JEMALLOC_TLS_MODEL   __attribute__((tls_model("initial-exec")))
140 +#endif
141 +#ifdef __ia64__
142 +#  define LG_SIZEOF_PTR                3
143 +#endif
144 +#ifdef __sparc64__
145 +#  define LG_SIZEOF_PTR                3
146 +#  define JEMALLOC_TLS_MODEL   __attribute__((tls_model("initial-exec")))
147 +#endif
148 +#ifdef __amd64__
149 +#  define LG_SIZEOF_PTR                3
150 +#  define CPU_SPINWAIT         __asm__ volatile("pause")
151 +#  define JEMALLOC_TLS_MODEL   __attribute__((tls_model("initial-exec")))
152 +#endif
153 +#ifdef __arm__
154 +#  define LG_SIZEOF_PTR                2
155 +#endif
156 +#ifdef __mips__
157 +#  define LG_SIZEOF_PTR                2
158 +#endif
159 +#ifdef __powerpc64__
160 +#  define LG_SIZEOF_PTR                3
161 +#elif defined(__powerpc__)
162 +#  define LG_SIZEOF_PTR                2
163 +#endif
164 +
165 +#ifndef JEMALLOC_TLS_MODEL
166 +#  define JEMALLOC_TLS_MODEL   /* Default. */
167 +#endif
168 +#ifdef __clang__
169 +#  undef JEMALLOC_TLS_MODEL
170 +#  define JEMALLOC_TLS_MODEL   /* clang does not support tls_model yet. */
171 +#endif
172 +
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
177 +
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)
182 +
183 +/* Mangle. */
184 +#define        open                    _open
185 +#define        read                    _read
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
192 --- a/src/jemalloc.c
193 +++ b/src/jemalloc.c
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)
197  
198 +const char     *__malloc_options_1_0;
199 +__sym_compat(_malloc_options, __malloc_options_1_0, FBSD_1.0);
200 +
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)
205  #endif
206                             ;
207  
208 -                       if ((opts = getenv(envname)) != NULL) {
209 +                       if (issetugid() == 0 && (opts = getenv(envname)) !=
210 +                           NULL) {
211                                 /*
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
216 --- a/src/mutex.c
217 +++ b/src/mutex.c
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));
222 +
223 +__weak_reference(_pthread_mutex_init_calloc_cb_stub,
224 +    _pthread_mutex_init_calloc_cb);
225 +
226 +int
227 +_pthread_mutex_init_calloc_cb_stub(pthread_mutex_t *mutex,
228 +    void *(calloc_cb)(size_t, size_t))
229 +{
230 +
231 +       return (0);
232 +}
233  #endif
234  
235  bool
236 diff --git a/src/util.c b/src/util.c
237 index 99ae26d..b80676c 100644
238 --- a/src/util.c
239 +++ b/src/util.c
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;
243  
244 +JEMALLOC_CATTR(visibility("hidden"), static)
245 +void
246 +wrtmessage_1_0(const char *s1, const char *s2, const char *s3,
247 +    const char *s4)
248 +{
249 +
250 +       wrtmessage(NULL, s1);
251 +       wrtmessage(NULL, s2);
252 +       wrtmessage(NULL, s3);
253 +       wrtmessage(NULL, s4);
254 +}
255 +
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);
259 +
260  /*
261   * glibc provides a non-standard strerror_r() when _GNU_SOURCE is defined, so
262   * provide a wrapper.