Merge b-s to m-c.
authorKyle Huey <khuey@kylehuey.com>
Wed, 24 Aug 2011 11:14:59 -0400
changeset 75810 d3e15e7073f92cd43479d5809b337d8ba031221d
parent 75801 ac653960b153fc8f96be4277e5edaae88461b123 (current diff)
parent 75809 d79e6c3c0616982736bd8044d089d7487367deb4 (diff)
child 75811 7143812c80a95473141f60888ee28005dd312c5f
child 75873 bcadab74517322e29f84141c5d265bda746ab7ff
push id3
push userfelipc@gmail.com
push dateFri, 30 Sep 2011 20:09:13 +0000
milestone9.0a1
Merge b-s to m-c.
memory/jemalloc/apply-ed-patches.pl
memory/jemalloc/build-crt.py
memory/jemalloc/crtvc8sp1-amd64.diff
memory/jemalloc/crtvc8sp1-intel.diff
memory/jemalloc/crtvc9sp1-amd64.diff
memory/jemalloc/crtvc9sp1-intel.diff
memory/jemalloc/ed.exe
memory/mozalloc/ld_malloc_wrappers.c
--- a/Makefile.in
+++ b/Makefile.in
@@ -60,23 +60,25 @@ TIERS += base
 #
 tier_base_dirs = \
 	config \
 	build \
 	probes \
 	$(NULL)
 
 ifndef LIBXUL_SDK
-tier_base_dirs += \
-	memory \
-	$(NULL)
+ifdef MOZ_MEMORY
+tier_base_dirs += memory/jemalloc
+endif
+
 ifeq ($(OS_TARGET),Android)
 tier_base_dirs += other-licenses/android
 endif
 
+tier_base_dirs += memory/mozalloc
 endif
 
 ifdef COMPILE_ENVIRONMENT
 include $(topsrcdir)/$(MOZ_BUILD_APP)/build.mk
 endif
 
 
 include $(topsrcdir)/config/config.mk
--- a/browser/installer/Makefile.in
+++ b/browser/installer/Makefile.in
@@ -83,20 +83,16 @@ ifdef MOZ_ANGLE
 DEFINES += -DMOZ_ANGLE=$(MOZ_ANGLE)
 DEFINES += -DMOZ_D3DX9_DLL=$(MOZ_D3DX9_DLL)
 DEFINES += -DMOZ_D3DCOMPILER_DLL=$(MOZ_D3DCOMPILER_DLL)
 endif
 
 include $(topsrcdir)/ipc/app/defs.mk
 DEFINES += -DMOZ_CHILD_PROCESS_NAME=$(MOZ_CHILD_PROCESS_NAME)
 
-ifdef WIN32_OLD_STYLE_JEMALLOC
-DEFINES += -DWIN32_OLD_STYLE_JEMALLOC=1
-endif
-
 ifneq (,$(filter aurora beta,$(MOZ_UPDATE_CHANNEL)))
 DEFINES += -DSHIP_FEEDBACK=1
 endif
 
 ifdef MOZ_PKG_MANIFEST_P
 MOZ_PKG_MANIFEST = package-manifest
 
 $(MOZ_PKG_MANIFEST): $(MOZ_PKG_MANIFEST_P) $(GLOBAL_DEPS)
--- a/browser/installer/package-manifest.in
+++ b/browser/installer/package-manifest.in
@@ -56,24 +56,18 @@
 #ifdef XP_MACOSX
 @BINPATH@/@MOZ_CHILD_PROCESS_NAME@.app/
 @BINPATH@/@DLL_PREFIX@plugin_child_interpose@DLL_SUFFIX@
 #else
 @BINPATH@/@MOZ_CHILD_PROCESS_NAME@
 #endif
 #ifdef XP_WIN32
 #ifdef MOZ_MEMORY
-#ifdef WIN32_OLD_STYLE_JEMALLOC
-@BINPATH@/mozcrt19.dll
-@BINPATH@/mozcpp19.dll
-#else
 @BINPATH@/jemalloc.dll
 #endif
-#endif
-#else
 #if _MSC_VER == 1400
 @BINPATH@/Microsoft.VC80.CRT.manifest
 @BINPATH@/msvcm80.dll
 @BINPATH@/msvcp80.dll
 @BINPATH@/msvcr80.dll
 #elif _MSC_VER == 1500
 @BINPATH@/Microsoft.VC90.CRT.manifest
 @BINPATH@/msvcm90.dll
--- a/browser/installer/removed-files.in
+++ b/browser/installer/removed-files.in
@@ -1267,24 +1267,18 @@ xpicleanup@BIN_SUFFIX@
   res/fonts/mathfontSymbol.properties
 #endif
 #ifdef XP_WIN
   components/brwsrcmp.dll
   components/jsd3250.dll
   components/nsPostUpdateWin.js
   js3250.dll
   plugins/npnul32.dll
-  #ifdef MOZ_MEMORY
-    Microsoft.VC80.CRT.manifest
-    msvcm80.dll
-    msvcp80.dll
-    msvcr80.dll
-  #else
-    mozcrt19.dll
-  #endif
+  mozcrt19.dll
+  mozcpp19.dll
 #endif
 @DLL_PREFIX@xpcom_core@DLL_SUFFIX@
 components/@DLL_PREFIX@jar50@DLL_SUFFIX@
 #ifdef XP_WIN
   components/xpinstal.dll
 #else
   components/@DLL_PREFIX@jsd@DLL_SUFFIX@
   components/@DLL_PREFIX@xpinstall@DLL_SUFFIX@
--- a/build/autoconf/mozconfig-find
+++ b/build/autoconf/mozconfig-find
@@ -37,17 +37,16 @@
 #
 # ***** END LICENSE BLOCK *****
 
 # mozconfigfind - Loads options from .mozconfig onto configure's
 #    command-line. The .mozconfig file is searched for in the 
 #    order:
 #       if $MOZCONFIG is set, use that.
 #       Otherwise, use $TOPSRCDIR/.mozconfig
-#       Otherwise, use $HOME/.mozconfig
 #
 topsrcdir=$1
 
 abspath() {
   if uname -s | grep -q MINGW; then
     # We have no way to figure out whether we're in gmake or pymake right
     # now. gmake gives us Unix-style paths while pymake gives us Windows-style
     # paths, so attempt to handle both.
@@ -62,32 +61,42 @@ abspath() {
       exit 0
     fi
   done
 
   # If we're at this point, we have a relative path
   echo `pwd`/$1
 }
 
+if [ -n "$MOZCONFIG" ] && ! [ -f "$MOZCONFIG" ]; then
+  echo "Specified MOZCONFIG \"$MOZCONFIG\" does not exist!"
+  exit 1
+fi
+
+if [ -n "$MOZ_MYCONFIG" ]; then
+  echo "Your environment currently has the MOZ_MYCONFIG variable set to \"$MOZ_MYCONFIG\". MOZ_MYCONFIG is no longer supported. Please use MOZCONFIG instead."
+  exit 1
+fi
+
 for _config in "$MOZCONFIG" \
-               "$MOZ_MYCONFIG"
+               "$topsrcdir/.mozconfig"
 do
-  if [ -n "$_config" ] && ! [ -f "$_config" ]; then
-    echo "Specified MOZCONFIG \"$_config\" does not exist!"
-    exit 1
+  if test -f "$_config"; then
+    echo `abspath $_config`
+    exit 0
   fi
 done
 
-for _config in "$MOZCONFIG" \
-               "$MOZ_MYCONFIG" \
-               "$topsrcdir/.mozconfig" \
-               "$topsrcdir/mozconfig" \
+# We used to support a number of other implicit .mozconfig locations. We now
+# detect if we were about to use any of these locations and issue an error if we
+# find any.
+for _config in "$topsrcdir/mozconfig" \
                "$topsrcdir/mozconfig.sh" \
                "$topsrcdir/myconfig.sh" \
                "$HOME/.mozconfig" \
                "$HOME/.mozconfig.sh" \
                "$HOME/.mozmyconfig.sh"
 do
   if test -f "$_config"; then
-    echo `abspath $_config`
-    exit 0
+    echo "You currently have a mozconfig at \"$_config\". This implicit location is no longer supported. Please move it to $topsrcdir/.mozconfig or specify it explicitly via \$MOZCONFIG.";
+    exit 1
   fi
 done
--- a/build/win32/Makefile.in
+++ b/build/win32/Makefile.in
@@ -59,17 +59,16 @@ DIRS += \
 PROGRAM = crashinject$(BIN_SUFFIX)
 USE_STATIC_LIBS = 1
 CPPSRCS = crashinject.cpp
 
 endif # ENABLE_TESTS
 
 include $(topsrcdir)/config/rules.mk
 
-ifndef MOZ_MEMORY
 ifdef WIN32_REDIST_DIR
 ifndef MOZ_DEBUG
 
 ifeq (1400,$(_MSC_VER))
 REDIST_FILES = \
 	Microsoft.VC80.CRT.manifest \
 	msvcm80.dll \
 	msvcp80.dll \
@@ -96,9 +95,8 @@ endif
 ifdef REDIST_FILES
 libs::
 	mkdir -p $(FINAL_TARGET)
 	install --preserve-timestamps $(foreach f,$(REDIST_FILES),"$(WIN32_REDIST_DIR)"/$(f)) $(FINAL_TARGET)
 endif
 
 endif # ! MOZ_DEBUG
 endif # WIN32_REDIST_DIR
-endif # ! MOZ_MEMORY
--- a/config/autoconf.mk.in
+++ b/config/autoconf.mk.in
@@ -622,28 +622,24 @@ USE_GSSAPI	= @USE_GSSAPI@
 MOZILLA_OFFICIAL = @MOZILLA_OFFICIAL@
 
 # Win32 options
 MOZ_BROWSE_INFO	= @MOZ_BROWSE_INFO@
 MOZ_TOOLS_DIR	= @MOZ_TOOLS_DIR@
 MOZ_QUANTIFY	= @MOZ_QUANTIFY@
 MSMANIFEST_TOOL = @MSMANIFEST_TOOL@
 WIN32_REDIST_DIR = @WIN32_REDIST_DIR@
-WIN32_CRT_SRC_DIR = @WIN32_CRT_SRC_DIR@
 MOZ_MEMORY_LDFLAGS = @MOZ_MEMORY_LDFLAGS@
-WIN32_OLD_STYLE_JEMALLOC = @WIN32_OLD_STYLE_JEMALLOC@
 WIN32_CRT_LIBS = @WIN32_CRT_LIBS@
 MOZ_CRT_CPU_ARCH = @MOZ_CRT_CPU_ARCH@
 
 # This is for custom CRT building
 ifdef MOZ_MEMORY
-ifdef WIN32_CRT_SRC_DIR
 DLLFLAGS = @DLLFLAGS@
 endif
-endif
 
 # Codesighs tools option, enables win32 mapfiles.
 MOZ_MAPINFO	= @MOZ_MAPINFO@
 
 MOZ_PHOENIX	= @MOZ_PHOENIX@
 MOZ_XULRUNNER	= @MOZ_XULRUNNER@
 
 MOZ_DISTRIBUTION_ID = @MOZ_DISTRIBUTION_ID@
--- a/config/config.mk
+++ b/config/config.mk
@@ -514,21 +514,26 @@ ifneq (,$(MOZ_DEBUG)$(NS_TRACE_MALLOC))
 ifndef MOZ_NO_DEBUG_RTL
 RTL_FLAGS=-MDd         # Dynamically linked, multithreaded MSVC4.0 debug RTL
 endif 
 endif # MOZ_DEBUG || NS_TRACE_MALLOC
 endif # USE_STATIC_LIBS
 endif # WINNT && !GNU_CC
 
 ifeq ($(OS_ARCH),Darwin)
-# Darwin doesn't cross-compile, so just set both types of flags here.
+# Compiling ObjC requires an Apple compiler anyway, so it's ok to set
+# host CMFLAGS here.
 HOST_CMFLAGS += -fobjc-exceptions
 HOST_CMMFLAGS += -fobjc-exceptions
 OS_COMPILE_CMFLAGS += -fobjc-exceptions
 OS_COMPILE_CMMFLAGS += -fobjc-exceptions
+ifeq ($(MOZ_WIDGET_TOOLKIT),uikit)
+OS_COMPILE_CMFLAGS += -fobjc-abi-version=2 -fobjc-legacy-dispatch
+OS_COMPILE_CMMFLAGS += -fobjc-abi-version=2 -fobjc-legacy-dispatch
+endif
 endif
 
 COMPILE_CFLAGS	= $(VISIBILITY_FLAGS) $(DEFINES) $(INCLUDES) $(DSO_CFLAGS) $(DSO_PIC_CFLAGS) $(CFLAGS) $(RTL_FLAGS) $(OS_COMPILE_CFLAGS)
 COMPILE_CXXFLAGS = $(STL_FLAGS) $(VISIBILITY_FLAGS) $(DEFINES) $(INCLUDES) $(DSO_CFLAGS) $(DSO_PIC_CFLAGS) $(CXXFLAGS) $(RTL_FLAGS) $(OS_COMPILE_CXXFLAGS)
 COMPILE_CMFLAGS = $(OS_COMPILE_CMFLAGS)
 COMPILE_CMMFLAGS = $(OS_COMPILE_CMMFLAGS)
 
 ifndef CROSS_COMPILE
--- a/configure.in
+++ b/configure.in
@@ -2101,17 +2101,27 @@ case "$target" in
     DLL_SUFFIX=".dylib"
     DSO_LDOPTS=''
     STRIP="$STRIP -x -S"
     _PLATFORM_DEFAULT_TOOLKIT='cairo-cocoa'
     TARGET_NSPR_MDCPUCFG='\"md/_darwin.cfg\"'
     # The ExceptionHandling framework is needed for Objective-C exception
     # logging code in nsObjCExceptions.h. Currently we only use that in debug
     # builds.
-    MOZ_DEBUG_LDFLAGS="$MOZ_DEBUG_LDFLAGS -framework ExceptionHandling"
+    _SAVE_LDFLAGS=$LDFLAGS
+     AC_MSG_CHECKING([for -framework ExceptionHandling])
+    LDFLAGS="$LDFLAGS -framework ExceptionHandling"
+    AC_TRY_LINK(,[return 0;],
+                ac_cv_have_framework_exceptionhandling="yes",
+                ac_cv_have_framework_exceptionhandling="no")
+    AC_MSG_RESULT([$ac_cv_have_framework_exceptionhandling])
+    if test "$ac_cv_have_framework_exceptionhandling" = "yes"; then
+      MOZ_DEBUG_LDFLAGS="$MOZ_DEBUG_LDFLAGS -framework ExceptionHandling";
+    fi
+    LDFLAGS=$_SAVE_LDFLAGS
     # Debug builds should always have frame pointers
     MOZ_DEBUG_FLAGS="-g -fno-omit-frame-pointer"
 
     if test "x$lto_is_enabled" = "xyes"; then
         echo "Skipping -dead_strip because lto is enabled."
     dnl DTrace and -dead_strip don't interact well. See bug 403132.
     dnl ===================================================================
     elif test "x$enable_dtrace" = "xyes"; then
@@ -3268,17 +3278,17 @@ MOZ_CHECK_HEADERS(gnu/libc-version.h nl_
 MOZ_CHECK_HEADERS(malloc.h)
 MOZ_CHECK_HEADERS(X11/XKBlib.h)
 MOZ_CHECK_HEADERS(io.h)
 
 dnl These are all the places some variant of statfs can be hiding.
 MOZ_CHECK_HEADERS(sys/statvfs.h sys/statfs.h sys/vfs.h sys/mount.h)
 
 dnl Quota support
-MOZ_CHECK_HEADERS(sys/quota.h)
+MOZ_CHECK_HEADERS(sys/quota.h sys/sysmacros.h)
 MOZ_CHECK_HEADERS(linux/quota.h)
 
 dnl Try for MMX support
 dnl NB - later gcc versions require -mmmx for this header to be successfully
 dnl included (or another option which implies it, such as -march=pentium-mmx)
 MOZ_CHECK_HEADERS(mmintrin.h)
 
 dnl Check whether the compiler supports the new-style C++ standard
@@ -4992,23 +5002,37 @@ cairo-os2)
     MOZ_WIDGET_TOOLKIT=os2
     USE_FC_FREETYPE=1
     TK_CFLAGS='$(MOZ_CAIRO_CFLAGS)'
     TK_LIBS='$(MOZ_CAIRO_LIBS)'
     MOZ_PDF_PRINTING=1
     ;;
 
 cairo-cocoa)
