1234370Sjasonediff --git a/doc/jemalloc.xml.in b/doc/jemalloc.xml.in 2251300Sjasoneindex abd5e6f..1d7491a 100644 3234370Sjasone--- a/doc/jemalloc.xml.in 4234370Sjasone+++ b/doc/jemalloc.xml.in 5234370Sjasone@@ -51,12 +51,23 @@ 6234370Sjasone <para>This manual describes jemalloc @jemalloc_version@. More information 7234370Sjasone can be found at the <ulink 8234370Sjasone url="http://www.canonware.com/jemalloc/">jemalloc website</ulink>.</para> 9234370Sjasone+ 10234370Sjasone+ <para>The following configuration options are enabled in libc's built-in 11234370Sjasone+ jemalloc: <option>--enable-dss</option>, 12234370Sjasone+ <option>--enable-experimental</option>, <option>--enable-fill</option>, 13234370Sjasone+ <option>--enable-lazy-lock</option>, <option>--enable-munmap</option>, 14234370Sjasone+ <option>--enable-stats</option>, <option>--enable-tcache</option>, 15234370Sjasone+ <option>--enable-tls</option>, <option>--enable-utrace</option>, and 16234370Sjasone+ <option>--enable-xmalloc</option>. Additionally, 17234370Sjasone+ <option>--enable-debug</option> is enabled in development versions of 18234370Sjasone+ FreeBSD (controlled by the <constant>MALLOC_PRODUCTION</constant> make 19234370Sjasone+ variable).</para> 20234370Sjasone </refsect1> 21234370Sjasone <refsynopsisdiv> 22234370Sjasone <title>SYNOPSIS</title> 23234370Sjasone <funcsynopsis> 24234370Sjasone <funcsynopsisinfo>#include <<filename class="headerfile">stdlib.h</filename>> 25234370Sjasone-#include <<filename class="headerfile">jemalloc/jemalloc.h</filename>></funcsynopsisinfo> 26234370Sjasone+#include <<filename class="headerfile">malloc_np.h</filename>></funcsynopsisinfo> 27234370Sjasone <refsect2> 28234370Sjasone <title>Standard API</title> 29234370Sjasone <funcprototype> 30251300Sjasone@@ -2180,4 +2191,16 @@ malloc_conf = "lg_chunk:24";]]></programlisting></para> 31234370Sjasone <para>The <function>posix_memalign<parameter/></function> function conforms 32234370Sjasone to IEEE Std 1003.1-2001 (“POSIX.1”).</para> 33234370Sjasone </refsect1> 34234370Sjasone+ <refsect1 id="history"> 35234370Sjasone+ <title>HISTORY</title> 36234370Sjasone+ <para>The <function>malloc_usable_size<parameter/></function> and 37234370Sjasone+ <function>posix_memalign<parameter/></function> functions first appeared in 38234370Sjasone+ FreeBSD 7.0.</para> 39234370Sjasone+ 40234370Sjasone+ <para>The <function>aligned_alloc<parameter/></function>, 41234370Sjasone+ <function>malloc_stats_print<parameter/></function>, 42234370Sjasone+ <function>mallctl*<parameter/></function>, and 43234370Sjasone+ <function>*allocm<parameter/></function> functions first appeared in 44234370Sjasone+ FreeBSD 10.0.</para> 45234370Sjasone+ </refsect1> 46234370Sjasone </refentry> 47234370Sjasonediff --git a/include/jemalloc/internal/jemalloc_internal.h.in b/include/jemalloc/internal/jemalloc_internal.h.in 48251300Sjasoneindex e46ac54..527449d 100644 49234370Sjasone--- a/include/jemalloc/internal/jemalloc_internal.h.in 50234370Sjasone+++ b/include/jemalloc/internal/jemalloc_internal.h.in 51234402Sjasone@@ -1,5 +1,8 @@ 52234402Sjasone #ifndef JEMALLOC_INTERNAL_H 53234402Sjasone #define JEMALLOC_INTERNAL_H 54234370Sjasone+#include "libc_private.h" 55234370Sjasone+#include "namespace.h" 56234370Sjasone+ 57234370Sjasone #include <math.h> 58235238Sjasone #ifdef _WIN32 59235238Sjasone # include <windows.h> 60235238Sjasone@@ -54,6 +57,9 @@ typedef intptr_t ssize_t; 61235238Sjasone #endif 62235238Sjasone #include <fcntl.h> 63234370Sjasone 64234370Sjasone+#include "un-namespace.h" 65234370Sjasone+#include "libc_private.h" 66234370Sjasone+ 67234370Sjasone #define JEMALLOC_NO_DEMANGLE 68234370Sjasone #include "../jemalloc@install_suffix@.h" 69234370Sjasone 70235385Sjasone@@ -95,13 +101,7 @@ static const bool config_fill = 71235385Sjasone false 72235385Sjasone #endif 73235385Sjasone ; 74235385Sjasone-static const bool config_lazy_lock = 75235385Sjasone-#ifdef JEMALLOC_LAZY_LOCK 76235385Sjasone- true 77235385Sjasone-#else 78235385Sjasone- false 79235385Sjasone-#endif 80235385Sjasone- ; 81235385Sjasone+static const bool config_lazy_lock = true; 82235385Sjasone static const bool config_prof = 83235385Sjasone #ifdef JEMALLOC_PROF 84235385Sjasone true 85234370Sjasonediff --git a/include/jemalloc/internal/mutex.h b/include/jemalloc/internal/mutex.h 86235238Sjasoneindex de44e14..564d604 100644 87234370Sjasone--- a/include/jemalloc/internal/mutex.h 88234370Sjasone+++ b/include/jemalloc/internal/mutex.h 89235238Sjasone@@ -43,9 +43,6 @@ struct malloc_mutex_s { 90234370Sjasone 91234370Sjasone #ifdef JEMALLOC_LAZY_LOCK 92234370Sjasone extern bool isthreaded; 93234370Sjasone-#else 94234543Sjasone-# undef isthreaded /* Undo private_namespace.h definition. */ 95234370Sjasone-# define isthreaded true 96234370Sjasone #endif 97234370Sjasone 98234370Sjasone bool malloc_mutex_init(malloc_mutex_t *mutex); 99234543Sjasonediff --git a/include/jemalloc/internal/private_namespace.h b/include/jemalloc/internal/private_namespace.h 100251300Sjasoneindex 65de316..366676b 100644 101234543Sjasone--- a/include/jemalloc/internal/private_namespace.h 102234543Sjasone+++ b/include/jemalloc/internal/private_namespace.h 103245868Sjasone@@ -216,7 +216,6 @@ 104234543Sjasone #define iralloc JEMALLOC_N(iralloc) 105242844Sjasone #define irallocx JEMALLOC_N(irallocx) 106234543Sjasone #define isalloc JEMALLOC_N(isalloc) 107234543Sjasone-#define isthreaded JEMALLOC_N(isthreaded) 108234543Sjasone #define ivsalloc JEMALLOC_N(ivsalloc) 109234543Sjasone #define jemalloc_postfork_child JEMALLOC_N(jemalloc_postfork_child) 110234543Sjasone #define jemalloc_postfork_parent JEMALLOC_N(jemalloc_postfork_parent) 111234370Sjasonediff --git a/include/jemalloc/jemalloc.h.in b/include/jemalloc/jemalloc.h.in 112242844Sjasoneindex 31b1304..c3ef2f5 100644 113234370Sjasone--- a/include/jemalloc/jemalloc.h.in 114234370Sjasone+++ b/include/jemalloc/jemalloc.h.in 115234370Sjasone@@ -15,6 +15,7 @@ extern "C" { 116234370Sjasone #define JEMALLOC_VERSION_GID "@jemalloc_version_gid@" 117234370Sjasone 118234370Sjasone #include "jemalloc_defs@install_suffix@.h" 119234370Sjasone+#include "jemalloc_FreeBSD.h" 120234370Sjasone 121234370Sjasone #ifdef JEMALLOC_EXPERIMENTAL 122234370Sjasone #define ALLOCM_LG_ALIGN(la) (la) 123234370Sjasonediff --git a/include/jemalloc/jemalloc_FreeBSD.h b/include/jemalloc/jemalloc_FreeBSD.h 124234370Sjasonenew file mode 100644 125251300Sjasoneindex 0000000..e6c8407 126234370Sjasone--- /dev/null 127234370Sjasone+++ b/include/jemalloc/jemalloc_FreeBSD.h 128251300Sjasone@@ -0,0 +1,117 @@ 129234370Sjasone+/* 130234370Sjasone+ * Override settings that were generated in jemalloc_defs.h as necessary. 131234370Sjasone+ */ 132234370Sjasone+ 133234370Sjasone+#undef JEMALLOC_OVERRIDE_VALLOC 134234370Sjasone+ 135234370Sjasone+#ifndef MALLOC_PRODUCTION 136234370Sjasone+#define JEMALLOC_DEBUG 137234370Sjasone+#endif 138234370Sjasone+ 139234370Sjasone+/* 140234370Sjasone+ * The following are architecture-dependent, so conditionally define them for 141234370Sjasone+ * each supported architecture. 142234370Sjasone+ */ 143234370Sjasone+#undef CPU_SPINWAIT 144234370Sjasone+#undef JEMALLOC_TLS_MODEL 145234370Sjasone+#undef STATIC_PAGE_SHIFT 146234370Sjasone+#undef LG_SIZEOF_PTR 147234370Sjasone+#undef LG_SIZEOF_INT 148234370Sjasone+#undef LG_SIZEOF_LONG 149234370Sjasone+#undef LG_SIZEOF_INTMAX_T 150234370Sjasone+ 151234370Sjasone+#ifdef __i386__ 152234370Sjasone+# define LG_SIZEOF_PTR 2 153234370Sjasone+# define CPU_SPINWAIT __asm__ volatile("pause") 154234370Sjasone+# define JEMALLOC_TLS_MODEL __attribute__((tls_model("initial-exec"))) 155234370Sjasone+#endif 156234370Sjasone+#ifdef __ia64__ 157234370Sjasone+# define LG_SIZEOF_PTR 3 158234370Sjasone+#endif 159234370Sjasone+#ifdef __sparc64__ 160234370Sjasone+# define LG_SIZEOF_PTR 3 161234370Sjasone+# define JEMALLOC_TLS_MODEL __attribute__((tls_model("initial-exec"))) 162234370Sjasone+#endif 163234370Sjasone+#ifdef __amd64__ 164234370Sjasone+# define LG_SIZEOF_PTR 3 165234370Sjasone+# define CPU_SPINWAIT __asm__ volatile("pause") 166234370Sjasone+# define JEMALLOC_TLS_MODEL __attribute__((tls_model("initial-exec"))) 167234370Sjasone+#endif 168234370Sjasone+#ifdef __arm__ 169234370Sjasone+# define LG_SIZEOF_PTR 2 170234370Sjasone+#endif 171234370Sjasone+#ifdef __mips__ 172235238Sjasone+#ifdef __mips_n64 173235238Sjasone+# define LG_SIZEOF_PTR 3 174235238Sjasone+#else 175234370Sjasone+# define LG_SIZEOF_PTR 2 176234370Sjasone+#endif 177235238Sjasone+#endif 178234370Sjasone+#ifdef __powerpc64__ 179234370Sjasone+# define LG_SIZEOF_PTR 3 180234370Sjasone+#elif defined(__powerpc__) 181234370Sjasone+# define LG_SIZEOF_PTR 2 182234370Sjasone+#endif 183234370Sjasone+ 184234370Sjasone+#ifndef JEMALLOC_TLS_MODEL 185234370Sjasone+# define JEMALLOC_TLS_MODEL /* Default. */ 186234370Sjasone+#endif 187234370Sjasone+ 188234370Sjasone+#define STATIC_PAGE_SHIFT PAGE_SHIFT 189234370Sjasone+#define LG_SIZEOF_INT 2 190234370Sjasone+#define LG_SIZEOF_LONG LG_SIZEOF_PTR 191234370Sjasone+#define LG_SIZEOF_INTMAX_T 3 192234370Sjasone+ 193234370Sjasone+/* Disable lazy-lock machinery, mangle isthreaded, and adjust its type. */ 194234370Sjasone+#undef JEMALLOC_LAZY_LOCK 195234370Sjasone+extern int __isthreaded; 196234370Sjasone+#define isthreaded ((bool)__isthreaded) 197234370Sjasone+ 198234370Sjasone+/* Mangle. */ 199251300Sjasone+#undef je_malloc 200251300Sjasone+#undef je_calloc 201251300Sjasone+#undef je_realloc 202251300Sjasone+#undef je_free 203251300Sjasone+#undef je_posix_memalign 204251300Sjasone+#undef je_malloc_usable_size 205251300Sjasone+#undef je_allocm 206251300Sjasone+#undef je_rallocm 207251300Sjasone+#undef je_sallocm 208251300Sjasone+#undef je_dallocm 209251300Sjasone+#undef je_nallocm 210251300Sjasone+#define je_malloc __malloc 211251300Sjasone+#define je_calloc __calloc 212251300Sjasone+#define je_realloc __realloc 213251300Sjasone+#define je_free __free 214251300Sjasone+#define je_posix_memalign __posix_memalign 215251300Sjasone+#define je_malloc_usable_size __malloc_usable_size 216251300Sjasone+#define je_allocm __allocm 217251300Sjasone+#define je_rallocm __rallocm 218251300Sjasone+#define je_sallocm __sallocm 219251300Sjasone+#define je_dallocm __dallocm 220251300Sjasone+#define je_nallocm __nallocm 221234370Sjasone+#define open _open 222234370Sjasone+#define read _read 223234370Sjasone+#define write _write 224234370Sjasone+#define close _close 225234370Sjasone+#define pthread_mutex_lock _pthread_mutex_lock 226234370Sjasone+#define pthread_mutex_unlock _pthread_mutex_unlock 227251300Sjasone+ 228251300Sjasone+#ifdef JEMALLOC_C_ 229251300Sjasone+/* 230251300Sjasone+ * Define 'weak' symbols so that an application can have its own versions 231251300Sjasone+ * of malloc, calloc, realloc, free, et al. 232251300Sjasone+ */ 233251300Sjasone+__weak_reference(__malloc, malloc); 234251300Sjasone+__weak_reference(__calloc, calloc); 235251300Sjasone+__weak_reference(__realloc, realloc); 236251300Sjasone+__weak_reference(__free, free); 237251300Sjasone+__weak_reference(__posix_memalign, posix_memalign); 238251300Sjasone+__weak_reference(__malloc_usable_size, malloc_usable_size); 239251300Sjasone+__weak_reference(__allocm, allocm); 240251300Sjasone+__weak_reference(__rallocm, rallocm); 241251300Sjasone+__weak_reference(__sallocm, sallocm); 242251300Sjasone+__weak_reference(__dallocm, dallocm); 243251300Sjasone+__weak_reference(__nallocm, nallocm); 244251300Sjasone+#endif 245251300Sjasone+ 246234370Sjasonediff --git a/src/jemalloc.c b/src/jemalloc.c 247251300Sjasoneindex bc350ed..352c98e 100644 248234370Sjasone--- a/src/jemalloc.c 249234370Sjasone+++ b/src/jemalloc.c 250235238Sjasone@@ -8,6 +8,10 @@ malloc_tsd_data(, arenas, arena_t *, NULL) 251234370Sjasone malloc_tsd_data(, thread_allocated, thread_allocated_t, 252234370Sjasone THREAD_ALLOCATED_INITIALIZER) 253234370Sjasone 254235238Sjasone+/* Work around <http://llvm.org/bugs/show_bug.cgi?id=12623>: */ 255235238Sjasone+const char *__malloc_options_1_0 = NULL; 256234370Sjasone+__sym_compat(_malloc_options, __malloc_options_1_0, FBSD_1.0); 257234370Sjasone+ 258234370Sjasone /* Runtime configuration options. */ 259235238Sjasone const char *je_malloc_conf; 260245868Sjasone bool opt_abort = 261251300Sjasone@@ -471,7 +475,8 @@ malloc_conf_init(void) 262234370Sjasone #endif 263234370Sjasone ; 264234370Sjasone 265234370Sjasone- if ((opts = getenv(envname)) != NULL) { 266234370Sjasone+ if (issetugid() == 0 && (opts = getenv(envname)) != 267234370Sjasone+ NULL) { 268234370Sjasone /* 269234370Sjasone * Do nothing; opts is already initialized to 270234370Sjasone * the value of the MALLOC_CONF environment 271234370Sjasonediff --git a/src/mutex.c b/src/mutex.c 272242844Sjasoneindex 55e18c2..6b6f438 100644 273234370Sjasone--- a/src/mutex.c 274234370Sjasone+++ b/src/mutex.c 275235238Sjasone@@ -66,6 +66,17 @@ pthread_create(pthread_t *__restrict thread, 276234370Sjasone #ifdef JEMALLOC_MUTEX_INIT_CB 277242844Sjasone JEMALLOC_EXPORT int _pthread_mutex_init_calloc_cb(pthread_mutex_t *mutex, 278234370Sjasone void *(calloc_cb)(size_t, size_t)); 279234370Sjasone+ 280234370Sjasone+__weak_reference(_pthread_mutex_init_calloc_cb_stub, 281234370Sjasone+ _pthread_mutex_init_calloc_cb); 282234370Sjasone+ 283234370Sjasone+int 284234370Sjasone+_pthread_mutex_init_calloc_cb_stub(pthread_mutex_t *mutex, 285234370Sjasone+ void *(calloc_cb)(size_t, size_t)) 286234370Sjasone+{ 287234370Sjasone+ 288234370Sjasone+ return (0); 289234370Sjasone+} 290234370Sjasone #endif 291234370Sjasone 292234370Sjasone bool 293234370Sjasonediff --git a/src/util.c b/src/util.c 294242844Sjasoneindex b3a0114..df1c5d5 100644 295234370Sjasone--- a/src/util.c 296234370Sjasone+++ b/src/util.c 297235238Sjasone@@ -58,6 +58,22 @@ wrtmessage(void *cbopaque, const char *s) 298234370Sjasone 299235238Sjasone JEMALLOC_EXPORT void (*je_malloc_message)(void *, const char *s); 300235238Sjasone 301235238Sjasone+JEMALLOC_ATTR(visibility("hidden")) 302234370Sjasone+void 303234370Sjasone+wrtmessage_1_0(const char *s1, const char *s2, const char *s3, 304234370Sjasone+ const char *s4) 305234370Sjasone+{ 306234370Sjasone+ 307234370Sjasone+ wrtmessage(NULL, s1); 308234370Sjasone+ wrtmessage(NULL, s2); 309234370Sjasone+ wrtmessage(NULL, s3); 310234370Sjasone+ wrtmessage(NULL, s4); 311234370Sjasone+} 312234370Sjasone+ 313234370Sjasone+void (*__malloc_message_1_0)(const char *s1, const char *s2, const char *s3, 314234370Sjasone+ const char *s4) = wrtmessage_1_0; 315234370Sjasone+__sym_compat(_malloc_message, __malloc_message_1_0, FBSD_1.0); 316234370Sjasone+ 317234370Sjasone /* 318235238Sjasone * Wrapper around malloc_message() that avoids the need for 319235238Sjasone * je_malloc_message(...) throughout the code. 320