Add --with-mangling.

Add the --with-mangling configure option, which can be used to specify
name mangling on a per public symbol basis that takes precedence over
--with-jemalloc-prefix.

Expose the memalign() and valloc() overrides even if
--with-jemalloc-prefix is specified.  This change does no real harm, and
simplifies the code.
This commit is contained in:
Jason Evans 2012-03-01 17:19:20 -08:00
parent 166a745b39
commit 0a5489e37d
15 changed files with 265 additions and 176 deletions

13
INSTALL
View File

@ -26,6 +26,19 @@ any of the following arguments (not a definitive list) to 'configure':
Embed one or more library paths, so that libjemalloc can find the libraries Embed one or more library paths, so that libjemalloc can find the libraries
it is linked to. This works only on ELF-based systems. it is linked to. This works only on ELF-based systems.
--with-mangling=<map>
Mangle public symbols specified in <map> which is a comma-separated list of
name:mangled pairs.
For example, to use ld's --wrap option as an alternative method for
overriding libc's malloc implementation, specify something like:
--with-mangling=malloc:__wrap_malloc,free:__wrap_free[...]
Note that mangling happens prior to application of the prefix specified by
--with-jemalloc-prefix, and mangled symbols are then ignored when applying
the prefix.
--with-jemalloc-prefix=<prefix> --with-jemalloc-prefix=<prefix>
Prefix all public APIs with <prefix>. For example, if <prefix> is Prefix all public APIs with <prefix>. For example, if <prefix> is
"prefix_", API changes like the following occur: "prefix_", API changes like the following occur:

View File