-    MOZ_WIDGET_TOOLKIT=cocoa
-    AC_DEFINE(MOZ_WIDGET_COCOA)
+    # Check if we have the Cocoa framework, or if we're targeting Cocoa Touch
+    _SAVE_LDFLAGS=$LDFLAGS
+    LDFLAGS="$LDFLAGS -framework Cocoa"
+    AC_TRY_LINK(,[return 0;],_HAVE_FRAMEWORK_COCOA=1,_HAVE_FRAMEWORK_COCOA=)
+    if test -z "$_HAVE_FRAMEWORK_COCOA"; then
+        LDFLAGS="$_SAVE_LDFLAGS -framework UIKit";
+        AC_TRY_LINK(,[return 0;],_HAVE_FRAMEWORK_UIKIT=1,
+                    AC_MSG_ERROR([Neither Cocoa nor UIKit frameworks were found. Are you using the correct SDK?]))
+        MOZ_WIDGET_TOOLKIT=uikit
+      AC_DEFINE(MOZ_WIDGET_UIKIT)
+      TK_LIBS='-framework Foundation -framework CoreFoundation -framework CoreGraphics -framework CoreText'
+    else
+      MOZ_WIDGET_TOOLKIT=cocoa
+      AC_DEFINE(MOZ_WIDGET_COCOA)
+      TK_LIBS='-framework QuartzCore -framework Carbon -framework CoreAudio -framework AudioToolbox -framework AudioUnit -framework AddressBook -framework OpenGL'
+    fi
     MOZ_USER_DIR="Mozilla"
     AC_DEFINE(XP_MACOSX)
-    TK_LIBS='-framework QuartzCore -framework Carbon -framework CoreAudio -framework AudioToolbox -framework AudioUnit -framework AddressBook -framework OpenGL'
+
     TK_CFLAGS="-DNO_X11"
-    LDFLAGS="$LDFLAGS -framework Cocoa -lobjc"
+    LDFLAGS="$LDFLAGS -lobjc"
     CFLAGS="$CFLAGS $TK_CFLAGS"
     CXXFLAGS="$CXXFLAGS $TK_CFLAGS"
     LIBXUL_LIBS='$(XPCOM_FROZEN_LDOPTS) $(LIBXUL_DIST)/bin/XUL'
     MOZ_FS_LAYOUT=bundle
     MOZ_WEBGL=1
     MOZ_INSTRUMENT_EVENT_LOOP=1
     ;;
 
@@ -7376,78 +7400,44 @@ else
     ;;
   *-*freebsd*)
     AC_DEFINE(MOZ_MEMORY_BSD)
     ;;
   *-android*|*-linuxandroid*)
     AC_DEFINE(MOZ_MEMORY_LINUX)
     AC_DEFINE(MOZ_MEMORY_ANDROID)
     _WRAP_MALLOC=1
-    export WRAP_MALLOC_LIB="-L$_objdir/dist/lib -lmozalloc -lmozutils"
+    export WRAP_MALLOC_LIB="-L$_objdir/dist/lib -lmozutils"
     WRAP_MALLOC_CFLAGS="-Wl,--wrap=dlopen -Wl,--wrap=dlclose -Wl,--wrap=dlerror -Wl,--wrap=dlsym -Wl,--wrap=dladdr"
     ;;
   *-*linux*)
     AC_DEFINE(MOZ_MEMORY_LINUX)
     ;;
   *-netbsd*)
     AC_DEFINE(MOZ_MEMORY_BSD)
     ;;
   *-solaris*)
     AC_DEFINE(MOZ_MEMORY_SOLARIS)
     ;;
   *-mingw*)
     AC_DEFINE(MOZ_MEMORY_WINDOWS)
-    AC_MSG_CHECKING([for VC2005/2008++ CRT source])
-    if test "$CC_VERSION" == "14.00.50727.762" -o "$CC_VERSION" == "15.00.30729.01"; then
-      if test -z "$WIN32_CRT_SRC_DIR" -a -n "$VCINSTALLDIR"; then
-        WIN32_CRT_SRC_DIR="$VCINSTALLDIR\crt\src"
-      fi
-      if test -n "$WIN32_CRT_SRC_DIR" -a -d "$WIN32_CRT_SRC_DIR"; then
-        AC_MSG_RESULT([yes])
-        dnl cpu check
-        case "${target_cpu}" in
-        i*86)
-          MOZ_CRT_CPU_ARCH=intel
-          ;;
-        x86_64)
-          MOZ_CRT_CPU_ARCH=amd64
-          ;;
-        *)
-          AC_MSG_ERROR([--enable-jemalloc not supported on ${target}])
-          ;;
-        esac
-        AC_SUBST(MOZ_CRT_CPU_ARCH)
-        WIN32_OLD_STYLE_JEMALLOC=1
-        AC_DEFINE(WIN32_OLD_STYLE_JEMALLOC)
-        WIN32_CRT_SRC_DIR=`cd "$WIN32_CRT_SRC_DIR" && pwd -W`
-        _objdir_win=`pwd -W`
-        WIN32_CUSTOM_CRT_DIR="$_objdir_win/memory/jemalloc/crtsrc/build/$MOZ_CRT_CPU_ARCH"
-        MOZ_MEMORY_LDFLAGS="-MANIFEST:NO -LIBPATH:\"$WIN32_CUSTOM_CRT_DIR\" -NODEFAULTLIB:msvcrt -NODEFAULTLIB:msvcrtd -NODEFAULTLIB:msvcprt -NODEFAULTLIB:msvcprtd -DEFAULTLIB:mozcrt19 -DEFAULTLIB:mozcpp19"
-      fi
-    fi
-    if test -z "$WIN32_OLD_STYLE_JEMALLOC"; then
-      AC_MSG_RESULT([no])
-      WIN32_NEW_STYLE_JEMALLOC=1
-      AC_DEFINE(WIN32_NEW_STYLE_JEMALLOC)
-      WIN32_CRT_SRC_DIR=
-      if test -z "$MOZ_DEBUG"; then
-        WIN32_CRT_LIBS="msvcrt.lib msvcprt.lib"
-      else
-        WIN32_CRT_LIBS="msvcrtd.lib msvcprtd.lib"
-      fi
-      dnl Look for a broken crtdll.obj
-      WIN32_CRTDLL_FULLPATH=`lib -nologo -list $WIN32_CRT_LIBS | grep crtdll\\.obj`
-      lib -NOLOGO -OUT:crtdll.obj $WIN32_CRT_LIBS -EXTRACT:$WIN32_CRTDLL_FULLPATH
-      if grep -q '__imp__\{0,1\}free' crtdll.obj; then
-        MOZ_MEMORY_LDFLAGS='-LIBPATH:$(DIST)/lib -NODEFAULTLIB:msvcrt -NODEFAULTLIB:msvcrtd -NODEFAULTLIB:msvcprt -NODEFAULTLIB:msvcprtd -DEFAULTLIB:mozcrt'
-      else
-        MOZ_MEMORY_LDFLAGS='$(DIST)/../memory/jemalloc/jemalloc.lib'
-      fi
-      rm crtdll.obj
-    fi
+    if test -z "$MOZ_DEBUG"; then
+      WIN32_CRT_LIBS="msvcrt.lib msvcprt.lib"
+    else
+      WIN32_CRT_LIBS="msvcrtd.lib msvcprtd.lib"
+    fi
+    dnl Look for a broken crtdll.obj
+    WIN32_CRTDLL_FULLPATH=`lib -nologo -list $WIN32_CRT_LIBS | grep crtdll\\.obj`
+    lib -NOLOGO -OUT:crtdll.obj $WIN32_CRT_LIBS -EXTRACT:$WIN32_CRTDLL_FULLPATH
+    if grep -q '__imp__\{0,1\}free' crtdll.obj; then
+      MOZ_MEMORY_LDFLAGS='-LIBPATH:$(DIST)/lib -NODEFAULTLIB:msvcrt -NODEFAULTLIB:msvcrtd -NODEFAULTLIB:msvcprt -NODEFAULTLIB:msvcprtd -DEFAULTLIB:mozcrt'
+    else
+      MOZ_MEMORY_LDFLAGS='$(DIST)/../memory/jemalloc/jemalloc.lib'
+    fi
+    rm crtdll.obj
 
     dnl Also pass this to NSPR/NSS
     DLLFLAGS="$DLLFLAGS $MOZ_MEMORY_LDFLAGS"
     export DLLFLAGS
     ;;
   *)
     AC_MSG_ERROR([--enable-jemalloc not supported on ${target}])
     ;;
@@ -7457,33 +7447,31 @@ else
     dnl NB: this must be kept in sync with jemalloc.h
     AC_DEFINE(HAVE_JEMALLOC_VALLOC)
   fi
   AC_DEFINE(HAVE_JEMALLOC_POSIX_MEMALIGN)
   AC_DEFINE(HAVE_JEMALLOC_MEMALIGN)
 fi # MOZ_MEMORY
 AC_SUBST(MOZ_MEMORY)
 AC_SUBST(MOZ_MEMORY_LDFLAGS)
-AC_SUBST(WIN32_OLD_STYLE_JEMALLOC)
 AC_SUBST(WIN32_CRT_LIBS)
-AC_SUBST(WIN32_CRT_SRC_DIR)
 dnl Need to set this for make because NSS doesn't have configure
 AC_SUBST(DLLFLAGS)
 
 dnl ========================================================
 dnl = Use malloc wrapper lib
 dnl ========================================================
 MOZ_ARG_ENABLE_BOOL(wrap-malloc,
 [  --enable-wrap-malloc    Wrap malloc calls (gnu linker only)],
     _WRAP_MALLOC=1,
     _WRAP_MALLOC= )
 
 if test -n "$_WRAP_MALLOC"; then
     if test "$GNU_CC"; then
-    WRAP_MALLOC_CFLAGS="${LDFLAGS} ${WRAP_MALLOC_CFLAGS} -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 -Wl,--wrap -Wl,posix_memalign"
+    WRAP_MALLOC_CFLAGS="${LDFLAGS} ${WRAP_MALLOC_CFLAGS} -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 -Wl,--wrap -Wl,posix_memalign -Wl,--wrap,malloc_usable_size"
     MKSHLIB="$MKSHLIB"' $(WRAP_MALLOC_CFLAGS) $(WRAP_MALLOC_LIB)'
     MKCSHLIB="$MKCSHLIB"' $(WRAP_MALLOC_CFLAGS) $(WRAP_MALLOC_LIB)'
     fi
 fi
 
 dnl ========================================================
 dnl = Location of malloc wrapper lib
 dnl ========================================================
@@ -8014,16 +8002,17 @@ if test "$_PEDANTIC"; then
     esac
 fi
 
 dnl ========================================================
 dnl Test for correct temporary object destruction order
 dnl ========================================================
 dnl We want to make sure the compiler follows the C++ spec here as 
 dnl xpcom and the string classes depend on it (bug 235381).
+if test -z "$CROSS_COMPILE"; then
 AC_MSG_CHECKING([for correct temporary object destruction order])
 AC_TRY_RUN([ class A {
              public:  A(int& x) : mValue(x) {}
                       ~A() { mValue--; }
                       operator char**() { return 0; }
              private:  int& mValue;
              };
              void func(char **arg) {}
@@ -8038,16 +8027,17 @@ AC_TRY_RUN([ class A {
              }
              ],
      result="yes", result="no", result="maybe")
 AC_MSG_RESULT([$result])
 
 if test "$result" = "no"; then
     AC_MSG_ERROR([Your compiler does not follow the C++ specification for temporary object destruction order.])
 fi
+fi
 
 dnl ========================================================
 dnl Autoconf test for gcc 2.7.2.x (and maybe others?) so that we don't
 dnl provide non-const forms of the operator== for comparing nsCOMPtrs to
 dnl raw pointers in nsCOMPtr.h.  (VC++ has the same bug.)
 dnl ========================================================
 _SAVE_CXXFLAGS=$CXXFLAGS
 CXXFLAGS="$CXXFLAGS ${_WARNINGS_CXXFLAGS}"
@@ -8521,17 +8511,17 @@ if test "$MOZ_TREE_CAIRO"; then
         FT_FONT_FEATURE="#define CAIRO_HAS_FT_FONT 1"
         MOZ_ENABLE_CAIRO_FT=1
         CAIRO_FT_CFLAGS="$FT2_CFLAGS"
     fi
     case "$MOZ_WIDGET_TOOLKIT" in
       qt)
         QT_SURFACE_FEATURE="#define CAIRO_HAS_QT_SURFACE 1"
         ;;
-      cocoa)
+      cocoa | uikit)
         QUARTZ_SURFACE_FEATURE="#define CAIRO_HAS_QUARTZ_SURFACE 1"
         QUARTZ_IMAGE_SURFACE_FEATURE="#define CAIRO_HAS_QUARTZ_IMAGE_SURFACE 1"
         QUARTZ_FONT_FEATURE="#define CAIRO_HAS_QUARTZ_FONT 1"
         ;;
       windows)
         WIN32_SURFACE_FEATURE="#define CAIRO_HAS_WIN32_SURFACE 1"
         WIN32_FONT_FEATURE="#define CAIRO_HAS_WIN32_FONT 1"
         if test "$MOZ_WINSDK_TARGETVER" -ge "06010000"; then
--- a/js/src/assembler/jit/ExecutableAllocator.h
+++ b/js/src/assembler/jit/ExecutableAllocator.h
@@ -369,17 +369,17 @@ public:
 #else
         intptr_t end = reinterpret_cast<intptr_t>(code) + size;
         __builtin___clear_cache(reinterpret_cast<char*>(code), reinterpret_cast<char*>(end));
 #endif
 #else
         _flush_cache(reinterpret_cast<char*>(code), size, BCACHE);
 #endif
     }
