diff --git a/jemalloc/configure.ac b/jemalloc/configure.ac index b0d470a0..127b6951 100644 --- a/jemalloc/configure.ac +++ b/jemalloc/configure.ac @@ -710,6 +710,14 @@ if test "x${enable_tls}" = "x0" ; then AC_DEFINE_UNQUOTED([NO_TLS], [ ]) fi +dnl ============================================================================ +dnl Check for allocator-related functions that should be wrapped. + +AC_CHECK_FUNC([memalign], + [AC_DEFINE([JEMALLOC_OVERRIDE_MEMALIGN])]) +AC_CHECK_FUNC([valloc], + [AC_DEFINE([JEMALLOC_OVERRIDE_VALLOC])]) + dnl ============================================================================ dnl Darwin-related configuration. diff --git a/jemalloc/include/jemalloc/jemalloc_defs.h.in b/jemalloc/include/jemalloc/jemalloc_defs.h.in index eed33a64..6bdcbaa4 100644 --- a/jemalloc/include/jemalloc/jemalloc_defs.h.in +++ b/jemalloc/include/jemalloc/jemalloc_defs.h.in @@ -98,6 +98,13 @@ */ #undef JEMALLOC_IVSALLOC +/* + * Define overrides for non-standard allocator-related functions if they + * are present on the system. + */ +#undef JEMALLOC_OVERRIDE_MEMALIGN +#undef JEMALLOC_OVERRIDE_VALLOC + /* * Darwin (OS X) uses zones to work around Mach-O symbol override shortcomings. */ diff --git a/jemalloc/src/jemalloc.c b/jemalloc/src/jemalloc.c index 0b60ce60..3f115d89 100644 --- a/jemalloc/src/jemalloc.c +++ b/jemalloc/src/jemalloc.c @@ -1145,6 +1145,45 @@ JEMALLOC_P(free)(void *ptr) * End malloc(3)-compatible functions. */ /******************************************************************************/ +/* + * Begin non-standard override functions. + * + * These overrides are omitted if the JEMALLOC_PREFIX is defined, since the + * entire point is to avoid accidental mixed allocator usage. + */ +#ifndef JEMALLOC_PREFIX + +#ifdef JEMALLOC_OVERRIDE_MEMALIGN +JEMALLOC_ATTR(malloc) +JEMALLOC_ATTR(visibility("default")) +void * +JEMALLOC_P(memalign)(size_t alignment, size_t size) +{ + void *ret; + + posix_memalign(&ret, alignment, size); + return (ret); +} +#endif + +#ifdef JEMALLOC_OVERRIDE_VALLOC +JEMALLOC_ATTR(malloc) +JEMALLOC_ATTR(visibility("default")) +void * +JEMALLOC_P(valloc)(size_t size) +{ + void *ret; + + posix_memalign(&ret, PAGE_SIZE, size); + return (ret); +} +#endif + +#endif /* JEMALLOC_PREFIX */ +/* + * End non-standard override functions. + */ +/******************************************************************************/ /* * Begin non-standard functions. */ @@ -1240,6 +1279,7 @@ iallocm(size_t size, size_t alignment, bool zero) return (imalloc(size)); } +JEMALLOC_ATTR(nonnull(1)) JEMALLOC_ATTR(visibility("default")) int JEMALLOC_P(allocm)(void **ptr, size_t *rsize, size_t size, int flags) @@ -1297,6 +1337,7 @@ OOM: return (ALLOCM_ERR_OOM); } +JEMALLOC_ATTR(nonnull(1)) JEMALLOC_ATTR(visibility("default")) int JEMALLOC_P(rallocm)(void **ptr, size_t *rsize, size_t size, size_t extra, @@ -1369,6 +1410,7 @@ OOM: return (ALLOCM_ERR_OOM); } +JEMALLOC_ATTR(nonnull(1)) JEMALLOC_ATTR(visibility("default")) int JEMALLOC_P(sallocm)(const void *ptr, size_t *rsize, int flags) @@ -1389,6 +1431,7 @@ JEMALLOC_P(sallocm)(const void *ptr, size_t *rsize, int flags) return (ALLOCM_SUCCESS); } +JEMALLOC_ATTR(nonnull(1)) JEMALLOC_ATTR(visibility("default")) int JEMALLOC_P(dallocm)(void *ptr, int flags)