1a4bd5210SJason Evansdiff --git a/doc/jemalloc.xml.in b/doc/jemalloc.xml.in 2*bde95144SJason Evansindex 3d2e721..b361db2 100644 3a4bd5210SJason Evans--- a/doc/jemalloc.xml.in 4a4bd5210SJason Evans+++ b/doc/jemalloc.xml.in 5c13244b9SJason Evans@@ -53,11 +53,23 @@ 6a4bd5210SJason Evans <para>This manual describes jemalloc @jemalloc_version@. More information 7a4bd5210SJason Evans can be found at the <ulink 8*bde95144SJason Evans url="http://jemalloc.net/">jemalloc website</ulink>.</para> 9a4bd5210SJason Evans+ 10a4bd5210SJason Evans+ <para>The following configuration options are enabled in libc's built-in 11d0e79aa3SJason Evans+ jemalloc: <option>--enable-fill</option>, 12a4bd5210SJason Evans+ <option>--enable-lazy-lock</option>, <option>--enable-munmap</option>, 13a4bd5210SJason Evans+ <option>--enable-stats</option>, <option>--enable-tcache</option>, 14a4bd5210SJason Evans+ <option>--enable-tls</option>, <option>--enable-utrace</option>, and 15a4bd5210SJason Evans+ <option>--enable-xmalloc</option>. Additionally, 16a4bd5210SJason Evans+ <option>--enable-debug</option> is enabled in development versions of 17a4bd5210SJason Evans+ FreeBSD (controlled by the <constant>MALLOC_PRODUCTION</constant> make 18a4bd5210SJason Evans+ variable).</para> 19d0e79aa3SJason Evans+ 20a4bd5210SJason Evans </refsect1> 21a4bd5210SJason Evans <refsynopsisdiv> 22a4bd5210SJason Evans <title>SYNOPSIS</title> 23c13244b9SJason Evans <funcsynopsis> 24c13244b9SJason Evans- <funcsynopsisinfo>#include <<filename class="headerfile">jemalloc/jemalloc.h</filename>></funcsynopsisinfo> 25c13244b9SJason Evans+ <funcsynopsisinfo>#include <<filename class="headerfile">stdlib.h</filename>> 26c13244b9SJason Evans+#include <<filename class="headerfile">malloc_np.h</filename>></funcsynopsisinfo> 27c13244b9SJason Evans <refsect2> 28c13244b9SJason Evans <title>Standard API</title> 29c13244b9SJason Evans <funcprototype> 30*bde95144SJason Evans@@ -2963,4 +2975,18 @@ malloc_conf = "lg_chunk:24";]]></programlisting></para> 31*bde95144SJason Evans <para>The <function>posix_memalign()</function> function conforms 32*bde95144SJason Evans to IEEE Std 1003.1-2001 (<quote>POSIX.1</quote>).</para> 33a4bd5210SJason Evans </refsect1> 34a4bd5210SJason Evans+ <refsect1 id="history"> 35a4bd5210SJason Evans+ <title>HISTORY</title> 36*bde95144SJason Evans+ <para>The <function>malloc_usable_size()</function> and 37*bde95144SJason Evans+ <function>posix_memalign()</function> functions first appeared in FreeBSD 38*bde95144SJason Evans+ 7.0.</para> 39a4bd5210SJason Evans+ 40*bde95144SJason Evans+ <para>The <function>aligned_alloc()</function>, 41*bde95144SJason Evans+ <function>malloc_stats_print()</function>, and 42*bde95144SJason Evans+ <function>mallctl*()</function> functions first appeared in FreeBSD 43*bde95144SJason Evans+ 10.0.</para> 44f921d10fSJason Evans+ 45*bde95144SJason Evans+ <para>The <function>*allocx()</function> functions first appeared in FreeBSD 46*bde95144SJason Evans+ 11.0.</para> 47a4bd5210SJason Evans+ </refsect1> 48a4bd5210SJason Evans </refentry> 49fbb1d85eSJason Evansdiff --git a/include/jemalloc/internal/arena.h b/include/jemalloc/internal/arena.h 50*bde95144SJason Evansindex f39ce54..a3ba55d 100644 51fbb1d85eSJason Evans--- a/include/jemalloc/internal/arena.h 52fbb1d85eSJason Evans+++ b/include/jemalloc/internal/arena.h 53*bde95144SJason Evans@@ -719,8 +719,13 @@ arena_miscelm_get_mutable(arena_chunk_t *chunk, size_t pageind) 54fbb1d85eSJason Evans JEMALLOC_ALWAYS_INLINE const arena_chunk_map_misc_t * 55fbb1d85eSJason Evans arena_miscelm_get_const(const arena_chunk_t *chunk, size_t pageind) 56fbb1d85eSJason Evans { 57fbb1d85eSJason Evans+#if 1 /* Work around gcc bug. */ 58fbb1d85eSJason Evans+ arena_chunk_t *mchunk = (arena_chunk_t *)chunk; 59fbb1d85eSJason Evans 60fbb1d85eSJason Evans+ return (arena_miscelm_get_mutable(mchunk, pageind)); 61fbb1d85eSJason Evans+#else 62fbb1d85eSJason Evans return (arena_miscelm_get_mutable((arena_chunk_t *)chunk, pageind)); 63fbb1d85eSJason Evans+#endif 64fbb1d85eSJason Evans } 65fbb1d85eSJason Evans 66fbb1d85eSJason Evans JEMALLOC_ALWAYS_INLINE size_t 67*bde95144SJason Evans@@ -779,8 +784,13 @@ arena_mapbitsp_get_mutable(arena_chunk_t *chunk, size_t pageind) 68fbb1d85eSJason Evans JEMALLOC_ALWAYS_INLINE const size_t * 69fbb1d85eSJason Evans arena_mapbitsp_get_const(const arena_chunk_t *chunk, size_t pageind) 70fbb1d85eSJason Evans { 71fbb1d85eSJason Evans+#if 1 /* Work around gcc bug. */ 72fbb1d85eSJason Evans+ arena_chunk_t *mchunk = (arena_chunk_t *)chunk; 73fbb1d85eSJason Evans 74fbb1d85eSJason Evans+ return (arena_mapbitsp_get_mutable(mchunk, pageind)); 75fbb1d85eSJason Evans+#else 76fbb1d85eSJason Evans return (arena_mapbitsp_get_mutable((arena_chunk_t *)chunk, pageind)); 77fbb1d85eSJason Evans+#endif 78fbb1d85eSJason Evans } 79fbb1d85eSJason Evans 80fbb1d85eSJason Evans JEMALLOC_ALWAYS_INLINE size_t 81a4bd5210SJason Evansdiff --git a/include/jemalloc/internal/jemalloc_internal.h.in b/include/jemalloc/internal/jemalloc_internal.h.in 82*bde95144SJason Evansindex fdc8fef..56a35a4 100644 83a4bd5210SJason Evans--- a/include/jemalloc/internal/jemalloc_internal.h.in 84a4bd5210SJason Evans+++ b/include/jemalloc/internal/jemalloc_internal.h.in 85d0e79aa3SJason Evans@@ -8,6 +8,9 @@ 86d0e79aa3SJason Evans #include <sys/ktrace.h> 87e722f8f8SJason Evans #endif 88a4bd5210SJason Evans 89a4bd5210SJason Evans+#include "un-namespace.h" 90a4bd5210SJason Evans+#include "libc_private.h" 91a4bd5210SJason Evans+ 92a4bd5210SJason Evans #define JEMALLOC_NO_DEMANGLE 93f921d10fSJason Evans #ifdef JEMALLOC_JET 94f921d10fSJason Evans # define JEMALLOC_N(n) jet_##n 95d0e79aa3SJason Evans@@ -42,13 +45,7 @@ static const bool config_fill = 96edaa25bdSJason Evans false 97edaa25bdSJason Evans #endif 98edaa25bdSJason Evans ; 99edaa25bdSJason Evans-static const bool config_lazy_lock = 100edaa25bdSJason Evans-#ifdef JEMALLOC_LAZY_LOCK 101edaa25bdSJason Evans- true 102edaa25bdSJason Evans-#else 103edaa25bdSJason Evans- false 104edaa25bdSJason Evans-#endif 105edaa25bdSJason Evans- ; 106edaa25bdSJason Evans+static const bool config_lazy_lock = true; 107df0d881dSJason Evans static const char * const config_malloc_conf = JEMALLOC_CONFIG_MALLOC_CONF; 108edaa25bdSJason Evans static const bool config_prof = 109edaa25bdSJason Evans #ifdef JEMALLOC_PROF 110d0e79aa3SJason Evansdiff --git a/include/jemalloc/internal/jemalloc_internal_decls.h b/include/jemalloc/internal/jemalloc_internal_decls.h 111*bde95144SJason Evansindex c907d91..4626632 100644 112d0e79aa3SJason Evans--- a/include/jemalloc/internal/jemalloc_internal_decls.h 113d0e79aa3SJason Evans+++ b/include/jemalloc/internal/jemalloc_internal_decls.h 114d0e79aa3SJason Evans@@ -1,6 +1,9 @@ 115d0e79aa3SJason Evans #ifndef JEMALLOC_INTERNAL_DECLS_H 116d0e79aa3SJason Evans #define JEMALLOC_INTERNAL_DECLS_H 117d0e79aa3SJason Evans 118d0e79aa3SJason Evans+#include "libc_private.h" 119d0e79aa3SJason Evans+#include "namespace.h" 120d0e79aa3SJason Evans+ 121d0e79aa3SJason Evans #include <math.h> 122d0e79aa3SJason Evans #ifdef _WIN32 123d0e79aa3SJason Evans # include <windows.h> 124a4bd5210SJason Evansdiff --git a/include/jemalloc/internal/mutex.h b/include/jemalloc/internal/mutex.h 125*bde95144SJason Evansindex b442d2d..76518db 100644 126a4bd5210SJason Evans--- a/include/jemalloc/internal/mutex.h 127a4bd5210SJason Evans+++ b/include/jemalloc/internal/mutex.h 128*bde95144SJason Evans@@ -57,9 +57,6 @@ struct malloc_mutex_s { 129a4bd5210SJason Evans 130a4bd5210SJason Evans #ifdef JEMALLOC_LAZY_LOCK 131a4bd5210SJason Evans extern bool isthreaded; 132a4bd5210SJason Evans-#else 1338ed34ab0SJason Evans-# undef isthreaded /* Undo private_namespace.h definition. */ 134a4bd5210SJason Evans-# define isthreaded true 135a4bd5210SJason Evans #endif 136a4bd5210SJason Evans 1371f0a49e8SJason Evans bool malloc_mutex_init(malloc_mutex_t *mutex, const char *name, 138*bde95144SJason Evans@@ -67,6 +64,7 @@ bool malloc_mutex_init(malloc_mutex_t *mutex, const char *name, 1391f0a49e8SJason Evans void malloc_mutex_prefork(tsdn_t *tsdn, malloc_mutex_t *mutex); 1401f0a49e8SJason Evans void malloc_mutex_postfork_parent(tsdn_t *tsdn, malloc_mutex_t *mutex); 1411f0a49e8SJason Evans void malloc_mutex_postfork_child(tsdn_t *tsdn, malloc_mutex_t *mutex); 142d0e79aa3SJason Evans+bool malloc_mutex_first_thread(void); 1431f0a49e8SJason Evans bool malloc_mutex_boot(void); 144d0e79aa3SJason Evans 145d0e79aa3SJason Evans #endif /* JEMALLOC_H_EXTERNS */ 146f921d10fSJason Evansdiff --git a/include/jemalloc/internal/private_symbols.txt b/include/jemalloc/internal/private_symbols.txt 147*bde95144SJason Evansindex 87c8c9b..df576f6 100644 148f921d10fSJason Evans--- a/include/jemalloc/internal/private_symbols.txt 149f921d10fSJason Evans+++ b/include/jemalloc/internal/private_symbols.txt 150*bde95144SJason Evans@@ -307,7 +307,6 @@ iralloct_realign 151f921d10fSJason Evans isalloc 152d0e79aa3SJason Evans isdalloct 153d0e79aa3SJason Evans isqalloc 154f921d10fSJason Evans-isthreaded 155f921d10fSJason Evans ivsalloc 156f921d10fSJason Evans ixalloc 157f921d10fSJason Evans jemalloc_postfork_child 158a4bd5210SJason Evansdiff --git a/include/jemalloc/jemalloc_FreeBSD.h b/include/jemalloc/jemalloc_FreeBSD.h 159a4bd5210SJason Evansnew file mode 100644 1601f0a49e8SJason Evansindex 0000000..c58a8f3 161a4bd5210SJason Evans--- /dev/null 162a4bd5210SJason Evans+++ b/include/jemalloc/jemalloc_FreeBSD.h 1631f0a49e8SJason Evans@@ -0,0 +1,162 @@ 164a4bd5210SJason Evans+/* 165a4bd5210SJason Evans+ * Override settings that were generated in jemalloc_defs.h as necessary. 166a4bd5210SJason Evans+ */ 167a4bd5210SJason Evans+ 168a4bd5210SJason Evans+#undef JEMALLOC_OVERRIDE_VALLOC 169a4bd5210SJason Evans+ 170a4bd5210SJason Evans+#ifndef MALLOC_PRODUCTION 171a4bd5210SJason Evans+#define JEMALLOC_DEBUG 172a4bd5210SJason Evans+#endif 173a4bd5210SJason Evans+ 1741f0a49e8SJason Evans+#undef JEMALLOC_DSS 1751f0a49e8SJason Evans+ 176a4bd5210SJason Evans+/* 177a4bd5210SJason Evans+ * The following are architecture-dependent, so conditionally define them for 178a4bd5210SJason Evans+ * each supported architecture. 179a4bd5210SJason Evans+ */ 180a4bd5210SJason Evans+#undef JEMALLOC_TLS_MODEL 181a4bd5210SJason Evans+#undef STATIC_PAGE_SHIFT 182a4bd5210SJason Evans+#undef LG_SIZEOF_PTR 183a4bd5210SJason Evans+#undef LG_SIZEOF_INT 184a4bd5210SJason Evans+#undef LG_SIZEOF_LONG 185a4bd5210SJason Evans+#undef LG_SIZEOF_INTMAX_T 186a4bd5210SJason Evans+ 187a4bd5210SJason Evans+#ifdef __i386__ 188a4bd5210SJason Evans+# define LG_SIZEOF_PTR 2 189a4bd5210SJason Evans+# define JEMALLOC_TLS_MODEL __attribute__((tls_model("initial-exec"))) 190a4bd5210SJason Evans+#endif 191a4bd5210SJason Evans+#ifdef __ia64__ 192a4bd5210SJason Evans+# define LG_SIZEOF_PTR 3 193a4bd5210SJason Evans+#endif 194a4bd5210SJason Evans+#ifdef __sparc64__ 195a4bd5210SJason Evans+# define LG_SIZEOF_PTR 3 196a4bd5210SJason Evans+# define JEMALLOC_TLS_MODEL __attribute__((tls_model("initial-exec"))) 197a4bd5210SJason Evans+#endif 198a4bd5210SJason Evans+#ifdef __amd64__ 199a4bd5210SJason Evans+# define LG_SIZEOF_PTR 3 200a4bd5210SJason Evans+# define JEMALLOC_TLS_MODEL __attribute__((tls_model("initial-exec"))) 201a4bd5210SJason Evans+#endif 202a4bd5210SJason Evans+#ifdef __arm__ 203a4bd5210SJason Evans+# define LG_SIZEOF_PTR 2 204a4bd5210SJason Evans+#endif 205d8e39d2dSJason Evans+#ifdef __aarch64__ 206d8e39d2dSJason Evans+# define LG_SIZEOF_PTR 3 207d8e39d2dSJason Evans+#endif 208a4bd5210SJason Evans+#ifdef __mips__ 209e722f8f8SJason Evans+#ifdef __mips_n64 210e722f8f8SJason Evans+# define LG_SIZEOF_PTR 3 211e722f8f8SJason Evans+#else 212a4bd5210SJason Evans+# define LG_SIZEOF_PTR 2 213a4bd5210SJason Evans+#endif 214e722f8f8SJason Evans+#endif 215a4bd5210SJason Evans+#ifdef __powerpc64__ 216a4bd5210SJason Evans+# define LG_SIZEOF_PTR 3 217a4bd5210SJason Evans+#elif defined(__powerpc__) 218a4bd5210SJason Evans+# define LG_SIZEOF_PTR 2 219a4bd5210SJason Evans+#endif 220df0d881dSJason Evans+#ifdef __riscv__ 221df0d881dSJason Evans+# define LG_SIZEOF_PTR 3 222df0d881dSJason Evans+#endif 223a4bd5210SJason Evans+ 224a4bd5210SJason Evans+#ifndef JEMALLOC_TLS_MODEL 225a4bd5210SJason Evans+# define JEMALLOC_TLS_MODEL /* Default. */ 226a4bd5210SJason Evans+#endif 227a4bd5210SJason Evans+ 228a4bd5210SJason Evans+#define STATIC_PAGE_SHIFT PAGE_SHIFT 229a4bd5210SJason Evans+#define LG_SIZEOF_INT 2 230a4bd5210SJason Evans+#define LG_SIZEOF_LONG LG_SIZEOF_PTR 231a4bd5210SJason Evans+#define LG_SIZEOF_INTMAX_T 3 232a4bd5210SJason Evans+ 233337776f8SJason Evans+#undef CPU_SPINWAIT 234337776f8SJason Evans+#include <machine/cpu.h> 235337776f8SJason Evans+#include <machine/cpufunc.h> 236337776f8SJason Evans+#define CPU_SPINWAIT cpu_spinwait() 237337776f8SJason Evans+ 238a4bd5210SJason Evans+/* Disable lazy-lock machinery, mangle isthreaded, and adjust its type. */ 239a4bd5210SJason Evans+#undef JEMALLOC_LAZY_LOCK 240a4bd5210SJason Evans+extern int __isthreaded; 241a4bd5210SJason Evans+#define isthreaded ((bool)__isthreaded) 242a4bd5210SJason Evans+ 243a4bd5210SJason Evans+/* Mangle. */ 244f8ca2db1SJason Evans+#undef je_malloc 245f8ca2db1SJason Evans+#undef je_calloc 246f8ca2db1SJason Evans+#undef je_posix_memalign 247d0e79aa3SJason Evans+#undef je_aligned_alloc 248df0d881dSJason Evans+#undef je_realloc 249df0d881dSJason Evans+#undef je_free 250f8ca2db1SJason Evans+#undef je_malloc_usable_size 251f921d10fSJason Evans+#undef je_mallocx 252f921d10fSJason Evans+#undef je_rallocx 253f921d10fSJason Evans+#undef je_xallocx 254f921d10fSJason Evans+#undef je_sallocx 255f921d10fSJason Evans+#undef je_dallocx 256df0d881dSJason Evans+#undef je_sdallocx 257f921d10fSJason Evans+#undef je_nallocx 258df0d881dSJason Evans+#undef je_mallctl 259df0d881dSJason Evans+#undef je_mallctlnametomib 260df0d881dSJason Evans+#undef je_mallctlbymib 261df0d881dSJason Evans+#undef je_malloc_stats_print 262f8ca2db1SJason Evans+#undef je_allocm 263f8ca2db1SJason Evans+#undef je_rallocm 264f8ca2db1SJason Evans+#undef je_sallocm 265f8ca2db1SJason Evans+#undef je_dallocm 266f8ca2db1SJason Evans+#undef je_nallocm 267f8ca2db1SJason Evans+#define je_malloc __malloc 268f8ca2db1SJason Evans+#define je_calloc __calloc 269f8ca2db1SJason Evans+#define je_posix_memalign __posix_memalign 270d0e79aa3SJason Evans+#define je_aligned_alloc __aligned_alloc 271df0d881dSJason Evans+#define je_realloc __realloc 272df0d881dSJason Evans+#define je_free __free 273f8ca2db1SJason Evans+#define je_malloc_usable_size __malloc_usable_size 274f921d10fSJason Evans+#define je_mallocx __mallocx 275f921d10fSJason Evans+#define je_rallocx __rallocx 276f921d10fSJason Evans+#define je_xallocx __xallocx 277f921d10fSJason Evans+#define je_sallocx __sallocx 278f921d10fSJason Evans+#define je_dallocx __dallocx 279df0d881dSJason Evans+#define je_sdallocx __sdallocx 280f921d10fSJason Evans+#define je_nallocx __nallocx 281df0d881dSJason Evans+#define je_mallctl __mallctl 282df0d881dSJason Evans+#define je_mallctlnametomib __mallctlnametomib 283df0d881dSJason Evans+#define je_mallctlbymib __mallctlbymib 284df0d881dSJason Evans+#define je_malloc_stats_print __malloc_stats_print 285f8ca2db1SJason Evans+#define je_allocm __allocm 286f8ca2db1SJason Evans+#define je_rallocm __rallocm 287f8ca2db1SJason Evans+#define je_sallocm __sallocm 288f8ca2db1SJason Evans+#define je_dallocm __dallocm 289f8ca2db1SJason Evans+#define je_nallocm __nallocm 290a4bd5210SJason Evans+#define open _open 291a4bd5210SJason Evans+#define read _read 292a4bd5210SJason Evans+#define write _write 293a4bd5210SJason Evans+#define close _close 294a4bd5210SJason Evans+#define pthread_mutex_lock _pthread_mutex_lock 295a4bd5210SJason Evans+#define pthread_mutex_unlock _pthread_mutex_unlock 296f8ca2db1SJason Evans+ 297f8ca2db1SJason Evans+#ifdef JEMALLOC_C_ 298f8ca2db1SJason Evans+/* 299f8ca2db1SJason Evans+ * Define 'weak' symbols so that an application can have its own versions 300f8ca2db1SJason Evans+ * of malloc, calloc, realloc, free, et al. 301f8ca2db1SJason Evans+ */ 302f8ca2db1SJason Evans+__weak_reference(__malloc, malloc); 303f8ca2db1SJason Evans+__weak_reference(__calloc, calloc); 304f8ca2db1SJason Evans+__weak_reference(__posix_memalign, posix_memalign); 305d0e79aa3SJason Evans+__weak_reference(__aligned_alloc, aligned_alloc); 306df0d881dSJason Evans+__weak_reference(__realloc, realloc); 307df0d881dSJason Evans+__weak_reference(__free, free); 308f8ca2db1SJason Evans+__weak_reference(__malloc_usable_size, malloc_usable_size); 309f921d10fSJason Evans+__weak_reference(__mallocx, mallocx); 310f921d10fSJason Evans+__weak_reference(__rallocx, rallocx); 311f921d10fSJason Evans+__weak_reference(__xallocx, xallocx); 312f921d10fSJason Evans+__weak_reference(__sallocx, sallocx); 313f921d10fSJason Evans+__weak_reference(__dallocx, dallocx); 314df0d881dSJason Evans+__weak_reference(__sdallocx, sdallocx); 315f921d10fSJason Evans+__weak_reference(__nallocx, nallocx); 316df0d881dSJason Evans+__weak_reference(__mallctl, mallctl); 317df0d881dSJason Evans+__weak_reference(__mallctlnametomib, mallctlnametomib); 318df0d881dSJason Evans+__weak_reference(__mallctlbymib, mallctlbymib); 319df0d881dSJason Evans+__weak_reference(__malloc_stats_print, malloc_stats_print); 320f8ca2db1SJason Evans+__weak_reference(__allocm, allocm); 321f8ca2db1SJason Evans+__weak_reference(__rallocm, rallocm); 322f8ca2db1SJason Evans+__weak_reference(__sallocm, sallocm); 323f8ca2db1SJason Evans+__weak_reference(__dallocm, dallocm); 324f8ca2db1SJason Evans+__weak_reference(__nallocm, nallocm); 325f8ca2db1SJason Evans+#endif 326f921d10fSJason Evansdiff --git a/include/jemalloc/jemalloc_rename.sh b/include/jemalloc/jemalloc_rename.sh 327f921d10fSJason Evansindex f943891..47d032c 100755 328f921d10fSJason Evans--- a/include/jemalloc/jemalloc_rename.sh 329f921d10fSJason Evans+++ b/include/jemalloc/jemalloc_rename.sh 330f921d10fSJason Evans@@ -19,4 +19,6 @@ done 331f921d10fSJason Evans 332f921d10fSJason Evans cat <<EOF 333f921d10fSJason Evans #endif 334f8ca2db1SJason Evans+ 335f921d10fSJason Evans+#include "jemalloc_FreeBSD.h" 336f921d10fSJason Evans EOF 337a4bd5210SJason Evansdiff --git a/src/jemalloc.c b/src/jemalloc.c 338*bde95144SJason Evansindex 38650ff..f659b55 100644 339a4bd5210SJason Evans--- a/src/jemalloc.c 340a4bd5210SJason Evans+++ b/src/jemalloc.c 341d0e79aa3SJason Evans@@ -4,6 +4,10 @@ 342d0e79aa3SJason Evans /******************************************************************************/ 343d0e79aa3SJason Evans /* Data. */ 344a4bd5210SJason Evans 345e722f8f8SJason Evans+/* Work around <http://llvm.org/bugs/show_bug.cgi?id=12623>: */ 346e722f8f8SJason Evans+const char *__malloc_options_1_0 = NULL; 347a4bd5210SJason Evans+__sym_compat(_malloc_options, __malloc_options_1_0, FBSD_1.0); 348a4bd5210SJason Evans+ 349a4bd5210SJason Evans /* Runtime configuration options. */ 350*bde95144SJason Evans const char *je_malloc_conf 351*bde95144SJason Evans #ifndef _WIN32 352*bde95144SJason Evans@@ -2756,6 +2760,107 @@ je_malloc_usable_size(JEMALLOC_USABLE_SIZE_CONST void *ptr) 353d0e79aa3SJason Evans */ 354d0e79aa3SJason Evans /******************************************************************************/ 355a4bd5210SJason Evans /* 356d0e79aa3SJason Evans+ * Begin compatibility functions. 357d0e79aa3SJason Evans+ */ 358d0e79aa3SJason Evans+ 359d0e79aa3SJason Evans+#define ALLOCM_LG_ALIGN(la) (la) 360d0e79aa3SJason Evans+#define ALLOCM_ALIGN(a) (ffsl(a)-1) 361d0e79aa3SJason Evans+#define ALLOCM_ZERO ((int)0x40) 362d0e79aa3SJason Evans+#define ALLOCM_NO_MOVE ((int)0x80) 363d0e79aa3SJason Evans+ 364d0e79aa3SJason Evans+#define ALLOCM_SUCCESS 0 365d0e79aa3SJason Evans+#define ALLOCM_ERR_OOM 1 366d0e79aa3SJason Evans+#define ALLOCM_ERR_NOT_MOVED 2 367d0e79aa3SJason Evans+ 368d0e79aa3SJason Evans+int 369d0e79aa3SJason Evans+je_allocm(void **ptr, size_t *rsize, size_t size, int flags) 370d0e79aa3SJason Evans+{ 371d0e79aa3SJason Evans+ void *p; 372d0e79aa3SJason Evans+ 373d0e79aa3SJason Evans+ assert(ptr != NULL); 374d0e79aa3SJason Evans+ 375d0e79aa3SJason Evans+ p = je_mallocx(size, flags); 376d0e79aa3SJason Evans+ if (p == NULL) 377d0e79aa3SJason Evans+ return (ALLOCM_ERR_OOM); 378d0e79aa3SJason Evans+ if (rsize != NULL) 3791f0a49e8SJason Evans+ *rsize = isalloc(tsdn_fetch(), p, config_prof); 380d0e79aa3SJason Evans+ *ptr = p; 381d0e79aa3SJason Evans+ return (ALLOCM_SUCCESS); 382d0e79aa3SJason Evans+} 383d0e79aa3SJason Evans+ 384d0e79aa3SJason Evans+int 385d0e79aa3SJason Evans+je_rallocm(void **ptr, size_t *rsize, size_t size, size_t extra, int flags) 386d0e79aa3SJason Evans+{ 387d0e79aa3SJason Evans+ int ret; 388d0e79aa3SJason Evans+ bool no_move = flags & ALLOCM_NO_MOVE; 389d0e79aa3SJason Evans+ 390d0e79aa3SJason Evans+ assert(ptr != NULL); 391d0e79aa3SJason Evans+ assert(*ptr != NULL); 392d0e79aa3SJason Evans+ assert(size != 0); 393d0e79aa3SJason Evans+ assert(SIZE_T_MAX - size >= extra); 394d0e79aa3SJason Evans+ 395d0e79aa3SJason Evans+ if (no_move) { 396d0e79aa3SJason Evans+ size_t usize = je_xallocx(*ptr, size, extra, flags); 397d0e79aa3SJason Evans+ ret = (usize >= size) ? ALLOCM_SUCCESS : ALLOCM_ERR_NOT_MOVED; 398d0e79aa3SJason Evans+ if (rsize != NULL) 399d0e79aa3SJason Evans+ *rsize = usize; 400d0e79aa3SJason Evans+ } else { 401d0e79aa3SJason Evans+ void *p = je_rallocx(*ptr, size+extra, flags); 402d0e79aa3SJason Evans+ if (p != NULL) { 403d0e79aa3SJason Evans+ *ptr = p; 404d0e79aa3SJason Evans+ ret = ALLOCM_SUCCESS; 405d0e79aa3SJason Evans+ } else 406d0e79aa3SJason Evans+ ret = ALLOCM_ERR_OOM; 407d0e79aa3SJason Evans+ if (rsize != NULL) 4081f0a49e8SJason Evans+ *rsize = isalloc(tsdn_fetch(), *ptr, config_prof); 409d0e79aa3SJason Evans+ } 410d0e79aa3SJason Evans+ return (ret); 411d0e79aa3SJason Evans+} 412d0e79aa3SJason Evans+ 413d0e79aa3SJason Evans+int 414d0e79aa3SJason Evans+je_sallocm(const void *ptr, size_t *rsize, int flags) 415d0e79aa3SJason Evans+{ 416d0e79aa3SJason Evans+ 417d0e79aa3SJason Evans+ assert(rsize != NULL); 418d0e79aa3SJason Evans+ *rsize = je_sallocx(ptr, flags); 419d0e79aa3SJason Evans+ return (ALLOCM_SUCCESS); 420d0e79aa3SJason Evans+} 421d0e79aa3SJason Evans+ 422d0e79aa3SJason Evans+int 423d0e79aa3SJason Evans+je_dallocm(void *ptr, int flags) 424d0e79aa3SJason Evans+{ 425d0e79aa3SJason Evans+ 426d0e79aa3SJason Evans+ je_dallocx(ptr, flags); 427d0e79aa3SJason Evans+ return (ALLOCM_SUCCESS); 428d0e79aa3SJason Evans+} 429d0e79aa3SJason Evans+ 430d0e79aa3SJason Evans+int 431d0e79aa3SJason Evans+je_nallocm(size_t *rsize, size_t size, int flags) 432d0e79aa3SJason Evans+{ 433d0e79aa3SJason Evans+ size_t usize; 434d0e79aa3SJason Evans+ 435d0e79aa3SJason Evans+ usize = je_nallocx(size, flags); 436d0e79aa3SJason Evans+ if (usize == 0) 437d0e79aa3SJason Evans+ return (ALLOCM_ERR_OOM); 438d0e79aa3SJason Evans+ if (rsize != NULL) 439d0e79aa3SJason Evans+ *rsize = usize; 440d0e79aa3SJason Evans+ return (ALLOCM_SUCCESS); 441d0e79aa3SJason Evans+} 442d0e79aa3SJason Evans+ 443d0e79aa3SJason Evans+#undef ALLOCM_LG_ALIGN 444d0e79aa3SJason Evans+#undef ALLOCM_ALIGN 445d0e79aa3SJason Evans+#undef ALLOCM_ZERO 446d0e79aa3SJason Evans+#undef ALLOCM_NO_MOVE 447d0e79aa3SJason Evans+ 448d0e79aa3SJason Evans+#undef ALLOCM_SUCCESS 449d0e79aa3SJason Evans+#undef ALLOCM_ERR_OOM 450d0e79aa3SJason Evans+#undef ALLOCM_ERR_NOT_MOVED 451d0e79aa3SJason Evans+ 452d0e79aa3SJason Evans+/* 453d0e79aa3SJason Evans+ * End compatibility functions. 454d0e79aa3SJason Evans+ */ 455d0e79aa3SJason Evans+/******************************************************************************/ 456d0e79aa3SJason Evans+/* 457d0e79aa3SJason Evans * The following functions are used by threading libraries for protection of 458d0e79aa3SJason Evans * malloc during fork(). 459d0e79aa3SJason Evans */ 460*bde95144SJason Evans@@ -2894,4 +2999,11 @@ jemalloc_postfork_child(void) 4611f0a49e8SJason Evans ctl_postfork_child(tsd_tsdn(tsd)); 462d0e79aa3SJason Evans } 463d0e79aa3SJason Evans 464d0e79aa3SJason Evans+void 465d0e79aa3SJason Evans+_malloc_first_thread(void) 466d0e79aa3SJason Evans+{ 467d0e79aa3SJason Evans+ 468d0e79aa3SJason Evans+ (void)malloc_mutex_first_thread(); 469d0e79aa3SJason Evans+} 470d0e79aa3SJason Evans+ 471d0e79aa3SJason Evans /******************************************************************************/ 472a4bd5210SJason Evansdiff --git a/src/mutex.c b/src/mutex.c 473*bde95144SJason Evansindex 6333e73..13f8d79 100644 474a4bd5210SJason Evans--- a/src/mutex.c 475a4bd5210SJason Evans+++ b/src/mutex.c 476e722f8f8SJason Evans@@ -66,6 +66,17 @@ pthread_create(pthread_t *__restrict thread, 477a4bd5210SJason Evans #ifdef JEMALLOC_MUTEX_INIT_CB 47882872ac0SJason Evans JEMALLOC_EXPORT int _pthread_mutex_init_calloc_cb(pthread_mutex_t *mutex, 479a4bd5210SJason Evans void *(calloc_cb)(size_t, size_t)); 480a4bd5210SJason Evans+ 481d0e79aa3SJason Evans+#pragma weak _pthread_mutex_init_calloc_cb 482a4bd5210SJason Evans+int 483d0e79aa3SJason Evans+_pthread_mutex_init_calloc_cb(pthread_mutex_t *mutex, 484a4bd5210SJason Evans+ void *(calloc_cb)(size_t, size_t)) 485a4bd5210SJason Evans+{ 486a4bd5210SJason Evans+ 487d0e79aa3SJason Evans+ return (((int (*)(pthread_mutex_t *, void *(*)(size_t, size_t))) 488d0e79aa3SJason Evans+ __libc_interposing[INTERPOS__pthread_mutex_init_calloc_cb])(mutex, 489d0e79aa3SJason Evans+ calloc_cb)); 490a4bd5210SJason Evans+} 491a4bd5210SJason Evans #endif 492a4bd5210SJason Evans 493a4bd5210SJason Evans bool 494*bde95144SJason Evans@@ -142,7 +153,7 @@ malloc_mutex_postfork_child(tsdn_t *tsdn, malloc_mutex_t *mutex) 495d0e79aa3SJason Evans } 496d0e79aa3SJason Evans 497d0e79aa3SJason Evans bool 4981f0a49e8SJason Evans-malloc_mutex_boot(void) 499d0e79aa3SJason Evans+malloc_mutex_first_thread(void) 500d0e79aa3SJason Evans { 501d0e79aa3SJason Evans 502d0e79aa3SJason Evans #ifdef JEMALLOC_MUTEX_INIT_CB 503*bde95144SJason Evans@@ -156,3 +167,14 @@ malloc_mutex_boot(void) 504d0e79aa3SJason Evans #endif 505d0e79aa3SJason Evans return (false); 506d0e79aa3SJason Evans } 507d0e79aa3SJason Evans+ 508d0e79aa3SJason Evans+bool 5091f0a49e8SJason Evans+malloc_mutex_boot(void) 510d0e79aa3SJason Evans+{ 511d0e79aa3SJason Evans+ 512d0e79aa3SJason Evans+#ifndef JEMALLOC_MUTEX_INIT_CB 513d0e79aa3SJason Evans+ return (malloc_mutex_first_thread()); 514d0e79aa3SJason Evans+#else 515d0e79aa3SJason Evans+ return (false); 516d0e79aa3SJason Evans+#endif 517d0e79aa3SJason Evans+} 518a4bd5210SJason Evansdiff --git a/src/util.c b/src/util.c 519*bde95144SJason Evansindex 7905267..bee1c77 100644 520a4bd5210SJason Evans--- a/src/util.c 521a4bd5210SJason Evans+++ b/src/util.c 5221f0a49e8SJason Evans@@ -67,6 +67,22 @@ wrtmessage(void *cbopaque, const char *s) 523a4bd5210SJason Evans 524e722f8f8SJason Evans JEMALLOC_EXPORT void (*je_malloc_message)(void *, const char *s); 525e722f8f8SJason Evans 526e722f8f8SJason Evans+JEMALLOC_ATTR(visibility("hidden")) 527a4bd5210SJason Evans+void 528a4bd5210SJason Evans+wrtmessage_1_0(const char *s1, const char *s2, const char *s3, 529a4bd5210SJason Evans+ const char *s4) 530a4bd5210SJason Evans+{ 531a4bd5210SJason Evans+ 532a4bd5210SJason Evans+ wrtmessage(NULL, s1); 533a4bd5210SJason Evans+ wrtmessage(NULL, s2); 534a4bd5210SJason Evans+ wrtmessage(NULL, s3); 535a4bd5210SJason Evans+ wrtmessage(NULL, s4); 536a4bd5210SJason Evans+} 537a4bd5210SJason Evans+ 538a4bd5210SJason Evans+void (*__malloc_message_1_0)(const char *s1, const char *s2, const char *s3, 539a4bd5210SJason Evans+ const char *s4) = wrtmessage_1_0; 540a4bd5210SJason Evans+__sym_compat(_malloc_message, __malloc_message_1_0, FBSD_1.0); 541a4bd5210SJason Evans+ 542a4bd5210SJason Evans /* 543e722f8f8SJason Evans * Wrapper around malloc_message() that avoids the need for 544e722f8f8SJason Evans * je_malloc_message(...) throughout the code. 545