-#elif WTF_CPU_ARM_THUMB2 && WTF_OS_IOS
+#elif WTF_CPU_ARM && WTF_OS_IOS
     static void cacheFlush(void* code, size_t size)
     {
         sys_dcache_flush(code, size);
         sys_icache_invalidate(code, size);
     }
 #elif WTF_CPU_ARM_THUMB2 && WTF_IOS
     static void cacheFlush(void* code, size_t size)
     {
--- a/js/src/assembler/wtf/Platform.h
+++ b/js/src/assembler/wtf/Platform.h
@@ -324,17 +324,17 @@
 #else
 #define WTF_THUMB_ARCH_VERSION 0
 #endif
 
 
 /* WTF_CPU_ARMV5_OR_LOWER - ARM instruction set v5 or earlier */
 /* On ARMv5 and below the natural alignment is required. 
    And there are some other differences for v5 or earlier. */
-#if !defined(ARMV5_OR_LOWER) && WTF_CPU_ARM && WTF_ARM_ARCH_VERSION >= 6
+#if !defined(ARMV5_OR_LOWER) && WTF_CPU_ARM && !(WTF_ARM_ARCH_VERSION >= 6)
 #define WTF_CPU_ARMV5_OR_LOWER 1
 #endif
 
 
 /* WTF_CPU_ARM_TRADITIONAL - Thumb2 is not available, only traditional ARM (v4 or greater) */
 /* WTF_CPU_ARM_THUMB2 - Thumb2 instruction set is available */
 /* Only one of these will be defined. */
 #if !defined(WTF_CPU_ARM_TRADITIONAL) && !defined(WTF_CPU_ARM_THUMB2)
@@ -1110,17 +1110,18 @@
 #endif
 
 #if ENABLE_JIT || ENABLE_YARR_JIT
 #define ENABLE_ASSEMBLER 1
 #endif
 /* Setting this flag prevents the assembler from using RWX memory; this may improve
    security but currectly comes at a significant performance cost. */
 #if WTF_PLATFORM_IOS
-#define ENABLE_ASSEMBLER_WX_EXCLUSIVE 1
+//XXX: this doesn't currently compile in the spidermonkey build
+#define ENABLE_ASSEMBLER_WX_EXCLUSIVE 0
 #endif
 
 /* Pick which allocator to use; we only need an executable allocator if the assembler is compiled in.
    On x86-64 we use a single fixed mmap, on other platforms we mmap on demand. */
 #if ENABLE_ASSEMBLER
 #if WTF_CPU_X86_64
 #define ENABLE_EXECUTABLE_ALLOCATOR_FIXED 1
 #else
--- a/js/src/config/config.mk
+++ b/js/src/config/config.mk
@@ -514,21 +514,26 @@ ifneq (,$(MOZ_DEBUG)$(NS_TRACE_MALLOC))
 ifndef MOZ_NO_DEBUG_RTL
 RTL_FLAGS=-MDd         # Dynamically linked, multithreaded MSVC4.0 debug RTL
 endif 
 endif # MOZ_DEBUG || NS_TRACE_MALLOC
 endif # USE_STATIC_LIBS
 endif # WINNT && !GNU_CC
 
 ifeq ($(OS_ARCH),Darwin)
-# Darwin doesn't cross-compile, so just set both types of flags here.
+# Compiling ObjC requires an Apple compiler anyway, so it's ok to set
+# host CMFLAGS here.
 HOST_CMFLAGS += -fobjc-exceptions
 HOST_CMMFLAGS += -fobjc-exceptions
 OS_COMPILE_CMFLAGS += -fobjc-exceptions
 OS_COMPILE_CMMFLAGS += -fobjc-exceptions
+ifeq ($(MOZ_WIDGET_TOOLKIT),uikit)
+OS_COMPILE_CMFLAGS += -fobjc-abi-version=2 -fobjc-legacy-dispatch
+OS_COMPILE_CMMFLAGS += -fobjc-abi-version=2 -fobjc-legacy-dispatch
+endif
 endif
 
 COMPILE_CFLAGS	= $(VISIBILITY_FLAGS) $(DEFINES) $(INCLUDES) $(DSO_CFLAGS) $(DSO_PIC_CFLAGS) $(CFLAGS) $(RTL_FLAGS) $(OS_COMPILE_CFLAGS)
 COMPILE_CXXFLAGS = $(STL_FLAGS) $(VISIBILITY_FLAGS) $(DEFINES) $(INCLUDES) $(DSO_CFLAGS) $(DSO_PIC_CFLAGS) $(CXXFLAGS) $(RTL_FLAGS) $(OS_COMPILE_CXXFLAGS)
 COMPILE_CMFLAGS = $(OS_COMPILE_CMFLAGS)
 COMPILE_CMMFLAGS = $(OS_COMPILE_CMMFLAGS)
 
 ifndef CROSS_COMPILE
--- a/js/src/configure.in
+++ b/js/src/configure.in
@@ -1114,16 +1114,17 @@ dnl ====================================
 dnl Check for MacOS deployment target version
 dnl ========================================================
 
 MOZ_ARG_ENABLE_STRING(macos-target,
                       [  --enable-macos-target=VER (default=10.5)
                           Set the minimum MacOS version needed at runtime],
                       [_MACOSX_DEPLOYMENT_TARGET=$enableval])
 
+if test "$target_cpu" != "arm"; then
 case "$target" in
 *-darwin*)
     if test -n "$_MACOSX_DEPLOYMENT_TARGET" ; then
         dnl Use the specified value
         export MACOSX_DEPLOYMENT_TARGET=$_MACOSX_DEPLOYMENT_TARGET
     else
         dnl No value specified on the command line or in the environment,
         dnl use architecture minimum.
@@ -1136,16 +1137,17 @@ case "$target" in
             ;;
           x86_64)
             export MACOSX_DEPLOYMENT_TARGET=10.6
             ;;
         esac
     fi
     ;;
 esac
+fi
 
 AC_SUBST(MACOSX_DEPLOYMENT_TARGET)
 
 dnl ========================================================
 dnl = Mac OS X SDK support
 dnl ========================================================
 MACOS_SDK_DIR=
 NEXT_ROOT=
@@ -2001,22 +2003,32 @@ case "$target" in
     _PEDANTIC=
     CFLAGS="$CFLAGS -fpascal-strings -fno-common"
     CXXFLAGS="$CXXFLAGS -fpascal-strings -fno-common"
     DLL_SUFFIX=".dylib"
     DSO_LDOPTS=''
     STRIP="$STRIP -x -S"
     _PLATFORM_DEFAULT_TOOLKIT='cairo-cocoa'
     TARGET_NSPR_MDCPUCFG='\"md/_darwin.cfg\"'
-    LDFLAGS="$LDFLAGS -framework Cocoa -lobjc"
+    LDFLAGS="$LDFLAGS -lobjc"
     LIBXUL_LIBS='$(XPCOM_FROZEN_LDOPTS) $(LIBXUL_DIST)/bin/XUL'
     # The ExceptionHandling framework is needed for Objective-C exception
     # logging code in nsObjCExceptions.h. Currently we only use that in debug
     # builds.
-    MOZ_DEBUG_LDFLAGS="$MOZ_DEBUG_LDFLAGS -framework ExceptionHandling"
+    _SAVE_LDFLAGS=$LDFLAGS
+     AC_MSG_CHECKING([for -framework ExceptionHandling])
+    LDFLAGS="$LDFLAGS -framework ExceptionHandling"
+    AC_TRY_LINK(,[return 0;],
+                ac_cv_have_framework_exceptionhandling="yes",
+                ac_cv_have_framework_exceptionhandling="no")
+    AC_MSG_RESULT([$ac_cv_have_framework_exceptionhandling])
+    if test  "$ac_cv_have_framework_exceptionhandling" = "yes"; then
+      MOZ_DEBUG_LDFLAGS="$MOZ_DEBUG_LDFLAGS -framework ExceptionHandling";
+    fi
+    LDFLAGS=$_SAVE_LDFLAGS
     # Debug builds should always have frame pointers
     MOZ_DEBUG_FLAGS="-g -fno-omit-frame-pointer"
 
     if test "x$lto_is_enabled" = "xyes"; then
         echo "Skipping -dead_strip because lto is enabled."
     dnl DTrace and -dead_strip don't interact well. See bug 403132.
     dnl ===================================================================
     elif test "x$enable_dtrace" = "xyes"; then
@@ -4375,16 +4387,19 @@ dnl ====================================
 dnl Defaults
 case "${CPU_ARCH}-${OS_TARGET}" in
 arm-Android)
     MOZ_THUMB=yes
     MOZ_ARCH=armv7-a
     MOZ_FPU=vfp
     MOZ_FLOAT_ABI=softfp
     ;;
+arm-Darwin)
+    MOZ_THUMB=yes
+    ;;
 arm-*)
     if test -n "$MOZ_PLATFORM_MAEMO"; then
         MOZ_THUMB=no
         MOZ_ARCH=armv7-a
         MOZ_FLOAT_ABI=softfp
     fi
     if test "$MOZ_PLATFORM_MAEMO" = 6; then
         MOZ_THUMB=yes
--- a/js/src/jstracer.cpp
+++ b/js/src/jstracer.cpp
@@ -7620,16 +7620,22 @@ static bool
 arm_check_vfp()
 {
     if (!arm_tests_initialized)
         arm_read_auxv();
 
     return arm_has_vfp;
 }
 
+#elif defined(__APPLE__)
+// Hardcoded for now, revisit in the future
+static unsigned int
+arm_check_arch() { return 6; }
+static bool
+arm_check_vfp() { return true; }
 #else
 #warning Not sure how to check for architecture variant on your platform. Assuming ARMv4.
 static unsigned int
 arm_check_arch() { return 4; }
 static bool
 arm_check_vfp() { return false; }
 #endif
 
--- a/js/src/nanojit/CodeAlloc.cpp
+++ b/js/src/nanojit/CodeAlloc.cpp
@@ -253,19 +253,23 @@ namespace nanojit
     }
 
     void CodeAlloc::flushICache(CodeList* &blocks) {
         for (CodeList *b = blocks; b != 0; b = b->next)
             flushICache(b->start(), b->size());
     }
 
 #if defined(AVMPLUS_UNIX) && defined(NANOJIT_ARM)
+#if defined(__APPLE__)
+#include <libkern/OSCacheControl.h>
+#else
 #include <asm/unistd.h>
 extern "C" void __clear_cache(char *BEG, char *END);
 #endif
+#endif
 
 #if defined(AVMPLUS_UNIX) && defined(NANOJIT_MIPS)
 #include <asm/cachectl.h>
 extern  "C" int cacheflush(char *addr, int nbytes, int cache);
 #endif
 
 #ifdef AVMPLUS_SPARC
 // Note: the linux #define provided by the compiler.
@@ -345,16 +349,20 @@ extern  "C" void sync_instruction_memory
         cacheflush((char *)start, len, BCACHE);
     }
 
 #elif defined AVMPLUS_UNIX
     #ifdef ANDROID
     void CodeAlloc::flushICache(void *start, size_t len) {
         cacheflush((int)start, (int)start + len, 0);
     }
+    #elif defined(AVMPLUS_ARM) && defined(__APPLE__)
+    void CodeAlloc::flushICache(void *start, size_t len) {
+        sys_dcache_flush(start, len);
+    }
     #else
     // fixme: __clear_cache is a libgcc feature, test for libgcc or gcc
     void CodeAlloc::flushICache(void *start, size_t len) {
         __clear_cache((char*)start, (char*)start + len);
     }
     #endif
 #endif // AVMPLUS_MAC && NANOJIT_PPC
 
--- a/js/src/nanojit/njcpudetect.h
+++ b/js/src/nanojit/njcpudetect.h
@@ -71,16 +71,17 @@
         defined(__ARM_ARCH_7M__) || \
         defined(__ARM_ARCH_7R__) || \
         defined(_ARM_ARCH_7)
 
     #define NJ_COMPILER_ARM_ARCH 7
 
 #elif   defined(__ARM_ARCH_6__) || \
         defined(__ARM_ARCH_6J__) || \
+        defined(__ARM_ARCH_6K__) || \
         defined(__ARM_ARCH_6T2__) || \
         defined(__ARM_ARCH_6Z__) || \
         defined(__ARM_ARCH_6ZK__) || \
         defined(__ARM_ARCH_6M__) || \
         defined(_ARM_ARCH_6)
 
     #define NJ_COMPILER_ARM_ARCH 6
 
--- a/memory/jemalloc/Makefile.in
+++ b/memory/jemalloc/Makefile.in
@@ -44,131 +44,63 @@ VPATH		= @srcdir@
 include $(DEPTH)/config/autoconf.mk
 
 MODULE		= jemalloc
 
 # jemalloc.c properly uses 'static', so don't burden it with manually exposing
 # symbols.
 VISIBILITY_FLAGS=
 
-ifeq (WINNT,$(OS_TARGET))
-ifdef WIN32_OLD_STYLE_JEMALLOC
-# Building the CRT from source
-CRT_OBJ_DIR = $(CURDIR)/crtsrc
-MOZ_CRT_DLL_NAME = mozcrt19
-MOZ_CRTCPP_DLL_NAME = mozcpp19
-MOZ_CRT_STATIC_LIBS = libcmt libcpmt
-MOZ_CRT_DLL = $(CRT_OBJ_DIR)/build/$(MOZ_CRT_CPU_ARCH)/$(MOZ_CRT_DLL_NAME).dll
-MOZ_CRT_IMPORT_LIB = $(CRT_OBJ_DIR)/build/$(MOZ_CRT_CPU_ARCH)/$(MOZ_CRT_DLL_NAME).lib
-MOZ_CRTCPP_DLL = $(CRT_OBJ_DIR)/build/$(MOZ_CRT_CPU_ARCH)/$(MOZ_CRTCPP_DLL_NAME).dll
-MOZ_CRTCPP_IMPORT_LIB = $(CRT_OBJ_DIR)/build/$(MOZ_CRT_CPU_ARCH)/$(MOZ_CRTCPP_DLL_NAME).lib
-
-# copy the CRT DLLs to dist/bin,
-# copy the import libs to dist/lib
-libs:: $(MOZ_CRT_DLL) $(MOZ_CRT_IMPORT_LIB)
-	$(INSTALL) $(MOZ_CRT_DLL) $(MOZ_CRTCPP_DLL) $(FINAL_TARGET)
-	$(INSTALL) $(MOZ_CRT_IMPORT_LIB) $(MOZ_CRTCPP_IMPORT_LIB) $(DIST)/lib
-
-$(MOZ_CRT_IMPORT_LIB): $(MOZ_CRT_DLL)
-
-define EXTRACT_CMD
-cd $(CRT_OBJ_DIR)/$(MOZ_CRT_CPU_ARCH)/$(i)_lib && lib "-extract:..\\build\\$(MOZ_CRT_CPU_ARCH)\\$(i)_obj\\unhandld.obj" eh.lib
-
-endef # don't touch the blank line. actually, don't touch anything in this file.
-
-# patch if necessary
-ifeq ($(CC_VERSION), 14.00.50727.762)
-CRTDIFF=crtvc8sp1-$(MOZ_CRT_CPU_ARCH).diff
-else
-CRTDIFF=crtvc9sp1-$(MOZ_CRT_CPU_ARCH).diff
-endif
-
-$(CRT_OBJ_DIR)/jemalloc.c: $(srcdir)/$(CRTDIFF)
-	rm -rf $(CRT_OBJ_DIR)
-	cp -R "$(WIN32_CRT_SRC_DIR)" $(CRT_OBJ_DIR)
-# per http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1189363&SiteID=1
-	$(foreach i,dll mt xdll xmt,$(EXTRACT_CMD))
-# truly awful
-#XXX: get ed into mozillabuild, bug 415123
-	$(PERL) $(srcdir)/apply-ed-patches.pl $(srcdir)/$(CRTDIFF) \
-	$(CRT_OBJ_DIR) $(srcdir)/ed.exe
-
-$(MOZ_CRT_DLL): \
-  $(CRT_OBJ_DIR)/jemalloc.c $(srcdir)/jemalloc.c $(srcdir)/jemalloc.h \
-  $(srcdir)/jemalloc_types.h $(srcdir)/rb.h
-	cp $(srcdir)/jemalloc.c $(srcdir)/jemalloc.h $(srcdir)/jemalloc_types.h $(srcdir)/rb.h \
-	$(CRT_OBJ_DIR)
-# this pretty much sucks, but nmake and make don't play well together
-	$(PYTHON) $(srcdir)/build-crt.py $(CRT_OBJ_DIR)
-# XXX: these don't link right for some reason; the problem is likely
-# that  not all the standard symbols are exported; looks like MSFT
-# never updated the sample.def files; could probably fix if someone
-# were ever bored enough. :-)
-	rm -f $(addsuffix .lib, $(addprefix $(CRT_OBJ_DIR)/build/$(MOZ_CRT_CPU_ARCH)/, $(MOZ_CRT_STATIC_LIBS)))
-	rm -f $(addsuffix .pdb, $(addprefix $(CRT_OBJ_DIR)/build/$(MOZ_CRT_CPU_ARCH)/, $(MOZ_CRT_STATIC_LIBS)))
-
-# but still export jemalloc.h
-EXPORTS = jemalloc.h jemalloc_types.h
-
-else
-
 CSRCS = jemalloc.c
 EXPORTS = jemalloc.h jemalloc_types.h
 LIBRARY_NAME = jemalloc
