1a4bd5210SJason Evansdiff --git a/doc/jemalloc.xml.in b/doc/jemalloc.xml.in 2*0ef50b4eSJason Evansindex 1e12fd3a..c42a7e10 100644 3a4bd5210SJason Evans--- a/doc/jemalloc.xml.in 4a4bd5210SJason Evans+++ b/doc/jemalloc.xml.in 51a78ec89SJason Evans@@ -53,11 +53,22 @@ 6a4bd5210SJason Evans <para>This manual describes jemalloc @jemalloc_version@. More information 7a4bd5210SJason Evans can be found at the <ulink 8bde95144SJason 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>, 12b7eaed25SJason Evans+ <option>--enable-lazy-lock</option>, <option>--enable-stats</option>, 131a78ec89SJason Evans+ <option>--enable-utrace</option>, <option>--enable-xmalloc</option>, and 141a78ec89SJason Evans+ <option>--with-malloc-conf=abort_conf:false</option>. 15b7eaed25SJason Evans+ Additionally, <option>--enable-debug</option> is enabled in development 16b7eaed25SJason Evans+ versions of FreeBSD (controlled by the 17b7eaed25SJason Evans+ <constant>MALLOC_PRODUCTION</constant> make variable).</para> 18d0e79aa3SJason Evans+ 19a4bd5210SJason Evans </refsect1> 20a4bd5210SJason Evans <refsynopsisdiv> 21a4bd5210SJason Evans <title>SYNOPSIS</title> 22c13244b9SJason Evans <funcsynopsis> 23c13244b9SJason Evans- <funcsynopsisinfo>#include <<filename class="headerfile">jemalloc/jemalloc.h</filename>></funcsynopsisinfo> 24c13244b9SJason Evans+ <funcsynopsisinfo>#include <<filename class="headerfile">stdlib.h</filename>> 25c13244b9SJason Evans+#include <<filename class="headerfile">malloc_np.h</filename>></funcsynopsisinfo> 26c13244b9SJason Evans <refsect2> 27c13244b9SJason Evans <title>Standard API</title> 28c13244b9SJason Evans <funcprototype> 29*0ef50b4eSJason Evans@@ -3376,4 +3387,18 @@ malloc_conf = "narenas:1";]]></programlisting></para> 30bde95144SJason Evans <para>The <function>posix_memalign()</function> function conforms 31bde95144SJason Evans to IEEE Std 1003.1-2001 (<quote>POSIX.1</quote>).</para> 32a4bd5210SJason Evans </refsect1> 33a4bd5210SJason Evans+ <refsect1 id="history"> 34a4bd5210SJason Evans+ <title>HISTORY</title> 35bde95144SJason Evans+ <para>The <function>malloc_usable_size()</function> and 36bde95144SJason Evans+ <function>posix_memalign()</function> functions first appeared in FreeBSD 37bde95144SJason Evans+ 7.0.</para> 38a4bd5210SJason Evans+ 39bde95144SJason Evans+ <para>The <function>aligned_alloc()</function>, 40bde95144SJason Evans+ <function>malloc_stats_print()</function>, and 41bde95144SJason Evans+ <function>mallctl*()</function> functions first appeared in FreeBSD 42bde95144SJason Evans+ 10.0.</para> 43f921d10fSJason Evans+ 44bde95144SJason Evans+ <para>The <function>*allocx()</function> functions first appeared in FreeBSD 45bde95144SJason Evans+ 11.0.</para> 46a4bd5210SJason Evans+ </refsect1> 47a4bd5210SJason Evans </refentry> 48b7eaed25SJason Evansdiff --git a/include/jemalloc/internal/hooks.h b/include/jemalloc/internal/hooks.h 49b7eaed25SJason Evansindex cd49afcb..85e2a991 100644 50b7eaed25SJason Evans--- a/include/jemalloc/internal/hooks.h 51b7eaed25SJason Evans+++ b/include/jemalloc/internal/hooks.h 52b7eaed25SJason Evans@@ -6,13 +6,6 @@ extern JEMALLOC_EXPORT void (*hooks_libc_hook)(); 53fbb1d85eSJason Evans 54b7eaed25SJason Evans #define JEMALLOC_HOOK(fn, hook) ((void)(hook != NULL && (hook(), 0)), fn) 55fbb1d85eSJason Evans 56b7eaed25SJason Evans-#define open JEMALLOC_HOOK(open, hooks_libc_hook) 57b7eaed25SJason Evans-#define read JEMALLOC_HOOK(read, hooks_libc_hook) 58b7eaed25SJason Evans-#define write JEMALLOC_HOOK(write, hooks_libc_hook) 59b7eaed25SJason Evans-#define readlink JEMALLOC_HOOK(readlink, hooks_libc_hook) 60b7eaed25SJason Evans-#define close JEMALLOC_HOOK(close, hooks_libc_hook) 61b7eaed25SJason Evans-#define creat JEMALLOC_HOOK(creat, hooks_libc_hook) 62b7eaed25SJason Evans-#define secure_getenv JEMALLOC_HOOK(secure_getenv, hooks_libc_hook) 63b7eaed25SJason Evans /* Note that this is undef'd and re-define'd in src/prof.c. */ 64b7eaed25SJason Evans #define _Unwind_Backtrace JEMALLOC_HOOK(_Unwind_Backtrace, hooks_libc_hook) 65fbb1d85eSJason Evans 66b7eaed25SJason Evansdiff --git a/include/jemalloc/internal/jemalloc_internal_decls.h b/include/jemalloc/internal/jemalloc_internal_decls.h 67*0ef50b4eSJason Evansindex be70df51..84cd70da 100644 68b7eaed25SJason Evans--- a/include/jemalloc/internal/jemalloc_internal_decls.h 69b7eaed25SJason Evans+++ b/include/jemalloc/internal/jemalloc_internal_decls.h 70b7eaed25SJason Evans@@ -1,6 +1,9 @@ 71b7eaed25SJason Evans #ifndef JEMALLOC_INTERNAL_DECLS_H 72b7eaed25SJason Evans #define JEMALLOC_INTERNAL_DECLS_H 73fbb1d85eSJason Evans 74b7eaed25SJason Evans+#include "libc_private.h" 75b7eaed25SJason Evans+#include "namespace.h" 76b7eaed25SJason Evans+ 77b7eaed25SJason Evans #include <math.h> 78b7eaed25SJason Evans #ifdef _WIN32 79b7eaed25SJason Evans # include <windows.h> 80b7eaed25SJason Evansdiff --git a/include/jemalloc/internal/jemalloc_preamble.h.in b/include/jemalloc/internal/jemalloc_preamble.h.in 81*0ef50b4eSJason Evansindex e621fbc8..dbdd5d6b 100644 82b7eaed25SJason Evans--- a/include/jemalloc/internal/jemalloc_preamble.h.in 83b7eaed25SJason Evans+++ b/include/jemalloc/internal/jemalloc_preamble.h.in 84d0e79aa3SJason Evans@@ -8,6 +8,9 @@ 85d0e79aa3SJason Evans #include <sys/ktrace.h> 86e722f8f8SJason Evans #endif 87a4bd5210SJason Evans 88a4bd5210SJason Evans+#include "un-namespace.h" 89a4bd5210SJason Evans+#include "libc_private.h" 90a4bd5210SJason Evans+ 91a4bd5210SJason Evans #define JEMALLOC_NO_DEMANGLE 92f921d10fSJason Evans #ifdef JEMALLOC_JET 93b7eaed25SJason Evans # undef JEMALLOC_IS_MALLOC 94*0ef50b4eSJason Evans@@ -79,13 +82,7 @@ static const bool config_fill = 95edaa25bdSJason Evans false 96edaa25bdSJason Evans #endif 97edaa25bdSJason Evans ; 98edaa25bdSJason Evans-static const bool config_lazy_lock = 99edaa25bdSJason Evans-#ifdef JEMALLOC_LAZY_LOCK 100edaa25bdSJason Evans- true 101edaa25bdSJason Evans-#else 102edaa25bdSJason Evans- false 103edaa25bdSJason Evans-#endif 104edaa25bdSJason Evans- ; 105edaa25bdSJason Evans+static const bool config_lazy_lock = true; 106df0d881dSJason Evans static const char * const config_malloc_conf = JEMALLOC_CONFIG_MALLOC_CONF; 107edaa25bdSJason Evans static const bool config_prof = 108edaa25bdSJason Evans #ifdef JEMALLOC_PROF 109a4bd5210SJason Evansdiff --git a/include/jemalloc/internal/mutex.h b/include/jemalloc/internal/mutex.h 110b7eaed25SJason Evansindex 6520c251..0013cbe9 100644 111a4bd5210SJason Evans--- a/include/jemalloc/internal/mutex.h 112a4bd5210SJason Evans+++ b/include/jemalloc/internal/mutex.h 113b7eaed25SJason Evans@@ -121,9 +121,6 @@ struct malloc_mutex_s { 114a4bd5210SJason Evans 115a4bd5210SJason Evans #ifdef JEMALLOC_LAZY_LOCK 116a4bd5210SJason Evans extern bool isthreaded; 117a4bd5210SJason Evans-#else 1188ed34ab0SJason Evans-# undef isthreaded /* Undo private_namespace.h definition. */ 119a4bd5210SJason Evans-# define isthreaded true 120a4bd5210SJason Evans #endif 121a4bd5210SJason Evans 1221f0a49e8SJason Evans bool malloc_mutex_init(malloc_mutex_t *mutex, const char *name, 123b7eaed25SJason Evans@@ -131,6 +128,7 @@ bool malloc_mutex_init(malloc_mutex_t *mutex, const char *name, 1241f0a49e8SJason Evans void malloc_mutex_prefork(tsdn_t *tsdn, malloc_mutex_t *mutex); 1251f0a49e8SJason Evans void malloc_mutex_postfork_parent(tsdn_t *tsdn, malloc_mutex_t *mutex); 1261f0a49e8SJason Evans void malloc_mutex_postfork_child(tsdn_t *tsdn, malloc_mutex_t *mutex); 127d0e79aa3SJason Evans+bool malloc_mutex_first_thread(void); 1281f0a49e8SJason Evans bool malloc_mutex_boot(void); 129b7eaed25SJason Evans void malloc_mutex_prof_data_reset(tsdn_t *tsdn, malloc_mutex_t *mutex); 130d0e79aa3SJason Evans 131*0ef50b4eSJason Evansdiff --git a/include/jemalloc/internal/tsd.h b/include/jemalloc/internal/tsd.h 132*0ef50b4eSJason Evansindex 0b9841aa..f03eee61 100644 133*0ef50b4eSJason Evans--- a/include/jemalloc/internal/tsd.h 134*0ef50b4eSJason Evans+++ b/include/jemalloc/internal/tsd.h 135*0ef50b4eSJason Evans@@ -122,7 +122,8 @@ struct tsd_s { 136*0ef50b4eSJason Evans t use_a_getter_or_setter_instead_##n; 137*0ef50b4eSJason Evans MALLOC_TSD 138*0ef50b4eSJason Evans #undef O 139*0ef50b4eSJason Evans-}; 140*0ef50b4eSJason Evans+/* AddressSanitizer requires TLS data to be aligned to at least 8 bytes. */ 141*0ef50b4eSJason Evans+} JEMALLOC_ALIGNED(16); 142*0ef50b4eSJason Evans 143*0ef50b4eSJason Evans /* 144*0ef50b4eSJason Evans * Wrapper around tsd_t that makes it possible to avoid implicit conversion 145a4bd5210SJason Evansdiff --git a/include/jemalloc/jemalloc_FreeBSD.h b/include/jemalloc/jemalloc_FreeBSD.h 146a4bd5210SJason Evansnew file mode 100644 147*0ef50b4eSJason Evansindex 00000000..b752b0e7 148a4bd5210SJason Evans--- /dev/null 149a4bd5210SJason Evans+++ b/include/jemalloc/jemalloc_FreeBSD.h 150b7eaed25SJason Evans@@ -0,0 +1,185 @@ 151a4bd5210SJason Evans+/* 152a4bd5210SJason Evans+ * Override settings that were generated in jemalloc_defs.h as necessary. 153a4bd5210SJason Evans+ */ 154a4bd5210SJason Evans+ 155a4bd5210SJason Evans+#undef JEMALLOC_OVERRIDE_VALLOC 156a4bd5210SJason Evans+ 157a4bd5210SJason Evans+#ifndef MALLOC_PRODUCTION 158a4bd5210SJason Evans+#define JEMALLOC_DEBUG 159a4bd5210SJason Evans+#endif 160a4bd5210SJason Evans+ 1611f0a49e8SJason Evans+#undef JEMALLOC_DSS 1621f0a49e8SJason Evans+ 163b7eaed25SJason Evans+#undef JEMALLOC_BACKGROUND_THREAD 164b7eaed25SJason Evans+ 165a4bd5210SJason Evans+/* 166a4bd5210SJason Evans+ * The following are architecture-dependent, so conditionally define them for 167a4bd5210SJason Evans+ * each supported architecture. 168a4bd5210SJason Evans+ */ 169a4bd5210SJason Evans+#undef JEMALLOC_TLS_MODEL 170c2a2eeffSMarius Strobl+#undef LG_PAGE 171b7eaed25SJason Evans+#undef LG_VADDR 172a4bd5210SJason Evans+#undef LG_SIZEOF_PTR 173a4bd5210SJason Evans+#undef LG_SIZEOF_INT 174a4bd5210SJason Evans+#undef LG_SIZEOF_LONG 175a4bd5210SJason Evans+#undef LG_SIZEOF_INTMAX_T 176a4bd5210SJason Evans+ 177a4bd5210SJason Evans+#ifdef __i386__ 178b7eaed25SJason Evans+# define LG_VADDR 32 179a4bd5210SJason Evans+# define LG_SIZEOF_PTR 2 180a4bd5210SJason Evans+# define JEMALLOC_TLS_MODEL __attribute__((tls_model("initial-exec"))) 181a4bd5210SJason Evans+#endif 182a4bd5210SJason Evans+#ifdef __ia64__ 183b7eaed25SJason Evans+# define LG_VADDR 64 184a4bd5210SJason Evans+# define LG_SIZEOF_PTR 3 185a4bd5210SJason Evans+#endif 186a4bd5210SJason Evans+#ifdef __sparc64__ 187b7eaed25SJason Evans+# define LG_VADDR 64 188a4bd5210SJason Evans+# define LG_SIZEOF_PTR 3 189a4bd5210SJason Evans+# define JEMALLOC_TLS_MODEL __attribute__((tls_model("initial-exec"))) 190a4bd5210SJason Evans+#endif 191a4bd5210SJason Evans+#ifdef __amd64__ 192b7eaed25SJason Evans+# define LG_VADDR 48 193a4bd5210SJason Evans+# define LG_SIZEOF_PTR 3 194a4bd5210SJason Evans+# define JEMALLOC_TLS_MODEL __attribute__((tls_model("initial-exec"))) 195a4bd5210SJason Evans+#endif 196a4bd5210SJason Evans+#ifdef __arm__ 197b7eaed25SJason Evans+# define LG_VADDR 32 198a4bd5210SJason Evans+# define LG_SIZEOF_PTR 2 199a4bd5210SJason Evans+#endif 200d8e39d2dSJason Evans+#ifdef __aarch64__ 201b7eaed25SJason Evans+# define LG_VADDR 48 202d8e39d2dSJason Evans+# define LG_SIZEOF_PTR 3 203d8e39d2dSJason Evans+#endif 204a4bd5210SJason Evans+#ifdef __mips__ 205e722f8f8SJason Evans+#ifdef __mips_n64 206b7eaed25SJason Evans+# define LG_VADDR 64 207e722f8f8SJason Evans+# define LG_SIZEOF_PTR 3 208e722f8f8SJason Evans+#else 209b7eaed25SJason Evans+# define LG_VADDR 32 210a4bd5210SJason Evans+# define LG_SIZEOF_PTR 2 211a4bd5210SJason Evans+#endif 212e722f8f8SJason Evans+#endif 213a4bd5210SJason Evans+#ifdef __powerpc64__ 214b7eaed25SJason Evans+# define LG_VADDR 64 215a4bd5210SJason Evans+# define LG_SIZEOF_PTR 3 216a4bd5210SJason Evans+#elif defined(__powerpc__) 217b7eaed25SJason Evans+# define LG_VADDR 32 218a4bd5210SJason Evans+# define LG_SIZEOF_PTR 2 219a4bd5210SJason Evans+#endif 220*0ef50b4eSJason Evans+#ifdef __riscv 221b7eaed25SJason Evans+# define LG_VADDR 64 222df0d881dSJason Evans+# define LG_SIZEOF_PTR 3 223df0d881dSJason Evans+#endif 224a4bd5210SJason Evans+ 225a4bd5210SJason Evans+#ifndef JEMALLOC_TLS_MODEL 226a4bd5210SJason Evans+# define JEMALLOC_TLS_MODEL /* Default. */ 227a4bd5210SJason Evans+#endif 228a4bd5210SJason Evans+ 229c2a2eeffSMarius Strobl+#define LG_PAGE PAGE_SHIFT 230a4bd5210SJason Evans+#define LG_SIZEOF_INT 2 231a4bd5210SJason Evans+#define LG_SIZEOF_LONG LG_SIZEOF_PTR 232a4bd5210SJason Evans+#define LG_SIZEOF_INTMAX_T 3 233a4bd5210SJason Evans+ 234337776f8SJason Evans+#undef CPU_SPINWAIT 235337776f8SJason Evans+#include <machine/cpu.h> 236337776f8SJason Evans+#include <machine/cpufunc.h> 237337776f8SJason Evans+#define CPU_SPINWAIT cpu_spinwait() 238337776f8SJason Evans+ 239a4bd5210SJason Evans+/* Disable lazy-lock machinery, mangle isthreaded, and adjust its type. */ 240a4bd5210SJason Evans+#undef JEMALLOC_LAZY_LOCK 241a4bd5210SJason Evans+extern int __isthreaded; 242a4bd5210SJason Evans+#define isthreaded ((bool)__isthreaded) 243a4bd5210SJason Evans+ 244a4bd5210SJason Evans+/* Mangle. */ 245f8ca2db1SJason Evans+#undef je_malloc 246f8ca2db1SJason Evans+#undef je_calloc 247f8ca2db1SJason Evans+#undef je_posix_memalign 248d0e79aa3SJason Evans+#undef je_aligned_alloc 249df0d881dSJason Evans+#undef je_realloc 250df0d881dSJason Evans+#undef je_free 251f8ca2db1SJason Evans+#undef je_malloc_usable_size 252f921d10fSJason Evans+#undef je_mallocx 253f921d10fSJason Evans+#undef je_rallocx 254f921d10fSJason Evans+#undef je_xallocx 255f921d10fSJason Evans+#undef je_sallocx 256f921d10fSJason Evans+#undef je_dallocx 257df0d881dSJason Evans+#undef je_sdallocx 258f921d10fSJason Evans+#undef je_nallocx 259df0d881dSJason Evans+#undef je_mallctl 260df0d881dSJason Evans+#undef je_mallctlnametomib 261df0d881dSJason Evans+#undef je_mallctlbymib 262df0d881dSJason Evans+#undef je_malloc_stats_print 263f8ca2db1SJason Evans+#undef je_allocm 264f8ca2db1SJason Evans+#undef je_rallocm 265f8ca2db1SJason Evans+#undef je_sallocm 266f8ca2db1SJason Evans+#undef je_dallocm 267f8ca2db1SJason Evans+#undef je_nallocm 268f8ca2db1SJason Evans+#define je_malloc __malloc 269f8ca2db1SJason Evans+#define je_calloc __calloc 270f8ca2db1SJason Evans+#define je_posix_memalign __posix_memalign 271d0e79aa3SJason Evans+#define je_aligned_alloc __aligned_alloc 272df0d881dSJason Evans+#define je_realloc __realloc 273df0d881dSJason Evans+#define je_free __free 274f8ca2db1SJason Evans+#define je_malloc_usable_size __malloc_usable_size 275f921d10fSJason Evans+#define je_mallocx __mallocx 276f921d10fSJason Evans+#define je_rallocx __rallocx 277f921d10fSJason Evans+#define je_xallocx __xallocx 278f921d10fSJason Evans+#define je_sallocx __sallocx 279f921d10fSJason Evans+#define je_dallocx __dallocx 280df0d881dSJason Evans+#define je_sdallocx __sdallocx 281f921d10fSJason Evans+#define je_nallocx __nallocx 282df0d881dSJason Evans+#define je_mallctl __mallctl 283df0d881dSJason Evans+#define je_mallctlnametomib __mallctlnametomib 284df0d881dSJason Evans+#define je_mallctlbymib __mallctlbymib 285df0d881dSJason Evans+#define je_malloc_stats_print __malloc_stats_print 286f8ca2db1SJason Evans+#define je_allocm __allocm 287f8ca2db1SJason Evans+#define je_rallocm __rallocm 288f8ca2db1SJason Evans+#define je_sallocm __sallocm 289f8ca2db1SJason Evans+#define je_dallocm __dallocm 290f8ca2db1SJason Evans+#define je_nallocm __nallocm 291a4bd5210SJason Evans+#define open _open 292a4bd5210SJason Evans+#define read _read 293a4bd5210SJason Evans+#define write _write 294a4bd5210SJason Evans+#define close _close 295b7eaed25SJason Evans+#define pthread_join _pthread_join 296b7eaed25SJason Evans+#define pthread_once _pthread_once 297b7eaed25SJason Evans+#define pthread_self _pthread_self 298b7eaed25SJason Evans+#define pthread_equal _pthread_equal 299a4bd5210SJason Evans+#define pthread_mutex_lock _pthread_mutex_lock 300b7eaed25SJason Evans+#define pthread_mutex_trylock _pthread_mutex_trylock 301a4bd5210SJason Evans+#define pthread_mutex_unlock _pthread_mutex_unlock 302b7eaed25SJason Evans+#define pthread_cond_init _pthread_cond_init 303b7eaed25SJason Evans+#define pthread_cond_wait _pthread_cond_wait 304b7eaed25SJason Evans+#define pthread_cond_timedwait _pthread_cond_timedwait 305b7eaed25SJason Evans+#define pthread_cond_signal _pthread_cond_signal 306f8ca2db1SJason Evans+ 307f8ca2db1SJason Evans+#ifdef JEMALLOC_C_ 308f8ca2db1SJason Evans+/* 309f8ca2db1SJason Evans+ * Define 'weak' symbols so that an application can have its own versions 310f8ca2db1SJason Evans+ * of malloc, calloc, realloc, free, et al. 311f8ca2db1SJason Evans+ */ 312f8ca2db1SJason Evans+__weak_reference(__malloc, malloc); 313f8ca2db1SJason Evans+__weak_reference(__calloc, calloc); 314f8ca2db1SJason Evans+__weak_reference(__posix_memalign, posix_memalign); 315d0e79aa3SJason Evans+__weak_reference(__aligned_alloc, aligned_alloc); 316df0d881dSJason Evans+__weak_reference(__realloc, realloc); 317df0d881dSJason Evans+__weak_reference(__free, free); 318f8ca2db1SJason Evans+__weak_reference(__malloc_usable_size, malloc_usable_size); 319f921d10fSJason Evans+__weak_reference(__mallocx, mallocx); 320f921d10fSJason Evans+__weak_reference(__rallocx, rallocx); 321f921d10fSJason Evans+__weak_reference(__xallocx, xallocx); 322f921d10fSJason Evans+__weak_reference(__sallocx, sallocx); 323f921d10fSJason Evans+__weak_reference(__dallocx, dallocx); 324df0d881dSJason Evans+__weak_reference(__sdallocx, sdallocx); 325f921d10fSJason Evans+__weak_reference(__nallocx, nallocx); 326df0d881dSJason Evans+__weak_reference(__mallctl, mallctl); 327df0d881dSJason Evans+__weak_reference(__mallctlnametomib, mallctlnametomib); 328df0d881dSJason Evans+__weak_reference(__mallctlbymib, mallctlbymib); 329df0d881dSJason Evans+__weak_reference(__malloc_stats_print, malloc_stats_print); 330f8ca2db1SJason Evans+__weak_reference(__allocm, allocm); 331f8ca2db1SJason Evans+__weak_reference(__rallocm, rallocm); 332f8ca2db1SJason Evans+__weak_reference(__sallocm, sallocm); 333f8ca2db1SJason Evans+__weak_reference(__dallocm, dallocm); 334f8ca2db1SJason Evans+__weak_reference(__nallocm, nallocm); 335f8ca2db1SJason Evans+#endif 336f921d10fSJason Evansdiff --git a/include/jemalloc/jemalloc_rename.sh b/include/jemalloc/jemalloc_rename.sh 337b7eaed25SJason Evansindex f9438912..47d032c1 100755 338f921d10fSJason Evans--- a/include/jemalloc/jemalloc_rename.sh 339f921d10fSJason Evans+++ b/include/jemalloc/jemalloc_rename.sh 340f921d10fSJason Evans@@ -19,4 +19,6 @@ done 341f921d10fSJason Evans 342f921d10fSJason Evans cat <<EOF 343f921d10fSJason Evans #endif 344f8ca2db1SJason Evans+ 345f921d10fSJason Evans+#include "jemalloc_FreeBSD.h" 346f921d10fSJason Evans EOF 347a4bd5210SJason Evansdiff --git a/src/jemalloc.c b/src/jemalloc.c 348*0ef50b4eSJason Evansindex f93c16fa..e0ad297b 100644 349a4bd5210SJason Evans--- a/src/jemalloc.c 350a4bd5210SJason Evans+++ b/src/jemalloc.c 351*0ef50b4eSJason Evans@@ -21,6 +21,10 @@ 352d0e79aa3SJason Evans /******************************************************************************/ 353d0e79aa3SJason Evans /* Data. */ 354a4bd5210SJason Evans 355e722f8f8SJason Evans+/* Work around <http://llvm.org/bugs/show_bug.cgi?id=12623>: */ 356e722f8f8SJason Evans+const char *__malloc_options_1_0 = NULL; 357a4bd5210SJason Evans+__sym_compat(_malloc_options, __malloc_options_1_0, FBSD_1.0); 358a4bd5210SJason Evans+ 359a4bd5210SJason Evans /* Runtime configuration options. */ 360bde95144SJason Evans const char *je_malloc_conf 361bde95144SJason Evans #ifndef _WIN32 362*0ef50b4eSJason Evans@@ -3160,6 +3164,103 @@ je_malloc_usable_size(JEMALLOC_USABLE_SIZE_CONST void *ptr) { 363d0e79aa3SJason Evans */ 364d0e79aa3SJason Evans /******************************************************************************/ 365a4bd5210SJason Evans /* 366d0e79aa3SJason Evans+ * Begin compatibility functions. 367d0e79aa3SJason Evans+ */ 368d0e79aa3SJason Evans+ 369d0e79aa3SJason Evans+#define ALLOCM_LG_ALIGN(la) (la) 370d0e79aa3SJason Evans+#define ALLOCM_ALIGN(a) (ffsl(a)-1) 371d0e79aa3SJason Evans+#define ALLOCM_ZERO ((int)0x40) 372d0e79aa3SJason Evans+#define ALLOCM_NO_MOVE ((int)0x80) 373d0e79aa3SJason Evans+ 374d0e79aa3SJason Evans+#define ALLOCM_SUCCESS 0 375d0e79aa3SJason Evans+#define ALLOCM_ERR_OOM 1 376d0e79aa3SJason Evans+#define ALLOCM_ERR_NOT_MOVED 2 377d0e79aa3SJason Evans+ 378d0e79aa3SJason Evans+int 379b7eaed25SJason Evans+je_allocm(void **ptr, size_t *rsize, size_t size, int flags) { 380d0e79aa3SJason Evans+ assert(ptr != NULL); 381d0e79aa3SJason Evans+ 382b7eaed25SJason Evans+ void *p = je_mallocx(size, flags); 383b7eaed25SJason Evans+ if (p == NULL) { 384d0e79aa3SJason Evans+ return (ALLOCM_ERR_OOM); 385b7eaed25SJason Evans+ } 386b7eaed25SJason Evans+ if (rsize != NULL) { 387b7eaed25SJason Evans+ *rsize = isalloc(tsdn_fetch(), p); 388b7eaed25SJason Evans+ } 389d0e79aa3SJason Evans+ *ptr = p; 390b7eaed25SJason Evans+ return ALLOCM_SUCCESS; 391d0e79aa3SJason Evans+} 392d0e79aa3SJason Evans+ 393d0e79aa3SJason Evans+int 394b7eaed25SJason Evans+je_rallocm(void **ptr, size_t *rsize, size_t size, size_t extra, int flags) { 395d0e79aa3SJason Evans+ assert(ptr != NULL); 396d0e79aa3SJason Evans+ assert(*ptr != NULL); 397d0e79aa3SJason Evans+ assert(size != 0); 398d0e79aa3SJason Evans+ assert(SIZE_T_MAX - size >= extra); 399d0e79aa3SJason Evans+ 400b7eaed25SJason Evans+ int ret; 401b7eaed25SJason Evans+ bool no_move = flags & ALLOCM_NO_MOVE; 402b7eaed25SJason Evans+ 403d0e79aa3SJason Evans+ if (no_move) { 404d0e79aa3SJason Evans+ size_t usize = je_xallocx(*ptr, size, extra, flags); 405d0e79aa3SJason Evans+ ret = (usize >= size) ? ALLOCM_SUCCESS : ALLOCM_ERR_NOT_MOVED; 406b7eaed25SJason Evans+ if (rsize != NULL) { 407d0e79aa3SJason Evans+ *rsize = usize; 408b7eaed25SJason Evans+ } 409d0e79aa3SJason Evans+ } else { 410d0e79aa3SJason Evans+ void *p = je_rallocx(*ptr, size+extra, flags); 411d0e79aa3SJason Evans+ if (p != NULL) { 412d0e79aa3SJason Evans+ *ptr = p; 413d0e79aa3SJason Evans+ ret = ALLOCM_SUCCESS; 414b7eaed25SJason Evans+ } else { 415d0e79aa3SJason Evans+ ret = ALLOCM_ERR_OOM; 416d0e79aa3SJason Evans+ } 417b7eaed25SJason Evans+ if (rsize != NULL) { 418b7eaed25SJason Evans+ *rsize = isalloc(tsdn_fetch(), *ptr); 419b7eaed25SJason Evans+ } 420b7eaed25SJason Evans+ } 421b7eaed25SJason Evans+ return ret; 422d0e79aa3SJason Evans+} 423d0e79aa3SJason Evans+ 424d0e79aa3SJason Evans+int 425b7eaed25SJason Evans+je_sallocm(const void *ptr, size_t *rsize, int flags) { 426d0e79aa3SJason Evans+ assert(rsize != NULL); 427d0e79aa3SJason Evans+ *rsize = je_sallocx(ptr, flags); 428b7eaed25SJason Evans+ return ALLOCM_SUCCESS; 429d0e79aa3SJason Evans+} 430d0e79aa3SJason Evans+ 431d0e79aa3SJason Evans+int 432b7eaed25SJason Evans+je_dallocm(void *ptr, int flags) { 433d0e79aa3SJason Evans+ je_dallocx(ptr, flags); 434b7eaed25SJason Evans+ return ALLOCM_SUCCESS; 435d0e79aa3SJason Evans+} 436d0e79aa3SJason Evans+ 437d0e79aa3SJason Evans+int 438b7eaed25SJason Evans+je_nallocm(size_t *rsize, size_t size, int flags) { 439b7eaed25SJason Evans+ size_t usize = je_nallocx(size, flags); 440b7eaed25SJason Evans+ if (usize == 0) { 441b7eaed25SJason Evans+ return ALLOCM_ERR_OOM; 442b7eaed25SJason Evans+ } 443b7eaed25SJason Evans+ if (rsize != NULL) { 444d0e79aa3SJason Evans+ *rsize = usize; 445b7eaed25SJason Evans+ } 446b7eaed25SJason Evans+ return ALLOCM_SUCCESS; 447d0e79aa3SJason Evans+} 448d0e79aa3SJason Evans+ 449d0e79aa3SJason Evans+#undef ALLOCM_LG_ALIGN 450d0e79aa3SJason Evans+#undef ALLOCM_ALIGN 451d0e79aa3SJason Evans+#undef ALLOCM_ZERO 452d0e79aa3SJason Evans+#undef ALLOCM_NO_MOVE 453d0e79aa3SJason Evans+ 454d0e79aa3SJason Evans+#undef ALLOCM_SUCCESS 455d0e79aa3SJason Evans+#undef ALLOCM_ERR_OOM 456d0e79aa3SJason Evans+#undef ALLOCM_ERR_NOT_MOVED 457d0e79aa3SJason Evans+ 458d0e79aa3SJason Evans+/* 459d0e79aa3SJason Evans+ * End compatibility functions. 460d0e79aa3SJason Evans+ */ 461d0e79aa3SJason Evans+/******************************************************************************/ 462d0e79aa3SJason Evans+/* 463d0e79aa3SJason Evans * The following functions are used by threading libraries for protection of 464d0e79aa3SJason Evans * malloc during fork(). 465d0e79aa3SJason Evans */ 466*0ef50b4eSJason Evans@@ -3323,4 +3424,11 @@ jemalloc_postfork_child(void) { 4671f0a49e8SJason Evans ctl_postfork_child(tsd_tsdn(tsd)); 468d0e79aa3SJason Evans } 469d0e79aa3SJason Evans 470d0e79aa3SJason Evans+void 471d0e79aa3SJason Evans+_malloc_first_thread(void) 472d0e79aa3SJason Evans+{ 473d0e79aa3SJason Evans+ 474d0e79aa3SJason Evans+ (void)malloc_mutex_first_thread(); 475d0e79aa3SJason Evans+} 476d0e79aa3SJason Evans+ 477d0e79aa3SJason Evans /******************************************************************************/ 478b7eaed25SJason Evansdiff --git a/src/malloc_io.c b/src/malloc_io.c 479*0ef50b4eSJason Evansindex 7bdc13f9..c8802c70 100644 480b7eaed25SJason Evans--- a/src/malloc_io.c 481b7eaed25SJason Evans+++ b/src/malloc_io.c 482*0ef50b4eSJason Evans@@ -75,6 +75,20 @@ wrtmessage(void *cbopaque, const char *s) { 483b7eaed25SJason Evans 484b7eaed25SJason Evans JEMALLOC_EXPORT void (*je_malloc_message)(void *, const char *s); 485b7eaed25SJason Evans 486b7eaed25SJason Evans+JEMALLOC_ATTR(visibility("hidden")) 487b7eaed25SJason Evans+void 488b7eaed25SJason Evans+wrtmessage_1_0(const char *s1, const char *s2, const char *s3, const char *s4) { 489b7eaed25SJason Evans+ 490b7eaed25SJason Evans+ wrtmessage(NULL, s1); 491b7eaed25SJason Evans+ wrtmessage(NULL, s2); 492b7eaed25SJason Evans+ wrtmessage(NULL, s3); 493b7eaed25SJason Evans+ wrtmessage(NULL, s4); 494b7eaed25SJason Evans+} 495b7eaed25SJason Evans+ 496b7eaed25SJason Evans+void (*__malloc_message_1_0)(const char *s1, const char *s2, const char *s3, 497b7eaed25SJason Evans+ const char *s4) = wrtmessage_1_0; 498b7eaed25SJason Evans+__sym_compat(_malloc_message, __malloc_message_1_0, FBSD_1.0); 499b7eaed25SJason Evans+ 500b7eaed25SJason Evans /* 501b7eaed25SJason Evans * Wrapper around malloc_message() that avoids the need for 502b7eaed25SJason Evans * je_malloc_message(...) throughout the code. 503a4bd5210SJason Evansdiff --git a/src/mutex.c b/src/mutex.c 504*0ef50b4eSJason Evansindex 30222b3e..b2c36283 100644 505a4bd5210SJason Evans--- a/src/mutex.c 506a4bd5210SJason Evans+++ b/src/mutex.c 507*0ef50b4eSJason Evans@@ -41,6 +41,17 @@ pthread_create(pthread_t *__restrict thread, 508a4bd5210SJason Evans #ifdef JEMALLOC_MUTEX_INIT_CB 50982872ac0SJason Evans JEMALLOC_EXPORT int _pthread_mutex_init_calloc_cb(pthread_mutex_t *mutex, 510a4bd5210SJason Evans void *(calloc_cb)(size_t, size_t)); 511a4bd5210SJason Evans+ 512d0e79aa3SJason Evans+#pragma weak _pthread_mutex_init_calloc_cb 513a4bd5210SJason Evans+int 514d0e79aa3SJason Evans+_pthread_mutex_init_calloc_cb(pthread_mutex_t *mutex, 515a4bd5210SJason Evans+ void *(calloc_cb)(size_t, size_t)) 516a4bd5210SJason Evans+{ 517a4bd5210SJason Evans+ 518d0e79aa3SJason Evans+ return (((int (*)(pthread_mutex_t *, void *(*)(size_t, size_t))) 519d0e79aa3SJason Evans+ __libc_interposing[INTERPOS__pthread_mutex_init_calloc_cb])(mutex, 520d0e79aa3SJason Evans+ calloc_cb)); 521a4bd5210SJason Evans+} 522a4bd5210SJason Evans #endif 523a4bd5210SJason Evans 524b7eaed25SJason Evans void 525*0ef50b4eSJason Evans@@ -131,6 +142,16 @@ mutex_addr_comp(const witness_t *witness1, void *mutex1, 526d0e79aa3SJason Evans } 527d0e79aa3SJason Evans 528d0e79aa3SJason Evans bool 529b7eaed25SJason Evans+malloc_mutex_first_thread(void) { 530d0e79aa3SJason Evans+ 531d0e79aa3SJason Evans+#ifndef JEMALLOC_MUTEX_INIT_CB 532d0e79aa3SJason Evans+ return (malloc_mutex_first_thread()); 533d0e79aa3SJason Evans+#else 534d0e79aa3SJason Evans+ return (false); 535d0e79aa3SJason Evans+#endif 536d0e79aa3SJason Evans+} 537a4bd5210SJason Evans+ 538b7eaed25SJason Evans+bool 539b7eaed25SJason Evans malloc_mutex_init(malloc_mutex_t *mutex, const char *name, 540b7eaed25SJason Evans witness_rank_t rank, malloc_mutex_lock_order_t lock_order) { 541b7eaed25SJason Evans mutex_prof_data_init(&mutex->prof_data); 542