1a4bd5210SJason Evansdiff --git a/doc/jemalloc.xml.in b/doc/jemalloc.xml.in 2*1f0a49e8SJason Evansindex c4a44e3..4626e9b 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 8a4bd5210SJason Evans url="http://www.canonware.com/jemalloc/">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*1f0a49e8SJason Evans@@ -2961,4 +2973,18 @@ malloc_conf = "lg_chunk:24";]]></programlisting></para> 31a4bd5210SJason Evans <para>The <function>posix_memalign<parameter/></function> function conforms 32a4bd5210SJason Evans to IEEE Std 1003.1-2001 (“POSIX.1”).</para> 33a4bd5210SJason Evans </refsect1> 34a4bd5210SJason Evans+ <refsect1 id="history"> 35a4bd5210SJason Evans+ <title>HISTORY</title> 36a4bd5210SJason Evans+ <para>The <function>malloc_usable_size<parameter/></function> and 37a4bd5210SJason Evans+ <function>posix_memalign<parameter/></function> functions first appeared in 38a4bd5210SJason Evans+ FreeBSD 7.0.</para> 39a4bd5210SJason Evans+ 40a4bd5210SJason Evans+ <para>The <function>aligned_alloc<parameter/></function>, 41d0e79aa3SJason Evans+ <function>malloc_stats_print<parameter/></function>, and 42d0e79aa3SJason Evans+ <function>mallctl*<parameter/></function> functions first appeared in 43a4bd5210SJason Evans+ FreeBSD 10.0.</para> 44f921d10fSJason Evans+ 45f921d10fSJason Evans+ <para>The <function>*allocx<parameter/></function> functions first appeared 46f921d10fSJason Evans+ in FreeBSD 11.0.</para> 47a4bd5210SJason Evans+ </refsect1> 48a4bd5210SJason Evans </refentry> 49a4bd5210SJason Evansdiff --git a/include/jemalloc/internal/jemalloc_internal.h.in b/include/jemalloc/internal/jemalloc_internal.h.in 50*1f0a49e8SJason Evansindex 51bf897..7de22ea 100644 51a4bd5210SJason Evans--- a/include/jemalloc/internal/jemalloc_internal.h.in 52a4bd5210SJason Evans+++ b/include/jemalloc/internal/jemalloc_internal.h.in 53d0e79aa3SJason Evans@@ -8,6 +8,9 @@ 54d0e79aa3SJason Evans #include <sys/ktrace.h> 55e722f8f8SJason Evans #endif 56a4bd5210SJason Evans 57a4bd5210SJason Evans+#include "un-namespace.h" 58a4bd5210SJason Evans+#include "libc_private.h" 59a4bd5210SJason Evans+ 60a4bd5210SJason Evans #define JEMALLOC_NO_DEMANGLE 61f921d10fSJason Evans #ifdef JEMALLOC_JET 62f921d10fSJason Evans # define JEMALLOC_N(n) jet_##n 63d0e79aa3SJason Evans@@ -42,13 +45,7 @@ static const bool config_fill = 64edaa25bdSJason Evans false 65edaa25bdSJason Evans #endif 66edaa25bdSJason Evans ; 67edaa25bdSJason Evans-static const bool config_lazy_lock = 68edaa25bdSJason Evans-#ifdef JEMALLOC_LAZY_LOCK 69edaa25bdSJason Evans- true 70edaa25bdSJason Evans-#else 71edaa25bdSJason Evans- false 72edaa25bdSJason Evans-#endif 73edaa25bdSJason Evans- ; 74edaa25bdSJason Evans+static const bool config_lazy_lock = true; 75df0d881dSJason Evans static const char * const config_malloc_conf = JEMALLOC_CONFIG_MALLOC_CONF; 76edaa25bdSJason Evans static const bool config_prof = 77edaa25bdSJason Evans #ifdef JEMALLOC_PROF 78d0e79aa3SJason Evansdiff --git a/include/jemalloc/internal/jemalloc_internal_decls.h b/include/jemalloc/internal/jemalloc_internal_decls.h 79df0d881dSJason Evansindex 2b8ca5d..42d97f2 100644 80d0e79aa3SJason Evans--- a/include/jemalloc/internal/jemalloc_internal_decls.h 81d0e79aa3SJason Evans+++ b/include/jemalloc/internal/jemalloc_internal_decls.h 82d0e79aa3SJason Evans@@ -1,6 +1,9 @@ 83d0e79aa3SJason Evans #ifndef JEMALLOC_INTERNAL_DECLS_H 84d0e79aa3SJason Evans #define JEMALLOC_INTERNAL_DECLS_H 85d0e79aa3SJason Evans 86d0e79aa3SJason Evans+#include "libc_private.h" 87d0e79aa3SJason Evans+#include "namespace.h" 88d0e79aa3SJason Evans+ 89d0e79aa3SJason Evans #include <math.h> 90d0e79aa3SJason Evans #ifdef _WIN32 91d0e79aa3SJason Evans # include <windows.h> 92a4bd5210SJason Evansdiff --git a/include/jemalloc/internal/mutex.h b/include/jemalloc/internal/mutex.h 93*1f0a49e8SJason Evansindex 5221799..60ab041 100644 94a4bd5210SJason Evans--- a/include/jemalloc/internal/mutex.h 95a4bd5210SJason Evans+++ b/include/jemalloc/internal/mutex.h 96*1f0a49e8SJason Evans@@ -52,9 +52,6 @@ struct malloc_mutex_s { 97a4bd5210SJason Evans 98a4bd5210SJason Evans #ifdef JEMALLOC_LAZY_LOCK 99a4bd5210SJason Evans extern bool isthreaded; 100a4bd5210SJason Evans-#else 1018ed34ab0SJason Evans-# undef isthreaded /* Undo private_namespace.h definition. */ 102a4bd5210SJason Evans-# define isthreaded true 103a4bd5210SJason Evans #endif 104a4bd5210SJason Evans 105*1f0a49e8SJason Evans bool malloc_mutex_init(malloc_mutex_t *mutex, const char *name, 106*1f0a49e8SJason Evans@@ -62,6 +59,7 @@ bool malloc_mutex_init(malloc_mutex_t *mutex, const char *name, 107*1f0a49e8SJason Evans void malloc_mutex_prefork(tsdn_t *tsdn, malloc_mutex_t *mutex); 108*1f0a49e8SJason Evans void malloc_mutex_postfork_parent(tsdn_t *tsdn, malloc_mutex_t *mutex); 109*1f0a49e8SJason Evans void malloc_mutex_postfork_child(tsdn_t *tsdn, malloc_mutex_t *mutex); 110d0e79aa3SJason Evans+bool malloc_mutex_first_thread(void); 111*1f0a49e8SJason Evans bool malloc_mutex_boot(void); 112d0e79aa3SJason Evans 113d0e79aa3SJason Evans #endif /* JEMALLOC_H_EXTERNS */ 114f921d10fSJason Evansdiff --git a/include/jemalloc/internal/private_symbols.txt b/include/jemalloc/internal/private_symbols.txt 115*1f0a49e8SJason Evansindex f2b6a55..69369c9 100644 116f921d10fSJason Evans--- a/include/jemalloc/internal/private_symbols.txt 117f921d10fSJason Evans+++ b/include/jemalloc/internal/private_symbols.txt 118*1f0a49e8SJason Evans@@ -311,7 +311,6 @@ iralloct_realign 119f921d10fSJason Evans isalloc 120d0e79aa3SJason Evans isdalloct 121d0e79aa3SJason Evans isqalloc 122f921d10fSJason Evans-isthreaded 123f921d10fSJason Evans ivsalloc 124f921d10fSJason Evans ixalloc 125f921d10fSJason Evans jemalloc_postfork_child 126a4bd5210SJason Evansdiff --git a/include/jemalloc/jemalloc_FreeBSD.h b/include/jemalloc/jemalloc_FreeBSD.h 127a4bd5210SJason Evansnew file mode 100644 128*1f0a49e8SJason Evansindex 0000000..c58a8f3 129a4bd5210SJason Evans--- /dev/null 130a4bd5210SJason Evans+++ b/include/jemalloc/jemalloc_FreeBSD.h 131*1f0a49e8SJason Evans@@ -0,0 +1,162 @@ 132a4bd5210SJason Evans+/* 133a4bd5210SJason Evans+ * Override settings that were generated in jemalloc_defs.h as necessary. 134a4bd5210SJason Evans+ */ 135a4bd5210SJason Evans+ 136a4bd5210SJason Evans+#undef JEMALLOC_OVERRIDE_VALLOC 137a4bd5210SJason Evans+ 138a4bd5210SJason Evans+#ifndef MALLOC_PRODUCTION 139a4bd5210SJason Evans+#define JEMALLOC_DEBUG 140a4bd5210SJason Evans+#endif 141a4bd5210SJason Evans+ 142*1f0a49e8SJason Evans+#undef JEMALLOC_DSS 143*1f0a49e8SJason Evans+ 144a4bd5210SJason Evans+/* 145a4bd5210SJason Evans+ * The following are architecture-dependent, so conditionally define them for 146a4bd5210SJason Evans+ * each supported architecture. 147a4bd5210SJason Evans+ */ 148a4bd5210SJason Evans+#undef JEMALLOC_TLS_MODEL 149a4bd5210SJason Evans+#undef STATIC_PAGE_SHIFT 150a4bd5210SJason Evans+#undef LG_SIZEOF_PTR 151a4bd5210SJason Evans+#undef LG_SIZEOF_INT 152a4bd5210SJason Evans+#undef LG_SIZEOF_LONG 153a4bd5210SJason Evans+#undef LG_SIZEOF_INTMAX_T 154a4bd5210SJason Evans+ 155a4bd5210SJason Evans+#ifdef __i386__ 156a4bd5210SJason Evans+# define LG_SIZEOF_PTR 2 157a4bd5210SJason Evans+# define JEMALLOC_TLS_MODEL __attribute__((tls_model("initial-exec"))) 158a4bd5210SJason Evans+#endif 159a4bd5210SJason Evans+#ifdef __ia64__ 160a4bd5210SJason Evans+# define LG_SIZEOF_PTR 3 161a4bd5210SJason Evans+#endif 162a4bd5210SJason Evans+#ifdef __sparc64__ 163a4bd5210SJason Evans+# define LG_SIZEOF_PTR 3 164a4bd5210SJason Evans+# define JEMALLOC_TLS_MODEL __attribute__((tls_model("initial-exec"))) 165a4bd5210SJason Evans+#endif 166a4bd5210SJason Evans+#ifdef __amd64__ 167a4bd5210SJason Evans+# define LG_SIZEOF_PTR 3 168a4bd5210SJason Evans+# define JEMALLOC_TLS_MODEL __attribute__((tls_model("initial-exec"))) 169a4bd5210SJason Evans+#endif 170a4bd5210SJason Evans+#ifdef __arm__ 171a4bd5210SJason Evans+# define LG_SIZEOF_PTR 2 172a4bd5210SJason Evans+#endif 173d8e39d2dSJason Evans+#ifdef __aarch64__ 174d8e39d2dSJason Evans+# define LG_SIZEOF_PTR 3 175d8e39d2dSJason Evans+#endif 176a4bd5210SJason Evans+#ifdef __mips__ 177e722f8f8SJason Evans+#ifdef __mips_n64 178e722f8f8SJason Evans+# define LG_SIZEOF_PTR 3 179e722f8f8SJason Evans+#else 180a4bd5210SJason Evans+# define LG_SIZEOF_PTR 2 181a4bd5210SJason Evans+#endif 182e722f8f8SJason Evans+#endif 183a4bd5210SJason Evans+#ifdef __powerpc64__ 184a4bd5210SJason Evans+# define LG_SIZEOF_PTR 3 185a4bd5210SJason Evans+#elif defined(__powerpc__) 186a4bd5210SJason Evans+# define LG_SIZEOF_PTR 2 187a4bd5210SJason Evans+#endif 188df0d881dSJason Evans+#ifdef __riscv__ 189df0d881dSJason Evans+# define LG_SIZEOF_PTR 3 190df0d881dSJason Evans+#endif 191a4bd5210SJason Evans+ 192a4bd5210SJason Evans+#ifndef JEMALLOC_TLS_MODEL 193a4bd5210SJason Evans+# define JEMALLOC_TLS_MODEL /* Default. */ 194a4bd5210SJason Evans+#endif 195a4bd5210SJason Evans+ 196a4bd5210SJason Evans+#define STATIC_PAGE_SHIFT PAGE_SHIFT 197a4bd5210SJason Evans+#define LG_SIZEOF_INT 2 198a4bd5210SJason Evans+#define LG_SIZEOF_LONG LG_SIZEOF_PTR 199a4bd5210SJason Evans+#define LG_SIZEOF_INTMAX_T 3 200a4bd5210SJason Evans+ 201337776f8SJason Evans+#undef CPU_SPINWAIT 202337776f8SJason Evans+#include <machine/cpu.h> 203337776f8SJason Evans+#include <machine/cpufunc.h> 204337776f8SJason Evans+#define CPU_SPINWAIT cpu_spinwait() 205337776f8SJason Evans+ 206a4bd5210SJason Evans+/* Disable lazy-lock machinery, mangle isthreaded, and adjust its type. */ 207a4bd5210SJason Evans+#undef JEMALLOC_LAZY_LOCK 208a4bd5210SJason Evans+extern int __isthreaded; 209a4bd5210SJason Evans+#define isthreaded ((bool)__isthreaded) 210a4bd5210SJason Evans+ 211a4bd5210SJason Evans+/* Mangle. */ 212f8ca2db1SJason Evans+#undef je_malloc 213f8ca2db1SJason Evans+#undef je_calloc 214f8ca2db1SJason Evans+#undef je_posix_memalign 215d0e79aa3SJason Evans+#undef je_aligned_alloc 216df0d881dSJason Evans+#undef je_realloc 217df0d881dSJason Evans+#undef je_free 218f8ca2db1SJason Evans+#undef je_malloc_usable_size 219f921d10fSJason Evans+#undef je_mallocx 220f921d10fSJason Evans+#undef je_rallocx 221f921d10fSJason Evans+#undef je_xallocx 222f921d10fSJason Evans+#undef je_sallocx 223f921d10fSJason Evans+#undef je_dallocx 224df0d881dSJason Evans+#undef je_sdallocx 225f921d10fSJason Evans+#undef je_nallocx 226df0d881dSJason Evans+#undef je_mallctl 227df0d881dSJason Evans+#undef je_mallctlnametomib 228df0d881dSJason Evans+#undef je_mallctlbymib 229df0d881dSJason Evans+#undef je_malloc_stats_print 230f8ca2db1SJason Evans+#undef je_allocm 231f8ca2db1SJason Evans+#undef je_rallocm 232f8ca2db1SJason Evans+#undef je_sallocm 233f8ca2db1SJason Evans+#undef je_dallocm 234f8ca2db1SJason Evans+#undef je_nallocm 235f8ca2db1SJason Evans+#define je_malloc __malloc 236f8ca2db1SJason Evans+#define je_calloc __calloc 237f8ca2db1SJason Evans+#define je_posix_memalign __posix_memalign 238d0e79aa3SJason Evans+#define je_aligned_alloc __aligned_alloc 239df0d881dSJason Evans+#define je_realloc __realloc 240df0d881dSJason Evans+#define je_free __free 241f8ca2db1SJason Evans+#define je_malloc_usable_size __malloc_usable_size 242f921d10fSJason Evans+#define je_mallocx __mallocx 243f921d10fSJason Evans+#define je_rallocx __rallocx 244f921d10fSJason Evans+#define je_xallocx __xallocx 245f921d10fSJason Evans+#define je_sallocx __sallocx 246f921d10fSJason Evans+#define je_dallocx __dallocx 247df0d881dSJason Evans+#define je_sdallocx __sdallocx 248f921d10fSJason Evans+#define je_nallocx __nallocx 249df0d881dSJason Evans+#define je_mallctl __mallctl 250df0d881dSJason Evans+#define je_mallctlnametomib __mallctlnametomib 251df0d881dSJason Evans+#define je_mallctlbymib __mallctlbymib 252df0d881dSJason Evans+#define je_malloc_stats_print __malloc_stats_print 253f8ca2db1SJason Evans+#define je_allocm __allocm 254f8ca2db1SJason Evans+#define je_rallocm __rallocm 255f8ca2db1SJason Evans+#define je_sallocm __sallocm 256f8ca2db1SJason Evans+#define je_dallocm __dallocm 257f8ca2db1SJason Evans+#define je_nallocm __nallocm 258a4bd5210SJason Evans+#define open _open 259a4bd5210SJason Evans+#define read _read 260a4bd5210SJason Evans+#define write _write 261a4bd5210SJason Evans+#define close _close 262a4bd5210SJason Evans+#define pthread_mutex_lock _pthread_mutex_lock 263a4bd5210SJason Evans+#define pthread_mutex_unlock _pthread_mutex_unlock 264f8ca2db1SJason Evans+ 265f8ca2db1SJason Evans+#ifdef JEMALLOC_C_ 266f8ca2db1SJason Evans+/* 267f8ca2db1SJason Evans+ * Define 'weak' symbols so that an application can have its own versions 268f8ca2db1SJason Evans+ * of malloc, calloc, realloc, free, et al. 269f8ca2db1SJason Evans+ */ 270f8ca2db1SJason Evans+__weak_reference(__malloc, malloc); 271f8ca2db1SJason Evans+__weak_reference(__calloc, calloc); 272f8ca2db1SJason Evans+__weak_reference(__posix_memalign, posix_memalign); 273d0e79aa3SJason Evans+__weak_reference(__aligned_alloc, aligned_alloc); 274df0d881dSJason Evans+__weak_reference(__realloc, realloc); 275df0d881dSJason Evans+__weak_reference(__free, free); 276f8ca2db1SJason Evans+__weak_reference(__malloc_usable_size, malloc_usable_size); 277f921d10fSJason Evans+__weak_reference(__mallocx, mallocx); 278f921d10fSJason Evans+__weak_reference(__rallocx, rallocx); 279f921d10fSJason Evans+__weak_reference(__xallocx, xallocx); 280f921d10fSJason Evans+__weak_reference(__sallocx, sallocx); 281f921d10fSJason Evans+__weak_reference(__dallocx, dallocx); 282df0d881dSJason Evans+__weak_reference(__sdallocx, sdallocx); 283f921d10fSJason Evans+__weak_reference(__nallocx, nallocx); 284df0d881dSJason Evans+__weak_reference(__mallctl, mallctl); 285df0d881dSJason Evans+__weak_reference(__mallctlnametomib, mallctlnametomib); 286df0d881dSJason Evans+__weak_reference(__mallctlbymib, mallctlbymib); 287df0d881dSJason Evans+__weak_reference(__malloc_stats_print, malloc_stats_print); 288f8ca2db1SJason Evans+__weak_reference(__allocm, allocm); 289f8ca2db1SJason Evans+__weak_reference(__rallocm, rallocm); 290f8ca2db1SJason Evans+__weak_reference(__sallocm, sallocm); 291f8ca2db1SJason Evans+__weak_reference(__dallocm, dallocm); 292f8ca2db1SJason Evans+__weak_reference(__nallocm, nallocm); 293f8ca2db1SJason Evans+#endif 294f921d10fSJason Evansdiff --git a/include/jemalloc/jemalloc_rename.sh b/include/jemalloc/jemalloc_rename.sh 295f921d10fSJason Evansindex f943891..47d032c 100755 296f921d10fSJason Evans--- a/include/jemalloc/jemalloc_rename.sh 297f921d10fSJason Evans+++ b/include/jemalloc/jemalloc_rename.sh 298f921d10fSJason Evans@@ -19,4 +19,6 @@ done 299f921d10fSJason Evans 300f921d10fSJason Evans cat <<EOF 301f921d10fSJason Evans #endif 302f8ca2db1SJason Evans+ 303f921d10fSJason Evans+#include "jemalloc_FreeBSD.h" 304f921d10fSJason Evans EOF 305a4bd5210SJason Evansdiff --git a/src/jemalloc.c b/src/jemalloc.c 306*1f0a49e8SJason Evansindex 40eb2ea..666c49d 100644 307a4bd5210SJason Evans--- a/src/jemalloc.c 308a4bd5210SJason Evans+++ b/src/jemalloc.c 309d0e79aa3SJason Evans@@ -4,6 +4,10 @@ 310d0e79aa3SJason Evans /******************************************************************************/ 311d0e79aa3SJason Evans /* Data. */ 312a4bd5210SJason Evans 313e722f8f8SJason Evans+/* Work around <http://llvm.org/bugs/show_bug.cgi?id=12623>: */ 314e722f8f8SJason Evans+const char *__malloc_options_1_0 = NULL; 315a4bd5210SJason Evans+__sym_compat(_malloc_options, __malloc_options_1_0, FBSD_1.0); 316a4bd5210SJason Evans+ 317a4bd5210SJason Evans /* Runtime configuration options. */ 318d0e79aa3SJason Evans const char *je_malloc_conf JEMALLOC_ATTR(weak); 31988ad2f8dSJason Evans bool opt_abort = 320*1f0a49e8SJason Evans@@ -2673,6 +2677,107 @@ je_malloc_usable_size(JEMALLOC_USABLE_SIZE_CONST void *ptr) 321d0e79aa3SJason Evans */ 322d0e79aa3SJason Evans /******************************************************************************/ 323a4bd5210SJason Evans /* 324d0e79aa3SJason Evans+ * Begin compatibility functions. 325d0e79aa3SJason Evans+ */ 326d0e79aa3SJason Evans+ 327d0e79aa3SJason Evans+#define ALLOCM_LG_ALIGN(la) (la) 328d0e79aa3SJason Evans+#define ALLOCM_ALIGN(a) (ffsl(a)-1) 329d0e79aa3SJason Evans+#define ALLOCM_ZERO ((int)0x40) 330d0e79aa3SJason Evans+#define ALLOCM_NO_MOVE ((int)0x80) 331d0e79aa3SJason Evans+ 332d0e79aa3SJason Evans+#define ALLOCM_SUCCESS 0 333d0e79aa3SJason Evans+#define ALLOCM_ERR_OOM 1 334d0e79aa3SJason Evans+#define ALLOCM_ERR_NOT_MOVED 2 335d0e79aa3SJason Evans+ 336d0e79aa3SJason Evans+int 337d0e79aa3SJason Evans+je_allocm(void **ptr, size_t *rsize, size_t size, int flags) 338d0e79aa3SJason Evans+{ 339d0e79aa3SJason Evans+ void *p; 340d0e79aa3SJason Evans+ 341d0e79aa3SJason Evans+ assert(ptr != NULL); 342d0e79aa3SJason Evans+ 343d0e79aa3SJason Evans+ p = je_mallocx(size, flags); 344d0e79aa3SJason Evans+ if (p == NULL) 345d0e79aa3SJason Evans+ return (ALLOCM_ERR_OOM); 346d0e79aa3SJason Evans+ if (rsize != NULL) 347*1f0a49e8SJason Evans+ *rsize = isalloc(tsdn_fetch(), p, config_prof); 348d0e79aa3SJason Evans+ *ptr = p; 349d0e79aa3SJason Evans+ return (ALLOCM_SUCCESS); 350d0e79aa3SJason Evans+} 351d0e79aa3SJason Evans+ 352d0e79aa3SJason Evans+int 353d0e79aa3SJason Evans+je_rallocm(void **ptr, size_t *rsize, size_t size, size_t extra, int flags) 354d0e79aa3SJason Evans+{ 355d0e79aa3SJason Evans+ int ret; 356d0e79aa3SJason Evans+ bool no_move = flags & ALLOCM_NO_MOVE; 357d0e79aa3SJason Evans+ 358d0e79aa3SJason Evans+ assert(ptr != NULL); 359d0e79aa3SJason Evans+ assert(*ptr != NULL); 360d0e79aa3SJason Evans+ assert(size != 0); 361d0e79aa3SJason Evans+ assert(SIZE_T_MAX - size >= extra); 362d0e79aa3SJason Evans+ 363d0e79aa3SJason Evans+ if (no_move) { 364d0e79aa3SJason Evans+ size_t usize = je_xallocx(*ptr, size, extra, flags); 365d0e79aa3SJason Evans+ ret = (usize >= size) ? ALLOCM_SUCCESS : ALLOCM_ERR_NOT_MOVED; 366d0e79aa3SJason Evans+ if (rsize != NULL) 367d0e79aa3SJason Evans+ *rsize = usize; 368d0e79aa3SJason Evans+ } else { 369d0e79aa3SJason Evans+ void *p = je_rallocx(*ptr, size+extra, flags); 370d0e79aa3SJason Evans+ if (p != NULL) { 371d0e79aa3SJason Evans+ *ptr = p; 372d0e79aa3SJason Evans+ ret = ALLOCM_SUCCESS; 373d0e79aa3SJason Evans+ } else 374d0e79aa3SJason Evans+ ret = ALLOCM_ERR_OOM; 375d0e79aa3SJason Evans+ if (rsize != NULL) 376*1f0a49e8SJason Evans+ *rsize = isalloc(tsdn_fetch(), *ptr, config_prof); 377d0e79aa3SJason Evans+ } 378d0e79aa3SJason Evans+ return (ret); 379d0e79aa3SJason Evans+} 380d0e79aa3SJason Evans+ 381d0e79aa3SJason Evans+int 382d0e79aa3SJason Evans+je_sallocm(const void *ptr, size_t *rsize, int flags) 383d0e79aa3SJason Evans+{ 384d0e79aa3SJason Evans+ 385d0e79aa3SJason Evans+ assert(rsize != NULL); 386d0e79aa3SJason Evans+ *rsize = je_sallocx(ptr, flags); 387d0e79aa3SJason Evans+ return (ALLOCM_SUCCESS); 388d0e79aa3SJason Evans+} 389d0e79aa3SJason Evans+ 390d0e79aa3SJason Evans+int 391d0e79aa3SJason Evans+je_dallocm(void *ptr, int flags) 392d0e79aa3SJason Evans+{ 393d0e79aa3SJason Evans+ 394d0e79aa3SJason Evans+ je_dallocx(ptr, flags); 395d0e79aa3SJason Evans+ return (ALLOCM_SUCCESS); 396d0e79aa3SJason Evans+} 397d0e79aa3SJason Evans+ 398d0e79aa3SJason Evans+int 399d0e79aa3SJason Evans+je_nallocm(size_t *rsize, size_t size, int flags) 400d0e79aa3SJason Evans+{ 401d0e79aa3SJason Evans+ size_t usize; 402d0e79aa3SJason Evans+ 403d0e79aa3SJason Evans+ usize = je_nallocx(size, flags); 404d0e79aa3SJason Evans+ if (usize == 0) 405d0e79aa3SJason Evans+ return (ALLOCM_ERR_OOM); 406d0e79aa3SJason Evans+ if (rsize != NULL) 407d0e79aa3SJason Evans+ *rsize = usize; 408d0e79aa3SJason Evans+ return (ALLOCM_SUCCESS); 409d0e79aa3SJason Evans+} 410d0e79aa3SJason Evans+ 411d0e79aa3SJason Evans+#undef ALLOCM_LG_ALIGN 412d0e79aa3SJason Evans+#undef ALLOCM_ALIGN 413d0e79aa3SJason Evans+#undef ALLOCM_ZERO 414d0e79aa3SJason Evans+#undef ALLOCM_NO_MOVE 415d0e79aa3SJason Evans+ 416d0e79aa3SJason Evans+#undef ALLOCM_SUCCESS 417d0e79aa3SJason Evans+#undef ALLOCM_ERR_OOM 418d0e79aa3SJason Evans+#undef ALLOCM_ERR_NOT_MOVED 419d0e79aa3SJason Evans+ 420d0e79aa3SJason Evans+/* 421d0e79aa3SJason Evans+ * End compatibility functions. 422d0e79aa3SJason Evans+ */ 423d0e79aa3SJason Evans+/******************************************************************************/ 424d0e79aa3SJason Evans+/* 425d0e79aa3SJason Evans * The following functions are used by threading libraries for protection of 426d0e79aa3SJason Evans * malloc during fork(). 427d0e79aa3SJason Evans */ 428*1f0a49e8SJason Evans@@ -2814,4 +2919,11 @@ jemalloc_postfork_child(void) 429*1f0a49e8SJason Evans ctl_postfork_child(tsd_tsdn(tsd)); 430d0e79aa3SJason Evans } 431d0e79aa3SJason Evans 432d0e79aa3SJason Evans+void 433d0e79aa3SJason Evans+_malloc_first_thread(void) 434d0e79aa3SJason Evans+{ 435d0e79aa3SJason Evans+ 436d0e79aa3SJason Evans+ (void)malloc_mutex_first_thread(); 437d0e79aa3SJason Evans+} 438d0e79aa3SJason Evans+ 439d0e79aa3SJason Evans /******************************************************************************/ 440a4bd5210SJason Evansdiff --git a/src/mutex.c b/src/mutex.c 441*1f0a49e8SJason Evansindex a1fac34..a24e420 100644 442a4bd5210SJason Evans--- a/src/mutex.c 443a4bd5210SJason Evans+++ b/src/mutex.c 444e722f8f8SJason Evans@@ -66,6 +66,17 @@ pthread_create(pthread_t *__restrict thread, 445a4bd5210SJason Evans #ifdef JEMALLOC_MUTEX_INIT_CB 44682872ac0SJason Evans JEMALLOC_EXPORT int _pthread_mutex_init_calloc_cb(pthread_mutex_t *mutex, 447a4bd5210SJason Evans void *(calloc_cb)(size_t, size_t)); 448a4bd5210SJason Evans+ 449d0e79aa3SJason Evans+#pragma weak _pthread_mutex_init_calloc_cb 450a4bd5210SJason Evans+int 451d0e79aa3SJason Evans+_pthread_mutex_init_calloc_cb(pthread_mutex_t *mutex, 452a4bd5210SJason Evans+ void *(calloc_cb)(size_t, size_t)) 453a4bd5210SJason Evans+{ 454a4bd5210SJason Evans+ 455d0e79aa3SJason Evans+ return (((int (*)(pthread_mutex_t *, void *(*)(size_t, size_t))) 456d0e79aa3SJason Evans+ __libc_interposing[INTERPOS__pthread_mutex_init_calloc_cb])(mutex, 457d0e79aa3SJason Evans+ calloc_cb)); 458a4bd5210SJason Evans+} 459a4bd5210SJason Evans #endif 460a4bd5210SJason Evans 461a4bd5210SJason Evans bool 462*1f0a49e8SJason Evans@@ -140,7 +151,7 @@ malloc_mutex_postfork_child(tsdn_t *tsdn, malloc_mutex_t *mutex) 463d0e79aa3SJason Evans } 464d0e79aa3SJason Evans 465d0e79aa3SJason Evans bool 466*1f0a49e8SJason Evans-malloc_mutex_boot(void) 467d0e79aa3SJason Evans+malloc_mutex_first_thread(void) 468d0e79aa3SJason Evans { 469d0e79aa3SJason Evans 470d0e79aa3SJason Evans #ifdef JEMALLOC_MUTEX_INIT_CB 471*1f0a49e8SJason Evans@@ -154,3 +165,14 @@ malloc_mutex_boot(void) 472d0e79aa3SJason Evans #endif 473d0e79aa3SJason Evans return (false); 474d0e79aa3SJason Evans } 475d0e79aa3SJason Evans+ 476d0e79aa3SJason Evans+bool 477*1f0a49e8SJason Evans+malloc_mutex_boot(void) 478d0e79aa3SJason Evans+{ 479d0e79aa3SJason Evans+ 480d0e79aa3SJason Evans+#ifndef JEMALLOC_MUTEX_INIT_CB 481d0e79aa3SJason Evans+ return (malloc_mutex_first_thread()); 482d0e79aa3SJason Evans+#else 483d0e79aa3SJason Evans+ return (false); 484d0e79aa3SJason Evans+#endif 485d0e79aa3SJason Evans+} 486a4bd5210SJason Evansdiff --git a/src/util.c b/src/util.c 487*1f0a49e8SJason Evansindex a1c4a2a..04f9153 100644 488a4bd5210SJason Evans--- a/src/util.c 489a4bd5210SJason Evans+++ b/src/util.c 490*1f0a49e8SJason Evans@@ -67,6 +67,22 @@ wrtmessage(void *cbopaque, const char *s) 491a4bd5210SJason Evans 492e722f8f8SJason Evans JEMALLOC_EXPORT void (*je_malloc_message)(void *, const char *s); 493e722f8f8SJason Evans 494e722f8f8SJason Evans+JEMALLOC_ATTR(visibility("hidden")) 495a4bd5210SJason Evans+void 496a4bd5210SJason Evans+wrtmessage_1_0(const char *s1, const char *s2, const char *s3, 497a4bd5210SJason Evans+ const char *s4) 498a4bd5210SJason Evans+{ 499a4bd5210SJason Evans+ 500a4bd5210SJason Evans+ wrtmessage(NULL, s1); 501a4bd5210SJason Evans+ wrtmessage(NULL, s2); 502a4bd5210SJason Evans+ wrtmessage(NULL, s3); 503a4bd5210SJason Evans+ wrtmessage(NULL, s4); 504a4bd5210SJason Evans+} 505a4bd5210SJason Evans+ 506a4bd5210SJason Evans+void (*__malloc_message_1_0)(const char *s1, const char *s2, const char *s3, 507a4bd5210SJason Evans+ const char *s4) = wrtmessage_1_0; 508a4bd5210SJason Evans+__sym_compat(_malloc_message, __malloc_message_1_0, FBSD_1.0); 509a4bd5210SJason Evans+ 510a4bd5210SJason Evans /* 511e722f8f8SJason Evans * Wrapper around malloc_message() that avoids the need for 512e722f8f8SJason Evans * je_malloc_message(...) throughout the code. 513