+
+ifeq (WINNT,$(OS_TARGET))
 FORCE_SHARED_LIB = 1
 
 MOZ_MEMORY_LDFLAGS = # Don't link against ourselves
 
 DEFFILE = $(srcdir)/jemalloc.def
 
 LDFLAGS += -ENTRY:DllMain
 
 NO_INSTALL_IMPORT_LIBRARY = 1
-
-endif
 else # Not Windows
 
 ifeq ($(OS_ARCH),SunOS)
 ifndef GNU_CC
 MODULE_OPTIMIZE_FLAGS = -xO5
 endif
 endif
 
-LIBRARY_NAME	= jemalloc
-
 # Build jemalloc as a shared lib.  This is mandatory for Darwin, since a library
 # init function is used on that platform.
 ifeq ($(OS_ARCH),Darwin)
 FORCE_SHARED_LIB= 1
 else
+# On Android, we're going to link jemalloc into mozutils, and that only works
+# properly if we only build a fakelib, which won't happen if we DIST_INSTALL
+ifneq ($(OS_TARGET),Android)
 DIST_INSTALL = 1
+endif
 FORCE_STATIC_LIB= 1
 endif
 
-EXPORTS = jemalloc.h jemalloc_types.h
-CSRCS   = jemalloc.c
-
 #XXX: PGO on Linux causes problems here
 # See bug 419470
 NO_PROFILE_GUIDED_OPTIMIZE = 1
 endif
 
-ifdef WRAP_MALLOC_CFLAGS
-DEFINES += -DWRAP_MALLOC
-endif
-
 include $(topsrcdir)/config/rules.mk
 
 ifeq (Darwin,$(OS_TARGET))
 LDFLAGS += -init _jemalloc_darwin_init
 endif
 
 ifeq (WINNT,$(OS_TARGET))
-ifndef WIN32_OLD_STYLE_JEMALLOC
-
 # Roll our own custom logic here for the import library
 
 ###############################################################################
 #
 # Linking Mozilla itself to jemalloc is not particularly difficult.  To do this
 # we avoid linking directly to the Microsoft-provided CRT import libraries.
 # Instead, we link to our own import library which we generate here.  To
 # replace the CRT's malloc/free/other memory management symbols we export
@@ -235,11 +167,9 @@ msvc_removed.lib: msvc_combined.lib crtd
 
 # Extract the broken object file out of the combined library
 crtdll.obj: msvc_combined.lib
 	lib -OUT:$@ $^ -EXTRACT:$(CRTDLL_FULLPATH)
 
 # Grab both CRT libraries and combine them into one library to simplify things
 msvc_combined.lib:
 	lib -OUT:$@ $(WIN32_CRT_LIBS)
-
 endif
