зеркало из https://github.com/mozilla/gecko-dev.git
bug 559263 - implement jemalloc for android r=vlad
This commit is contained in:
Родитель
62bf73ee94
Коммит
74db90d53e
26
configure.in
26
configure.in
|
@ -7141,23 +7141,23 @@ if test "$MOZ_MEMORY"; then
|
|||
dnl The generic feature tests that determine how to compute ncpus are long and
|
||||
dnl complicated. Therefore, simply define special cpp variables for the
|
||||
dnl platforms we have special knowledge of.
|
||||
case "${target_os}" in
|
||||
darwin*)
|
||||
case "${target}" in
|
||||
*-darwin*)
|
||||
AC_DEFINE(MOZ_MEMORY_DARWIN)
|
||||
;;
|
||||
*freebsd*)
|
||||
*-*freebsd*)
|
||||
AC_DEFINE(MOZ_MEMORY_BSD)
|
||||
;;
|
||||
*linux*)
|
||||
*-*linux*)
|
||||
AC_DEFINE(MOZ_MEMORY_LINUX)
|
||||
;;
|
||||
netbsd*)
|
||||
*-netbsd*)
|
||||
AC_DEFINE(MOZ_MEMORY_BSD)
|
||||
;;
|
||||
solaris*)
|
||||
*-solaris*)
|
||||
AC_DEFINE(MOZ_MEMORY_SOLARIS)
|
||||
;;
|
||||
msvc*|mks*|cygwin*|mingw*)
|
||||
*-msvc*|*-mks*|*-cygwin*|*-mingw*)
|
||||
AC_DEFINE(MOZ_MEMORY_WINDOWS)
|
||||
dnl This is sort of awful. Will revisit if we add support for more versions
|
||||
if test "$CC_VERSION" != "14.00.50727.762" -a "$CC_VERSION" != "15.00.30729.01"; then
|
||||
|
@ -7191,17 +7191,21 @@ if test "$MOZ_MEMORY"; then
|
|||
DLLFLAGS="$DLLFLAGS $MOZ_MEMORY_LDFLAGS"
|
||||
export DLLFLAGS
|
||||
;;
|
||||
*wince)
|
||||
*-*wince)
|
||||
AC_DEFINE(MOZ_MEMORY_WINCE)
|
||||
AC_DEFINE(MOZ_MEMORY_WINDOWS)
|
||||
if test -z "$WINCE_WINDOWS_MOBILE"; then
|
||||
AC_DEFINE(MOZ_MEMORY_WINCE6)
|
||||
fi
|
||||
;;
|
||||
*winmo)
|
||||
*-*winmo)
|
||||
AC_DEFINE(MOZ_MEMORY_WINCE)
|
||||
AC_DEFINE(MOZ_MEMORY_WINDOWS)
|
||||
;;
|
||||
*-android*)
|
||||
AC_DEFINE(MOZ_MEMORY_LINUX)
|
||||
AC_DEFINE(MOZ_MEMORY_ANDROID)
|
||||
;;
|
||||
*)
|
||||
AC_MSG_ERROR([--enable-jemalloc not supported on ${target}])
|
||||
;;
|
||||
|
@ -7230,8 +7234,8 @@ MOZ_ARG_ENABLE_BOOL(wrap-malloc,
|
|||
|
||||
if test -n "$_WRAP_MALLOC"; then
|
||||
if test "$GNU_CC"; then
|
||||
WRAP_MALLOC_CFLAGS="${LDFLAGS} -Wl,--wrap -Wl,malloc -Wl,--wrap -Wl,free -Wl,--wrap -Wl,realloc -Wl,--wrap -Wl,__builtin_new -Wl,--wrap -Wl,__builtin_vec_new -Wl,--wrap -Wl,__builtin_delete -Wl,--wrap -Wl,__builtin_vec_delete -Wl,--wrap -Wl,PR_Free -Wl,--wrap -Wl,PR_Malloc -Wl,--wrap -Wl,PR_Calloc -Wl,--wrap -Wl,PR_Realloc"
|
||||
MKSHLIB='$(CXX) $(DSO_LDOPTS) $(WRAP_MALLOC_CFLAGS) -o $@'
|
||||
WRAP_MALLOC_CFLAGS="${LDFLAGS} -Wl,--wrap -Wl,malloc -Wl,--wrap -Wl,calloc -Wl,--wrap -Wl,valloc -Wl,--wrap -Wl,free -Wl,--wrap -Wl,realloc -Wl,--wrap -Wl,memalign -Wl,--wrap -Wl,__builtin_new -Wl,--wrap -Wl,__builtin_vec_new -Wl,--wrap -Wl,__builtin_delete -Wl,--wrap -Wl,__builtin_vec_delete -Wl,--wrap -Wl,PR_Free -Wl,--wrap -Wl,PR_Malloc -Wl,--wrap -Wl,PR_Calloc -Wl,--wrap -Wl,PR_Realloc -Wl,--wrap -Wl,strdup -Wl,--wrap -Wl,strndup"
|
||||
MKSHLIB='$(CXX) $(DSO_LDOPTS) $(WRAP_MALLOC_CFLAGS) $(WRAP_MALLOC_LIB) -o $@'
|
||||
fi
|
||||
fi
|
||||
|
||||
|
|
|
@ -4293,30 +4293,34 @@ if test "$MOZ_MEMORY"; then
|
|||
dnl The generic feature tests that determine how to compute ncpus are long and
|
||||
dnl complicated. Therefore, simply define special cpp variables for the
|
||||
dnl platforms we have special knowledge of.
|
||||
case "${target_os}" in
|
||||
darwin*)
|
||||
case "${target}" in
|
||||
*-darwin*)
|
||||
AC_DEFINE(MOZ_MEMORY_DARWIN)
|
||||
;;
|
||||
*freebsd*)
|
||||
*-*freebsd*)
|
||||
AC_DEFINE(MOZ_MEMORY_BSD)
|
||||
;;
|
||||
*linux*)
|
||||
*-*linux*)
|
||||
AC_DEFINE(MOZ_MEMORY_LINUX)
|
||||
;;
|
||||
netbsd*)
|
||||
*-netbsd*)
|
||||
AC_DEFINE(MOZ_MEMORY_BSD)
|
||||
;;
|
||||
solaris*)
|
||||
*-solaris*)
|
||||
AC_DEFINE(MOZ_MEMORY_SOLARIS)
|
||||
;;
|
||||
msvc*|mks*|cygwin*|mingw*)
|
||||
*-msvc*|*-mks*|*-cygwin*|*-mingw*)
|
||||
AC_DEFINE(MOZ_MEMORY_WINDOWS)
|
||||
# the interesting bits will get passed down in MOZ_MEMORY_LDFLAGS
|
||||
;;
|
||||
*wince|*winmo)
|
||||
*-*wince|*-*winmo)
|
||||
AC_DEFINE(MOZ_MEMORY_WINCE)
|
||||
AC_DEFINE(MOZ_MEMORY_WINDOWS)
|
||||
;;
|
||||
*-android*)
|
||||
AC_DEFINE(MOZ_MEMORY_LINUX)
|
||||
AC_DEFINE(MOZ_MEMORY_ANDROID)
|
||||
;;
|
||||
*)
|
||||
AC_MSG_ERROR([--enable-jemalloc not supported on ${target}])
|
||||
;;
|
||||
|
@ -4335,8 +4339,8 @@ MOZ_ARG_ENABLE_BOOL(wrap-malloc,
|
|||
|
||||
if test -n "$_WRAP_MALLOC"; then
|
||||
if test "$GNU_CC"; then
|
||||
WRAP_MALLOC_CFLAGS="${LDFLAGS} -Wl,--wrap -Wl,malloc -Wl,--wrap -Wl,free -Wl,--wrap -Wl,realloc -Wl,--wrap -Wl,__builtin_new -Wl,--wrap -Wl,__builtin_vec_new -Wl,--wrap -Wl,__builtin_delete -Wl,--wrap -Wl,__builtin_vec_delete -Wl,--wrap -Wl,PR_Free -Wl,--wrap -Wl,PR_Malloc -Wl,--wrap -Wl,PR_Calloc -Wl,--wrap -Wl,PR_Realloc"
|
||||
MKSHLIB='$(CXX) $(DSO_LDOPTS) $(WRAP_MALLOC_CFLAGS) -o $@'
|
||||
WRAP_MALLOC_CFLAGS="${LDFLAGS} -Wl,--wrap -Wl,malloc -Wl,--wrap -Wl,calloc -Wl,--wrap -Wl,valloc -Wl,--wrap -Wl,free -Wl,--wrap -Wl,realloc -Wl,--wrap -Wl,memalign -Wl,--wrap -Wl,__builtin_new -Wl,--wrap -Wl,__builtin_vec_new -Wl,--wrap -Wl,__builtin_delete -Wl,--wrap -Wl,__builtin_vec_delete -Wl,--wrap -Wl,PR_Free -Wl,--wrap -Wl,PR_Malloc -Wl,--wrap -Wl,PR_Calloc -Wl,--wrap -Wl,PR_Realloc -Wl,--wrap -Wl,strdup -Wl,--wrap -Wl,strndup"
|
||||
MKSHLIB='$(CXX) $(DSO_LDOPTS) $(WRAP_MALLOC_CFLAGS) $(WRAP_MALLOC_LIB) -o $@'
|
||||
fi
|
||||
fi
|
||||
|
||||
|
|
|
@ -135,6 +135,10 @@ CSRCS = jemalloc.c
|
|||
NO_PROFILE_GUIDED_OPTIMIZE = 1
|
||||
endif
|
||||
|
||||
ifdef WRAP_MALLOC_CFLAGS
|
||||
DEFINES += -DWRAP_MALLOC
|
||||
endif
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
ifeq (Darwin,$(OS_TARGET))
|
||||
|
|
|
@ -182,7 +182,7 @@
|
|||
# define MALLOC_PAGEFILE_WRITE_SIZE 512
|
||||
#endif
|
||||
|
||||
#ifdef MOZ_MEMORY_LINUX
|
||||
#if defined(MOZ_MEMORY_LINUX) && !defined(MOZ_MEMORY_ANDROID)
|
||||
#define _GNU_SOURCE /* For mremap(2). */
|
||||
#define issetugid() 0
|
||||
#if 0 /* Enable in order to test decommit code on Linux. */
|
||||
|
@ -316,7 +316,7 @@ __FBSDID("$FreeBSD: head/lib/libc/stdlib/malloc.c 180599 2008-07-18 19:35:44Z ja
|
|||
#endif
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#ifndef MOZ_MEMORY_SOLARIS
|
||||
#if !defined(MOZ_MEMORY_SOLARIS) && !defined(MOZ_MEMORY_ANDROID)
|
||||
#include <sys/sysctl.h>
|
||||
#endif
|
||||
#include <sys/uio.h>
|
||||
|
@ -606,7 +606,7 @@ static bool malloc_initialized = false;
|
|||
/* No init lock for Windows. */
|
||||
#elif defined(MOZ_MEMORY_DARWIN)
|
||||
static malloc_mutex_t init_lock = {OS_SPINLOCK_INIT};
|
||||
#elif defined(MOZ_MEMORY_LINUX)
|
||||
#elif defined(MOZ_MEMORY_LINUX) && !defined(MOZ_MEMORY_ANDROID)
|
||||
static malloc_mutex_t init_lock = PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP;
|
||||
#elif defined(MOZ_MEMORY)
|
||||
static malloc_mutex_t init_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
@ -1335,7 +1335,7 @@ malloc_mutex_init(malloc_mutex_t *mutex)
|
|||
return (true);
|
||||
#elif defined(MOZ_MEMORY_DARWIN)
|
||||
mutex->lock = OS_SPINLOCK_INIT;
|
||||
#elif defined(MOZ_MEMORY_LINUX)
|
||||
#elif defined(MOZ_MEMORY_LINUX) && !defined(MOZ_MEMORY_ANDROID)
|
||||
pthread_mutexattr_t attr;
|
||||
if (pthread_mutexattr_init(&attr) != 0)
|
||||
return (true);
|
||||
|
@ -1399,7 +1399,7 @@ malloc_spin_init(malloc_spinlock_t *lock)
|
|||
return (true);
|
||||
#elif defined(MOZ_MEMORY_DARWIN)
|
||||
lock->lock = OS_SPINLOCK_INIT;
|
||||
#elif defined(MOZ_MEMORY_LINUX)
|
||||
#elif defined(MOZ_MEMORY_LINUX) && !defined(MOZ_MEMORY_ANDROID)
|
||||
pthread_mutexattr_t attr;
|
||||
if (pthread_mutexattr_init(&attr) != 0)
|
||||
return (true);
|
||||
|
@ -5505,7 +5505,7 @@ MALLOC_OUT:
|
|||
#endif
|
||||
}
|
||||
|
||||
#if (!defined(MOZ_MEMORY_WINDOWS) && !defined(MOZ_MEMORY_DARWIN))
|
||||
#if (!defined(MOZ_MEMORY_WINDOWS) && !defined(MOZ_MEMORY_DARWIN) && !defined(MOZ_MEMORY_ANDROID))
|
||||
/* Prevent potential deadlock on malloc locks after fork. */
|
||||
pthread_atfork(_malloc_prefork, _malloc_postfork, _malloc_postfork);
|
||||
#endif
|
||||
|
@ -5753,7 +5753,7 @@ malloc_shutdown()
|
|||
# define ZONE_INLINE
|
||||
#endif
|
||||
|
||||
/* Mangle standard interfaces on Darwin and Windows CE,
|
||||
/* Mangle standard interfaces on Darwin and Android,
|
||||
in order to avoid linking problems. */
|
||||
#if defined(MOZ_MEMORY_DARWIN)
|
||||
#define malloc(a) moz_malloc(a)
|
||||
|
@ -5763,6 +5763,25 @@ malloc_shutdown()
|
|||
#define free(a) moz_free(a)
|
||||
#endif
|
||||
|
||||
#if defined(MOZ_MEMORY_ANDROID) || defined(WRAP_MALLOC)
|
||||
inline void sys_free(void* ptr) {return free(ptr);}
|
||||
#define malloc(a) je_malloc(a)
|
||||
#define valloc(a) je_valloc(a)
|
||||
#define calloc(a, b) je_calloc(a, b)
|
||||
#define realloc(a, b) je_realloc(a, b)
|
||||
#define free(a) je_free(a)
|
||||
char *je_strndup(const char *src, size_t len) {
|
||||
char* dst = (char*)je_malloc(len + 1);
|
||||
if(dst)
|
||||
strncpy(dst, src, len + 1);
|
||||
return dst;
|
||||
}
|
||||
char *je_strdup(const char *src) {
|
||||
size_t len = strlen(src);
|
||||
return je_strndup(src, len );
|
||||
}
|
||||
#endif
|
||||
|
||||
ZONE_INLINE
|
||||
void *
|
||||
malloc(size_t size)
|
||||
|
@ -6040,9 +6059,13 @@ free(void *ptr)
|
|||
/*
|
||||
* Begin non-standard functions.
|
||||
*/
|
||||
|
||||
#ifdef MOZ_MEMORY_ANDROID
|
||||
size_t
|
||||
malloc_usable_size(void *ptr)
|
||||
#else
|
||||
size_t
|
||||
malloc_usable_size(const void *ptr)
|
||||
#endif
|
||||
{
|
||||
|
||||
#ifdef MALLOC_VALIDATE
|
||||
|
@ -6429,10 +6452,12 @@ jemalloc_darwin_init(void)
|
|||
* passed an extra argument for the caller return address, which will be
|
||||
* ignored.
|
||||
*/
|
||||
#ifndef WRAP_MALLOC
|
||||
void (*__free_hook)(void *ptr) = free;
|
||||
void *(*__malloc_hook)(size_t size) = malloc;
|
||||
void *(*__realloc_hook)(void *ptr, size_t size) = realloc;
|
||||
void *(*__memalign_hook)(size_t alignment, size_t size) = memalign;
|
||||
#endif
|
||||
|
||||
#elif defined(RTLD_DEEPBIND)
|
||||
/*
|
||||
|
|
|
@ -89,6 +89,17 @@ void free(void *ptr);
|
|||
int posix_memalign(void **memptr, size_t alignment, size_t size);
|
||||
#endif /* MOZ_MEMORY_DARWIN, MOZ_MEMORY_LINUX */
|
||||
|
||||
#if defined(MOZ_MEMORY_ANDROID) || defined(WRAP_MALLOC)
|
||||
void *je_malloc(size_t size);
|
||||
void *je_valloc(size_t size);
|
||||
void *je_calloc(size_t num, size_t size);
|
||||
void *je_realloc(void *ptr, size_t size);
|
||||
void je_free(void *ptr);
|
||||
int je_posix_memalign(void **memptr, size_t alignment, size_t size);
|
||||
char *je_strndup(const char *src, size_t len);
|
||||
char *je_strdup(const char *src);
|
||||
#endif
|
||||
|
||||
/* Linux has memalign and malloc_usable_size */
|
||||
#if !defined(MOZ_MEMORY_LINUX)
|
||||
void *memalign(size_t alignment, size_t size);
|
||||
|
|
|
@ -54,6 +54,19 @@ LIBRARY_NAME = mozalloc
|
|||
FORCE_SHARED_LIB= 1
|
||||
DIST_INSTALL = 1
|
||||
|
||||
ifdef MOZ_MEMORY
|
||||
ifneq (,$(findstring mozalloc,$(WRAP_MALLOC_LIB)))
|
||||
EXTRA_DSO_LDOPTS += $(DIST)/lib/libjemalloc.a
|
||||
WRAP_MALLOC_LIB=
|
||||
WRAP_MALLOC_CFLAGS=
|
||||
DEFINES += -DWRAP_MALLOC
|
||||
CSRCS = wraps.c
|
||||
ifeq (,$(filter-out Linux,$(OS_TARGET)))
|
||||
EXTRA_DSO_LDOPTS += -lpthread
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq (,$(filter-out WINCE,$(OS_ARCH)))
|
||||
# mozalloc gets its allocation methods from the shunt, which gets their
|
||||
# implementation by direcly linking with jemalloc.obj
|
||||
|
|
|
@ -74,6 +74,16 @@
|
|||
#define UNLIKELY(x) (x)
|
||||
#endif
|
||||
|
||||
#if defined(MOZ_MEMORY_ANDROID) || defined(WRAP_MALLOC)
|
||||
#include "jemalloc.h"
|
||||
#define malloc(a) je_malloc(a)
|
||||
#define valloc(a) je_valloc(a)
|
||||
#define calloc(a, b) je_calloc(a, b)
|
||||
#define realloc(a, b) je_realloc(a, b)
|
||||
#define free(a) je_free(a)
|
||||
#define strdup(a) je_strdup(a)
|
||||
#define strndup(a, b) je_strndup(a, b)
|
||||
#endif
|
||||
|
||||
void
|
||||
moz_free(void* ptr)
|
||||
|
|
|
@ -203,10 +203,18 @@ MOZALLOC_EXPORT void* moz_valloc(size_t size)
|
|||
# define MOZALLOC_EXPORT_NEW
|
||||
#endif
|
||||
|
||||
#ifdef ANDROID
|
||||
// Android doesn't fully support exceptions, so its <new> header
|
||||
// has operators that don't specify throw() at all.
|
||||
#define MOZALLOC_THROW_IF_HAS_EXCEPTIONS /**/
|
||||
#else
|
||||
#define MOZALLOC_THROW_IF_HAS_EXCEPTIONS throw()
|
||||
#endif
|
||||
|
||||
#ifdef MOZ_CPP_EXCEPTIONS
|
||||
#define MOZALLOC_THROW_BAD_ALLOC throw(std::bad_alloc)
|
||||
#else
|
||||
#define MOZALLOC_THROW_BAD_ALLOC throw()
|
||||
#define MOZALLOC_THROW_BAD_ALLOC MOZALLOC_THROW_IF_HAS_EXCEPTIONS
|
||||
#endif
|
||||
|
||||
MOZALLOC_EXPORT_NEW MOZALLOC_INLINE
|
||||
|
@ -216,7 +224,7 @@ void* operator new(size_t size) MOZALLOC_THROW_BAD_ALLOC
|
|||
}
|
||||
|
||||
MOZALLOC_EXPORT_NEW MOZALLOC_INLINE
|
||||
void* operator new(size_t size, const std::nothrow_t&) throw()
|
||||
void* operator new(size_t size, const std::nothrow_t&) MOZALLOC_THROW_IF_HAS_EXCEPTIONS
|
||||
{
|
||||
return moz_malloc(size);
|
||||
}
|
||||
|
@ -228,31 +236,31 @@ void* operator new[](size_t size) MOZALLOC_THROW_BAD_ALLOC
|
|||
}
|
||||
|
||||
MOZALLOC_EXPORT_NEW MOZALLOC_INLINE
|
||||
void* operator new[](size_t size, const std::nothrow_t&) throw()
|
||||
void* operator new[](size_t size, const std::nothrow_t&) MOZALLOC_THROW_IF_HAS_EXCEPTIONS
|
||||
{
|
||||
return moz_malloc(size);
|
||||
}
|
||||
|
||||
MOZALLOC_EXPORT_NEW MOZALLOC_INLINE
|
||||
void operator delete(void* ptr) throw()
|
||||
void operator delete(void* ptr) MOZALLOC_THROW_IF_HAS_EXCEPTIONS
|
||||
{
|
||||
return moz_free(ptr);
|
||||
}
|
||||
|
||||
MOZALLOC_EXPORT_NEW MOZALLOC_INLINE
|
||||
void operator delete(void* ptr, const std::nothrow_t&) throw()
|
||||
void operator delete(void* ptr, const std::nothrow_t&) MOZALLOC_THROW_IF_HAS_EXCEPTIONS
|
||||
{
|
||||
return moz_free(ptr);
|
||||
}
|
||||
|
||||
MOZALLOC_EXPORT_NEW MOZALLOC_INLINE
|
||||
void operator delete[](void* ptr) throw()
|
||||
void operator delete[](void* ptr) MOZALLOC_THROW_IF_HAS_EXCEPTIONS
|
||||
{
|
||||
return moz_free(ptr);
|
||||
}
|
||||
|
||||
MOZALLOC_EXPORT_NEW MOZALLOC_INLINE
|
||||
void operator delete[](void* ptr, const std::nothrow_t&) throw()
|
||||
void operator delete[](void* ptr, const std::nothrow_t&) MOZALLOC_THROW_IF_HAS_EXCEPTIONS
|
||||
{
|
||||
return moz_free(ptr);
|
||||
}
|
||||
|
@ -284,25 +292,25 @@ struct MOZALLOC_EXPORT fallible_t { };
|
|||
} /* namespace mozilla */
|
||||
|
||||
MOZALLOC_INLINE
|
||||
void* operator new(size_t size, const mozilla::fallible_t&) throw()
|
||||
void* operator new(size_t size, const mozilla::fallible_t&) MOZALLOC_THROW_IF_HAS_EXCEPTIONS
|
||||
{
|
||||
return moz_malloc(size);
|
||||
}
|
||||
|
||||
MOZALLOC_INLINE
|
||||
void* operator new[](size_t size, const mozilla::fallible_t&) throw()
|
||||
void* operator new[](size_t size, const mozilla::fallible_t&) MOZALLOC_THROW_IF_HAS_EXCEPTIONS
|
||||
{
|
||||
return moz_malloc(size);
|
||||
}
|
||||
|
||||
MOZALLOC_INLINE
|
||||
void operator delete(void* ptr, const mozilla::fallible_t&) throw()
|
||||
void operator delete(void* ptr, const mozilla::fallible_t&) MOZALLOC_THROW_IF_HAS_EXCEPTIONS
|
||||
{
|
||||
moz_free(ptr);
|
||||
}
|
||||
|
||||
MOZALLOC_INLINE
|
||||
void operator delete[](void* ptr, const mozilla::fallible_t&) throw()
|
||||
void operator delete[](void* ptr, const mozilla::fallible_t&) MOZALLOC_THROW_IF_HAS_EXCEPTIONS
|
||||
{
|
||||
moz_free(ptr);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,102 @@
|
|||
#include <stddef.h> // for size_t
|
||||
#include <stdlib.h> // for malloc, free
|
||||
#include "mozalloc.h"
|
||||
#ifdef MOZ_MEMORY_ANDROID
|
||||
#include <android/log.h>
|
||||
#define LOG(args...) __android_log_print(ANDROID_LOG_INFO, "wrap", args)
|
||||
#endif
|
||||
#include <malloc.h>
|
||||
|
||||
#ifdef __malloc_hook
|
||||
static void* moz_malloc_hook(size_t size, const void *caller)
|
||||
{
|
||||
return moz_malloc(size);
|
||||
}
|
||||
|
||||
static void* moz_realloc_hook(void *ptr, size_t size, const void *caller)
|
||||
{
|
||||
return moz_realloc(ptr, size);
|
||||
}
|
||||
|
||||
static void moz_free_hook(void *ptr, const void *caller)
|
||||
{
|
||||
moz_free(ptr);
|
||||
}
|
||||
|
||||
static void* moz_memalign_hook(size_t align, size_t size, const void *caller)
|
||||
{
|
||||
return moz_memalign(align, size);
|
||||
}
|
||||
|
||||
static void
|
||||
moz_malloc_init_hook (void)
|
||||
{
|
||||
__malloc_hook = moz_malloc_hook;
|
||||
__realloc_hook = moz_realloc_hook;
|
||||
__free_hook = moz_free_hook;
|
||||
__memalign_hook = moz_memalign_hook;
|
||||
}
|
||||
|
||||
/* Override initializing hook from the C library. */
|
||||
void (*__malloc_initialize_hook) (void) = moz_malloc_init_hook;
|
||||
#endif
|
||||
|
||||
inline void __wrap_free(void* ptr)
|
||||
{
|
||||
moz_free(ptr);
|
||||
}
|
||||
|
||||
inline void* __wrap_malloc(size_t size)
|
||||
{
|
||||
return moz_malloc(size);
|
||||
}
|
||||
|
||||
inline void* __wrap_realloc(void* ptr, size_t size)
|
||||
{
|
||||
return moz_realloc(ptr, size);
|
||||
}
|
||||
|
||||
inline void* __wrap_calloc(size_t num, size_t size)
|
||||
{
|
||||
return moz_calloc(num, size);
|
||||
}
|
||||
|
||||
inline void* __wrap_valloc(size_t size)
|
||||
{
|
||||
return moz_valloc(size);
|
||||
}
|
||||
|
||||
inline void* __wrap_memalign(size_t align, size_t size)
|
||||
{
|
||||
return moz_memalign(align, size);
|
||||
}
|
||||
|
||||
inline char* __wrap_strdup(char* str)
|
||||
{
|
||||
return moz_strdup(str);
|
||||
}
|
||||
|
||||
inline char* __wrap_strndup(const char* str, size_t size) {
|
||||
return moz_strndup(str, size);
|
||||
}
|
||||
|
||||
|
||||
inline void __wrap_PR_Free(void* ptr)
|
||||
{
|
||||
moz_free(ptr);
|
||||
}
|
||||
|
||||
inline void* __wrap_PR_Malloc(size_t size)
|
||||
{
|
||||
return moz_malloc(size);
|
||||
}
|
||||
|
||||
inline void* __wrap_PR_Realloc(void* ptr, size_t size)
|
||||
{
|
||||
return moz_realloc(ptr, size);
|
||||
}
|
||||
|
||||
inline void* __wrap_PR_Calloc(size_t num, size_t size)
|
||||
{
|
||||
return moz_calloc(num, size);
|
||||
}
|
|
@ -292,12 +292,18 @@ DEFAULT_GMAKE_FLAGS += \
|
|||
OS_LIBS= \
|
||||
STANDARDS_CFLAGS="-std=gnu89" \
|
||||
DSO_CFLAGS="$(CFLAGS) -DCHECK_FORK_GETPID -DRTLD_NOLOAD=0 -include $(topsrcdir)/security/manager/android_stub.h" \
|
||||
DSO_LDOPTS="-shared $(LDFLAGS)" \
|
||||
DSO_LDOPTS="-shared $(LDFLAGS) $(WRAP_MALLOC_CFLAGS) $(WRAP_MALLOC_LIB) " \
|
||||
$(NULL)
|
||||
endif
|
||||
|
||||
SKIP_CHK=1
|
||||
endif
|
||||
ifdef WRAP_MALLOC_CFLAGS
|
||||
DEFAULT_GMAKE_FLAGS += \
|
||||
LDFLAGS="$(LDFLAGS) $(WRAP_MALLOC_CFLAGS) $(WRAP_MALLOC_LIB) " \
|
||||
$(NULL)
|
||||
endif
|
||||
|
||||
SUBMAKEFILES = boot/Makefile ssl/Makefile pki/Makefile locales/Makefile
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
|
|
@ -60,6 +60,10 @@ endif
|
|||
|
||||
LIBS = $(DIST)/lib/$(LIB_PREFIX)xpt.$(LIB_SUFFIX)
|
||||
|
||||
ifdef WRAP_MALLOC_CFLAGS
|
||||
LIBS += -lmozalloc
|
||||
endif
|
||||
|
||||
USE_STATIC_LIBS = 1
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
|
Загрузка…
Ссылка в новой задаче