bug 481579 - changes to shunt and tools for jemalloc on windows ce r=dougt
--- a/allmakefiles.sh
+++ b/allmakefiles.sh
@@ -65,16 +65,17 @@ config/mkdepend/Makefile
config/doxygen.cfg
config/tests/src-simple/Makefile
probes/Makefile
extensions/Makefile
build/wince/tools/Makefile
build/wince/shunt/Makefile
build/wince/shunt/include/windows.h
build/wince/shunt/include/ymath.h
+build/wince/shunt/include/stdlib.h
build/wince/shunt/include/sys/Makefile
"
if [ "$MOZ_MEMORY" ]; then
add_makefiles "
memory/jemalloc/Makefile
"
fi
--- a/build/Makefile.in
+++ b/build/Makefile.in
@@ -49,18 +49,23 @@ ifeq (,$(filter WINCE WINNT OS2,$(OS_ARC
DIRS = unix
endif
ifeq (WINNT,$(OS_ARCH))
DIRS = win32
endif
ifdef WINCE
+# We need jemalloc built before the shunt
+ifdef MOZ_MEMORY
+DIRS += wince/tools $(DEPTH)/memory/jemalloc wince/shunt
+else
DIRS += wince/tools wince/shunt
endif
+endif
DIRS += pgo
include $(topsrcdir)/config/rules.mk
# we install to _leaktest/
TARGET_DEPTH = ..
include $(srcdir)/automation-build.mk
--- a/build/wince/shunt/Makefile.in
+++ b/build/wince/shunt/Makefile.in
@@ -48,28 +48,35 @@ export NO_SHUNT = 1
include $(DEPTH)/config/autoconf.mk
MODULE = mozce_shunt
LIBRARY_NAME = mozce_shunt
FORCE_SHARED_LIB= 1
DIST_INSTALL = 1
-
EXPORTS = include/windows.h \
include/ymath.h \
+ include/stdlib.h \
include/direct.h \
include/errno.h \
include/fcntl.h \
include/io.h \
include/mbstring.h \
include/mozce_shunt.h \
include/process.h \
include/signal.h \
$(NULL)
DIRS += include/sys
+ifdef MOZ_MEMORY
+REQUIRES = jemalloc
+JEMALLOC_LIB = $(DIST)/lib/jemalloc.lib
+CFLAGS += -DMOZ_MEMORY
+CXXFLAGS += -DMOZ_MEMORY
+endif
+
CPPSRCS = map.cpp
DEFINES += -DMOZCE_SHUNT_EXPORTS
include $(topsrcdir)/config/rules.mk
--- a/build/wince/shunt/include/mozce_shunt.h
+++ b/build/wince/shunt/include/mozce_shunt.h
@@ -35,38 +35,108 @@
*
* ***** END LICENSE BLOCK ***** */
#ifndef MOZCE_SHUNT_H
#define MOZCE_SHUNT_H
#ifdef MOZCE_SHUNT_EXPORTS
+#define _CRTIMP __declspec(dllexport)
#define MOZCE_SHUNT_API __declspec(dllexport)
+#define MOZCE_SHUNT_IMPORT_API __declspec(dllexport)
#else
-#define MOZCE_SHUNT_API __declspec(dllimport)
+#define MOZCE_SHUNT_API
+#define MOZCE_SHUNT_IMPORT_API __declspec(dllimport)
+#endif
+
+#ifdef MOZ_MEMORY
+#ifdef __cplusplus
+
+
+#define _NEW_
+void * operator new(size_t _Size);
+void operator delete(void * ptr);
+void *operator new[](size_t size);
+void operator delete[](void *ptr);
+
+extern "C" {
#endif
+
+extern void* moz_malloc(size_t);
+extern void* moz_valloc(size_t);
+extern void* moz_calloc(size_t, size_t);
+extern void* moz_realloc(void*, unsigned int);
+extern void moz_free(void*);
+MOZCE_SHUNT_API void* __cdecl malloc(size_t);
+MOZCE_SHUNT_API void* __cdecl valloc(size_t);
+MOZCE_SHUNT_API void* __cdecl calloc(size_t, size_t);
+MOZCE_SHUNT_API void* __cdecl realloc(void*, unsigned int);
+MOZCE_SHUNT_API void __cdecl free(void*);
+
+
+MOZCE_SHUNT_API char*
+mozce_strdup(const char*);
+
+MOZCE_SHUNT_API unsigned short*
+mozce_wcsdup(const unsigned short* );
+
+MOZCE_SHUNT_API char*
+mozce_strndup(const char *, unsigned int);
+
+MOZCE_SHUNT_API unsigned short*
+mozce_wcsndup(const unsigned short*, unsigned int);
+
+#ifdef __cplusplus
+} //extern "C"
+#endif
+
+
+#undef _strdup
+#undef strdup
+#undef _strndup
+#undef strndup
+#undef _wcsdup
+#undef wcsdup
+#undef _wcsndup
+#undef wcsndup
+
+
+
+#define _strdup mozce_strdup
+#define _strndup mozce_strndup
+
+#define _wcsdup mozce_wcsdup
+#define _wcsndup mozce_wcsndup
+
+#endif
+
#define strdup _strdup
+#define strndup _strndup
+#define wcsdup _wcsdup
+#define wcsndup _wcsndup
+
+
#define strcmpi _stricmp
#define stricmp _stricmp
#define wgetcwd _wgetcwd
#define vsnprintf _vsnprintf
#define SHGetSpecialFolderPathW SHGetSpecialFolderPath
#define SHGetPathFromIDListW SHGetPathFromIDList
#define FONTENUMPROCW FONTENUMPROC
#ifdef __cplusplus
extern "C" {
#endif
/* errno and family */
-extern MOZCE_SHUNT_API int errno;
-MOZCE_SHUNT_API char* strerror(int);
+extern MOZCE_SHUNT_IMPORT_API int errno;
+MOZCE_SHUNT_IMPORT_API char* strerror(int);
/* abort */
MOZCE_SHUNT_API void abort(void);
/* Environment stuff */
MOZCE_SHUNT_API char* getenv(const char* inName);
MOZCE_SHUNT_API int putenv(const char *a);
MOZCE_SHUNT_API char SetEnvironmentVariableW(const unsigned short * name, const unsigned short * value );
new file mode 100644
--- /dev/null
+++ b/build/wince/shunt/include/stdlib.h.in
@@ -0,0 +1,76 @@
+/* ***** 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 MOZCE Lib.
+ *
+ * The Initial Developer of the Original Code is Brad Lassey <blassey@mozilla.com>.
+
+ * Portions created by the Initial Developer are Copyright (C) 2009
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * 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 ***** */
+
+
+#ifndef MOZCE_STDLIB_H
+#define MOZCE_STDLIB_H
+#ifdef MOZ_MEMORY
+
+#undef strdup
+#undef _strdup
+#undef wcsdup
+#undef _wcsdup
+#undef strndup
+#undef _strndup
+#undef wcsndup
+#undef _wcsndup
+
+#endif
+
+#include "@WINCE_SDK_DIR@/Include/Armv4i/stdlib.h"
+
+#ifdef MOZ_MEMORY
+#undef strdup
+#undef _strdup
+#undef wcsdup
+#undef _wcsdup
+#undef strndup
+#undef _strndup
+#undef wcsndup
+#undef _wcsndup
+
+#define _strdup mozce_strdup
+#define strdup _strdup
+#define _strndup mozce_strndup
+#define strndup _strndup
+#define _wcsdup mozce_wcsdup
+#define wcsdup _wcsdup
+#define _wcsndup mozce_wcsndup
+#define wcsndup _wcsndup
+
+#endif
+
+#endif
--- a/build/wince/shunt/map.cpp
+++ b/build/wince/shunt/map.cpp
@@ -31,21 +31,88 @@
* 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 "stdlib.h"
+
+#include "include/mozce_shunt.h"
+#include "time_conversions.h"
+#include <stdlib.h>
#include "Windows.h"
-
-#include "mozce_shunt.h"
-#include "time_conversions.h"
+
+#ifdef MOZ_MEMORY
+void * operator new(size_t _Size)
+{
+ void *p = moz_malloc(_Size);
+ return (p);
+}
+
+void operator delete(void * ptr)
+{
+ moz_free(ptr);
+}
+void *operator new[](size_t size)
+{
+ void* p = moz_malloc(size);
+ return (p);
+}
+void operator delete[](void *ptr)
+{
+ moz_free(ptr);
+}
+
+MOZCE_SHUNT_API char*
+mozce_strndup( const char *src, size_t len ) {
+ char* dst = (char*)moz_malloc(len + 1);
+ if(dst)
+ strncpy(dst, src, len + 1);
+ return dst;
+}
+
+
+MOZCE_SHUNT_API char*
+mozce_strdup(const char *src ) {
+ size_t len = strlen(src);
+ return mozce_strndup(src, len );
+}
+
+MOZCE_SHUNT_API unsigned short*
+mozce_wcsndup( const unsigned short *src, size_t len ) {
+ wchar_t* dst = (wchar_t*)moz_malloc(sizeof(wchar_t) * (len + 1));
+ if(dst)
+ wcsncpy(dst, src, len + 1);
+ return dst;
+}
+
+MOZCE_SHUNT_API unsigned short*
+mozce_wcsdup( const unsigned short *src ) {
+ size_t len = wcslen(src);
+ return mozce_wcsndup(src, len);
+}
+MOZCE_SHUNT_API void* __cdecl malloc(size_t size) {
+ return moz_malloc(size);
+}
+MOZCE_SHUNT_API void* __cdecl valloc(size_t size) {
+ return moz_valloc(size);
+}
+MOZCE_SHUNT_API void* __cdecl calloc(size_t size, size_t num) {
+ return moz_calloc(size, num);
+}
+MOZCE_SHUNT_API void* __cdecl realloc(void* ptr, size_t size) {
+ return moz_realloc(ptr, size);
+}
+MOZCE_SHUNT_API void __cdecl free(void* ptr) {
+ return moz_free(ptr);
+}
+
+#endif
////////////////////////////////////////////////////////
// Environment Variable Stuff
////////////////////////////////////////////////////////
typedef struct env_entry env_entry;
#define ENV_IS_STATIC 0
@@ -319,22 +386,22 @@ MOZCE_SHUNT_API unsigned int ExpandEnvir
////////////////////////////////////////////////////////
// errno
////////////////////////////////////////////////////////
-MOZCE_SHUNT_API char* strerror(int inErrno)
+MOZCE_SHUNT_IMPORT_API char* strerror(int inErrno)
{
return "Unknown Error";
}
-MOZCE_SHUNT_API int errno = 0;
+MOZCE_SHUNT_IMPORT_API int errno = 0;
////////////////////////////////////////////////////////
// File System Stuff
////////////////////////////////////////////////////////
MOZCE_SHUNT_API unsigned short * _wgetcwd(unsigned short * dir, unsigned long size)
{
--- a/build/wince/tools/Makefile
+++ b/build/wince/tools/Makefile
@@ -84,16 +84,17 @@ ifeq ($(SDKDIR),)
else
CFLAGS += -DWIN_SDK_PATH='"$(subst \,\\,$(SDKDIR))"'
endif
endif
ifdef VPATH
CFLAGS += -DSHUNT_INC='"$(OBJDIR)/dist/include/mozce_shunt"'
CFLAGS += -DSHUNT_LIB='"$(OBJDIR)/dist/lib"'
+CFLAGS += -DJEMALLOC_LIB='"$(OBJDIR)/dist/lib/jemalloc.lib"'
endif
CFLAGS += -DEBUG -Zi
SDK_TOOLS = $(MOZCE_TOOLS_BIN_DIR)/arm-wince-as.exe \
$(MOZCE_TOOLS_BIN_DIR)/arm-wince-gcc.exe \
$(MOZCE_TOOLS_BIN_DIR)/arm-wince-lib.exe \
$(MOZCE_TOOLS_BIN_DIR)/arm-wince-link.exe \
$(MOZCE_TOOLS_BIN_DIR)/arm-wince-res.exe
--- a/build/wince/tools/Makefile.in
+++ b/build/wince/tools/Makefile.in
@@ -42,13 +42,17 @@ VPATH = @srcdir@
TOPSRCDIR = $(topsrcdir)
OBJDIR = $(shell cd $(DEPTH); pwd -W)
CFLAGS += -DHAVE_SHUNT
MOZCE_NOT_CONFIGURE=1
include $(DEPTH)/config/autoconf.mk
+ifdef MOZ_MEMORY
+CFLAGS += -DMOZ_MEMORY
+endif
+
include $(topsrcdir)/build/wince/tools/Makefile
export::
tools::
\ No newline at end of file
--- a/build/wince/tools/arm-wince-gcc.c
+++ b/build/wince/tools/arm-wince-gcc.c
@@ -15,32 +15,33 @@ main(int argc, char **argv)
args[i++] = CL_PATH;
#ifdef HAVE_SHUNT // simple test to see if we're in configure or not
if(!getenv("NO_SHUNT")) {
args[i++] = "/I\"" SHUNT_INC "\"";
args[i++] = "/FI\"mozce_shunt.h\"";
}
#endif
-
+#ifdef MOZ_MEMORY
+ args[i++] = "/DMOZ_MEMORY";
+#endif
args[i++] = "/DMOZCE_STATIC_BUILD";
args[i++] = "/DUNICODE";
args[i++] = "/D_UNICODE_";
args[i++] = "/DARM";
args[i++] = "/D_ARM_";
args[i++] = "/DWINCE";
args[i++] = "/D_WIN32_WCE=0x502";
args[i++] = "/DUNDER_CE";
// args[i++] = "/DWIN32_PLATFORM_WFSP";
args[i++] = "/DWIN32_PLATFORM_PSPC";
// args[i++] = "/DPOCKETPC2003_UI_MODEL";
args[i++] = "/D_WINDOWS";
args[i++] = "/DNO_ERRNO";
- args[i++] = "/Zc:wchar_t-"; //
args[i++] = "/GS-"; // disable security checks
args[i++] = "/GR-"; // disable C++ RTTI
startOfArgvs = i;
i += argpath_conv(&argv[1], &args[i]);
// if /Fe is passed, then link
@@ -73,29 +74,28 @@ main(int argc, char **argv)
args[i++] = "/link";
args[i++] = "/ENTRY:main";
args[i++] = "/SUBSYSTEM:WINDOWSCE,5.02";
args[i++] = "/LIBPATH:\"" WCE_LIB "\"";
args[i++] = "/LIBPATH:\"" WCE_CRT "\"";
+ args[i++] = "/NODEFAULTLIB";
+#ifdef MOZ_MEMORY
+ args[i++] = JEMALLOC_LIB;
+#endif
#ifdef HAVE_SHUNT // simple test to see if we're in configure or not
if(!getenv("NO_SHUNT")) {
args[i++] = "/LIBPATH:\"" SHUNT_LIB "\"";
args[i++] = "mozce_shunt.lib";
}
#endif
args[i++] = "winsock.lib";
args[i++] = "corelibc.lib";
args[i++] = "coredll.lib";
-
-
- //args[i++] = "/NODEFAULTLIB:LIBC";
- args[i++] = "/NODEFAULTLIB:OLDNAMES";
-
}
args[i] = NULL;
// dumpargs(args);
return run(args);
}
--- a/build/wince/tools/arm-wince-link.c
+++ b/build/wince/tools/arm-wince-link.c
@@ -8,33 +8,33 @@ main(int argc, char **argv)
int i = 0;
int j = 0;
int k = 0;
int s = 0;
args[i++] = LINK_PATH;
args[i++] = "/LIBPATH:\"" WCE_LIB "\"";
args[i++] = "/LIBPATH:\"" WCE_CRT "\"";
+ args[i++] = "/NODEFAULTLIB";
+#ifdef MOZ_MEMORY
+ args[i++] = JEMALLOC_LIB;
+#endif
#ifdef HAVE_SHUNT // simple test to see if we're in configure or not
if(getenv("NO_SHUNT") == NULL) {
args[i++] = "/LIBPATH:\"" SHUNT_LIB "\"";
args[i++] = "mozce_shunt.lib";
}
#endif
args[i++] = "corelibc.lib";
args[i++] = "coredll.lib";
args[i++] = "ceshell.lib";
args[i++] = "mmtimer.lib";
- args[i++] = "/NODEFAULTLIB:LIBC";
- args[i++] = "/NODEFAULTLIB:OLDNAMES";
- args[i++] = "/NODEFAULTLIB:MSVCRT";
-
// if -DLL is not passed, then change the entry to 'main'
while(argv[j]) {
if (strncmp(argv[j], "-DLL", 4) == 0 ||
strncmp(argv[j], "/DLL", 4) == 0) {
k = 1;
}
if (strncmp(argv[j], "-entry", 6) == 0 ||