-endif
deleted file mode 100755
--- a/memory/jemalloc/apply-ed-patches.pl
+++ /dev/null
@@ -1,84 +0,0 @@
-#!/bin/perl
-# ***** BEGIN LICENSE BLOCK *****
-# Version: MPL 1.1/GPL 2.0/LGPL 2.1
-#
-# The contents of this file are subject to the Mozilla Public License Version
-# 1.1 (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-# http://www.mozilla.org/MPL/
-#
-# Software distributed under the License is distributed on an "AS IS" basis,
-# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
-# for the specific language governing rights and limitations under the
-# License.
-#
-# The Original Code is Mozilla build system.
-#
-# The Initial Developer of the Original Code is
-# Mozilla Foundation.
-# Portions created by the Initial Developer are Copyright (C) 2008
-# the Initial Developer. All Rights Reserved.
-#
-# Contributor(s):
-#  Ted Mielczarek <ted.mielczarek@gmail.com>
-#
-# Alternatively, the contents of this file may be used under the terms of
-# either the GNU General Public License Version 2 or later (the "GPL"), or
-# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
-# in which case the provisions of the GPL or the LGPL are applicable instead
-# of those above. If you wish to allow use of your version of this file only
-# under the terms of either the GPL or the LGPL, and not to allow others to
-# use your version of this file under the terms of the MPL, indicate your
-# decision by deleting the provisions above and replace them with the notice
-# and other provisions required by the GPL or the LGPL. If you do not delete
-# the provisions above, a recipient may use your version of this file under
-# the terms of any one of the MPL, the GPL or the LGPL.
-#
-# ***** END LICENSE BLOCK *****
-
-# Usage: apply-ed-patches.pl <source patch> <target directory> <path to ed>
-
-use FileHandle;
-
-sub do_patch {
-  my ($ed, $target_file, $patch_file, $fh) = @_;
-  # these keep winding up read only for me
-  chmod 0666, $target_file;
-  print $fh "w\n";
-  $fh->close();
-  print "$ed -s $target_file < $patch_file\n";
-  system "$ed -s $target_file < $patch_file\n";
-}
-
-my $header_done = 0;
-my ($target_file,$patch_file) = ('','');
-my $source_patch = $ARGV[0];
-my $srcdir = $ARGV[1];
-my $ed = $ARGV[2];
-$srcdir = "$srcdir/" unless $srcdir =~ m|/$|;
-my $pfh = new FileHandle($source_patch, 'r');
-while(<$pfh>) {
-  # skip initial comment header
-  next if !$header_done && /^#/;
-  $header_done = 1;
-
-  next if /^Only in/;
-  if (/^diff -re (\S+)/) {
-    my $new_file = $1;
-    $new_file =~ s|^crt/src/||;
-    $new_file = "$srcdir$new_file";
-    my $new_patch_file = "$new_file.patch";
-
-    if ($target_file ne '') {
-      do_patch $ed, $target_file, $patch_file, $fh;
-    }
-    $target_file = $new_file;
-    $patch_file = $new_patch_file;
-    $fh = new FileHandle($patch_file, 'w');
-    next;
-  }
-
-  print $fh $_ if $fh;
-}
-
-do_patch $ed, $target_file, $patch_file, $fh;
deleted file mode 100644
--- a/memory/jemalloc/build-crt.py
+++ /dev/null
@@ -1,20 +0,0 @@
-#!/usr/bin/env python
-
-import os, sys
-from subprocess import Popen, STDOUT, PIPE
-
-if 'MAKEFLAGS' in os.environ:
-  del os.environ['MAKEFLAGS']
-proc = Popen(['nmake', 'dll_', 'dll_p', 'mt'], stdout=PIPE, stderr=STDOUT,
-             cwd=sys.argv[1])
-
-while True:
-  line = proc.stdout.readline()
-  if line == '':
-    break
-  line = line.rstrip()
-  # explicitly ignore this fatal-sounding non-fatal error
-  if line == "NMAKE : fatal error U1052: file 'makefile.sub' not found" or line == "Stop.":
-    continue
-  print line
-sys.exit(proc.wait())
deleted file mode 100644
--- a/memory/jemalloc/crtvc8sp1-amd64.diff
+++ /dev/null
@@ -1,235 +0,0 @@
-diff -re crt/src/AMD64/_sample_.def crtsrc/AMD64/_sample_.def
-1160d
-717,718d
-663a
-    posix_memalign
-.
-637a
-    memalign
-.
-494a
-    malloc_usable_size
-    jemalloc_stats
-.
-330,335d
-318d
-307,308d
-75d
-9c
-LIBRARY MOZCRT19
-.
-diff -re crt/src/_sample_.rc crtsrc/_sample_.rc
-41c
-            VALUE "ProductName", "Mozilla Custom C Runtime"
-.
-39c
-            VALUE "OriginalFilename", "MOZCRT19.DLL"
-.
-37c
-            VALUE "OriginalFilename", "MOZCRT19D.DLL"
-.
-33c
-            VALUE "InternalName", "MOZCRT19.DLL"
-.
-31c
-            VALUE "InternalName", "MOZCRT19D.DLL"
-.
-27c
-            VALUE "CompanyName", "Mozilla Foundation"
-.
-Only in crtsrc/: build
-diff -re crt/src/crt0.c crtsrc/crt0.c
-273c
-	/*
-	 * this used to happen in _mtinit, but we need it before malloc
-	 */
-	_init_pointers();       /* initialize global function pointers */
-
-        if ( malloc_init_hard() )           /* initialize heap */
-.
-101a
-extern BOOL malloc_init_hard(void);
-.
-diff -re crt/src/crt0dat.c crtsrc/crt0dat.c
-789d
-778d
-diff -re crt/src/crtexe.c crtsrc/crtexe.c
-333,335d
-diff -re crt/src/crtheap.c crtsrc/crtheap.c
-61c
-    pv = calloc(count, size);
-.
-58,59d
-diff -re crt/src/crtlib.c crtsrc/crtlib.c
-781,788d
-416d
-400a
-		malloc_shutdown();
-
-.
-359d
-340d
-310,311d
-300d
-287c
-            /*
-             * this used to happen in _mtinit, but we need it before malloc
-             */
-            _init_pointers();       /* initialize global function pointers */
-
-            if ( malloc_init_hard() )   /* initialize heap */
-.
-43a
-extern BOOL malloc_init_hard(void);
-extern void malloc_shutdown(void);
-
-.
-diff -re crt/src/dllcrt0.c crtsrc/dllcrt0.c
-236,237d
-183d
-173d
-158d
-153,155d
-diff -re crt/src/gs_report.c crtsrc/gs_report.c
-23,41d
-diff -re crt/src/internal.h crtsrc/internal.h
-407a
-#endif
-.
-403a
-#if 0
-.
-diff -re crt/src/invarg.c crtsrc/invarg.c
-103a
-VOID NTAPI RtlCaptureContext (PCONTEXT ContextRecord);
-.
-diff -re crt/src/makefile crtsrc/makefile
-1840c
--def:$(DEFFILE2_DIR)\sample_p.def
-.
-1816c
- $(DEFFILE2_DIR)\sample_p.def $(CPPSRC_OBJS_DLL:*=dll) \
-.
-1745a
-$(DEFFILE_DIR)\$(RETAIL_LIB_NAME).def : $(DEFFILE_DIR)\_sample_.def
-	copy $** $@
-.
-1274d
-1228,1230d
-754c
-dll_ :: $(OBJROOT) $(OBJCPUDIR) $(OBJDIR_DLL) $(OBJDIR_DLL)\$(PURE_OBJ_DIR) \
-   	$(OBJDIR_DLL)\$(CPP_OBJ_DIR) \
-   	$(RELDIR_CPU) $(PDBDIR_CPU_DLL) $(MAKE_DIRS_DLL)
-.
-334c
-CC_OPTS_BASE=-c -nologo -Zlp8 -W3 -GFy -DWIND32
-.
-307,309c
-LINKER=link
-LINKLIB=link -lib
-LINKIMPLIB=link -lib
-.
-302,304c
-LINKER=link -nologo
-LINKLIB=link -lib -nologo
-LINKIMPLIB=link -lib -nologo
-.
-209d
-21,24c
-RETAIL_DLL_NAME=MOZCRT19
-RETAIL_LIB_NAME=mozcrt19
-RETAIL_DLLCPP_NAME=MOZCPP19
-RETAIL_LIBCPP_NAME=mozcpp19
-.
-diff -re crt/src/makefile.inc crtsrc/makefile.inc
-1624a
-$(OBJDIR)\unhandld.obj: $(PREOBJDIR)\unhandld.obj
-        copy $(PREOBJDIR)\unhandld.obj $@
-
-.
-1134a
-        $(OBJDIR)\memmove.obj \
-.
-618d
-402d
-342,353c
-        $(OBJDIR)\jemalloc.obj \
-.
-334,335d
-329,330d
-327d
-323d
-320d
-diff -re crt/src/makefile.sub crtsrc/makefile.sub
-103c
-LIB=link -lib -nologo
-.
-69c
-CFLAGS=$(CFLAGS) -O2 -DMOZ_MEMORY=1 -DMOZ_MEMORY_WINDOWS=1 -DMOZ_MEMORY_SIZEOF_PTR_2POW=3
-.
-67c
-CFLAGS=$(CFLAGS) -O2 -DMOZ_MEMORY=1 -DMOZ_MEMORY_WINDOWS=1 -DMOZ_MEMORY_SIZEOF_PTR_2POW=3
-.
-diff -re crt/src/malloc.h crtsrc/malloc.h
-189a
-#endif
-.
-177a
-
-#if 0
-.
-161d
-83a
-#endif
-.
-70a
-#if 0
-.
-diff -re crt/src/mlock.c crtsrc/mlock.c
-274c
-#endif
-.
-262a
-#if 0
-.
-diff -re crt/src/new.cpp crtsrc/new.cpp
-60d
-52,55d
-37,38c
-        break;
-.
-diff -re crt/src/nothrownew.cpp crtsrc/nothrownew.cpp
-37a
-#endif
-.
-31a
-#if 1
-        break;
-#else
-
-.
-diff -re crt/src/sample_p.def crtsrc/sample_p.def
-8c
-LIBRARY MOZCPP19
-.
-diff -re crt/src/sample_p.rc crtsrc/sample_p.rc
-41c
-            VALUE "ProductName", "Mozilla Custom C++ Runtime"
-.
-39c
-            VALUE "OriginalFilename", "MOZCPP19.DLL"
-.
-37c
-            VALUE "OriginalFilename", "MOZCPP19D.DLL"
-.
-33c
-            VALUE "InternalName", "MOZCPP19.DLL"
-.
-31c
-            VALUE "InternalName", "MOZCPP19D.DLL"
-.
-27c
-            VALUE "CompanyName", "Mozilla Foundation"
-.
-diff -re crt/src/tidtable.c crtsrc/tidtable.c
-393,394d
deleted file mode 100644
--- a/memory/jemalloc/crtvc8sp1-intel.diff
+++ /dev/null
@@ -1,229 +0,0 @@
-# The Microsoft C Runtime source code to which this document refers is available
-# directly from Microsoft Corporation, under a separate license.
-# Please ensure that if you are using that source code, you have appropriate
-# rights to use it.  By providing you access to this file, Mozilla Corporation
-# and its affiliates do not purport to grant any rights in that source code. 
-# Binaries are available under separate licenses at 
-# http://www.microsoft.com/downloads/details.aspx?familyid=200b2fd9-ae1a-4a14-984d-389c36f85647&displaylang=en
-diff -re crt/src/_sample_.rc ./crtsrc/_sample_.rc
-41c
-            VALUE "ProductName", "Mozilla Custom C Runtime"
-.
-39c
-            VALUE "OriginalFilename", "MOZCRT19.DLL"
-.
-37c
-            VALUE "OriginalFilename", "MOZCRT19D.DLL"
-.
-33c
-            VALUE "InternalName", "MOZCRT19.DLL"
-.
-31c
-            VALUE "InternalName", "MOZCRT19D.DLL"
-.
-27c
-            VALUE "CompanyName", "Mozilla Foundation"
-.
-diff -re crt/src/crt0.c ./crtsrc/crt0.c
-273c
-	/*
-	 * this used to happen in _mtinit, but we need it before malloc
-	 */
-	_init_pointers();       /* initialize global function pointers */
-
-        if ( malloc_init_hard() )           /* initialize heap */
-.
-101a
-extern BOOL malloc_init_hard(void);
-.
-diff -re crt/src/crt0dat.c ./crtsrc/crt0dat.c
-789d
-778d
-diff -re crt/src/crtexe.c ./crtsrc/crtexe.c
-333,335d
-diff -re crt/src/crtheap.c ./crtsrc/crtheap.c
-61c
-    pv = calloc(count, size);
-.
-58,59d
-diff -re crt/src/crtlib.c ./crtsrc/crtlib.c
-781,788d
-416d
-400a
-		malloc_shutdown();
-
-.
-359d
-340d
-310,311d
-300d
-287c
-            /*
-             * this used to happen in _mtinit, but we need it before malloc
-             */
-            _init_pointers();       /* initialize global function pointers */
-
-            if ( malloc_init_hard() )   /* initialize heap */
-.
-43a
-extern BOOL malloc_init_hard(void);
-extern void malloc_shutdown(void);
-
-.
-diff -re crt/src/dllcrt0.c ./crtsrc/dllcrt0.c
-236,237d
-183d
-173d
-158d
-153,155d
-diff -re crt/src/intel/_sample_.def ./crtsrc/intel/_sample_.def
-1208d
-723,724d
-669a
-    posix_memalign
-.
-643a
-    memalign
-.
-500a
-    malloc_usable_size
-    jemalloc_stats
-.
-336,341d
-324d
-313,314d
-81d
-9c
-LIBRARY MOZCRT19
-.
-diff -re crt/src/internal.h ./crtsrc/internal.h
-407a
-#endif
-.
-403a
-#if 0
-.
-diff -re crt/src/makefile ./crtsrc/makefile
-1840c
--def:$(DEFFILE2_DIR)\sample_p.def
-.
-1816c
- $(DEFFILE2_DIR)\sample_p.def $(CPPSRC_OBJS_DLL:*=dll) \
-.
-1745a
-$(DEFFILE_DIR)\$(RETAIL_LIB_NAME).def : $(DEFFILE_DIR)\_sample_.def
-	copy $** $@
-.
-1274d
-1228,1230d
-754c
-dll_ :: $(OBJROOT) $(OBJCPUDIR) $(OBJDIR_DLL) $(OBJDIR_DLL)\$(PURE_OBJ_DIR) \
-   	$(OBJDIR_DLL)\$(CPP_OBJ_DIR) \
-   	$(RELDIR_CPU) $(PDBDIR_CPU_DLL) $(MAKE_DIRS_DLL)
-.
-334c
-CC_OPTS_BASE=-c -nologo -Zlp8 -W3 -GFy -DWIND32
-.
-307,309c
-LINKER=link
-LINKLIB=link -lib
-LINKIMPLIB=link -lib
-.
-302,304c
-LINKER=link -nologo
-LINKLIB=link -lib -nologo
-LINKIMPLIB=link -lib -nologo
-.
-209d
-21,24c
-RETAIL_DLL_NAME=MOZCRT19
-RETAIL_LIB_NAME=mozcrt19
-RETAIL_DLLCPP_NAME=MOZCPP19
-RETAIL_LIBCPP_NAME=mozcpp19
-.
-diff -re crt/src/makefile.inc ./crtsrc/makefile.inc
-1624a
-$(OBJDIR)\unhandld.obj: $(PREOBJDIR)\unhandld.obj
-        copy $(PREOBJDIR)\unhandld.obj $@
-
-.
-618d
-402d
-342,353c
-        $(OBJDIR)\jemalloc.obj \
-.
-334,335d
-329,330d
-327d
-323d
-320d
-diff -re crt/src/makefile.sub ./crtsrc/makefile.sub
-103c
-LIB=link -lib -nologo
-.
-69c
-CFLAGS=$(CFLAGS) -O2 -DMOZ_MEMORY=1 -DMOZ_MEMORY_WINDOWS=1
-.
-diff -re crt/src/malloc.h ./crtsrc/malloc.h
-189a
-#endif
-.
-177a
-
-#if 0
-.
-161d
-83a
-#endif
-.
-70a
-#if 0
-.
-diff -re crt/src/mlock.c ./crtsrc/mlock.c
-274c
-#endif
-.
-262a
-#if 0
-.
-diff -re crt/src/new.cpp ./crtsrc/new.cpp
-60d
-52,55d
-37,38c
-        break;
-.
-diff -re crt/src/nothrownew.cpp ./crtsrc/nothrownew.cpp
-37a
-#endif
-.
-31a
-#if 1
-        break;
-#else
-
-.
-diff -re crt/src/sample_p.def ./crtsrc/sample_p.def
-8c
-LIBRARY MOZCPP19
-.
-diff -re crt/src/sample_p.rc ./crtsrc/sample_p.rc
-41c
-            VALUE "ProductName", "Mozilla Custom C++ Runtime"
-.
-39c
-            VALUE "OriginalFilename", "MOZCPP19.DLL"
-.
-37c
-            VALUE "OriginalFilename", "MOZCPP19D.DLL"
-.
-33c
-            VALUE "InternalName", "MOZCPP19.DLL"
-.
-31c
-            VALUE "InternalName", "MOZCPP19D.DLL"
-.
-27c
-            VALUE "CompanyName", "Mozilla Foundation"
-.
-diff -re crt/src/tidtable.c ./crtsrc/tidtable.c
-393,394d
deleted file mode 100644
--- a/memory/jemalloc/crtvc9sp1-amd64.diff
+++ /dev/null
@@ -1,250 +0,0 @@
-diff -re crt/src/AMD64/_sample_.def crtsrc/AMD64/_sample_.def
-1150d
-712,713d
-658a
-    posix_memalign
-.
-632a
-    memalign
-.
-489a
-    malloc_usable_size
-.
-461a
-    jemalloc_stats
-.
-325,330d
-313d
-307,308d
-75d
-9c
-LIBRARY MOZCRT19
-.
-diff -re crt/src/_sample_.rc crtsrc/_sample_.rc
-41c
-            VALUE "ProductName", "Mozilla Custom C Runtime"
-.
-39c
-            VALUE "OriginalFilename", "MOZCRT19.DLL"
-.
-37c
-            VALUE "OriginalFilename", "MOZCRT19D.DLL"
-.
-33c
-            VALUE "InternalName", "MOZCRT19.DLL"
-.
-31c
-            VALUE "InternalName", "MOZCRT19D.DLL"
-.
-27c
-            VALUE "CompanyName", "Mozilla Foundation"
-.
-diff -re crt/src/crt0.c crtsrc/crt0.c
-212c
-        /*
-         * this used to happen in _mtinit, but we need it before malloc
-         */
-        _init_pointers();       /* initialize global function pointers */
-
-        if ( malloc_init_hard() )                /* initialize heap */
-.
-87a
-extern BOOL malloc_init_hard(void);
-.
-diff -re crt/src/crt0dat.c crtsrc/crt0dat.c
-837d
-826d
-diff -re crt/src/crtdll.c crtsrc/crtdll.c
-31,40d
-diff -re crt/src/crtexe.c crtsrc/crtexe.c
-322,324d
-35,45d
-diff -re crt/src/crtheap.c crtsrc/crtheap.c
-61c
-    pv = calloc(count, size);
-.
-58,59d
-diff -re crt/src/crtlib.c crtsrc/crtlib.c
-686,693d
-355d
-339a
-                 malloc_shutdown();
-
-.
-298d
-279d
-249,250d
-239d
-226c
-            /*
-             * this used to happen in _mtinit, but we need it before malloc
-             */
-            _init_pointers();       /* initialize global function pointers */
-
-            if ( malloc_init_hard() )   /* initialize heap */
-.
-43a
-extern BOOL malloc_init_hard(void);
-extern void malloc_shutdown(void);
-
-.
-diff -re crt/src/dllcrt0.c crtsrc/dllcrt0.c
-189,190d
-136d
-126d
-111d
-106,108d
-diff -re crt/src/gs_report.c crtsrc/gs_report.c
-41c
-#endif
-.
-22c
-#if 0
-.
-diff -re crt/src/intel/_sample_.def crtsrc/intel/_sample_.def
-1198d
-718,719d
-664a
-    posix_memalign
-.
-638a
-    memalign
-.
-495a
-    malloc_usable_size
-.
-467a
-    jemalloc_stats
-.
-331,336d
-319d
-313,314d
-81d
-9c
-LIBRARY MOZCRT19
-.
-diff -re crt/src/internal.h crtsrc/internal.h
-413a
-#endif
-.
-409c
-#if 0
-.
-diff -re crt/src/invarg.c crtsrc/invarg.c
-53c
-#endif
-.
-34c
-#if 0
-.
-diff -re crt/src/makefile crtsrc/makefile
-1873c
--def:$(DEFFILE2_DIR)\sample_p.def
-.
-1841c
- $(DEFFILE2_DIR)\sample_p.def $(CPPSRC_OBJS_DLL:*=dll) \
-.
-1771a
-$(DEFFILE_DIR)\$(RETAIL_LIB_NAME).def : $(DEFFILE_DIR)\_sample_.def
-	copy $** $@
-.
-1290d
-1235,1237d
-760c
-dll_ :: $(OBJROOT) $(OBJCPUDIR) $(OBJDIR_DLL) $(OBJDIR_DLL)\$(PURE_OBJ_DIR) \
-   	$(OBJDIR_DLL)\$(CPP_OBJ_DIR) \
-   	$(RELDIR_CPU) $(PDBDIR_CPU_DLL) $(MAKE_DIRS_DLL)
-.
-340c
-CC_OPTS_BASE=-c -nologo -Zlp8 -W3 -GFy -DWIND32
-.
-213d
-21,24c
-RETAIL_DLL_NAME=MOZCRT19
-RETAIL_LIB_NAME=mozcrt19
-RETAIL_DLLCPP_NAME=MOZCPP19
-RETAIL_LIBCPP_NAME=mozcpp19
-.
-diff -re crt/src/makefile.inc crtsrc/makefile.inc
-1636a
-$(OBJDIR)\unhandld.obj: $(PREOBJDIR)\unhandld.obj
-        copy $(PREOBJDIR)\unhandld.obj $@
-
-.
-623d
-621d
-405d
-344,356c
-        $(OBJDIR)\jemalloc.obj  \
-.
-336,337d
-331,332d
-329d
-325d
-321,322d
-diff -re crt/src/makefile.sub crtsrc/makefile.sub
-66c
-CFLAGS=$(CFLAGS) -O2 -DMOZ_MEMORY=1 -DMOZ_MEMORY_WINDOWS=1 -DMOZ_MEMORY_SIZEOF_PTR_2POW=3
-.
-diff -re crt/src/malloc.h crtsrc/malloc.h
-189a
-#endif
-.
-177a
-
-#if 0
-.
-83a
-#endif
-.
-70a
-#if 0
-.
-diff -re crt/src/mlock.c crtsrc/mlock.c
-274c
-#endif
-.
-262a
-#if 0
-.
-diff -re crt/src/new.cpp crtsrc/new.cpp
-60d
-52,55d
-37,38c
-        break;
-.
-diff -re crt/src/nothrownew.cpp crtsrc/nothrownew.cpp
-38c
-#endif
-.
-31a
-#if 1
-        break;
-#else
-
-.
-diff -re crt/src/sample_p.def crtsrc/sample_p.def
-8c
-LIBRARY mozcpp19
-.
-diff -re crt/src/sample_p.rc crtsrc/sample_p.rc
-41c
-            VALUE "ProductName", "Mozilla Custom C++ Runtime"
-.
-39c
-            VALUE "OriginalFilename", "MOZCPP19.DLL"
-.
-37c
-            VALUE "OriginalFilename", "MOZCPP19D.DLL"
-.
-33c
-            VALUE "InternalName", "MOZCPP19.DLL"
-.
-31c
-            VALUE "InternalName", "MOZCPP19D.DLL"
-.
-27c
-            VALUE "CompanyName", "Mozilla Foundation"
-.
-diff -re crt/src/tidtable.c crtsrc/tidtable.c
-360,361d
deleted file mode 100644
--- a/memory/jemalloc/crtvc9sp1-intel.diff
+++ /dev/null
@@ -1,221 +0,0 @@
-# The Microsoft C Runtime source code to which this document refers is available
-# directly from Microsoft Corporation, under a separate license.
-# Please ensure that if you are using that source code, you have appropriate
-# rights to use it.  By providing you access to this file, Mozilla Corporation
-# and its affiliates do not purport to grant any rights in that source code. 
-# Binaries are available under separate licenses at 
-# http://www.microsoft.com/downloads/details.aspx?familyid=9B2DA534-3E03-4391-8A4D-074B9F2BC1BF&displaylang=en
-diff -re crt/src/_sample_.rc crtsrc/_sample_.rc
-41c
-            VALUE "ProductName", "Mozilla Custom C Runtime"
-.
-39c
-            VALUE "OriginalFilename", "MOZCRT19.DLL"
-.
-37c
-            VALUE "OriginalFilename", "MOZCRT19D.DLL"
-.
-33c
-            VALUE "InternalName", "MOZCRT19.DLL"
-.
-31c
-            VALUE "InternalName", "MOZCRT19D.DLL"
-.
-27c
-            VALUE "CompanyName", "Mozilla Foundation"
-.
-diff -re crt/src/crt0.c crtsrc/crt0.c
-212c
-        /*
-         * this used to happen in _mtinit, but we need it before malloc
-         */
-        _init_pointers();       /* initialize global function pointers */
-
-        if ( malloc_init_hard() )                /* initialize heap */
-.
-87a
-extern BOOL malloc_init_hard(void);
-.
-diff -re crt/src/crt0dat.c crtsrc/crt0dat.c
-837d
-826d
-diff -re crt/src/crtdll.c crtsrc/crtdll.c
-31,40d
-diff -re crt/src/crtexe.c crtsrc/crtexe.c
-322,324d
-35,45d
-diff -re crt/src/crtheap.c crtsrc/crtheap.c
-61c
-    pv = calloc(count, size);
-.
-58,59d
-diff -re crt/src/crtlib.c crtsrc/crtlib.c
-686,693d
-355d
-339a
-                 malloc_shutdown();
-
-.
-298d
-279d
-249,250d
-239d
-226c
-            /*
-             * this used to happen in _mtinit, but we need it before malloc
-             */
-            _init_pointers();       /* initialize global function pointers */
-
-            if ( malloc_init_hard() )   /* initialize heap */
-.
-43a
-extern BOOL malloc_init_hard(void);
-extern void malloc_shutdown(void);
-
-.
-diff -re crt/src/dllcrt0.c crtsrc/dllcrt0.c
-189,190d
-136d
-126d
-111d
-106,108d
-diff -re crt/src/intel/_sample_.def crtsrc/intel/_sample_.def
-1198d
-718,719d
-664a
-    posix_memalign
-.
-638a
-    memalign
-.
-495a
-    malloc_usable_size
-.
-467a
-    jemalloc_stats
-.
-331,336d
-319d
-313,314d
-81d
-9c
-LIBRARY MOZCRT19
-.
-diff -re crt/src/internal.h crtsrc/internal.h
-413a
-#endif
-.
-409c
-#if 0
-.
-diff -re crt/src/makefile crtsrc/makefile
-1873c
--def:$(DEFFILE2_DIR)\sample_p.def
-.
-1841c
- $(DEFFILE2_DIR)\sample_p.def $(CPPSRC_OBJS_DLL:*=dll) \
-.
-1771a
-$(DEFFILE_DIR)\$(RETAIL_LIB_NAME).def : $(DEFFILE_DIR)\_sample_.def
-	copy $** $@
-.
-1290d
-1235,1237d
-760c
-dll_ :: $(OBJROOT) $(OBJCPUDIR) $(OBJDIR_DLL) $(OBJDIR_DLL)\$(PURE_OBJ_DIR) \
-   	$(OBJDIR_DLL)\$(CPP_OBJ_DIR) \
-   	$(RELDIR_CPU) $(PDBDIR_CPU_DLL) $(MAKE_DIRS_DLL)
-.
-340c
-CC_OPTS_BASE=-c -nologo -Zlp8 -W3 -GFy -DWIND32
-.
-213d
-21,24c
-RETAIL_DLL_NAME=MOZCRT19
-RETAIL_LIB_NAME=mozcrt19
-RETAIL_DLLCPP_NAME=MOZCPP19
-RETAIL_LIBCPP_NAME=mozcpp19
-.
-diff -re crt/src/makefile.inc crtsrc/makefile.inc
-1636a
-$(OBJDIR)\unhandld.obj: $(PREOBJDIR)\unhandld.obj
-        copy $(PREOBJDIR)\unhandld.obj $@
-
-.
-623d
-621d
-405d
-344,356c
-        $(OBJDIR)\jemalloc.obj  \
-.
-336,337d
-331,332d
-329d
-325d
-321,322d
-diff -re crt/src/makefile.sub crtsrc/makefile.sub
-66c
-CFLAGS=$(CFLAGS) -O2 -DMOZ_MEMORY=1 -DMOZ_MEMORY_WINDOWS=1
-.
-diff -re crt/src/malloc.h crtsrc/malloc.h
-189a
-#endif
-.
-177a
-
-#if 0
-.
-83a
-#endif
-.
-70a
-#if 0
-.
-diff -re crt/src/mlock.c crtsrc/mlock.c
-274c
-#endif
-.
-262a
-#if 0
-.
-diff -re crt/src/new.cpp crtsrc/new.cpp
-60d
-52,55d
-37,38c
-        break;
-.
-diff -re crt/src/nothrownew.cpp crtsrc/nothrownew.cpp
-38c
-#endif
-.
-31a
-#if 1
-        break;
-#else
-
-.
-diff -re crt/src/sample_p.def crtsrc/sample_p.def
-8c
-LIBRARY mozcpp19
-.
-diff -re crt/src/sample_p.rc crtsrc/sample_p.rc
-41c
-            VALUE "ProductName", "Mozilla Custom C++ Runtime"
-.
-39c
-            VALUE "OriginalFilename", "MOZCPP19.DLL"
-.
-37c
-            VALUE "OriginalFilename", "MOZCPP19D.DLL"
-.
-33c
-            VALUE "InternalName", "MOZCPP19.DLL"
-.
-31c
-            VALUE "InternalName", "MOZCPP19D.DLL"
-.
-27c
-            VALUE "CompanyName", "Mozilla Foundation"
-.
-diff -re crt/src/tidtable.c crtsrc/tidtable.c
-360,361d
deleted file mode 100755
index fc812ea2dbbfe486643cf38a8f6ee68886e24819..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
GIT binary patch
literal 0
Hc$@<O00001
--- a/memory/jemalloc/jemalloc.c
+++ b/memory/jemalloc/jemalloc.c
@@ -198,27 +198,19 @@
 #include <stdlib.h>
 #include <limits.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include <string.h>
 
 #ifdef MOZ_MEMORY_WINDOWS
 
