1diff --git a/doc/jemalloc.xml.in b/doc/jemalloc.xml.in 2index 877c500..7d659a7 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 <<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> 27 <refsect2> 28 <title>Standard API</title> 29 <funcprototype> 30@@ -2101,4 +2112,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> 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> 47diff --git a/include/jemalloc/internal/jemalloc_internal.h.in b/include/jemalloc/internal/jemalloc_internal.h.in 48index 268cd14..2acd2eb 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 <math.h> 58 #ifdef _WIN32 59 # include <windows.h> 60@@ -54,6 +57,9 @@ typedef intptr_t ssize_t; 61 #endif 62 #include <fcntl.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@@ -95,13 +101,7 @@ static const bool config_fill = 71 false 72 #endif 73 ; 74-static const bool config_lazy_lock = 75-#ifdef JEMALLOC_LAZY_LOCK 76- true 77-#else 78- false 79-#endif 80- ; 81+static const bool config_lazy_lock = true; 82 static const bool config_prof = 83 #ifdef JEMALLOC_PROF 84 true 85diff --git a/include/jemalloc/internal/mutex.h b/include/jemalloc/internal/mutex.h 86index 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 { 90 91 #ifdef JEMALLOC_LAZY_LOCK 92 extern bool isthreaded; 93-#else 94-# undef isthreaded /* Undo private_namespace.h definition. */ 95-# define isthreaded true 96 #endif 97 98 bool malloc_mutex_init(malloc_mutex_t *mutex); 99diff --git a/include/jemalloc/internal/private_namespace.h b/include/jemalloc/internal/private_namespace.h 100index b816647..b8ce6b1 100644 101--- a/include/jemalloc/internal/private_namespace.h 102+++ b/include/jemalloc/internal/private_namespace.h 103@@ -186,7 +186,6 @@ 104 #define iqalloc JEMALLOC_N(iqalloc) 105 #define iralloc JEMALLOC_N(iralloc) 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) 111diff --git a/include/jemalloc/jemalloc.h.in b/include/jemalloc/jemalloc.h.in 112index ad06948..505dd38 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@" 117 118 #include "jemalloc_defs@install_suffix@.h" 119+#include "jemalloc_FreeBSD.h" 120 121 #ifdef JEMALLOC_EXPERIMENTAL 122 #define ALLOCM_LG_ALIGN(la) (la) 123diff --git a/include/jemalloc/jemalloc_FreeBSD.h b/include/jemalloc/jemalloc_FreeBSD.h 124new file mode 100644 125index 0000000..9efab93 126--- /dev/null 127+++ b/include/jemalloc/jemalloc_FreeBSD.h 128@@ -0,0 +1,80 @@ 129+/* 130+ * Override settings that were generated in jemalloc_defs.h as necessary. 131+ */ 132+ 133+#undef JEMALLOC_OVERRIDE_VALLOC 134+ 135+#ifndef MALLOC_PRODUCTION 136+#define JEMALLOC_DEBUG 137+#endif 138+ 139+/* 140+ * The following are architecture-dependent, so conditionally define them for 141+ * each supported architecture. 142+ */ 143+#undef CPU_SPINWAIT 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 150+ 151+#ifdef __i386__ 152+# define LG_SIZEOF_PTR 2 153+# define CPU_SPINWAIT __asm__ volatile("pause") 154+# define JEMALLOC_TLS_MODEL __attribute__((tls_model("initial-exec"))) 155+#endif 156+#ifdef __ia64__ 157+# define LG_SIZEOF_PTR 3 158+#endif 159+#ifdef __sparc64__ 160+# define LG_SIZEOF_PTR 3 161+# define JEMALLOC_TLS_MODEL __attribute__((tls_model("initial-exec"))) 162+#endif 163+#ifdef __amd64__ 164+# define LG_SIZEOF_PTR 3 165+# define CPU_SPINWAIT __asm__ volatile("pause") 166+# define JEMALLOC_TLS_MODEL __attribute__((tls_model("initial-exec"))) 167+#endif 168+#ifdef __arm__ 169+# define LG_SIZEOF_PTR 2 170+#endif 171+#ifdef __mips__ 172+#ifdef __mips_n64 173+# define LG_SIZEOF_PTR 3 174+#else 175+# define LG_SIZEOF_PTR 2 176+#endif 177+#endif 178+#ifdef __powerpc64__ 179+# define LG_SIZEOF_PTR 3 180+#elif defined(__powerpc__) 181+# define LG_SIZEOF_PTR 2 182+#endif 183+ 184+#ifndef JEMALLOC_TLS_MODEL 185+# define JEMALLOC_TLS_MODEL /* Default. */ 186+#endif 187+#ifdef __clang__ 188+# undef JEMALLOC_TLS_MODEL 189+# define JEMALLOC_TLS_MODEL /* clang does not support tls_model yet. */ 190+#endif 191+ 192+#define STATIC_PAGE_SHIFT PAGE_SHIFT 193+#define LG_SIZEOF_INT 2 194+#define LG_SIZEOF_LONG LG_SIZEOF_PTR 195+#define LG_SIZEOF_INTMAX_T 3 196+ 197+/* Disable lazy-lock machinery, mangle isthreaded, and adjust its type. */ 198+#undef JEMALLOC_LAZY_LOCK 199+extern int __isthreaded; 200+#define isthreaded ((bool)__isthreaded) 201+ 202+/* Mangle. */ 203+#define open _open 204+#define read _read 205+#define write _write 206+#define close _close 207+#define pthread_mutex_lock _pthread_mutex_lock 208+#define pthread_mutex_unlock _pthread_mutex_unlock 209diff --git a/src/jemalloc.c b/src/jemalloc.c 210index bc54cd7..fa9fcf0 100644 211--- a/src/jemalloc.c 212+++ b/src/jemalloc.c 213@@ -8,6 +8,10 @@ malloc_tsd_data(, arenas, arena_t *, NULL) 214 malloc_tsd_data(, thread_allocated, thread_allocated_t, 215 THREAD_ALLOCATED_INITIALIZER) 216 217+/* Work around <http://llvm.org/bugs/show_bug.cgi?id=12623>: */ 218+const char *__malloc_options_1_0 = NULL; 219+__sym_compat(_malloc_options, __malloc_options_1_0, FBSD_1.0); 220+ 221 /* Runtime configuration options. */ 222 const char *je_malloc_conf; 223 #ifdef JEMALLOC_DEBUG 224@@ -429,7 +433,8 @@ malloc_conf_init(void) 225 #endif 226 ; 227 228- if ((opts = getenv(envname)) != NULL) { 229+ if (issetugid() == 0 && (opts = getenv(envname)) != 230+ NULL) { 231 /* 232 * Do nothing; opts is already initialized to 233 * the value of the MALLOC_CONF environment 234diff --git a/src/mutex.c b/src/mutex.c 235index 37a843e..4a90a05 100644 236--- a/src/mutex.c 237+++ b/src/mutex.c 238@@ -66,6 +66,17 @@ pthread_create(pthread_t *__restrict thread, 239 #ifdef JEMALLOC_MUTEX_INIT_CB 240 int _pthread_mutex_init_calloc_cb(pthread_mutex_t *mutex, 241 void *(calloc_cb)(size_t, size_t)); 242+ 243+__weak_reference(_pthread_mutex_init_calloc_cb_stub, 244+ _pthread_mutex_init_calloc_cb); 245+ 246+int 247+_pthread_mutex_init_calloc_cb_stub(pthread_mutex_t *mutex, 248+ void *(calloc_cb)(size_t, size_t)) 249+{ 250+ 251+ return (0); 252+} 253 #endif 254 255 bool 256diff --git a/src/util.c b/src/util.c 257index 9b73c3e..f94799f 100644 258--- a/src/util.c 259+++ b/src/util.c 260@@ -58,6 +58,22 @@ wrtmessage(void *cbopaque, const char *s) 261 262 JEMALLOC_EXPORT void (*je_malloc_message)(void *, const char *s); 263 264+JEMALLOC_ATTR(visibility("hidden")) 265+void 266+wrtmessage_1_0(const char *s1, const char *s2, const char *s3, 267+ const char *s4) 268+{ 269+ 270+ wrtmessage(NULL, s1); 271+ wrtmessage(NULL, s2); 272+ wrtmessage(NULL, s3); 273+ wrtmessage(NULL, s4); 274+} 275+ 276+void (*__malloc_message_1_0)(const char *s1, const char *s2, const char *s3, 277+ const char *s4) = wrtmessage_1_0; 278+__sym_compat(_malloc_message, __malloc_message_1_0, FBSD_1.0); 279+ 280 /* 281 * Wrapper around malloc_message() that avoids the need for 282 * je_malloc_message(...) throughout the code. 283