Bug 758010 - Wrap operator new/delete on Android. r=khuey

This commit is contained in:
Mike Hommey 2012-05-26 10:21:33 +02:00
parent fddcae6618
commit 11b04e4bcf
3 changed files with 34 additions and 0 deletions

View File

@ -7295,6 +7295,10 @@ if test -n "$_WRAP_MALLOC"; then
WRAP_LDFLAGS="${WRAP_LDFLAGS} -Wl,--wrap=__builtin_new,--wrap=__builtin_vec_new,--wrap=__builtin_delete,--wrap=__builtin_vec_delete"
WRAP_LDFLAGS="${WRAP_LDFLAGS} -Wl,--wrap=strdup,--wrap=strndup"
WRAP_LDFLAGS="${WRAP_LDFLAGS} -Wl,--wrap=posix_memalign,--wrap=malloc_usable_size"
dnl Wrap operator new and operator delete on Android.
if test "$OS_TARGET" = "Android"; then
WRAP_LDFLAGS="${WRAP_LDFLAGS} -Wl,--wrap=_Znwj,--wrap=_Znaj,--wrap=_ZdlPv,--wrap=_ZdaPv"
fi
else
AC_MSG_ERROR([--enable-wrap-malloc is not supported for non-GNU toolchains])
fi

View File

@ -4058,6 +4058,10 @@ if test -n "$_WRAP_MALLOC"; then
WRAP_LDFLAGS="${WRAP_LDFLAGS} -Wl,--wrap=__builtin_new,--wrap=__builtin_vec_new,--wrap=__builtin_delete,--wrap=__builtin_vec_delete"
WRAP_LDFLAGS="${WRAP_LDFLAGS} -Wl,--wrap=strdup,--wrap=strndup"
WRAP_LDFLAGS="${WRAP_LDFLAGS} -Wl,--wrap=posix_memalign,--wrap=malloc_usable_size"
dnl Wrap operator new and operator delete on Android.
if test "$OS_TARGET" = "Android"; then
WRAP_LDFLAGS="${WRAP_LDFLAGS} -Wl,--wrap=_Znwj,--wrap=_Znaj,--wrap=_ZdlPv,--wrap=_ZdaPv"
fi
else
AC_MSG_ERROR([--enable-wrap-malloc is not supported for non-GNU toolchains])
fi

View File

@ -7,6 +7,32 @@
#ifdef ANDROID
#define wrap(a) __wrap_ ## a
/* operator new wrapper implementation */
static void *
new(unsigned int size)
{
return malloc(size);
}
/* operator new(unsigned int) */
MOZ_EXPORT_API(void *)
wrap(_Znwj)(unsigned int) __attribute__((alias("new")));
/* operator new[](unsigned int) */
MOZ_EXPORT_API(void *)
wrap(_Znaj)(unsigned int) __attribute__((alias("new")));
/* operator delete wrapper implementation */
static void
delete(void *ptr)
{
free(ptr);
}
/* operator delete(void*) */
MOZ_EXPORT_API(void)
wrap(_ZdlPv)(void *ptr) __attribute__((alias("delete")));
/* operator delete[](void*) */
MOZ_EXPORT_API(void)
wrap(_ZdaPv)(void *ptr) __attribute__((alias("delete")));
#endif
#if defined(XP_WIN) || defined(XP_MACOSX)