-/* XXXkhuey switch to not patching the CRT for jemalloc all the time */
-/* We use ifndef NEW_STYLE here because when we're build as part of the CRT
-   we don't have access to AC_DEFINEs */
-#ifndef WIN32_NEW_STYLE_JEMALLOC
-#include <cruntime.h>
-#include <internal.h>
-#else
 /* Some defines from the CRT internal headers that we need here. */
 #define _CRT_SPINCOUNT 5000
 #define __crtInitCritSecAndSpinCount InitializeCriticalSectionAndSpinCount
-#endif
 #include <io.h>
 #include <windows.h>
 
 #pragma warning( disable: 4267 4996 4146 )
 
 #define	bool BOOL
 #define	false FALSE
 #define	true TRUE
@@ -5843,40 +5835,64 @@ malloc_shutdown()
 /******************************************************************************/
 /*
  * Begin malloc(3)-compatible functions.
  */
 
 /*
  * Mangle standard interfaces, in order to avoid linking problems.
  */
-#if defined(MOZ_MEMORY_DARWIN) || defined(MOZ_MEMORY_ANDROID) || \
-    defined(WRAP_MALLOC) || defined(WIN32_NEW_STYLE_JEMALLOC)
-inline void sys_free(void* ptr) {return free(ptr);}
-#define	malloc(a)               je_malloc(a)
-#if defined(WIN32_NEW_STYLE_JEMALLOC) || defined(MOZ_MEMORY_DARWIN)
-#define	memalign(a, b)          je_memalign(a, b)
-#endif
-#define	posix_memalign(a, b, c) je_posix_memalign(a, b, c)
-#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	malloc_usable_size(a)   je_malloc_usable_size(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;
+#if defined(MOZ_MEMORY_DARWIN) || defined(MOZ_MEMORY_WINDOWS) || \
+    defined(MOZ_MEMORY_ANDROID)
+
+#ifdef MOZ_MEMORY_ANDROID
+/*
+ * On Android, we use __wrap_* instead of je_* to accomodate with the
+ * linker's --wrap option we use. That option prefixes the function
+ * names it is given with __wrap_.
+ */
+#define wrap(a) __wrap_ ## a
+
+/* Extra wrappers for NSPR alloc functions */
+void *
+__wrap_PR_Malloc(size_t size) __attribute__((alias("__wrap_malloc")));
+void *
+__wrap_PR_Calloc(size_t num, size_t size) __attribute__((alias("__wrap_calloc")));
+void *
+__wrap_PR_Realloc(void *ptr, size_t size) __attribute__((alias("__wrap_realloc")));
+void
+__wrap_PR_Free(void *ptr) __attribute__((alias("__wrap_free")));
+
+#else
+#define wrap(a) je_ ## a
+#endif
+
+#define malloc(a)               wrap(malloc)(a)
+#define memalign(a, b)          wrap(memalign)(a, b)
+#define posix_memalign(a, b, c) wrap(posix_memalign)(a, b, c)
+#define valloc(a)               wrap(valloc)(a)
+#define calloc(a, b)            wrap(calloc)(a, b)
+#define realloc(a, b)           wrap(realloc)(a, b)
+#define free(a)                 wrap(free)(a)
+#define malloc_usable_size(a)   wrap(malloc_usable_size)(a)
+
+void *malloc(size_t size);
+
+char *
+wrap(strndup)(const char *src, size_t len) {
+	char* dst = (char*) 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 );
+
+char *
+wrap(strdup)(const char *src) {
+	size_t len = strlen(src);
+	return wrap(strndup)(src, len);
 }
 #endif
 
 /*
  * We are not able to assume that we can replace the OSX allocator with
  * jemalloc on future unreleased versions of OSX. Despite this, we call
  * jemalloc functions directly from mozalloc. Since it's pretty dangerous to
  * mix the allocators, we need to call the OSX allocators from the functions
@@ -6015,19 +6031,18 @@ RETURN:
 		abort();
 	}
 #endif
 	UTRACE(0, size, ret);
 	return (ret);
 }
 
 #ifdef MOZ_MEMORY_ELF
-extern __typeof(memalign_internal)
-        memalign __attribute__((alias ("memalign_internal"),
-				visibility ("default")));
+extern void *
+memalign(size_t alignment, size_t size) __attribute__((alias ("memalign_internal"), visibility ("default")));
 #endif
 
 int
 posix_memalign(void **memptr, size_t alignment, size_t size)
 {
 	void *result;
 
 	/* Make sure that alignment is a large enough power of 2. */
@@ -6774,33 +6789,31 @@ jemalloc_darwin_init(void)
  * glibc provides the RTLD_DEEPBIND flag for dlopen which can make it possible
  * to inconsistently reference libc's malloc(3)-compatible functions
  * (bug 493541).
  *
  * These definitions interpose hooks in glibc.  The functions are actually
  * 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)
 /*
  * XXX On systems that support RTLD_GROUP or DF_1_GROUP, do their
  * implementations permit similar inconsistencies?  Should STV_SINGLETON
  * visibility be used for interposition where available?
  */
 #  error "Interposing malloc is unsafe on this system without libc malloc hooks."
 #endif
 
-#ifdef WIN32_NEW_STYLE_JEMALLOC
+#ifdef MOZ_MEMORY_WINDOWS
 /*
  * In the new style jemalloc integration jemalloc is built as a separate
  * shared library.  Since we're no longer hooking into the CRT binary,
  * we need to initialize the heap at the first opportunity we get.
  * DLL_PROCESS_ATTACH in DllMain is that opportunity.
  */
 BOOL APIENTRY DllMain(HINSTANCE hModule, 
                       DWORD reason, 
--- a/memory/jemalloc/jemalloc.h
+++ b/memory/jemalloc/jemalloc.h
@@ -45,33 +45,33 @@ extern const char *_malloc_options;
 void	*malloc(size_t size);
 void	*valloc(size_t size);
 void	*calloc(size_t num, size_t size);
 void	*realloc(void *ptr, size_t size);
 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_DARWIN) || defined(MOZ_MEMORY_ANDROID) || \
-    defined(WRAP_MALLOC) || defined(WIN32_NEW_STYLE_JEMALLOC)
+/* Android doesn't have posix_memalign */
+#ifdef MOZ_MEMORY_ANDROID
+int	posix_memalign(void **memptr, size_t alignment, size_t size);
+#endif
+
+#if defined(MOZ_MEMORY_DARWIN) || defined(MOZ_MEMORY_WINDOWS)
 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);
 void *je_memalign(size_t alignment, size_t size);
 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);
-#if defined(MOZ_MEMORY_ANDROID)
-size_t  je_malloc_usable_size(void *ptr);
-#else
 size_t	je_malloc_usable_size(const void *ptr);
 #endif
-#endif
 
 /* Linux has memalign and malloc_usable_size */
 #if !defined(MOZ_MEMORY_LINUX)
 void	*memalign(size_t alignment, size_t size);
 size_t	malloc_usable_size(const void *ptr);
 #endif /* MOZ_MEMORY_LINUX */
 
 void	jemalloc_stats(jemalloc_stats_t *stats);
--- a/memory/mozalloc/Makefile.in
+++ b/memory/mozalloc/Makefile.in
@@ -50,26 +50,16 @@ STL_FLAGS	= -D_HAS_EXCEPTIONS=0
 endif
 
 MODULE		= mozalloc
 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_WITH_JEMALLOC
-CSRCS = ld_malloc_wrappers.c
-ifeq (,$(filter-out Linux,$(OS_TARGET)))
-EXTRA_DSO_LDOPTS += -lpthread
-endif
-endif
 ifeq ($(OS_ARCH),Darwin)
 EXTRA_DSO_LDOPTS += -L$(DIST)/lib -ljemalloc
 endif
 endif
 
 ifeq (,$(filter-out OS2,$(OS_ARCH)))
 # The strndup declaration in string.h is in an ifdef __USE_GNU section
 DEFINES		+= -D_GNU_SOURCE
deleted file mode 100644
--- a/memory/mozalloc/ld_malloc_wrappers.c
+++ /dev/null
@@ -1,140 +0,0 @@
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Mozilla Foundation.
- * Portions created by the Initial Developer are Copyright (C) 2010
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *  Brad Lassey <blassey@mozilla.com>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#include <stddef.h>             // for size_t
-#include <stdlib.h>             // for malloc, free
-#include "mozalloc.h"
-#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);
-}
-
-inline int __wrap_posix_memalign(void **memptr, size_t alignment, size_t size)
-{
-  return moz_posix_memalign(memptr, alignment, size);
-}
--- a/memory/mozalloc/mozalloc.cpp
+++ b/memory/mozalloc/mozalloc.cpp
@@ -71,36 +71,29 @@
 #if defined(__GNUC__) && (__GNUC__ > 2)
 #define LIKELY(x)    (__builtin_expect(!!(x), 1))
 #define UNLIKELY(x)  (__builtin_expect(!!(x), 0))
 #else
 #define LIKELY(x)    (x)
 #define UNLIKELY(x)  (x)
 #endif
 
-#if defined(MOZ_MEMORY_DARWIN) || defined(MOZ_MEMORY_ANDROID) || \
-    defined(WRAP_MALLOC_WITH_JEMALLOC)
+#ifdef MOZ_MEMORY_DARWIN
 #include "jemalloc.h"
 #define malloc(a)               je_malloc(a)
 #define posix_memalign(a, b, c) je_posix_memalign(a, b, c)
 #define valloc(a)               je_valloc(a)
 #define calloc(a, b)            je_calloc(a, b)
-#ifndef MOZ_MEMORY_DARWIN
-   // These functions could be passed a memory region that was not allocated by
-   // jemalloc, so use the system-provided functions, which will in turn call
-   // the jemalloc versions when appropriate.
-#  define realloc(a, b)         je_realloc(a, b)
-#  define free(a)               je_free(a)
-#  define malloc_usable_size(a) je_malloc_usable_size(a)
-#endif
-#ifndef MOZ_MEMORY_ANDROID
 #define memalign(a, b)          je_memalign(a, b)