@ -303,6 +303,16 @@ AC_PATH_PROG([AR], [ar], , [$PATH])
AC_PATH_PROG([LD], [ld], , [$PATH]) AC_PATH_PROG([LD], [ld], , [$PATH])
AC_PATH_PROG([AUTOCONF], [autoconf], , [$PATH]) AC_PATH_PROG([AUTOCONF], [autoconf], , [$PATH])
dnl Perform no name mangling by default.
AC_ARG_WITH([mangling],
[AS_HELP_STRING([--with-mangling=<map>], [Mangle symbols in <map>])],
[mangling_map="$with_mangling"], [mangling_map=""])
for nm in `echo ${mangling_map} |tr ',' ' '` ; do
n="je_`echo ${nm} |tr ':' ' ' |awk '{print $1}'`"
m=`echo ${nm} |tr ':' ' ' |awk '{print $2}'`
AC_DEFINE_UNQUOTED([${n}], [${m}])
done
dnl Do not prefix public APIs by default. dnl Do not prefix public APIs by default.
AC_ARG_WITH([jemalloc_prefix], AC_ARG_WITH([jemalloc_prefix],
[AS_HELP_STRING([--with-jemalloc-prefix=<prefix>], [Prefix to prepend to all public APIs])], [AS_HELP_STRING([--with-jemalloc-prefix=<prefix>], [Prefix to prepend to all public APIs])],
@ -317,8 +327,15 @@ if test "x$JEMALLOC_PREFIX" != "x" ; then
JEMALLOC_CPREFIX=`echo ${JEMALLOC_PREFIX} | tr "a-z" "A-Z"` JEMALLOC_CPREFIX=`echo ${JEMALLOC_PREFIX} | tr "a-z" "A-Z"`
AC_DEFINE_UNQUOTED([JEMALLOC_PREFIX], ["$JEMALLOC_PREFIX"]) AC_DEFINE_UNQUOTED([JEMALLOC_PREFIX], ["$JEMALLOC_PREFIX"])
AC_DEFINE_UNQUOTED([JEMALLOC_CPREFIX], ["$JEMALLOC_CPREFIX"]) AC_DEFINE_UNQUOTED([JEMALLOC_CPREFIX], ["$JEMALLOC_CPREFIX"])
AC_DEFINE_UNQUOTED([JEMALLOC_P(string_that_no_one_should_want_to_use_as_a_jemalloc_API_prefix)], [${JEMALLOC_PREFIX}##string_that_no_one_should_want_to_use_as_a_jemalloc_API_prefix])
fi fi
dnl Generate macros to rename public symbols. All public symbols are prefixed
dnl with je_ in the source code, so these macro definitions are needed even if
dnl --with-jemalloc-prefix wasn't specified.
for stem in malloc_conf malloc_message malloc calloc posix_memalign realloc free malloc_usable_size malloc_stats_print mallctl mallctlnametomib mallctlbymib memalign valloc allocm dallocm nallocm rallocm sallocm; do
n="je_${stem}"
m="${JEMALLOC_PREFIX}${stem}"
AC_DEFINE_UNQUOTED([${n}], [${m}])
done
dnl Do not mangle library-private APIs by default. dnl Do not mangle library-private APIs by default.
AC_ARG_WITH([private_namespace], AC_ARG_WITH([private_namespace],

View File

@ -74,7 +74,7 @@ int ctl_bymib(const size_t *mib, size_t miblen, void *oldp, size_t *oldlenp,
bool ctl_boot(void); bool ctl_boot(void);
#define xmallctl(name, oldp, oldlenp, newp, newlen) do { \ #define xmallctl(name, oldp, oldlenp, newp, newlen) do { \
if (JEMALLOC_P(mallctl)(name, oldp, oldlenp, newp, newlen) \ if (je_mallctl(name, oldp, oldlenp, newp, newlen) \
!= 0) { \ != 0) { \
malloc_write("<jemalloc>: Failure in xmallctl(\""); \ malloc_write("<jemalloc>: Failure in xmallctl(\""); \
malloc_write(name); \ malloc_write(name); \
@ -84,7 +84,7 @@ bool ctl_boot(void);
} while (0) } while (0)
#define xmallctlnametomib(name, mibp, miblenp) do { \ #define xmallctlnametomib(name, mibp, miblenp) do { \
if (JEMALLOC_P(mallctlnametomib)(name, mibp, miblenp) != 0) { \ if (je_mallctlnametomib(name, mibp, miblenp) != 0) { \
malloc_write( \ malloc_write( \
"<jemalloc>: Failure in xmallctlnametomib(\""); \ "<jemalloc>: Failure in xmallctlnametomib(\""); \
malloc_write(name); \ malloc_write(name); \
@ -94,7 +94,7 @@ bool ctl_boot(void);
} while (0) } while (0)
#define xmallctlbymib(mib, miblen, oldp, oldlenp, newp, newlen) do { \ #define xmallctlbymib(mib, miblen, oldp, oldlenp, newp, newlen) do { \
if (JEMALLOC_P(mallctlbymib)(mib, miblen, oldp, oldlenp, newp, \ if (je_mallctlbymib(mib, miblen, oldp, oldlenp, newp, \
newlen) != 0) { \ newlen) != 0) { \
malloc_write( \ malloc_write( \
"<jemalloc>: Failure in xmallctlbymib()\n"); \ "<jemalloc>: Failure in xmallctlbymib()\n"); \

View File

@ -30,7 +30,7 @@
#include <pthread.h> #include <pthread.h>
#include <math.h> #include <math.h>
#define JEMALLOC_MANGLE #define JEMALLOC_NO_DEMANGLE
#include "../jemalloc@install_suffix@.h" #include "../jemalloc@install_suffix@.h"
#include "jemalloc/internal/private_namespace.h" #include "jemalloc/internal/private_namespace.h"
@ -149,7 +149,7 @@ static const bool config_ivsalloc =
#include "jemalloc/internal/qr.h" #include "jemalloc/internal/qr.h"
#include "jemalloc/internal/ql.h" #include "jemalloc/internal/ql.h"
extern void (*JEMALLOC_P(malloc_message))(void *wcbopaque, const char *s); extern void (*je_malloc_message)(void *wcbopaque, const char *s);
/* /*
* Define a custom assert() in order to reduce the chances of deadlock during * Define a custom assert() in order to reduce the chances of deadlock during
@ -618,13 +618,13 @@ sa2u(size_t size, size_t alignment, size_t *run_size_p)
/* /*
* Wrapper around malloc_message() that avoids the need for * Wrapper around malloc_message() that avoids the need for
* JEMALLOC_P(malloc_message)(...) throughout the code. * je_malloc_message(...) throughout the code.
*/ */
JEMALLOC_INLINE void JEMALLOC_INLINE void
malloc_write(const char *s) malloc_write(const char *s)
{ {
JEMALLOC_P(malloc_message)(NULL, s); je_malloc_message(NULL, s);
} }
/* /*

View File

@ -15,9 +15,6 @@ extern "C" {
#define JEMALLOC_VERSION_GID "@jemalloc_version_gid@" #define JEMALLOC_VERSION_GID "@jemalloc_version_gid@"
#include "jemalloc_defs@install_suffix@.h" #include "jemalloc_defs@install_suffix@.h"
#ifndef JEMALLOC_P
# define JEMALLOC_P(s) s
#endif
#define ALLOCM_LG_ALIGN(la) (la) #define ALLOCM_LG_ALIGN(la) (la)
#if LG_SIZEOF_PTR == 2 #if LG_SIZEOF_PTR == 2
@ -32,34 +29,99 @@ extern "C" {
#define ALLOCM_ERR_OOM 1 #define ALLOCM_ERR_OOM 1
#define ALLOCM_ERR_NOT_MOVED 2 #define ALLOCM_ERR_NOT_MOVED 2
extern const char *JEMALLOC_P(malloc_conf); /*
extern void (*JEMALLOC_P(malloc_message))(void *, const char *); * The je_ prefix on the following public symbol declarations is an artifact of
* namespace management, and should be omitted in application code unless
* JEMALLOC_NO_DEMANGLE is defined (see below).
*/
extern const char *je_malloc_conf;
extern void (*je_malloc_message)(void *, const char *);
void *JEMALLOC_P(malloc)(size_t size) JEMALLOC_ATTR(malloc); void *je_malloc(size_t size) JEMALLOC_ATTR(malloc);
void *JEMALLOC_P(calloc)(size_t num, size_t size) JEMALLOC_ATTR(malloc); void *je_calloc(size_t num, size_t size) JEMALLOC_ATTR(malloc);
int JEMALLOC_P(posix_memalign)(void **memptr, size_t alignment, size_t size) int je_posix_memalign(void **memptr, size_t alignment, size_t size)
JEMALLOC_ATTR(nonnull(1)); JEMALLOC_ATTR(nonnull(1));
void *JEMALLOC_P(realloc)(void *ptr, size_t size); void *je_realloc(void *ptr, size_t size);
void JEMALLOC_P(free)(void *ptr); void je_free(void *ptr);
size_t JEMALLOC_P(malloc_usable_size)(const void *ptr); size_t je_malloc_usable_size(const void *ptr);
void JEMALLOC_P(malloc_stats_print)(void (*write_cb)(void *, const char *), void je_malloc_stats_print(void (*write_cb)(void *, const char *),
void *cbopaque, const char *opts); void *je_cbopaque, const char *opts);
int JEMALLOC_P(mallctl)(const char *name, void *oldp, size_t *oldlenp, int je_mallctl(const char *name, void *oldp, size_t *oldlenp, void *newp,
void *newp, size_t newlen); size_t newlen);
int JEMALLOC_P(mallctlnametomib)(const char *name, size_t *mibp, int je_mallctlnametomib(const char *name, size_t *mibp, size_t *miblenp);
size_t *miblenp); int je_mallctlbymib(const size_t *mib, size_t miblen, void *oldp,
int JEMALLOC_P(mallctlbymib)(const size_t *mib, size_t miblen, void *oldp,
size_t *oldlenp, void *newp, size_t newlen); size_t *oldlenp, void *newp, size_t newlen);
int JEMALLOC_P(allocm)(void **ptr, size_t *rsize, size_t size, int flags) int je_allocm(void **ptr, size_t *rsize, size_t size, int flags)
JEMALLOC_ATTR(nonnull(1)); JEMALLOC_ATTR(nonnull(1));
int JEMALLOC_P(rallocm)(void **ptr, size_t *rsize, size_t size, int je_rallocm(void **ptr, size_t *rsize, size_t size, size_t extra,
size_t extra, int flags) JEMALLOC_ATTR(nonnull(1)); int flags) JEMALLOC_ATTR(nonnull(1));
int JEMALLOC_P(sallocm)(const void *ptr, size_t *rsize, int flags) int je_sallocm(const void *ptr, size_t *rsize, int flags)
JEMALLOC_ATTR(nonnull(1)); JEMALLOC_ATTR(nonnull(1));
int JEMALLOC_P(dallocm)(void *ptr, int flags) JEMALLOC_ATTR(nonnull(1)); int je_dallocm(void *ptr, int flags) JEMALLOC_ATTR(nonnull(1));
int JEMALLOC_P(nallocm)(size_t *rsize, size_t size, int flags); int je_nallocm(size_t *rsize, size_t size, int flags);
/*
* By default application code must explicitly refer to mangled symbol names,
* so that it is possible to use jemalloc in conjunction with another allocator
* in the same application. Define JEMALLOC_MANGLE in order to cause automatic
* name mangling that matches the API prefixing that happened as a result of
* --with-mangling and/or --with-jemalloc-prefix configuration settings.
*/
#ifdef JEMALLOC_MANGLE
#ifndef JEMALLOC_NO_DEMANGLE
#define JEMALLOC_NO_DEMANGLE
#endif
#define malloc_conf je_malloc_conf
#define malloc_message je_malloc_message
#define malloc je_malloc
#define calloc je_calloc
#define posix_memalign je_posix_memalign
#define realloc je_realloc
#define free je_free
#define malloc_usable_size je_malloc_usable_size
#define malloc_stats_print je_malloc_stats_print
#define mallctl je_mallctl
#define mallctlnametomib je_mallctlnametomib
#define mallctlbymib je_mallctlbymib
#define memalign je_memalign
#define valloc je_valloc
#define allocm je_allocm
#define dallocm je_dallocm
#define nallocm je_nallocm
#define rallocm je_rallocm
#define sallocm je_sallocm
#endif
/*
* The je_* macros can be used as stable alternative names for the public
* jemalloc API if JEMALLOC_NO_DEMANGLE is defined. This is primarily meant
* for use in jemalloc itself, but it can be used by application code to
* provide isolation from the name mangling specified via --with-mangling
* and/or --with-jemalloc-prefix.
*/
#ifndef JEMALLOC_NO_DEMANGLE
#undef je_malloc_conf
#undef je_malloc_message
#undef je_malloc
#undef je_calloc
#undef je_posix_memalign
#undef je_realloc
#undef je_free
#undef je_malloc_usable_size
#undef je_malloc_stats_print
#undef je_mallctl
#undef je_mallctlnametomib
#undef je_mallctlbymib
#undef je_memalign
#undef je_valloc
#undef je_allocm
#undef je_dallocm
#undef je_nallocm
#undef je_rallocm
#undef je_sallocm
#endif
#ifdef __cplusplus #ifdef __cplusplus
}; };

View File

@ -1,22 +1,35 @@
#ifndef JEMALLOC_DEFS_H_
#define JEMALLOC_DEFS_H_
/* /*
* If JEMALLOC_PREFIX is defined, it will cause all public APIs to be prefixed. * If JEMALLOC_PREFIX is defined via --with-jemalloc-prefix, it will cause all
* This makes it possible, with some care, to use multiple allocators * public APIs to be prefixed. This makes it possible, with some care, to use
* simultaneously. * multiple allocators simultaneously.
*
* In many cases it is more convenient to manually prefix allocator function
* calls than to let macros do it automatically, particularly when using
* multiple allocators simultaneously. Define JEMALLOC_MANGLE before
* #include'ing jemalloc.h in order to cause name mangling that corresponds to
* the API prefixing.
*/ */
#undef JEMALLOC_PREFIX #undef JEMALLOC_PREFIX
#undef JEMALLOC_CPREFIX #undef JEMALLOC_CPREFIX
#if (defined(JEMALLOC_PREFIX) && defined(JEMALLOC_MANGLE))
#undef JEMALLOC_P /*
#endif * Name mangling for public symbols is controlled by --with-mangling and
* --with-jemalloc-prefix. With default settings the je_ prefix is stripped by
* these macro definitions.
*/
#undef je_malloc_conf
#undef je_malloc_message
#undef je_malloc
#undef je_calloc
#undef je_posix_memalign
#undef je_realloc
#undef je_free
#undef je_malloc_usable_size
#undef je_malloc_stats_print
#undef je_mallctl
#undef je_mallctlnametomib
#undef je_mallctlbymib
#undef je_memalign
#undef je_valloc
#undef je_allocm
#undef je_dallocm
#undef je_nallocm
#undef je_rallocm
#undef je_sallocm
/* /*
* JEMALLOC_PRIVATE_NAMESPACE is used as a prefix for all library-private APIs. * JEMALLOC_PRIVATE_NAMESPACE is used as a prefix for all library-private APIs.
@ -150,5 +163,3 @@
/* sizeof(long) == 2^LG_SIZEOF_LONG. */ /* sizeof(long) == 2^LG_SIZEOF_LONG. */
#undef LG_SIZEOF_LONG #undef LG_SIZEOF_LONG
#endif /* JEMALLOC_DEFS_H_ */

View File

@ -36,7 +36,7 @@ size_t lg_pagesize;
unsigned ncpus; unsigned ncpus;
/* Runtime configuration options. */ /* Runtime configuration options. */
const char *JEMALLOC_P(malloc_conf) JEMALLOC_ATTR(visibility("default")); const char *je_malloc_conf JEMALLOC_ATTR(visibility("default"));
#ifdef JEMALLOC_DEBUG #ifdef JEMALLOC_DEBUG
bool opt_abort = true; bool opt_abort = true;
# ifdef JEMALLOC_FILL # ifdef JEMALLOC_FILL
@ -81,7 +81,7 @@ wrtmessage(void *cbopaque, const char *s)
UNUSED int result = write(STDERR_FILENO, s, strlen(s)); UNUSED int result = write(STDERR_FILENO, s, strlen(s));
} }
void (*JEMALLOC_P(malloc_message))(void *, const char *s) void (*je_malloc_message)(void *, const char *s)
JEMALLOC_ATTR(visibility("default")) = wrtmessage; JEMALLOC_ATTR(visibility("default")) = wrtmessage;
/******************************************************************************/ /******************************************************************************/
@ -230,7 +230,7 @@ stats_print_atexit(void)
} }
} }
} }
JEMALLOC_P(malloc_stats_print)(NULL, NULL, NULL); je_malloc_stats_print(NULL, NULL, NULL);
} }
thread_allocated_t * thread_allocated_t *
@ -422,12 +422,12 @@ malloc_conf_init(void)
/* Get runtime configuration. */ /* Get runtime configuration. */
switch (i) { switch (i) {
case 0: case 0:
if (JEMALLOC_P(malloc_conf) != NULL) { if (je_malloc_conf != NULL) {
/* /*
* Use options that were compiled into the * Use options that were compiled into the
* program. * program.
*/ */
opts = JEMALLOC_P(malloc_conf); opts = je_malloc_conf;
} else { } else {
/* No configuration specified. */ /* No configuration specified. */
buf[0] = '\0'; buf[0] = '\0';
@ -836,7 +836,7 @@ jemalloc_darwin_init(void)
JEMALLOC_ATTR(malloc) JEMALLOC_ATTR(malloc)
JEMALLOC_ATTR(visibility("default")) JEMALLOC_ATTR(visibility("default"))
void * void *
JEMALLOC_P(malloc)(size_t size) je_malloc(size_t size)
{ {
void *ret; void *ret;
size_t usize; size_t usize;
@ -990,7 +990,7 @@ RETURN:
JEMALLOC_ATTR(nonnull(1)) JEMALLOC_ATTR(nonnull(1))
JEMALLOC_ATTR(visibility("default")) JEMALLOC_ATTR(visibility("default"))
int int
JEMALLOC_P(posix_memalign)(void **memptr, size_t alignment, size_t size) je_posix_memalign(void **memptr, size_t alignment, size_t size)
{ {
return imemalign(memptr, alignment, size, true); return imemalign(memptr, alignment, size, true);
@ -999,7 +999,7 @@ JEMALLOC_P(posix_memalign)(void **memptr, size_t alignment, size_t size)
JEMALLOC_ATTR(malloc) JEMALLOC_ATTR(malloc)
JEMALLOC_ATTR(visibility("default")) JEMALLOC_ATTR(visibility("default"))
void * void *
JEMALLOC_P(calloc)(size_t num, size_t size) je_calloc(size_t num, size_t size)
{ {
void *ret; void *ret;
size_t num_size; size_t num_size;
@ -1077,7 +1077,7 @@ RETURN:
JEMALLOC_ATTR(visibility("default")) JEMALLOC_ATTR(visibility("default"))
void * void *
JEMALLOC_P(realloc)(void *ptr, size_t size) je_realloc(void *ptr, size_t size)
{ {
void *ret; void *ret;
size_t usize; size_t usize;
@ -1207,7 +1207,7 @@ RETURN:
JEMALLOC_ATTR(visibility("default")) JEMALLOC_ATTR(visibility("default"))
void void
JEMALLOC_P(free)(void *ptr) je_free(void *ptr)
{ {
if (ptr != NULL) { if (ptr != NULL) {
@ -1234,17 +1234,13 @@ JEMALLOC_P(free)(void *ptr)
/******************************************************************************/ /******************************************************************************/
/* /*
* Begin non-standard override 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 #ifdef JEMALLOC_OVERRIDE_MEMALIGN
JEMALLOC_ATTR(malloc) JEMALLOC_ATTR(malloc)
JEMALLOC_ATTR(visibility("default")) JEMALLOC_ATTR(visibility("default"))
void * void *
JEMALLOC_P(memalign)(size_t alignment, size_t size) je_memalign(size_t alignment, size_t size)
{ {
void *ret void *ret
#ifdef JEMALLOC_CC_SILENCE #ifdef JEMALLOC_CC_SILENCE
@ -1260,7 +1256,7 @@ JEMALLOC_P(memalign)(size_t alignment, size_t size)
JEMALLOC_ATTR(malloc) JEMALLOC_ATTR(malloc)
JEMALLOC_ATTR(visibility("default")) JEMALLOC_ATTR(visibility("default"))
void * void *
JEMALLOC_P(valloc)(size_t size) je_valloc(size_t size)
{ {
void *ret void *ret
#ifdef JEMALLOC_CC_SILENCE #ifdef JEMALLOC_CC_SILENCE
@ -1272,7 +1268,7 @@ JEMALLOC_P(valloc)(size_t size)
} }
#endif #endif
#if defined(__GLIBC__) && !defined(__UCLIBC__) #if (!defined(JEMALLOC_PREFIX) && defined(__GLIBC__) && !defined(__UCLIBC__))
/* /*
* glibc provides the RTLD_DEEPBIND flag for dlopen which can make it possible * glibc provides the RTLD_DEEPBIND flag for dlopen which can make it possible
* to inconsistently reference libc's malloc(3)-compatible functions * to inconsistently reference libc's malloc(3)-compatible functions
@ -1283,20 +1279,18 @@ JEMALLOC_P(valloc)(size_t size)
* ignored. * ignored.
*/ */
JEMALLOC_ATTR(visibility("default")) JEMALLOC_ATTR(visibility("default"))
void (* const __free_hook)(void *ptr) = JEMALLOC_P(free); void (* const __free_hook)(void *ptr) = je_free;
JEMALLOC_ATTR(visibility("default")) JEMALLOC_ATTR(visibility("default"))
void *(* const __malloc_hook)(size_t size) = JEMALLOC_P(malloc); void *(* const __malloc_hook)(size_t size) = je_malloc;
JEMALLOC_ATTR(visibility("default")) JEMALLOC_ATTR(visibility("default"))
void *(* const __realloc_hook)(void *ptr, size_t size) = JEMALLOC_P(realloc); void *(* const __realloc_hook)(void *ptr, size_t size) = je_realloc;
JEMALLOC_ATTR(visibility("default")) JEMALLOC_ATTR(visibility("default"))
void *(* const __memalign_hook)(size_t alignment, size_t size) = void *(* const __memalign_hook)(size_t alignment, size_t size) = je_memalign;
JEMALLOC_P(memalign);
#endif #endif
#endif /* JEMALLOC_PREFIX */
/* /*
* End non-standard override functions. * End non-standard override functions.
*/ */
@ -1307,7 +1301,7 @@ void *(* const __memalign_hook)(size_t alignment, size_t size) =
JEMALLOC_ATTR(visibility("default")) JEMALLOC_ATTR(visibility("default"))
size_t size_t
JEMALLOC_P(malloc_usable_size)(const void *ptr) je_malloc_usable_size(const void *ptr)
{ {
size_t ret; size_t ret;
@ -1325,8 +1319,8 @@ JEMALLOC_P(malloc_usable_size)(const void *ptr)
JEMALLOC_ATTR(visibility("default")) JEMALLOC_ATTR(visibility("default"))
void void
JEMALLOC_P(malloc_stats_print)(void (*write_cb)(void *, const char *), je_malloc_stats_print(void (*write_cb)(void *, const char *), void *cbopaque,
void *cbopaque, const char *opts) const char *opts)
{ {
stats_print(write_cb, cbopaque, opts); stats_print(write_cb, cbopaque, opts);
@ -1334,7 +1328,7 @@ JEMALLOC_P(malloc_stats_print)(void (*write_cb)(void *, const char *),
JEMALLOC_ATTR(visibility("default")) JEMALLOC_ATTR(visibility("default"))
int int
JEMALLOC_P(mallctl)(const char *name, void *oldp, size_t *oldlenp, void *newp, je_mallctl(const char *name, void *oldp, size_t *oldlenp, void *newp,
size_t newlen) size_t newlen)
{ {
@ -1346,7 +1340,7 @@ JEMALLOC_P(mallctl)(const char *name, void *oldp, size_t *oldlenp, void *newp,
JEMALLOC_ATTR(visibility("default")) JEMALLOC_ATTR(visibility("default"))
int int
JEMALLOC_P(mallctlnametomib)(const char *name, size_t *mibp, size_t *miblenp) je_mallctlnametomib(const char *name, size_t *mibp, size_t *miblenp)
{ {
if (malloc_init()) if (malloc_init())
@ -1357,8 +1351,8 @@ JEMALLOC_P(mallctlnametomib)(const char *name, size_t *mibp, size_t *miblenp)
JEMALLOC_ATTR(visibility("default")) JEMALLOC_ATTR(visibility("default"))
int int
JEMALLOC_P(mallctlbymib)(const size_t *mib, size_t miblen, void *oldp, je_mallctlbymib(const size_t *mib, size_t miblen, void *oldp, size_t *oldlenp,
size_t *oldlenp, void *newp, size_t newlen) void *newp, size_t newlen)
{ {
if (malloc_init()) if (malloc_init())
@ -1385,7 +1379,7 @@ iallocm(size_t usize, size_t alignment, bool zero)
JEMALLOC_ATTR(nonnull(1)) JEMALLOC_ATTR(nonnull(1))
JEMALLOC_ATTR(visibility("default")) JEMALLOC_ATTR(visibility("default"))
int int
JEMALLOC_P(allocm)(void **ptr, size_t *rsize, size_t size, int flags) je_allocm(void **ptr, size_t *rsize, size_t size, int flags)
{ {
void *p; void *p;
size_t usize; size_t usize;
@ -1451,8 +1445,7 @@ OOM:
JEMALLOC_ATTR(nonnull(1)) JEMALLOC_ATTR(nonnull(1))
JEMALLOC_ATTR(visibility("default")) JEMALLOC_ATTR(visibility("default"))
int int
JEMALLOC_P(rallocm)(void **ptr, size_t *rsize, size_t size, size_t extra, je_rallocm(void **ptr, size_t *rsize, size_t size, size_t extra, int flags)
int flags)
{ {
void *p, *q; void *p, *q;
size_t usize; size_t usize;
@ -1544,7 +1537,7 @@ OOM:
JEMALLOC_ATTR(nonnull(1)) JEMALLOC_ATTR(nonnull(1))
JEMALLOC_ATTR(visibility("default")) JEMALLOC_ATTR(visibility("default"))
int int
JEMALLOC_P(sallocm)(const void *ptr, size_t *rsize, int flags) je_sallocm(const void *ptr, size_t *rsize, int flags)
{ {
size_t sz; size_t sz;
@ -1565,7 +1558,7 @@ JEMALLOC_P(sallocm)(const void *ptr, size_t *rsize, int flags)
JEMALLOC_ATTR(nonnull(1)) JEMALLOC_ATTR(nonnull(1))
JEMALLOC_ATTR(visibility("default")) JEMALLOC_ATTR(visibility("default"))
int int
JEMALLOC_P(dallocm)(void *ptr, int flags) je_dallocm(void *ptr, int flags)
{ {
size_t usize; size_t usize;
@ -1588,7 +1581,7 @@ JEMALLOC_P(dallocm)(void *ptr, int flags)
JEMALLOC_ATTR(visibility("default")) JEMALLOC_ATTR(visibility("default"))
int int
JEMALLOC_P(nallocm)(size_t *rsize, size_t size, int flags) je_nallocm(size_t *rsize, size_t size, int flags)
{ {
size_t usize; size_t usize;
size_t alignment = (ZU(1) << (flags & ALLOCM_LG_ALIGN_MASK) size_t alignment = (ZU(1) << (flags & ALLOCM_LG_ALIGN_MASK)

View File

@ -108,7 +108,7 @@ malloc_vcprintf(void (*write_cb)(void *, const char *), void *cbopaque,
* function, so use the default one. malloc_write() is an * function, so use the default one. malloc_write() is an
* inline function, so use malloc_message() directly here. * inline function, so use malloc_message() directly here.
*/ */
write_cb = JEMALLOC_P(malloc_message); write_cb = je_malloc_message;
cbopaque = NULL; cbopaque = NULL;
} }
@ -376,8 +376,7 @@ stats_print(void (*write_cb)(void *, const char *), void *cbopaque,
* */ * */
epoch = 1; epoch = 1;
u64sz = sizeof(uint64_t); u64sz = sizeof(uint64_t);
err = JEMALLOC_P(mallctl)("epoch", &epoch, &u64sz, &epoch, err = je_mallctl("epoch", &epoch, &u64sz, &epoch, sizeof(uint64_t));
sizeof(uint64_t));
if (err != 0) { if (err != 0) {
if (err == EAGAIN) { if (err == EAGAIN) {
malloc_write("<jemalloc>: Memory allocation failure in " malloc_write("<jemalloc>: Memory allocation failure in "
@ -395,7 +394,7 @@ stats_print(void (*write_cb)(void *, const char *), void *cbopaque,
* function, so use the default one. malloc_write() is an * function, so use the default one. malloc_write() is an
* inline function, so use malloc_message() directly here. * inline function, so use malloc_message() directly here.
*/ */
write_cb = JEMALLOC_P(malloc_message); write_cb = je_malloc_message;
cbopaque = NULL; cbopaque = NULL;
} }
@ -448,22 +447,22 @@ stats_print(void (*write_cb)(void *, const char *), void *cbopaque,
write_cb(cbopaque, "\n"); write_cb(cbopaque, "\n");
#define OPT_WRITE_BOOL(n) \ #define OPT_WRITE_BOOL(n) \
if ((err = JEMALLOC_P(mallctl)("opt."#n, &bv, &bsz, \ if ((err = je_mallctl("opt."#n, &bv, &bsz, NULL, 0)) \
NULL, 0)) == 0) { \ == 0) { \
write_cb(cbopaque, " opt."#n": "); \ write_cb(cbopaque, " opt."#n": "); \
write_cb(cbopaque, bv ? "true" : "false"); \ write_cb(cbopaque, bv ? "true" : "false"); \
write_cb(cbopaque, "\n"); \ write_cb(cbopaque, "\n"); \
} }
#define OPT_WRITE_SIZE_T(n) \ #define OPT_WRITE_SIZE_T(n) \
if ((err = JEMALLOC_P(mallctl)("opt."#n, &sv, &ssz, \ if ((err = je_mallctl("opt."#n, &sv, &ssz, NULL, 0)) \
NULL, 0)) == 0) { \ == 0) { \
write_cb(cbopaque, " opt."#n": "); \ write_cb(cbopaque, " opt."#n": "); \
write_cb(cbopaque, u2s(sv, 10, s)); \ write_cb(cbopaque, u2s(sv, 10, s)); \
write_cb(cbopaque, "\n"); \ write_cb(cbopaque, "\n"); \
} }
#define OPT_WRITE_SSIZE_T(n) \ #define OPT_WRITE_SSIZE_T(n) \
if ((err = JEMALLOC_P(mallctl)("opt."#n, &ssv, &sssz, \ if ((err = je_mallctl("opt."#n, &ssv, &sssz, NULL, 0)) \
NULL, 0)) == 0) { \ == 0) { \
if (ssv >= 0) { \ if (ssv >= 0) { \
write_cb(cbopaque, " opt."#n": "); \ write_cb(cbopaque, " opt."#n": "); \
write_cb(cbopaque, u2s(ssv, 10, s)); \ write_cb(cbopaque, u2s(ssv, 10, s)); \
@ -474,8 +473,8 @@ stats_print(void (*write_cb)(void *, const char *), void *cbopaque,
write_cb(cbopaque, "\n"); \ write_cb(cbopaque, "\n"); \
} }
#define OPT_WRITE_CHAR_P(n) \ #define OPT_WRITE_CHAR_P(n) \
if ((err = JEMALLOC_P(mallctl)("opt."#n, &cpv, &cpsz, \ if ((err = je_mallctl("opt."#n, &cpv, &cpsz, NULL, 0)) \
NULL, 0)) == 0) { \ == 0) { \
write_cb(cbopaque, " opt."#n": \""); \ write_cb(cbopaque, " opt."#n": \""); \
write_cb(cbopaque, cpv); \ write_cb(cbopaque, cpv); \
write_cb(cbopaque, "\"\n"); \ write_cb(cbopaque, "\"\n"); \
@ -535,15 +534,15 @@ stats_print(void (*write_cb)(void *, const char *), void *cbopaque,
write_cb(cbopaque, write_cb(cbopaque,
"Min active:dirty page ratio per arena: N/A\n"); "Min active:dirty page ratio per arena: N/A\n");
} }
if ((err = JEMALLOC_P(mallctl)("arenas.tcache_max", &sv, if ((err = je_mallctl("arenas.tcache_max", &sv, &ssz, NULL, 0))
&ssz, NULL, 0)) == 0) { == 0) {
write_cb(cbopaque, write_cb(cbopaque,
"Maximum thread-cached size class: "); "Maximum thread-cached size class: ");
write_cb(cbopaque, u2s(sv, 10, s)); write_cb(cbopaque, u2s(sv, 10, s));
write_cb(cbopaque, "\n"); write_cb(cbopaque, "\n");
} }
if ((err = JEMALLOC_P(mallctl)("opt.lg_tcache_gc_sweep", &ssv, if ((err = je_mallctl("opt.lg_tcache_gc_sweep", &ssv, &ssz,
&ssz, NULL, 0)) == 0) { NULL, 0)) == 0) {
size_t tcache_gc_sweep = (1U << ssv); size_t tcache_gc_sweep = (1U << ssv);
bool tcache_enabled; bool tcache_enabled;
CTL_GET("opt.tcache", &tcache_enabled, bool); CTL_GET("opt.tcache", &tcache_enabled, bool);
@ -552,8 +551,8 @@ stats_print(void (*write_cb)(void *, const char *), void *cbopaque,
u2s(tcache_gc_sweep, 10, s) : "N/A"); u2s(tcache_gc_sweep, 10, s) : "N/A");
write_cb(cbopaque, "\n"); write_cb(cbopaque, "\n");
} }
if ((err = JEMALLOC_P(mallctl)("opt.prof", &bv, &bsz, NULL, 0)) if ((err = je_mallctl("opt.prof", &bv, &bsz, NULL, 0)) == 0 &&
== 0 && bv) { bv) {
CTL_GET("opt.lg_prof_sample", &sv, size_t); CTL_GET("opt.lg_prof_sample", &sv, size_t);
write_cb(cbopaque, "Average profile sample interval: "); write_cb(cbopaque, "Average profile sample interval: ");
write_cb(cbopaque, u2s((((uint64_t)1U) << sv), 10, s)); write_cb(cbopaque, u2s((((uint64_t)1U) << sv), 10, s));

View File

@ -67,14 +67,14 @@ static void *
zone_malloc(malloc_zone_t *zone, size_t size) zone_malloc(malloc_zone_t *zone, size_t size)
{ {
return (JEMALLOC_P(malloc)(size)); return (je_malloc(size));
} }
static void * static void *
zone_calloc(malloc_zone_t *zone, size_t num, size_t size) zone_calloc(malloc_zone_t *zone, size_t num, size_t size)
{ {
return (JEMALLOC_P(calloc)(num, size)); return (je_calloc(num, size));
} }
static void * static void *
@ -82,7 +82,7 @@ zone_valloc(malloc_zone_t *zone, size_t size)
{ {
void *ret = NULL; /* Assignment avoids useless compiler warning. */ void *ret = NULL; /* Assignment avoids useless compiler warning. */
JEMALLOC_P(posix_memalign)(&ret, PAGE_SIZE, size); je_posix_memalign(&ret, PAGE_SIZE, size);
return (ret); return (ret);
} }
@ -91,14 +91,14 @@ static void
zone_free(malloc_zone_t *zone, void *ptr) zone_free(malloc_zone_t *zone, void *ptr)
{ {
JEMALLOC_P(free)(ptr); je_free(ptr);
} }
static void * static void *
zone_realloc(malloc_zone_t *zone, void *ptr, size_t size) zone_realloc(malloc_zone_t *zone, void *ptr, size_t size)
{ {
return (JEMALLOC_P(realloc)(ptr, size)); return (je_realloc(ptr, size));
} }
#if (JEMALLOC_ZONE_VERSION >= 6) #if (JEMALLOC_ZONE_VERSION >= 6)
@ -107,7 +107,7 @@ zone_memalign(malloc_zone_t *zone, size_t alignment, size_t size)
{ {
void *ret = NULL; /* Assignment avoids useless compiler warning. */ void *ret = NULL; /* Assignment avoids useless compiler warning. */
JEMALLOC_P(posix_memalign)(&ret, alignment, size); je_posix_memalign(&ret, alignment, size);
return (ret); return (ret);
} }
@ -117,7 +117,7 @@ zone_free_definite_size(malloc_zone_t *zone, void *ptr, size_t size)
{ {
assert(ivsalloc(ptr) == size); assert(ivsalloc(ptr) == size);
JEMALLOC_P(free)(ptr); je_free(ptr);
} }
#endif #endif
@ -208,7 +208,7 @@ ozone_free(malloc_zone_t *zone, void *ptr)
{ {
if (ivsalloc(ptr) != 0) if (ivsalloc(ptr) != 0)
JEMALLOC_P(free)(ptr); je_free(ptr);
else { else {
size_t size = szone.size(zone, ptr); size_t size = szone.size(zone, ptr);
if (size != 0) if (size != 0)
@ -222,17 +222,17 @@ ozone_realloc(malloc_zone_t *zone, void *ptr, size_t size)
size_t oldsize; size_t oldsize;
if (ptr == NULL) if (ptr == NULL)
return (JEMALLOC_P(malloc)(size)); return (je_malloc(size));
oldsize = ivsalloc(ptr); oldsize = ivsalloc(ptr);
if (oldsize != 0) if (oldsize != 0)
return (JEMALLOC_P(realloc)(ptr, size)); return (je_realloc(ptr, size));
else { else {
oldsize = szone.size(zone, ptr); oldsize = szone.size(zone, ptr);
if (oldsize == 0) if (oldsize == 0)
return (JEMALLOC_P(malloc)(size)); return (je_malloc(size));
else { else {
void *ret = JEMALLOC_P(malloc)(size); void *ret = je_malloc(size);
if (ret != NULL) { if (ret != NULL) {
memcpy(ret, ptr, (oldsize < size) ? oldsize : memcpy(ret, ptr, (oldsize < size) ? oldsize :
size); size);
@ -268,7 +268,7 @@ ozone_free_definite_size(malloc_zone_t *zone, void *ptr, size_t size)
if (ivsalloc(ptr) != 0) { if (ivsalloc(ptr) != 0) {
assert(ivsalloc(ptr) == size); assert(ivsalloc(ptr) == size);
JEMALLOC_P(free)(ptr); je_free(ptr);
} else { } else {
assert(size == szone.size(zone, ptr)); assert(size == szone.size(zone, ptr));
szone.free_definite_size(zone, ptr, size); szone.free_definite_size(zone, ptr, size);

View File

@ -20,8 +20,7 @@ thread_start(void *arg)
size_t sz, usize; size_t sz, usize;
sz = sizeof(a0); sz = sizeof(a0);
if ((err = JEMALLOC_P(mallctl)("thread.allocated", &a0, &sz, NULL, if ((err = mallctl("thread.allocated", &a0, &sz, NULL, 0))) {
0))) {
if (err == ENOENT) { if (err == ENOENT) {
#ifdef JEMALLOC_STATS #ifdef JEMALLOC_STATS
assert(false); assert(false);
@ -33,8 +32,7 @@ thread_start(void *arg)
exit(1); exit(1);
} }
sz = sizeof(ap0); sz = sizeof(ap0);
if ((err = JEMALLOC_P(mallctl)("thread.allocatedp", &ap0, &sz, NULL, if ((err = mallctl("thread.allocatedp", &ap0, &sz, NULL, 0))) {
0))) {
if (err == ENOENT) { if (err == ENOENT) {
#ifdef JEMALLOC_STATS #ifdef JEMALLOC_STATS
assert(false); assert(false);
@ -48,8 +46,7 @@ thread_start(void *arg)
assert(*ap0 == a0); assert(*ap0 == a0);
sz = sizeof(d0); sz = sizeof(d0);
if ((err = JEMALLOC_P(mallctl)("thread.deallocated", &d0, &sz, NULL, if ((err = mallctl("thread.deallocated", &d0, &sz, NULL, 0))) {
0))) {
if (err == ENOENT) { if (err == ENOENT) {
#ifdef JEMALLOC_STATS #ifdef JEMALLOC_STATS
assert(false); assert(false);
@ -61,8 +58,7 @@ thread_start(void *arg)
exit(1); exit(1);
} }
sz = sizeof(dp0); sz = sizeof(dp0);
if ((err = JEMALLOC_P(mallctl)("thread.deallocatedp", &dp0, &sz, NULL, if ((err = mallctl("thread.deallocatedp", &dp0, &sz, NULL, 0))) {
0))) {
if (err == ENOENT) { if (err == ENOENT) {
#ifdef JEMALLOC_STATS #ifdef JEMALLOC_STATS
assert(false); assert(false);
@ -75,28 +71,28 @@ thread_start(void *arg)
} }
assert(*dp0 == d0); assert(*dp0 == d0);
p = JEMALLOC_P(malloc)(1); p = malloc(1);
if (p == NULL) { if (p == NULL) {
fprintf(stderr, "%s(): Error in malloc()\n", __func__); fprintf(stderr, "%s(): Error in malloc()\n", __func__);
exit(1); exit(1);
} }
sz = sizeof(a1); sz = sizeof(a1);
JEMALLOC_P(mallctl)("thread.allocated", &a1, &sz, NULL, 0); mallctl("thread.allocated", &a1, &sz, NULL, 0);
sz = sizeof(ap1); sz = sizeof(ap1);
JEMALLOC_P(mallctl)("thread.allocatedp", &ap1, &sz, NULL, 0); mallctl("thread.allocatedp", &ap1, &sz, NULL, 0);
assert(*ap1 == a1); assert(*ap1 == a1);
assert(ap0 == ap1); assert(ap0 == ap1);
usize = JEMALLOC_P(malloc_usable_size)(p); usize = malloc_usable_size(p);
assert(a0 + usize <= a1); assert(a0 + usize <= a1);
JEMALLOC_P(free)(p); free(p);
sz = sizeof(d1); sz = sizeof(d1);
JEMALLOC_P(mallctl)("thread.deallocated", &d1, &sz, NULL, 0); mallctl("thread.deallocated", &d1, &sz, NULL, 0);
sz = sizeof(dp1); sz = sizeof(dp1);
JEMALLOC_P(mallctl)("thread.deallocatedp", &dp1, &sz, NULL, 0); mallctl("thread.deallocatedp", &dp1, &sz, NULL, 0);
assert(*dp1 == d1); assert(*dp1 == d1);
assert(dp0 == dp1); assert(dp0 == dp1);

View File

@ -23,13 +23,13 @@ main(void)
sz = 42; sz = 42;
nsz = 0; nsz = 0;
r = JEMALLOC_P(nallocm)(&nsz, sz, 0); r = nallocm(&nsz, sz, 0);
if (r != ALLOCM_SUCCESS) { if (r != ALLOCM_SUCCESS) {
fprintf(stderr, "Unexpected nallocm() error\n"); fprintf(stderr, "Unexpected nallocm() error\n");
abort(); abort();
} }
rsz = 0; rsz = 0;
r = JEMALLOC_P(allocm)(&p, &rsz, sz, 0); r = allocm(&p, &rsz, sz, 0);
if (r != ALLOCM_SUCCESS) { if (r != ALLOCM_SUCCESS) {
fprintf(stderr, "Unexpected allocm() error\n"); fprintf(stderr, "Unexpected allocm() error\n");
abort(); abort();
@ -38,32 +38,32 @@ main(void)
fprintf(stderr, "Real size smaller than expected\n"); fprintf(stderr, "Real size smaller than expected\n");
if (nsz != rsz) if (nsz != rsz)
fprintf(stderr, "nallocm()/allocm() rsize mismatch\n"); fprintf(stderr, "nallocm()/allocm() rsize mismatch\n");
if (JEMALLOC_P(dallocm)(p, 0) != ALLOCM_SUCCESS) if (dallocm(p, 0) != ALLOCM_SUCCESS)
fprintf(stderr, "Unexpected dallocm() error\n"); fprintf(stderr, "Unexpected dallocm() error\n");
r = JEMALLOC_P(allocm)(&p, NULL, sz, 0); r = allocm(&p, NULL, sz, 0);
if (r != ALLOCM_SUCCESS) { if (r != ALLOCM_SUCCESS) {
fprintf(stderr, "Unexpected allocm() error\n"); fprintf(stderr, "Unexpected allocm() error\n");
abort(); abort();
} }
if (JEMALLOC_P(dallocm)(p, 0) != ALLOCM_SUCCESS) if (dallocm(p, 0) != ALLOCM_SUCCESS)
fprintf(stderr, "Unexpected dallocm() error\n"); fprintf(stderr, "Unexpected dallocm() error\n");
nsz = 0; nsz = 0;
r = JEMALLOC_P(nallocm)(&nsz, sz, ALLOCM_ZERO); r = nallocm(&nsz, sz, ALLOCM_ZERO);
if (r != ALLOCM_SUCCESS) { if (r != ALLOCM_SUCCESS) {
fprintf(stderr, "Unexpected nallocm() error\n"); fprintf(stderr, "Unexpected nallocm() error\n");
abort(); abort();
} }
rsz = 0; rsz = 0;
r = JEMALLOC_P(allocm)(&p, &rsz, sz, ALLOCM_ZERO); r = allocm(&p, &rsz, sz, ALLOCM_ZERO);
if (r != ALLOCM_SUCCESS) { if (r != ALLOCM_SUCCESS) {
fprintf(stderr, "Unexpected allocm() error\n"); fprintf(stderr, "Unexpected allocm() error\n");
abort(); abort();
} }
if (nsz != rsz) if (nsz != rsz)
fprintf(stderr, "nallocm()/allocm() rsize mismatch\n"); fprintf(stderr, "nallocm()/allocm() rsize mismatch\n");
if (JEMALLOC_P(dallocm)(p, 0) != ALLOCM_SUCCESS) if (dallocm(p, 0) != ALLOCM_SUCCESS)
fprintf(stderr, "Unexpected dallocm() error\n"); fprintf(stderr, "Unexpected dallocm() error\n");
#if LG_SIZEOF_PTR == 3 #if LG_SIZEOF_PTR == 3
@ -74,14 +74,14 @@ main(void)
sz = 0x80000000LU; sz = 0x80000000LU;
#endif #endif
nsz = 0; nsz = 0;
r = JEMALLOC_P(nallocm)(&nsz, sz, ALLOCM_ALIGN(alignment)); r = nallocm(&nsz, sz, ALLOCM_ALIGN(alignment));
if (r == ALLOCM_SUCCESS) { if (r == ALLOCM_SUCCESS) {
fprintf(stderr, fprintf(stderr,
"Expected error for nallocm(&nsz, %zu, 0x%x)\n", "Expected error for nallocm(&nsz, %zu, 0x%x)\n",
sz, ALLOCM_ALIGN(alignment)); sz, ALLOCM_ALIGN(alignment));
} }
rsz = 0; rsz = 0;
r = JEMALLOC_P(allocm)(&p, &rsz, sz, ALLOCM_ALIGN(alignment)); r = allocm(&p, &rsz, sz, ALLOCM_ALIGN(alignment));
if (r == ALLOCM_SUCCESS) { if (r == ALLOCM_SUCCESS) {
fprintf(stderr, fprintf(stderr,
"Expected error for allocm(&p, %zu, 0x%x)\n", "Expected error for allocm(&p, %zu, 0x%x)\n",
@ -98,11 +98,11 @@ main(void)
sz = 0x84000001LU; sz = 0x84000001LU;
#endif #endif
nsz = 0; nsz = 0;
r = JEMALLOC_P(nallocm)(&nsz, sz, ALLOCM_ALIGN(alignment)); r = nallocm(&nsz, sz, ALLOCM_ALIGN(alignment));
if (r != ALLOCM_SUCCESS) if (r != ALLOCM_SUCCESS)
fprintf(stderr, "Unexpected nallocm() error\n"); fprintf(stderr, "Unexpected nallocm() error\n");
rsz = 0; rsz = 0;
r = JEMALLOC_P(allocm)(&p, &rsz, sz, ALLOCM_ALIGN(alignment)); r = allocm(&p, &rsz, sz, ALLOCM_ALIGN(alignment));
if (r == ALLOCM_SUCCESS) { if (r == ALLOCM_SUCCESS) {
fprintf(stderr, fprintf(stderr,
"Expected error for allocm(&p, %zu, 0x%x)\n", "Expected error for allocm(&p, %zu, 0x%x)\n",
@ -116,14 +116,14 @@ main(void)
sz = 0xfffffff0LU; sz = 0xfffffff0LU;
#endif #endif
nsz = 0; nsz = 0;
r = JEMALLOC_P(nallocm)(&nsz, sz, ALLOCM_ALIGN(alignment)); r = nallocm(&nsz, sz, ALLOCM_ALIGN(alignment));
if (r == ALLOCM_SUCCESS) { if (r == ALLOCM_SUCCESS) {
fprintf(stderr, fprintf(stderr,
"Expected error for nallocm(&nsz, %zu, 0x%x)\n", "Expected error for nallocm(&nsz, %zu, 0x%x)\n",
sz, ALLOCM_ALIGN(alignment)); sz, ALLOCM_ALIGN(alignment));
} }
rsz = 0; rsz = 0;
r = JEMALLOC_P(allocm)(&p, &rsz, sz, ALLOCM_ALIGN(alignment)); r = allocm(&p, &rsz, sz, ALLOCM_ALIGN(alignment));
if (r == ALLOCM_SUCCESS) { if (r == ALLOCM_SUCCESS) {
fprintf(stderr, fprintf(stderr,
"Expected error for allocm(&p, %zu, 0x%x)\n", "Expected error for allocm(&p, %zu, 0x%x)\n",
@ -145,7 +145,7 @@ main(void)
sz += (alignment >> (LG_SIZEOF_PTR-1)) - 1) { sz += (alignment >> (LG_SIZEOF_PTR-1)) - 1) {
for (i = 0; i < NITER; i++) { for (i = 0; i < NITER; i++) {
nsz = 0; nsz = 0;
r = JEMALLOC_P(nallocm)(&nsz, sz, r = nallocm(&nsz, sz,
ALLOCM_ALIGN(alignment) | ALLOCM_ZERO); ALLOCM_ALIGN(alignment) | ALLOCM_ZERO);
if (r != ALLOCM_SUCCESS) { if (r != ALLOCM_SUCCESS) {
fprintf(stderr, fprintf(stderr,
@ -155,7 +155,7 @@ main(void)
exit(1); exit(1);
} }
rsz = 0; rsz = 0;
r = JEMALLOC_P(allocm)(&ps[i], &rsz, sz, r = allocm(&ps[i], &rsz, sz,
ALLOCM_ALIGN(alignment) | ALLOCM_ZERO); ALLOCM_ALIGN(alignment) | ALLOCM_ZERO);
if (r != ALLOCM_SUCCESS) { if (r != ALLOCM_SUCCESS) {
fprintf(stderr, fprintf(stderr,
@ -179,14 +179,14 @@ main(void)
"%p inadequately aligned for" "%p inadequately aligned for"
" alignment: %zu\n", p, alignment); " alignment: %zu\n", p, alignment);
} }
JEMALLOC_P(sallocm)(ps[i], &rsz, 0); sallocm(ps[i], &rsz, 0);
total += rsz; total += rsz;
if (total >= (MAXALIGN << 1)) if (total >= (MAXALIGN << 1))
break; break;
} }
for (i = 0; i < NITER; i++) { for (i = 0; i < NITER; i++) {
if (ps[i] != NULL) { if (ps[i] != NULL) {
JEMALLOC_P(dallocm)(ps[i], 0); dallocm(ps[i], 0);
ps[i] = NULL; ps[i] = NULL;
} }
} }

View File

@ -17,8 +17,7 @@ main(void)
fprintf(stderr, "Test begin\n"); fprintf(stderr, "Test begin\n");
sz = sizeof(lg_chunk); sz = sizeof(lg_chunk);
if ((err = JEMALLOC_P(mallctl)("opt.lg_chunk", &lg_chunk, &sz, NULL, if ((err = mallctl("opt.lg_chunk", &lg_chunk, &sz, NULL, 0))) {
0))) {
assert(err != ENOENT); assert(err != ENOENT);
fprintf(stderr, "%s(): Error in mallctl(): %s\n", __func__, fprintf(stderr, "%s(): Error in mallctl(): %s\n", __func__,
strerror(err)); strerror(err));

View File

@ -24,7 +24,7 @@ main(void)
/* Test error conditions. */ /* Test error conditions. */
for (alignment = 0; alignment < sizeof(void *); alignment++) { for (alignment = 0; alignment < sizeof(void *); alignment++) {
err = JEMALLOC_P(posix_memalign)(&p, alignment, 1); err = posix_memalign(&p, alignment, 1);
if (err != EINVAL) { if (err != EINVAL) {
fprintf(stderr, fprintf(stderr,
"Expected error for invalid alignment %zu\n", "Expected error for invalid alignment %zu\n",
@ -34,7 +34,7 @@ main(void)
for (alignment = sizeof(size_t); alignment < MAXALIGN; for (alignment = sizeof(size_t); alignment < MAXALIGN;
alignment <<= 1) { alignment <<= 1) {
err = JEMALLOC_P(posix_memalign)(&p, alignment + 1, 1); err = posix_memalign(&p, alignment + 1, 1);
if (err == 0) { if (err == 0) {
fprintf(stderr, fprintf(stderr,
"Expected error for invalid alignment %zu\n", "Expected error for invalid alignment %zu\n",
@ -49,7 +49,7 @@ main(void)
alignment = 0x80000000LU; alignment = 0x80000000LU;
size = 0x80000000LU; size = 0x80000000LU;
#endif #endif
err = JEMALLOC_P(posix_memalign)(&p, alignment, size); err = posix_memalign(&p, alignment, size);
if (err == 0) { if (err == 0) {
fprintf(stderr, fprintf(stderr,
"Expected error for posix_memalign(&p, %zu, %zu)\n", "Expected error for posix_memalign(&p, %zu, %zu)\n",
@ -63,7 +63,7 @@ main(void)
alignment = 0x40000000LU; alignment = 0x40000000LU;
size = 0x84000001LU; size = 0x84000001LU;
#endif #endif
err = JEMALLOC_P(posix_memalign)(&p, alignment, size); err = posix_memalign(&p, alignment, size);
if (err == 0) { if (err == 0) {
fprintf(stderr, fprintf(stderr,
"Expected error for posix_memalign(&p, %zu, %zu)\n", "Expected error for posix_memalign(&p, %zu, %zu)\n",
@ -76,7 +76,7 @@ main(void)
#else #else
size = 0xfffffff0LU; size = 0xfffffff0LU;
#endif #endif
err = JEMALLOC_P(posix_memalign)(&p, alignment, size); err = posix_memalign(&p, alignment, size);
if (err == 0) { if (err == 0) {
fprintf(stderr, fprintf(stderr,
"Expected error for posix_memalign(&p, %zu, %zu)\n", "Expected error for posix_memalign(&p, %zu, %zu)\n",
@ -95,7 +95,7 @@ main(void)
size < 3 * alignment && size < (1U << 31); size < 3 * alignment && size < (1U << 31);
size += (alignment >> (LG_SIZEOF_PTR-1)) - 1) { size += (alignment >> (LG_SIZEOF_PTR-1)) - 1) {
for (i = 0; i < NITER; i++) { for (i = 0; i < NITER; i++) {
err = JEMALLOC_P(posix_memalign)(&ps[i], err = posix_memalign(&ps[i],
alignment, size); alignment, size);
if (err) { if (err) {
fprintf(stderr, fprintf(stderr,
@ -103,13 +103,13 @@ main(void)
size, size, strerror(err)); size, size, strerror(err));
exit(1); exit(1);
} }
total += JEMALLOC_P(malloc_usable_size)(ps[i]); total += malloc_usable_size(ps[i]);
if (total >= (MAXALIGN << 1)) if (total >= (MAXALIGN << 1))
break; break;
} }
for (i = 0; i < NITER; i++) { for (i = 0; i < NITER; i++) {
if (ps[i] != NULL) { if (ps[i] != NULL) {
JEMALLOC_P(free)(ps[i]); free(ps[i]);
ps[i] = NULL; ps[i] = NULL;
} }
} }

View File

@ -24,14 +24,14 @@ main(void)
pagesize = (size_t)result; pagesize = (size_t)result;
} }
r = JEMALLOC_P(allocm)(&p, &sz, 42, 0); r = allocm(&p, &sz, 42, 0);
if (r != ALLOCM_SUCCESS) { if (r != ALLOCM_SUCCESS) {
fprintf(stderr, "Unexpected allocm() error\n"); fprintf(stderr, "Unexpected allocm() error\n");
abort(); abort();
} }
q = p; q = p;
r = JEMALLOC_P(rallocm)(&q, &tsz, sz, 0, ALLOCM_NO_MOVE); r = rallocm(&q, &tsz, sz, 0, ALLOCM_NO_MOVE);
if (r != ALLOCM_SUCCESS) if (r != ALLOCM_SUCCESS)
fprintf(stderr, "Unexpected rallocm() error\n"); fprintf(stderr, "Unexpected rallocm() error\n");
if (q != p) if (q != p)
@ -42,7 +42,7 @@ main(void)
} }
q = p; q = p;
r = JEMALLOC_P(rallocm)(&q, &tsz, sz, 5, ALLOCM_NO_MOVE); r = rallocm(&q, &tsz, sz, 5, ALLOCM_NO_MOVE);
if (r != ALLOCM_SUCCESS) if (r != ALLOCM_SUCCESS)
fprintf(stderr, "Unexpected rallocm() error\n"); fprintf(stderr, "Unexpected rallocm() error\n");
if (q != p) if (q != p)
@ -53,7 +53,7 @@ main(void)
} }
q = p; q = p;
r = JEMALLOC_P(rallocm)(&q, &tsz, sz + 5, 0, ALLOCM_NO_MOVE); r = rallocm(&q, &tsz, sz + 5, 0, ALLOCM_NO_MOVE);
if (r != ALLOCM_ERR_NOT_MOVED) if (r != ALLOCM_ERR_NOT_MOVED)
fprintf(stderr, "Unexpected rallocm() result\n"); fprintf(stderr, "Unexpected rallocm() result\n");
if (q != p) if (q != p)
@ -64,7 +64,7 @@ main(void)
} }
q = p; q = p;
r = JEMALLOC_P(rallocm)(&q, &tsz, sz + 5, 0, 0); r = rallocm(&q, &tsz, sz + 5, 0, 0);
if (r != ALLOCM_SUCCESS) if (r != ALLOCM_SUCCESS)
fprintf(stderr, "Unexpected rallocm() error\n"); fprintf(stderr, "Unexpected rallocm() error\n");
if (q == p) if (q == p)
@ -76,7 +76,7 @@ main(void)
p = q; p = q;
sz = tsz; sz = tsz;
r = JEMALLOC_P(rallocm)(&q, &tsz, pagesize*2, 0, 0); r = rallocm(&q, &tsz, pagesize*2, 0, 0);
if (r != ALLOCM_SUCCESS) if (r != ALLOCM_SUCCESS)
fprintf(stderr, "Unexpected rallocm() error\n"); fprintf(stderr, "Unexpected rallocm() error\n");
if (q == p) if (q == p)
@ -88,7 +88,7 @@ main(void)
p = q; p = q;
sz = tsz; sz = tsz;
r = JEMALLOC_P(rallocm)(&q, &tsz, pagesize*4, 0, 0); r = rallocm(&q, &tsz, pagesize*4, 0, 0);
if (r != ALLOCM_SUCCESS) if (r != ALLOCM_SUCCESS)
fprintf(stderr, "Unexpected rallocm() error\n"); fprintf(stderr, "Unexpected rallocm() error\n");
if (tsz == sz) { if (tsz == sz) {
@ -98,7 +98,7 @@ main(void)
p = q; p = q;
sz = tsz; sz = tsz;
r = JEMALLOC_P(rallocm)(&q, &tsz, pagesize*2, 0, ALLOCM_NO_MOVE); r = rallocm(&q, &tsz, pagesize*2, 0, ALLOCM_NO_MOVE);
if (r != ALLOCM_SUCCESS) if (r != ALLOCM_SUCCESS)
fprintf(stderr, "Unexpected rallocm() error\n"); fprintf(stderr, "Unexpected rallocm() error\n");
if (q != p) if (q != p)
@ -109,7 +109,7 @@ main(void)
} }
sz = tsz; sz = tsz;
r = JEMALLOC_P(rallocm)(&q, &tsz, pagesize*4, 0, ALLOCM_NO_MOVE); r = rallocm(&q, &tsz, pagesize*4, 0, ALLOCM_NO_MOVE);
if (r != ALLOCM_SUCCESS) if (r != ALLOCM_SUCCESS)
fprintf(stderr, "Unexpected rallocm() error\n"); fprintf(stderr, "Unexpected rallocm() error\n");
if (q != p) if (q != p)
@ -120,7 +120,7 @@ main(void)
} }
sz = tsz; sz = tsz;
JEMALLOC_P(dallocm)(p, 0); dallocm(p, 0);
fprintf(stderr, "Test end\n"); fprintf(stderr, "Test end\n");
return (0); return (0);

View File

@ -18,22 +18,22 @@ thread_start(void *arg)
size_t size; size_t size;
int err; int err;
p = JEMALLOC_P(malloc)(1); p = malloc(1);
if (p == NULL) { if (p == NULL) {
fprintf(stderr, "%s(): Error in malloc()\n", __func__); fprintf(stderr, "%s(): Error in malloc()\n", __func__);
return (void *)1; return (void *)1;
} }
size = sizeof(arena_ind); size = sizeof(arena_ind);
if ((err = JEMALLOC_P(mallctl)("thread.arena", &arena_ind, &size, if ((err = mallctl("thread.arena", &arena_ind, &size, &main_arena_ind,
&main_arena_ind, sizeof(main_arena_ind)))) { sizeof(main_arena_ind)))) {
fprintf(stderr, "%s(): Error in mallctl(): %s\n", __func__, fprintf(stderr, "%s(): Error in mallctl(): %s\n", __func__,
strerror(err)); strerror(err));
return (void *)1; return (void *)1;
} }
size = sizeof(arena_ind); size = sizeof(arena_ind);
if ((err = JEMALLOC_P(mallctl)("thread.arena", &arena_ind, &size, NULL, if ((err = mallctl("thread.arena", &arena_ind, &size, NULL,
0))) { 0))) {
fprintf(stderr, "%s(): Error in mallctl(): %s\n", __func__, fprintf(stderr, "%s(): Error in mallctl(): %s\n", __func__,
strerror(err)); strerror(err));
@ -57,7 +57,7 @@ main(void)
fprintf(stderr, "Test begin\n"); fprintf(stderr, "Test begin\n");
p = JEMALLOC_P(malloc)(1); p = malloc(1);
if (p == NULL) { if (p == NULL) {
fprintf(stderr, "%s(): Error in malloc()\n", __func__); fprintf(stderr, "%s(): Error in malloc()\n", __func__);
ret = 1; ret = 1;
@ -65,8 +65,7 @@ main(void)
} }
size = sizeof(arena_ind); size = sizeof(arena_ind);
if ((err = JEMALLOC_P(mallctl)("thread.arena", &arena_ind, &size, NULL, if ((err = mallctl("thread.arena", &arena_ind, &size, NULL, 0))) {
0))) {
fprintf(stderr, "%s(): Error in mallctl(): %s\n", __func__, fprintf(stderr, "%s(): Error in mallctl(): %s\n", __func__,
strerror(err)); strerror(err));
ret = 1; ret = 1;