1a4bd5210SJason Evansdiff --git a/doc/jemalloc.xml.in b/doc/jemalloc.xml.in 2*df0d881dSJason Evansindex bc5dbd1..ba182da 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*df0d881dSJason Evans@@ -2905,4 +2917,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*df0d881dSJason Evansindex 3f54391..d240256 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; 75*df0d881dSJason 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 79*df0d881dSJason 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 93d0e79aa3SJason Evansindex f051f29..561378f 100644 94a4bd5210SJason Evans--- a/include/jemalloc/internal/mutex.h 95a4bd5210SJason Evans+++ b/include/jemalloc/internal/mutex.h 96d0e79aa3SJason Evans@@ -47,15 +47,13 @@ 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 105a4bd5210SJason Evans bool malloc_mutex_init(malloc_mutex_t *mutex); 106d0e79aa3SJason Evans void malloc_mutex_prefork(malloc_mutex_t *mutex); 107d0e79aa3SJason Evans void malloc_mutex_postfork_parent(malloc_mutex_t *mutex); 108d0e79aa3SJason Evans void malloc_mutex_postfork_child(malloc_mutex_t *mutex); 109d0e79aa3SJason Evans+bool malloc_mutex_first_thread(void); 110d0e79aa3SJason Evans bool mutex_boot(void); 111d0e79aa3SJason Evans 112d0e79aa3SJason Evans #endif /* JEMALLOC_H_EXTERNS */ 113f921d10fSJason Evansdiff --git a/include/jemalloc/internal/private_symbols.txt b/include/jemalloc/internal/private_symbols.txt 114*df0d881dSJason Evansindex 5880996..6e94e03 100644 115f921d10fSJason Evans--- a/include/jemalloc/internal/private_symbols.txt 116f921d10fSJason Evans+++ b/include/jemalloc/internal/private_symbols.txt 117*df0d881dSJason Evans@@ -296,7 +296,6 @@ iralloct_realign 118f921d10fSJason Evans isalloc 119d0e79aa3SJason Evans isdalloct 120d0e79aa3SJason Evans isqalloc 121f921d10fSJason Evans-isthreaded 122f921d10fSJason Evans ivsalloc 123f921d10fSJason Evans ixalloc 124f921d10fSJason Evans jemalloc_postfork_child 125a4bd5210SJason Evansdiff --git a/include/jemalloc/jemalloc_FreeBSD.h b/include/jemalloc/jemalloc_FreeBSD.h 126a4bd5210SJason Evansnew file mode 100644 127*df0d881dSJason Evansindex 0000000..433dab5 128a4bd5210SJason Evans--- /dev/null 129a4bd5210SJason Evans+++ b/include/jemalloc/jemalloc_FreeBSD.h 130*df0d881dSJason Evans@@ -0,0 +1,160 @@ 131a4bd5210SJason Evans+/* 132a4bd5210SJason Evans+ * Override settings that were generated in jemalloc_defs.h as necessary. 133a4bd5210SJason Evans+ */ 134a4bd5210SJason Evans+ 135a4bd5210SJason Evans+#undef JEMALLOC_OVERRIDE_VALLOC 136a4bd5210SJason Evans+ 137a4bd5210SJason Evans+#ifndef MALLOC_PRODUCTION 138a4bd5210SJason Evans+#define JEMALLOC_DEBUG 139a4bd5210SJason Evans+#endif 140a4bd5210SJason Evans+ 141a4bd5210SJason Evans+/* 142a4bd5210SJason Evans+ * The following are architecture-dependent, so conditionally define them for 143a4bd5210SJason Evans+ * each supported architecture. 144a4bd5210SJason Evans+ */ 145a4bd5210SJason Evans+#undef JEMALLOC_TLS_MODEL 146a4bd5210SJason Evans+#undef STATIC_PAGE_SHIFT 147a4bd5210SJason Evans+#undef LG_SIZEOF_PTR 148a4bd5210SJason Evans+#undef LG_SIZEOF_INT 149a4bd5210SJason Evans+#undef LG_SIZEOF_LONG 150a4bd5210SJason Evans+#undef LG_SIZEOF_INTMAX_T 151a4bd5210SJason Evans+ 152a4bd5210SJason Evans+#ifdef __i386__ 153a4bd5210SJason Evans+# define LG_SIZEOF_PTR 2 154a4bd5210SJason Evans+# define JEMALLOC_TLS_MODEL __attribute__((tls_model("initial-exec"))) 155a4bd5210SJason Evans+#endif 156a4bd5210SJason Evans+#ifdef __ia64__ 157a4bd5210SJason Evans+# define LG_SIZEOF_PTR 3 158a4bd5210SJason Evans+#endif 159a4bd5210SJason Evans+#ifdef __sparc64__ 160a4bd5210SJason Evans+# define LG_SIZEOF_PTR 3 161a4bd5210SJason Evans+# define JEMALLOC_TLS_MODEL __attribute__((tls_model("initial-exec"))) 162a4bd5210SJason Evans+#endif 163a4bd5210SJason Evans+#ifdef __amd64__ 164a4bd5210SJason Evans+# define LG_SIZEOF_PTR 3 165a4bd5210SJason Evans+# define JEMALLOC_TLS_MODEL __attribute__((tls_model("initial-exec"))) 166a4bd5210SJason Evans+#endif 167a4bd5210SJason Evans+#ifdef __arm__ 168a4bd5210SJason Evans+# define LG_SIZEOF_PTR 2 169a4bd5210SJason Evans+#endif 170d8e39d2dSJason Evans+#ifdef __aarch64__ 171d8e39d2dSJason Evans+# define LG_SIZEOF_PTR 3 172d8e39d2dSJason Evans+#endif 173a4bd5210SJason Evans+#ifdef __mips__ 174e722f8f8SJason Evans+#ifdef __mips_n64 175e722f8f8SJason Evans+# define LG_SIZEOF_PTR 3 176e722f8f8SJason Evans+#else 177a4bd5210SJason Evans+# define LG_SIZEOF_PTR 2 178a4bd5210SJason Evans+#endif 179e722f8f8SJason Evans+#endif 180a4bd5210SJason Evans+#ifdef __powerpc64__ 181a4bd5210SJason Evans+# define LG_SIZEOF_PTR 3 182a4bd5210SJason Evans+#elif defined(__powerpc__) 183a4bd5210SJason Evans+# define LG_SIZEOF_PTR 2 184a4bd5210SJason Evans+#endif 185*df0d881dSJason Evans+#ifdef __riscv__ 186*df0d881dSJason Evans+# define LG_SIZEOF_PTR 3 187*df0d881dSJason Evans+#endif 188a4bd5210SJason Evans+ 189a4bd5210SJason Evans+#ifndef JEMALLOC_TLS_MODEL 190a4bd5210SJason Evans+# define JEMALLOC_TLS_MODEL /* Default. */ 191a4bd5210SJason Evans+#endif 192a4bd5210SJason Evans+ 193a4bd5210SJason Evans+#define STATIC_PAGE_SHIFT PAGE_SHIFT 194a4bd5210SJason Evans+#define LG_SIZEOF_INT 2 195a4bd5210SJason Evans+#define LG_SIZEOF_LONG LG_SIZEOF_PTR 196a4bd5210SJason Evans+#define LG_SIZEOF_INTMAX_T 3 197a4bd5210SJason Evans+ 198337776f8SJason Evans+#undef CPU_SPINWAIT 199337776f8SJason Evans+#include <machine/cpu.h> 200337776f8SJason Evans+#include <machine/cpufunc.h> 201337776f8SJason Evans+#define CPU_SPINWAIT cpu_spinwait() 202337776f8SJason Evans+ 203a4bd5210SJason Evans+/* Disable lazy-lock machinery, mangle isthreaded, and adjust its type. */ 204a4bd5210SJason Evans+#undef JEMALLOC_LAZY_LOCK 205a4bd5210SJason Evans+extern int __isthreaded; 206a4bd5210SJason Evans+#define isthreaded ((bool)__isthreaded) 207a4bd5210SJason Evans+ 208a4bd5210SJason Evans+/* Mangle. */ 209f8ca2db1SJason Evans+#undef je_malloc 210f8ca2db1SJason Evans+#undef je_calloc 211f8ca2db1SJason Evans+#undef je_posix_memalign 212d0e79aa3SJason Evans+#undef je_aligned_alloc 213*df0d881dSJason Evans+#undef je_realloc 214*df0d881dSJason Evans+#undef je_free 215f8ca2db1SJason Evans+#undef je_malloc_usable_size 216f921d10fSJason Evans+#undef je_mallocx 217f921d10fSJason Evans+#undef je_rallocx 218f921d10fSJason Evans+#undef je_xallocx 219f921d10fSJason Evans+#undef je_sallocx 220f921d10fSJason Evans+#undef je_dallocx 221*df0d881dSJason Evans+#undef je_sdallocx 222f921d10fSJason Evans+#undef je_nallocx 223*df0d881dSJason Evans+#undef je_mallctl 224*df0d881dSJason Evans+#undef je_mallctlnametomib 225*df0d881dSJason Evans+#undef je_mallctlbymib 226*df0d881dSJason Evans+#undef je_malloc_stats_print 227f8ca2db1SJason Evans+#undef je_allocm 228f8ca2db1SJason Evans+#undef je_rallocm 229f8ca2db1SJason Evans+#undef je_sallocm 230f8ca2db1SJason Evans+#undef je_dallocm 231f8ca2db1SJason Evans+#undef je_nallocm 232f8ca2db1SJason Evans+#define je_malloc __malloc 233f8ca2db1SJason Evans+#define je_calloc __calloc 234f8ca2db1SJason Evans+#define je_posix_memalign __posix_memalign 235d0e79aa3SJason Evans+#define je_aligned_alloc __aligned_alloc 236*df0d881dSJason Evans+#define je_realloc __realloc 237*df0d881dSJason Evans+#define je_free __free 238f8ca2db1SJason Evans+#define je_malloc_usable_size __malloc_usable_size 239f921d10fSJason Evans+#define je_mallocx __mallocx 240f921d10fSJason Evans+#define je_rallocx __rallocx 241f921d10fSJason Evans+#define je_xallocx __xallocx 242f921d10fSJason Evans+#define je_sallocx __sallocx 243f921d10fSJason Evans+#define je_dallocx __dallocx 244*df0d881dSJason Evans+#define je_sdallocx __sdallocx 245f921d10fSJason Evans+#define je_nallocx __nallocx 246*df0d881dSJason Evans+#define je_mallctl __mallctl 247*df0d881dSJason Evans+#define je_mallctlnametomib __mallctlnametomib 248*df0d881dSJason Evans+#define je_mallctlbymib __mallctlbymib 249*df0d881dSJason Evans+#define je_malloc_stats_print __malloc_stats_print 250f8ca2db1SJason Evans+#define je_allocm __allocm 251f8ca2db1SJason Evans+#define je_rallocm __rallocm 252f8ca2db1SJason Evans+#define je_sallocm __sallocm 253f8ca2db1SJason Evans+#define je_dallocm __dallocm 254f8ca2db1SJason Evans+#define je_nallocm __nallocm 255a4bd5210SJason Evans+#define open _open 256a4bd5210SJason Evans+#define read _read 257a4bd5210SJason Evans+#define write _write 258a4bd5210SJason Evans+#define close _close 259a4bd5210SJason Evans+#define pthread_mutex_lock _pthread_mutex_lock 260a4bd5210SJason Evans+#define pthread_mutex_unlock _pthread_mutex_unlock 261f8ca2db1SJason Evans+ 262f8ca2db1SJason Evans+#ifdef JEMALLOC_C_ 263f8ca2db1SJason Evans+/* 264f8ca2db1SJason Evans+ * Define 'weak' symbols so that an application can have its own versions 265f8ca2db1SJason Evans+ * of malloc, calloc, realloc, free, et al. 266f8ca2db1SJason Evans+ */ 267f8ca2db1SJason Evans+__weak_reference(__malloc, malloc); 268f8ca2db1SJason Evans+__weak_reference(__calloc, calloc); 269f8ca2db1SJason Evans+__weak_reference(__posix_memalign, posix_memalign); 270d0e79aa3SJason Evans+__weak_reference(__aligned_alloc, aligned_alloc); 271*df0d881dSJason Evans+__weak_reference(__realloc, realloc); 272*df0d881dSJason Evans+__weak_reference(__free, free); 273f8ca2db1SJason Evans+__weak_reference(__malloc_usable_size, malloc_usable_size); 274f921d10fSJason Evans+__weak_reference(__mallocx, mallocx); 275f921d10fSJason Evans+__weak_reference(__rallocx, rallocx); 276f921d10fSJason Evans+__weak_reference(__xallocx, xallocx); 277f921d10fSJason Evans+__weak_reference(__sallocx, sallocx); 278f921d10fSJason Evans+__weak_reference(__dallocx, dallocx); 279*df0d881dSJason Evans+__weak_reference(__sdallocx, sdallocx); 280f921d10fSJason Evans+__weak_reference(__nallocx, nallocx); 281*df0d881dSJason Evans+__weak_reference(__mallctl, mallctl); 282*df0d881dSJason Evans+__weak_reference(__mallctlnametomib, mallctlnametomib); 283*df0d881dSJason Evans+__weak_reference(__mallctlbymib, mallctlbymib); 284*df0d881dSJason Evans+__weak_reference(__malloc_stats_print, malloc_stats_print); 285f8ca2db1SJason Evans+__weak_reference(__allocm, allocm); 286f8ca2db1SJason Evans+__weak_reference(__rallocm, rallocm); 287f8ca2db1SJason Evans+__weak_reference(__sallocm, sallocm); 288f8ca2db1SJason Evans+__weak_reference(__dallocm, dallocm); 289f8ca2db1SJason Evans+__weak_reference(__nallocm, nallocm); 290f8ca2db1SJason Evans+#endif 291f921d10fSJason Evansdiff --git a/include/jemalloc/jemalloc_rename.sh b/include/jemalloc/jemalloc_rename.sh 292f921d10fSJason Evansindex f943891..47d032c 100755 293f921d10fSJason Evans--- a/include/jemalloc/jemalloc_rename.sh 294f921d10fSJason Evans+++ b/include/jemalloc/jemalloc_rename.sh 295f921d10fSJason Evans@@ -19,4 +19,6 @@ done 296f921d10fSJason Evans 297f921d10fSJason Evans cat <<EOF 298f921d10fSJason Evans #endif 299f8ca2db1SJason Evans+ 300f921d10fSJason Evans+#include "jemalloc_FreeBSD.h" 301f921d10fSJason Evans EOF 302a4bd5210SJason Evansdiff --git a/src/jemalloc.c b/src/jemalloc.c 303*df0d881dSJason Evansindex 0735376..a34b85c 100644 304a4bd5210SJason Evans--- a/src/jemalloc.c 305a4bd5210SJason Evans+++ b/src/jemalloc.c 306d0e79aa3SJason Evans@@ -4,6 +4,10 @@ 307d0e79aa3SJason Evans /******************************************************************************/ 308d0e79aa3SJason Evans /* Data. */ 309a4bd5210SJason Evans 310e722f8f8SJason Evans+/* Work around <http://llvm.org/bugs/show_bug.cgi?id=12623>: */ 311e722f8f8SJason Evans+const char *__malloc_options_1_0 = NULL; 312a4bd5210SJason Evans+__sym_compat(_malloc_options, __malloc_options_1_0, FBSD_1.0); 313a4bd5210SJason Evans+ 314a4bd5210SJason Evans /* Runtime configuration options. */ 315d0e79aa3SJason Evans const char *je_malloc_conf JEMALLOC_ATTR(weak); 31688ad2f8dSJason Evans bool opt_abort = 317*df0d881dSJason Evans@@ -2611,6 +2615,107 @@ je_malloc_usable_size(JEMALLOC_USABLE_SIZE_CONST void *ptr) 318d0e79aa3SJason Evans */ 319d0e79aa3SJason Evans /******************************************************************************/ 320a4bd5210SJason Evans /* 321d0e79aa3SJason Evans+ * Begin compatibility functions. 322d0e79aa3SJason Evans+ */ 323d0e79aa3SJason Evans+ 324d0e79aa3SJason Evans+#define ALLOCM_LG_ALIGN(la) (la) 325d0e79aa3SJason Evans+#define ALLOCM_ALIGN(a) (ffsl(a)-1) 326d0e79aa3SJason Evans+#define ALLOCM_ZERO ((int)0x40) 327d0e79aa3SJason Evans+#define ALLOCM_NO_MOVE ((int)0x80) 328d0e79aa3SJason Evans+ 329d0e79aa3SJason Evans+#define ALLOCM_SUCCESS 0 330d0e79aa3SJason Evans+#define ALLOCM_ERR_OOM 1 331d0e79aa3SJason Evans+#define ALLOCM_ERR_NOT_MOVED 2 332d0e79aa3SJason Evans+ 333d0e79aa3SJason Evans+int 334d0e79aa3SJason Evans+je_allocm(void **ptr, size_t *rsize, size_t size, int flags) 335d0e79aa3SJason Evans+{ 336d0e79aa3SJason Evans+ void *p; 337d0e79aa3SJason Evans+ 338d0e79aa3SJason Evans+ assert(ptr != NULL); 339d0e79aa3SJason Evans+ 340d0e79aa3SJason Evans+ p = je_mallocx(size, flags); 341d0e79aa3SJason Evans+ if (p == NULL) 342d0e79aa3SJason Evans+ return (ALLOCM_ERR_OOM); 343d0e79aa3SJason Evans+ if (rsize != NULL) 344d0e79aa3SJason Evans+ *rsize = isalloc(p, config_prof); 345d0e79aa3SJason Evans+ *ptr = p; 346d0e79aa3SJason Evans+ return (ALLOCM_SUCCESS); 347d0e79aa3SJason Evans+} 348d0e79aa3SJason Evans+ 349d0e79aa3SJason Evans+int 350d0e79aa3SJason Evans+je_rallocm(void **ptr, size_t *rsize, size_t size, size_t extra, int flags) 351d0e79aa3SJason Evans+{ 352d0e79aa3SJason Evans+ int ret; 353d0e79aa3SJason Evans+ bool no_move = flags & ALLOCM_NO_MOVE; 354d0e79aa3SJason Evans+ 355d0e79aa3SJason Evans+ assert(ptr != NULL); 356d0e79aa3SJason Evans+ assert(*ptr != NULL); 357d0e79aa3SJason Evans+ assert(size != 0); 358d0e79aa3SJason Evans+ assert(SIZE_T_MAX - size >= extra); 359d0e79aa3SJason Evans+ 360d0e79aa3SJason Evans+ if (no_move) { 361d0e79aa3SJason Evans+ size_t usize = je_xallocx(*ptr, size, extra, flags); 362d0e79aa3SJason Evans+ ret = (usize >= size) ? ALLOCM_SUCCESS : ALLOCM_ERR_NOT_MOVED; 363d0e79aa3SJason Evans+ if (rsize != NULL) 364d0e79aa3SJason Evans+ *rsize = usize; 365d0e79aa3SJason Evans+ } else { 366d0e79aa3SJason Evans+ void *p = je_rallocx(*ptr, size+extra, flags); 367d0e79aa3SJason Evans+ if (p != NULL) { 368d0e79aa3SJason Evans+ *ptr = p; 369d0e79aa3SJason Evans+ ret = ALLOCM_SUCCESS; 370d0e79aa3SJason Evans+ } else 371d0e79aa3SJason Evans+ ret = ALLOCM_ERR_OOM; 372d0e79aa3SJason Evans+ if (rsize != NULL) 373d0e79aa3SJason Evans+ *rsize = isalloc(*ptr, config_prof); 374d0e79aa3SJason Evans+ } 375d0e79aa3SJason Evans+ return (ret); 376d0e79aa3SJason Evans+} 377d0e79aa3SJason Evans+ 378d0e79aa3SJason Evans+int 379d0e79aa3SJason Evans+je_sallocm(const void *ptr, size_t *rsize, int flags) 380d0e79aa3SJason Evans+{ 381d0e79aa3SJason Evans+ 382d0e79aa3SJason Evans+ assert(rsize != NULL); 383d0e79aa3SJason Evans+ *rsize = je_sallocx(ptr, flags); 384d0e79aa3SJason Evans+ return (ALLOCM_SUCCESS); 385d0e79aa3SJason Evans+} 386d0e79aa3SJason Evans+ 387d0e79aa3SJason Evans+int 388d0e79aa3SJason Evans+je_dallocm(void *ptr, int flags) 389d0e79aa3SJason Evans+{ 390d0e79aa3SJason Evans+ 391d0e79aa3SJason Evans+ je_dallocx(ptr, flags); 392d0e79aa3SJason Evans+ return (ALLOCM_SUCCESS); 393d0e79aa3SJason Evans+} 394d0e79aa3SJason Evans+ 395d0e79aa3SJason Evans+int 396d0e79aa3SJason Evans+je_nallocm(size_t *rsize, size_t size, int flags) 397d0e79aa3SJason Evans+{ 398d0e79aa3SJason Evans+ size_t usize; 399d0e79aa3SJason Evans+ 400d0e79aa3SJason Evans+ usize = je_nallocx(size, flags); 401d0e79aa3SJason Evans+ if (usize == 0) 402d0e79aa3SJason Evans+ return (ALLOCM_ERR_OOM); 403d0e79aa3SJason Evans+ if (rsize != NULL) 404d0e79aa3SJason Evans+ *rsize = usize; 405d0e79aa3SJason Evans+ return (ALLOCM_SUCCESS); 406d0e79aa3SJason Evans+} 407d0e79aa3SJason Evans+ 408d0e79aa3SJason Evans+#undef ALLOCM_LG_ALIGN 409d0e79aa3SJason Evans+#undef ALLOCM_ALIGN 410d0e79aa3SJason Evans+#undef ALLOCM_ZERO 411d0e79aa3SJason Evans+#undef ALLOCM_NO_MOVE 412d0e79aa3SJason Evans+ 413d0e79aa3SJason Evans+#undef ALLOCM_SUCCESS 414d0e79aa3SJason Evans+#undef ALLOCM_ERR_OOM 415d0e79aa3SJason Evans+#undef ALLOCM_ERR_NOT_MOVED 416d0e79aa3SJason Evans+ 417d0e79aa3SJason Evans+/* 418d0e79aa3SJason Evans+ * End compatibility functions. 419d0e79aa3SJason Evans+ */ 420d0e79aa3SJason Evans+/******************************************************************************/ 421d0e79aa3SJason Evans+/* 422d0e79aa3SJason Evans * The following functions are used by threading libraries for protection of 423d0e79aa3SJason Evans * malloc during fork(). 424d0e79aa3SJason Evans */ 425*df0d881dSJason Evans@@ -2717,4 +2822,11 @@ jemalloc_postfork_child(void) 426d0e79aa3SJason Evans ctl_postfork_child(); 427d0e79aa3SJason Evans } 428d0e79aa3SJason Evans 429d0e79aa3SJason Evans+void 430d0e79aa3SJason Evans+_malloc_first_thread(void) 431d0e79aa3SJason Evans+{ 432d0e79aa3SJason Evans+ 433d0e79aa3SJason Evans+ (void)malloc_mutex_first_thread(); 434d0e79aa3SJason Evans+} 435d0e79aa3SJason Evans+ 436d0e79aa3SJason Evans /******************************************************************************/ 437a4bd5210SJason Evansdiff --git a/src/mutex.c b/src/mutex.c 438d0e79aa3SJason Evansindex 2d47af9..934d5aa 100644 439a4bd5210SJason Evans--- a/src/mutex.c 440a4bd5210SJason Evans+++ b/src/mutex.c 441e722f8f8SJason Evans@@ -66,6 +66,17 @@ pthread_create(pthread_t *__restrict thread, 442a4bd5210SJason Evans #ifdef JEMALLOC_MUTEX_INIT_CB 44382872ac0SJason Evans JEMALLOC_EXPORT int _pthread_mutex_init_calloc_cb(pthread_mutex_t *mutex, 444a4bd5210SJason Evans void *(calloc_cb)(size_t, size_t)); 445a4bd5210SJason Evans+ 446d0e79aa3SJason Evans+#pragma weak _pthread_mutex_init_calloc_cb 447a4bd5210SJason Evans+int 448d0e79aa3SJason Evans+_pthread_mutex_init_calloc_cb(pthread_mutex_t *mutex, 449a4bd5210SJason Evans+ void *(calloc_cb)(size_t, size_t)) 450a4bd5210SJason Evans+{ 451a4bd5210SJason Evans+ 452d0e79aa3SJason Evans+ return (((int (*)(pthread_mutex_t *, void *(*)(size_t, size_t))) 453d0e79aa3SJason Evans+ __libc_interposing[INTERPOS__pthread_mutex_init_calloc_cb])(mutex, 454d0e79aa3SJason Evans+ calloc_cb)); 455a4bd5210SJason Evans+} 456a4bd5210SJason Evans #endif 457a4bd5210SJason Evans 458a4bd5210SJason Evans bool 459d0e79aa3SJason Evans@@ -137,7 +148,7 @@ malloc_mutex_postfork_child(malloc_mutex_t *mutex) 460d0e79aa3SJason Evans } 461d0e79aa3SJason Evans 462d0e79aa3SJason Evans bool 463d0e79aa3SJason Evans-mutex_boot(void) 464d0e79aa3SJason Evans+malloc_mutex_first_thread(void) 465d0e79aa3SJason Evans { 466d0e79aa3SJason Evans 467d0e79aa3SJason Evans #ifdef JEMALLOC_MUTEX_INIT_CB 468d0e79aa3SJason Evans@@ -151,3 +162,14 @@ mutex_boot(void) 469d0e79aa3SJason Evans #endif 470d0e79aa3SJason Evans return (false); 471d0e79aa3SJason Evans } 472d0e79aa3SJason Evans+ 473d0e79aa3SJason Evans+bool 474d0e79aa3SJason Evans+mutex_boot(void) 475d0e79aa3SJason Evans+{ 476d0e79aa3SJason Evans+ 477d0e79aa3SJason Evans+#ifndef JEMALLOC_MUTEX_INIT_CB 478d0e79aa3SJason Evans+ return (malloc_mutex_first_thread()); 479d0e79aa3SJason Evans+#else 480d0e79aa3SJason Evans+ return (false); 481d0e79aa3SJason Evans+#endif 482d0e79aa3SJason Evans+} 483a4bd5210SJason Evansdiff --git a/src/util.c b/src/util.c 484*df0d881dSJason Evansindex 02673c7..116e981 100644 485a4bd5210SJason Evans--- a/src/util.c 486a4bd5210SJason Evans+++ b/src/util.c 487*df0d881dSJason Evans@@ -66,6 +66,22 @@ wrtmessage(void *cbopaque, const char *s) 488a4bd5210SJason Evans 489e722f8f8SJason Evans JEMALLOC_EXPORT void (*je_malloc_message)(void *, const char *s); 490e722f8f8SJason Evans 491e722f8f8SJason Evans+JEMALLOC_ATTR(visibility("hidden")) 492a4bd5210SJason Evans+void 493a4bd5210SJason Evans+wrtmessage_1_0(const char *s1, const char *s2, const char *s3, 494a4bd5210SJason Evans+ const char *s4) 495a4bd5210SJason Evans+{ 496a4bd5210SJason Evans+ 497a4bd5210SJason Evans+ wrtmessage(NULL, s1); 498a4bd5210SJason Evans+ wrtmessage(NULL, s2); 499a4bd5210SJason Evans+ wrtmessage(NULL, s3); 500a4bd5210SJason Evans+ wrtmessage(NULL, s4); 501a4bd5210SJason Evans+} 502a4bd5210SJason Evans+ 503a4bd5210SJason Evans+void (*__malloc_message_1_0)(const char *s1, const char *s2, const char *s3, 504a4bd5210SJason Evans+ const char *s4) = wrtmessage_1_0; 505a4bd5210SJason Evans+__sym_compat(_malloc_message, __malloc_message_1_0, FBSD_1.0); 506a4bd5210SJason Evans+ 507a4bd5210SJason Evans /* 508e722f8f8SJason Evans * Wrapper around malloc_message() that avoids the need for 509e722f8f8SJason Evans * je_malloc_message(...) throughout the code. 510