-#endif
 #define strdup(a)               je_strdup(a)
 #define strndup(a, b)           je_strndup(a, b)
+/* We omit functions which could be passed a memory region that was not
+ * allocated by jemalloc (realloc, free and malloc_usable_size). Instead,
+ * we use the system-provided functions, which will in turn call the
+ * jemalloc versions when appropriate */
 #endif
 
 void
 moz_free(void* ptr)
 {
     free(ptr);
 }
 
--- a/mobile/app/Makefile.in
+++ b/mobile/app/Makefile.in
@@ -43,16 +43,17 @@ VPATH     = @srcdir@
 include $(DEPTH)/config/autoconf.mk
 
 DIRS = profile/extensions
 
 PREF_JS_EXPORTS = $(srcdir)/mobile.js
 DIST_FILES = application.ini
 
 ifndef LIBXUL_SDK
+ifneq (Android,$(OS_TARGET))
 PROGRAM=$(MOZ_APP_NAME)$(BIN_SUFFIX)
 
 CPPSRCS = nsBrowserApp.cpp
 
 LOCAL_INCLUDES += -I$(topsrcdir)/toolkit/xre
 LOCAL_INCLUDES += -I$(topsrcdir)/xpcom/base
 LOCAL_INCLUDES += -I$(topsrcdir)/xpcom/build
 
@@ -70,16 +71,17 @@ ifeq ($(OS_ARCH),WINNT)
 OS_LIBS += $(call EXPAND_LIBNAME,version)
 endif
 
 ifdef _MSC_VER
 # Always enter a Windows program through wmain, whether or not we're
 # a console application.
 WIN32_EXE_LDFLAGS += -ENTRY:wmainCRTStartup
 endif
+endif
 endif #LIBXUL_SDK
 
 # Make sure the standalone glue doesn't try to get libxpcom.so from mobile/app.
 NSDISTMODE = copy
 
 include $(topsrcdir)/config/rules.mk
 
 GRE_MILESTONE = $(shell $(PYTHON) $(topsrcdir)/config/printconfigsetting.py $(LIBXUL_DIST)/bin/platform.ini Build Milestone)
--- a/mobile/installer/package-manifest.in
+++ b/mobile/installer/package-manifest.in
@@ -53,36 +53,36 @@
 @BINPATH@/@DLL_PREFIX@xul@DLL_SUFFIX@
 #endif
 #ifdef XP_MACOSX
 @BINPATH@/@MOZ_CHILD_PROCESS_NAME@.app/
 #else
 @BINPATH@/@MOZ_CHILD_PROCESS_NAME@
 #endif
 #ifdef XP_WIN32
-#ifndef MOZ_MEMORY
+#ifdef MOZ_MEMORY
+@BINPATH@/jemalloc.dll
+#endif
 #if _MSC_VER == 1400
 @BINPATH@/Microsoft.VC80.CRT.manifest
 @BINPATH@/msvcm80.dll
 @BINPATH@/msvcp80.dll
 @BINPATH@/msvcr80.dll
 #elif _MSC_VER == 1500
 @BINPATH@/Microsoft.VC90.CRT.manifest
 @BINPATH@/msvcm90.dll
 @BINPATH@/msvcp90.dll
 @BINPATH@/msvcr90.dll
 #elif _MSC_VER == 1600
 @BINPATH@/msvcp100.dll
 @BINPATH@/msvcr100.dll
 #endif
-#else
-@BINPATH@/mozcrt19.dll
-@BINPATH@/mozcpp19.dll
+
 #endif
-#endif
+
 #ifdef ANDROID
 @BINPATH@/AndroidManifest.xml
 @BINPATH@/resources.arsc
 @BINPATH@/classes.dex
 @BINPATH@/@DLL_PREFIX@mozutils@DLL_SUFFIX@
 @BINPATH@/res/drawable
 @BINPATH@/res/drawable-hdpi
 @BINPATH@/res/layout
--- a/mobile/installer/removed-files.in
+++ b/mobile/installer/removed-files.in
@@ -1,4 +1,8 @@
 README.txt
 #if MOZ_UPDATE_CHANNEL != beta
 extensions/feedback@mobile.mozilla.org.xpi
 #endif
+#ifdef XP_WIN
+  mozcrt19.dll
+  mozcpp19.dll
+#endif
--- a/other-licenses/android/Makefile.in
+++ b/other-licenses/android/Makefile.in
@@ -69,12 +69,16 @@ CSRCS = \
   linker_format.c \
   rt.c \
   $(NULL)
 
 EXPORTS = APKOpen.h
 
 EXTRA_DSO_LDOPTS += $(ZLIB_LIBS)
 
+ifdef MOZ_MEMORY
+SHARED_LIBRARY_LIBS = $(call EXPAND_LIBNAME_PATH,jemalloc,$(DEPTH)/memory/jemalloc)
+endif
+
 WRAP_MALLOC_LIB =
 WRAP_MALLOC_CFLAGS =
 
 include $(topsrcdir)/config/rules.mk
--- a/security/manager/Makefile.in
+++ b/security/manager/Makefile.in
@@ -139,16 +139,18 @@ ABS_DIST := $(call core_abspath,$(DIST))
 ifeq ($(HOST_OS_ARCH),WINNT)
 ifdef CYGDRIVE_MOUNT
 ABS_DIST := $(shell cygpath -w $(ABS_DIST) | sed -e 's|\\|/|g')
 endif
 ifneq (,$(filter mingw%,$(host_os)))
 ABS_DIST := $(shell cd $(DIST) && pwd -W)
 endif
 endif
+# For all variables such as DLLFLAGS, that may contain $(DIST)
+DIST := $(ABS_DIST)
 NSPR_INCLUDE_DIR = $(firstword $(filter -I%,$(NSPR_CFLAGS)))
 ifneq (,$(strip $(NSPR_INCLUDE_DIR)))
 NSPR_INCLUDE_DIR := $(subst -I,,$(subst -I$(DIST),-I$(ABS_DIST),$(NSPR_INCLUDE_DIR)))
 else
 NSPR_INCLUDE_DIR = $(ABS_DIST)/include/nspr
 endif
 NSPR_LIB_DIR = $(firstword $(filter -L%,$(NSPR_LIBS)))
 ifneq (,$(strip $(NSPR_LIB_DIR)))
--- a/toolkit/mozapps/installer/packager.mk
+++ b/toolkit/mozapps/installer/packager.mk
@@ -85,17 +85,30 @@ SDK           = $(SDK_PATH)$(PKG_BASENAM
 # JavaScript Shell packaging
 ifndef LIBXUL_SDK
 JSSHELL_BINS  = \
   $(DIST)/bin/js$(BIN_SUFFIX) \
   $(NULL)
 ifndef MOZ_NATIVE_NSPR
 JSSHELL_BINS += $(DIST)/bin/$(LIB_PREFIX)nspr4$(DLL_SUFFIX)
 ifeq ($(OS_ARCH),WINNT)
-JSSHELL_BINS += $(DIST)/bin/mozcrt19$(DLL_SUFFIX)
+ifdef MOZ_MEMORY
+JSSHELL_BINS += $(DIST)/bin/jemalloc$(DLL_SUFFIX)
+endif
+ifeq ($(_MSC_VER),1400)
+JSSHELL_BINS += $(DIST)/bin/Microsoft.VC80.CRT.manifest
+JSSHELL_BINS += $(DIST)/bin/msvcr80.dll
+endif
+ifeq ($(_MSC_VER),1500)
+JSSHELL_BINS += $(DIST)/bin/Microsoft.VC90.CRT.manifest
+JSSHELL_BINS += $(DIST)/bin/msvcr90.dll
+endif
+ifeq ($(_MSC_VER),1500)
+JSSHELL_BINS += $(DIST)/bin/msvcr100.dll
+endif
 else
 JSSHELL_BINS += \
   $(DIST)/bin/$(LIB_PREFIX)plds4$(DLL_SUFFIX) \
   $(DIST)/bin/$(LIB_PREFIX)plc4$(DLL_SUFFIX) \
   $(NULL)
 endif
 endif # MOZ_NATIVE_NSPR
 MAKE_JSSHELL  = $(ZIP) -9j $(PKG_JSSHELL) $(JSSHELL_BINS)
--- a/xpcom/build/XPCOM.h
+++ b/xpcom/build/XPCOM.h
@@ -135,17 +135,17 @@
 
 // interfaces that include something above
 
 #include "nsILocalFileWin.h"
 #include "nsIObjectInputStream.h"
 #include "nsIObjectOutputStream.h"
 #include "nsIPipe.h"
 
-#ifdef XP_MACOSX
+#ifdef MOZ_WIDGET_COCOA
 #include "nsILocalFileMac.h"
 #include "nsIMacUtils.h"
 #endif
 
 #ifdef XP_OS2
 #include "nsILocalFileOS2.h"
 #endif
 
--- a/xpcom/build/XPCOMModule.inc
+++ b/xpcom/build/XPCOMModule.inc
@@ -69,16 +69,16 @@
     COMPONENT(HASH_PROPERTY_BAG, nsHashPropertyBagConstructor)
 
     COMPONENT(UUID_GENERATOR, nsUUIDGeneratorConstructor)
 
 #if defined(XP_WIN)
     COMPONENT(WINDOWSREGKEY, nsWindowsRegKeyConstructor)
 #endif
 
-#ifdef XP_MACOSX
+#if defined(MOZ_WIDGET_COCOA)
     COMPONENT(MACUTILSIMPL, nsMacUtilsImplConstructor)
 #endif
 
     COMPONENT(SYSTEMINFO, nsSystemInfoConstructor)
     COMPONENT(MEMORY_REPORTER_MANAGER, nsMemoryReporterManagerConstructor)
     COMPONENT(IOUTIL, nsIOUtilConstructor)
     COMPONENT(CYCLE_COLLECTOR_LOGGER, nsCycleCollectorLoggerConstructor)
--- a/xpcom/build/nsXPComInit.cpp
+++ b/xpcom/build/nsXPComInit.cpp
@@ -123,17 +123,17 @@ extern nsresult nsStringInputStreamConst
 #include "nsRecyclingAllocator.h"
 
 #include "SpecialSystemDirectory.h"
 
 #if defined(XP_WIN)
 #include "nsWindowsRegKey.h"
 #endif
 
-#ifdef XP_MACOSX
+#ifdef MOZ_WIDGET_COCOA
 #include "nsMacUtilsImpl.h"
 #endif
 
 #include "nsSystemInfo.h"
 #include "nsMemoryReporterManager.h"
 
 #include <locale.h>
 #include "mozilla/Services.h"
@@ -210,17 +210,17 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsVariant
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsRecyclingAllocatorImpl)
 
 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsHashPropertyBag, Init)
 
 NS_GENERIC_AGGREGATED_CONSTRUCTOR_INIT(nsProperties, Init)
 
 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsUUIDGenerator, Init)
 
-#ifdef XP_MACOSX
+#ifdef MOZ_WIDGET_COCOA
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsMacUtilsImpl)
 #endif
 
 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsSystemInfo, Init)
 
 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsMemoryReporterManager, Init)
 
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsIOUtil)
--- a/xpcom/components/ManifestParser.cpp
+++ b/xpcom/components/ManifestParser.cpp
@@ -39,17 +39,17 @@
 #include "ManifestParser.h"
 
 #include <string.h>
 
 #include "prio.h"
 #include "prprf.h"
 #if defined(XP_WIN)
 #include <windows.h>
-#elif defined(XP_MACOSX)
+#elif defined(MOZ_WIDGET_COCOA)
 #include <CoreServices/CoreServices.h>
 #elif defined(MOZ_WIDGET_GTK2)
 #include <gtk/gtk.h>
 #endif
 
 #ifdef ANDROID
 #include "AndroidBridge.h"
 #endif
@@ -481,17 +481,17 @@ ParseManifestCommon(NSLocationType aType
   nsAutoString osVersion;
 #if defined(XP_WIN)
   OSVERSIONINFO info = { sizeof(OSVERSIONINFO) };
   if (GetVersionEx(&info)) {
     nsTextFormatter::ssprintf(osVersion, NS_LITERAL_STRING("%ld.%ld").get(),
                                          info.dwMajorVersion,
                                          info.dwMinorVersion);
   }
-#elif defined(XP_MACOSX)
+#elif defined(MOZ_WIDGET_COCOA)
   SInt32 majorVersion, minorVersion;
   if ((Gestalt(gestaltSystemVersionMajor, &majorVersion) == noErr) &&
       (Gestalt(gestaltSystemVersionMinor, &minorVersion) == noErr)) {
     nsTextFormatter::ssprintf(osVersion, NS_LITERAL_STRING("%ld.%ld").get(),
                                          majorVersion,
                                          minorVersion);
   }
 #elif defined(MOZ_WIDGET_GTK2)
--- a/xpcom/io/SpecialSystemDirectory.cpp
+++ b/xpcom/io/SpecialSystemDirectory.cpp
@@ -558,17 +558,17 @@ GetSpecialSystemDirectory(SystemDirector
                 }
             }
             nsCString tString = nsDependentCString(tPath);
             if (tString.Find("/", PR_FALSE, 0, -1)) {
                 tString.ReplaceChar('/','\\');
             }
             return NS_NewNativeLocalFile(tString, PR_TRUE, aFile);
         }
-#elif defined(XP_MACOSX)
+#elif defined(MOZ_WIDGET_COCOA)
         {
             return GetOSXFolderType(kUserDomain, kTemporaryFolderType, aFile);
         }
 
 #elif defined(XP_UNIX)
         {
             static const char *tPath = nsnull;
             if (!tPath) {
@@ -892,17 +892,17 @@ GetSpecialSystemDirectory(SystemDirector
         }
 #endif
         default:
             break;
     }
     return NS_ERROR_NOT_AVAILABLE;
 }
 
-#if defined (XP_MACOSX)
+#if defined (MOZ_WIDGET_COCOA)
 nsresult
 GetOSXFolderType(short aDomain, OSType aFolderType, nsILocalFile **localFile)
 {
     OSErr err;
     FSRef fsRef;
     nsresult rv = NS_ERROR_FAILURE;
 
     err = ::FSFindFolder(aDomain, aFolderType, kCreateFolder, &fsRef);
--- a/xpcom/io/SpecialSystemDirectory.h
+++ b/xpcom/io/SpecialSystemDirectory.h
@@ -39,17 +39,17 @@
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef _SPECIALSYSTEMDIRECTORY_H_
 #define _SPECIALSYSTEMDIRECTORY_H_
 
 #include "nscore.h"
 #include "nsILocalFile.h"
 
-#ifdef XP_MACOSX
+#ifdef MOZ_WIDGET_COCOA
 #include <Carbon/Carbon.h>
 #include "nsILocalFileMac.h"
 #include "prenv.h"
 #endif
 
 extern void StartupSpecialSystemDirectory();
 extern void ShutdownSpecialSystemDirectory();
 
@@ -126,14 +126,14 @@ enum SystemDirectories {
   OS2_OS2Directory          =   402,   
   OS2_DesktopDirectory      =   403,   
   OS2_HomeDirectory         =   404
 };
 
 nsresult
 GetSpecialSystemDirectory(SystemDirectories aSystemSystemDirectory,
                           nsILocalFile** aFile);
-#ifdef XP_MACOSX
+#ifdef MOZ_WIDGET_COCOA
 nsresult
 GetOSXFolderType(short aDomain, OSType aFolderType, nsILocalFile **localFile);
 #endif
 
 #endif
--- a/xpcom/io/nsAppFileLocationProvider.cpp
+++ b/xpcom/io/nsAppFileLocationProvider.cpp
@@ -43,17 +43,17 @@
 #include "nsIAtom.h"
 #include "nsILocalFile.h"
 #include "nsString.h"
 #include "nsXPIDLString.h"
 #include "nsISimpleEnumerator.h"
 #include "prenv.h"
 #include "nsCRT.h"
 
-#if defined(XP_MACOSX)
+#if defined(MOZ_WIDGET_COCOA)
 #include <Carbon/Carbon.h>
 #include "nsILocalFileMac.h"
 #elif defined(XP_OS2)
 #define INCL_DOSPROCESS
 #define INCL_DOSMODULEMGR
 #include <os2.h>
 #elif defined(XP_WIN)
 #include <windows.h>
@@ -63,33 +63,33 @@
 #include <stdlib.h>
 #include <sys/param.h>
 #endif
 
 
 // WARNING: These hard coded names need to go away. They need to
 // come from localizable resources
 
-#if defined(XP_MACOSX)
+#if defined(MOZ_WIDGET_COCOA)
 #define APP_REGISTRY_NAME NS_LITERAL_CSTRING("Application Registry")
 #define ESSENTIAL_FILES   NS_LITERAL_CSTRING("Essential Files")
 #elif defined(XP_WIN) || defined(XP_OS2)
 #define APP_REGISTRY_NAME NS_LITERAL_CSTRING("registry.dat")
 #else
 #define APP_REGISTRY_NAME NS_LITERAL_CSTRING("appreg")
 #endif
 
 // define default product directory
 #define DEFAULT_PRODUCT_DIR NS_LITERAL_CSTRING(MOZ_USER_DIR)
 
 // Locally defined keys used by nsAppDirectoryEnumerator
 #define NS_ENV_PLUGINS_DIR          "EnvPlugins"    // env var MOZ_PLUGIN_PATH
 #define NS_USER_PLUGINS_DIR         "UserPlugins"
 
-#ifdef XP_MACOSX
+#ifdef MOZ_WIDGET_COCOA
 #define NS_MACOSX_USER_PLUGIN_DIR   "OSXUserPlugins"
 #define NS_MACOSX_LOCAL_PLUGIN_DIR  "OSXLocalPlugins"
 #define NS_MACOSX_JAVA2_PLUGIN_DIR  "OSXJavaPlugins"
 #elif XP_UNIX
 #define NS_SYSTEM_PLUGINS_DIR       "SysPlugins"
 #endif
 
 #define DEFAULTS_DIR_NAME           NS_LITERAL_CSTRING("defaults")
@@ -123,17 +123,17 @@ nsAppFileLocationProvider::GetFile(const
 {
     nsCOMPtr<nsILocalFile>  localFile;
     nsresult rv = NS_ERROR_FAILURE;
 
     NS_ENSURE_ARG(prop);
     *_retval = nsnull;
     *persistent = PR_TRUE;
 
-#ifdef XP_MACOSX
+#ifdef MOZ_WIDGET_COCOA
     FSRef fileRef;
     nsCOMPtr<nsILocalFileMac> macFile;
 #endif
     
     if (nsCRT::strcmp(prop, NS_APP_APPLICATION_REGISTRY_DIR) == 0)
     {
         rv = GetProductDirectory(getter_AddRefs(localFile));
     }
@@ -189,17 +189,17 @@ nsAppFileLocationProvider::GetFile(const
             rv = localFile->AppendRelativeNativePath(CHROME_DIR_NAME);
     }
     else if (nsCRT::strcmp(prop, NS_APP_PLUGINS_DIR) == 0)
     {
         rv = CloneMozBinDirectory(getter_AddRefs(localFile));
         if (NS_SUCCEEDED(rv))
             rv = localFile->AppendRelativeNativePath(PLUGINS_DIR_NAME);
     }
-#ifdef XP_MACOSX
+#ifdef MOZ_WIDGET_COCOA
     else if (nsCRT::strcmp(prop, NS_MACOSX_USER_PLUGIN_DIR) == 0)
     {
         if (::FSFindFolder(kUserDomain, kInternetPlugInFolderType, false, &fileRef) == noErr) {
             rv = NS_NewLocalFileWithFSRef(&fileRef, PR_TRUE, getter_AddRefs(macFile));
             if (NS_SUCCEEDED(rv))
                 localFile = macFile;
         }
     }
@@ -319,17 +319,17 @@ NS_METHOD nsAppFileLocationProvider::Clo
 NS_METHOD nsAppFileLocationProvider::GetProductDirectory(nsILocalFile **aLocalFile, PRBool aLocal)
 {
     NS_ENSURE_ARG_POINTER(aLocalFile);
 
     nsresult rv;
     PRBool exists;
     nsCOMPtr<nsILocalFile> localDir;
 
-#if defined(XP_MACOSX)
+#if defined(MOZ_WIDGET_COCOA)
     FSRef fsRef;
     OSType folderType = aLocal ? (OSType) kCachedDataFolderType : (OSType) kDomainLibraryFolderType;
     OSErr err = ::FSFindFolder(kUserDomain, folderType, kCreateFolder, &fsRef);
     if (err) return NS_ERROR_FAILURE;
     NS_NewLocalFile(EmptyString(), PR_TRUE, getter_AddRefs(localDir));
     if (!localDir) return NS_ERROR_FAILURE;
     nsCOMPtr<nsILocalFileMac> localDirMac(do_QueryInterface(localDir));
     rv = localDirMac->InitWithFSRef(&fsRef);
@@ -390,17 +390,17 @@ NS_METHOD nsAppFileLocationProvider::Get
     NS_ENSURE_ARG_POINTER(aLocalFile);
 
     nsresult rv;
     nsCOMPtr<nsILocalFile> localDir;
 
     rv = GetProductDirectory(getter_AddRefs(localDir), aLocal);
     if (NS_FAILED(rv)) return rv;
 
-#if defined(XP_MACOSX) || defined(XP_OS2) || defined(XP_WIN)
+#if defined(MOZ_WIDGET_COCOA) || defined(XP_OS2) || defined(XP_WIN)
     // These 3 platforms share this part of the path - do them as one
     rv = localDir->AppendRelativeNativePath(NS_LITERAL_CSTRING("Profiles"));
     if (NS_FAILED(rv)) return rv;
 
     PRBool exists;
     rv = localDir->Exists(&exists);
     if (NS_SUCCEEDED(rv) && !exists)
         rv = localDir->Create(nsIFile::DIRECTORY_TYPE, 0775);
@@ -547,17 +547,17 @@ NS_IMETHODIMP
 nsAppFileLocationProvider::GetFiles(const char *prop, nsISimpleEnumerator **_retval)
 {
     NS_ENSURE_ARG_POINTER(_retval);
     *_retval = nsnull;
     nsresult rv = NS_ERROR_FAILURE;
     
     if (!nsCRT::strcmp(prop, NS_APP_PLUGINS_DIR_LIST))
     {
-#ifdef XP_MACOSX
+#ifdef MOZ_WIDGET_COCOA
         // As of Java for Mac OS X 10.5 Update 10, Apple has (in effect) deprecated Java Plugin2 on
         // on OS X 10.5, and removed the soft link to it from /Library/Internet Plug-Ins/.  Java
         // Plugin2 is still present and usable, but there are no longer any links to it in the
         // "normal" locations.  So we won't be able to find it unless we look in the "non-normal"
         // location where it actually is.  Safari can use the WebKit-specific JavaPluginCocoa.bundle,
         // which (of course) is still fully supported on OS X 10.5.  But we have no alternative to
         // using Java Plugin2.  For more information see bug 668639.
         static const char* keys[] = { NS_APP_PLUGINS_DIR, NS_MACOSX_USER_PLUGIN_DIR,
--- a/xpcom/io/nsDirectoryService.cpp
+++ b/xpcom/io/nsDirectoryService.cpp
@@ -56,34 +56,34 @@
 #include <shlobj.h>
 #include <stdlib.h>
 #include <stdio.h>
 #elif defined(XP_UNIX)
 #include <unistd.h>
 #include <stdlib.h>
 #include <sys/param.h>
 #include "prenv.h"
-#ifdef XP_MACOSX
+#ifdef MOZ_WIDGET_COCOA
 #include <CoreServices/CoreServices.h>
 #include <Carbon/Carbon.h>
 #endif
 #elif defined(XP_OS2)
 #define MAX_PATH _MAX_PATH
 #endif
 
 #include "SpecialSystemDirectory.h"
 #include "nsAppFileLocationProvider.h"
 
 #define COMPONENT_DIRECTORY     NS_LITERAL_CSTRING("components")
 
 // define home directory
 // For Windows platform, We are choosing Appdata folder as HOME
 #if defined (XP_WIN)
 #define HOME_DIR NS_WIN_APPDATA_DIR
-#elif defined (XP_MACOSX)
+#elif defined (MOZ_WIDGET_COCOA)
 #define HOME_DIR NS_OSX_HOME_DIR
 #elif defined (XP_UNIX)
 #define HOME_DIR NS_UNIX_HOME_DIR
 #elif defined (XP_OS2)
 #define HOME_DIR NS_OS2_HOME_DIR
 #endif
 
 //----------------------------------------------------------------------------------------
@@ -134,17 +134,17 @@ nsDirectoryService::GetCurrentProcessDir
         if (lastSlash)
             *(lastSlash + 1) = L'\0';
 
         localFile->InitWithPath(nsDependentString(buf));
         *aFile = localFile;
         return NS_OK;
     }
 
-#elif defined(XP_MACOSX)
+#elif defined(MOZ_WIDGET_COCOA)
     // Works even if we're not bundled.
     CFBundleRef appBundle = CFBundleGetMainBundle();
     if (appBundle != nsnull)
     {
         CFURLRef bundleURL = CFBundleCopyExecutableURL(appBundle);
         if (bundleURL != nsnull)
         {
             CFURLRef parentURL = CFURLCreateCopyDeletingLastPathComponent(kCFAllocatorDefault, bundleURL);
@@ -610,17 +610,17 @@ nsDirectoryService::GetFile(const char *
     {
         rv = GetSpecialSystemDirectory(OS_CurrentProcessDirectory, getter_AddRefs(localFile)); 
     }
     else if (inAtom == nsDirectoryService::sOS_CurrentWorkingDirectory)
     {
         rv = GetSpecialSystemDirectory(OS_CurrentWorkingDirectory, getter_AddRefs(localFile)); 
     }
        
-#if defined(XP_MACOSX)
+#if defined(MOZ_WIDGET_COCOA)
     else if (inAtom == nsDirectoryService::sDirectory)
     {
         rv = GetOSXFolderType(kClassicDomain, kSystemFolderType, getter_AddRefs(localFile));
     }
     else if (inAtom == nsDirectoryService::sTrashDirectory)
     {
         rv = GetOSXFolderType(kClassicDomain, kTrashFolderType, getter_AddRefs(localFile));
     }
--- a/xpcom/io/nsDirectoryServiceAtomList.h
+++ b/xpcom/io/nsDirectoryServiceAtomList.h
@@ -40,17 +40,17 @@ DIR_ATOM(sCurrentProcess, NS_XPCOM_CURRE
 DIR_ATOM(sGRE_Directory, NS_GRE_DIR)
 DIR_ATOM(sOS_DriveDirectory, NS_OS_DRIVE_DIR)
 DIR_ATOM(sOS_TemporaryDirectory, NS_OS_TEMP_DIR)
 DIR_ATOM(sOS_CurrentProcessDirectory, NS_OS_CURRENT_PROCESS_DIR)
 DIR_ATOM(sOS_CurrentWorkingDirectory, NS_OS_CURRENT_WORKING_DIR)
 DIR_ATOM(sOS_HomeDirectory, NS_OS_HOME_DIR)
 DIR_ATOM(sOS_DesktopDirectory, NS_OS_DESKTOP_DIR)
 DIR_ATOM(sInitCurrentProcess_dummy, NS_XPCOM_INIT_CURRENT_PROCESS_DIR)
-#if defined (XP_MACOSX)
+#if defined (MOZ_WIDGET_COCOA)
 DIR_ATOM(sDirectory, NS_OS_SYSTEM_DIR)
 DIR_ATOM(sTrashDirectory, NS_MAC_TRASH_DIR)
 DIR_ATOM(sStartupDirectory, NS_MAC_STARTUP_DIR)
 DIR_ATOM(sShutdownDirectory, NS_MAC_SHUTDOWN_DIR)
 DIR_ATOM(sAppleMenuDirectory, NS_MAC_APPLE_MENU_DIR)
 DIR_ATOM(sControlPanelDirectory, NS_MAC_CONTROL_PANELS_DIR)
 DIR_ATOM(sExtensionDirectory, NS_MAC_EXTENSIONS_DIR)
 DIR_ATOM(sFontsDirectory, NS_MAC_FONTS_DIR)
--- a/xpcom/io/nsDirectoryServiceDefs.h
+++ b/xpcom/io/nsDirectoryServiceDefs.h
@@ -81,21 +81,21 @@
 /* Property will return the current location of the the GRE directory.  
  * If no GRE is used, this propery will behave like 
  * NS_XPCOM_CURRENT_PROCESS_DIR.
  */
 #define NS_GRE_DIR                              "GreD"
 
 /* Platform Specific Locations */
 
-#if !defined (XP_UNIX) || defined(XP_MACOSX)
+#if !defined (XP_UNIX) || defined(MOZ_WIDGET_COCOA)
     #define NS_OS_SYSTEM_DIR                    "SysD"
 #endif
 
-#if defined (XP_MACOSX)
+#if defined (MOZ_WIDGET_COCOA)
     #define NS_MAC_DESKTOP_DIR                  NS_OS_DESKTOP_DIR
     #define NS_MAC_TRASH_DIR                    "Trsh"
     #define NS_MAC_STARTUP_DIR                  "Strt"
     #define NS_MAC_SHUTDOWN_DIR                 "Shdwn"
     #define NS_MAC_APPLE_MENU_DIR               "ApplMenu"
     #define NS_MAC_CONTROL_PANELS_DIR           "CntlPnl"
     #define NS_MAC_EXTENSIONS_DIR               "Exts"
     #define NS_MAC_FONTS_DIR                    "Fnts"
--- a/xpcom/io/nsLocalFileCommon.cpp
+++ b/xpcom/io/nsLocalFileCommon.cpp
@@ -58,17 +58,17 @@ void NS_StartupLocalFile()
     nsLocalFile::GlobalInit();
 }
 
 void NS_ShutdownLocalFile()
 {
     nsLocalFile::GlobalShutdown();
 }
 
-#if !defined(XP_MACOSX) && !defined(XP_WIN)
+#if !defined(MOZ_WIDGET_COCOA) && !defined(XP_WIN)
 NS_IMETHODIMP
 nsLocalFile::InitWithFile(nsILocalFile *aFile)
 {
     NS_ENSURE_ARG(aFile);
     
     nsCAutoString path;
     aFile->GetNativePath(path);
     if (path.IsEmpty())