Bug 826779 - Get DMD to build on Windows; r=bbondy
authorEhsan Akhgari <ehsan@mozilla.com>
Fri, 04 Jan 2013 13:57:27 -0500
changeset 117673 2c7233ca6ffd4c120cfde4c52bcaa1282fc4987b
parent 117672 a1f3bc9f0bb949f63ab5d0d48779d535f067a64e
child 117674 e9e8cb0ae4929a6f334b6d136b37d8d27d4f30f4
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersbbondy
bugs826779
milestone20.0a1
Bug 826779 - Get DMD to build on Windows; r=bbondy
memory/replace/dmd/DMD.cpp
memory/replace/dmd/Makefile.in
--- a/memory/replace/dmd/DMD.cpp
+++ b/memory/replace/dmd/DMD.cpp
@@ -10,20 +10,18 @@
 #include <errno.h>
 #include <limits.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
 #ifdef XP_WIN
-#error "Windows not supported yet, sorry."
-// XXX: This will be needed when Windows is supported (bug 819839).
-//#include <process.h>
-//#define getpid _getpid
+#include <windows.h>
+#include <process.h>
 #else
 #include <unistd.h>
 #endif
 
 #ifdef ANDROID
 #include <android/log.h>
 #endif
 
@@ -37,17 +35,31 @@
 #include "mozilla/HashFunctions.h"
 #include "mozilla/Likely.h"
 
 // MOZ_REPLACE_ONLY_MEMALIGN saves us from having to define
 // replace_{posix_memalign,aligned_alloc,valloc}.  It requires defining
 // PAGE_SIZE.  Nb: sysconf() is expensive, but it's only used for (the obsolete
 // and rarely used) valloc.
 #define MOZ_REPLACE_ONLY_MEMALIGN 1
+#ifdef XP_WIN
+#define PAGE_SIZE GetPageSize()
+static long GetPageSize()
+{
+  SYSTEM_INFO si;
+  GetSystemInfo(&si);
+  return si.dwPageSize;
+}
+static void* valloc(size_t size)
+{
+  return VirtualAlloc(NULL, size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
+}
+#else
 #define PAGE_SIZE sysconf(_SC_PAGESIZE)
+#endif
 #include "replace_malloc.h"
 #undef MOZ_REPLACE_ONLY_MEMALIGN
 #undef PAGE_SIZE
 
 namespace mozilla {
 namespace dmd {
 
 //---------------------------------------------------------------------------
@@ -270,18 +282,16 @@ static const size_t kNoSize = size_t(-1)
 
 //---------------------------------------------------------------------------
 // The global lock
 //---------------------------------------------------------------------------
 
 // MutexBase implements the platform-specific parts of a mutex.
 #ifdef XP_WIN
 
-#include <windows.h>
-
 class MutexBase
 {
   CRITICAL_SECTION mCS;
 
   DISALLOW_COPY_AND_ASSIGN(MutexBase);
 
 public:
   MutexBase()
@@ -402,19 +412,19 @@ public:
 
 //---------------------------------------------------------------------------
 // Thread-local storage and blocking of intercepts
 //---------------------------------------------------------------------------
 
 #ifdef XP_WIN
 
 #define DMD_TLS_INDEX_TYPE              DWORD
-#define DMD_CREATE_TLS_INDEX(i_)        PR_BEGIN_MACRO                        \
+#define DMD_CREATE_TLS_INDEX(i_)        do {                                  \
                                           (i_) = TlsAlloc();                  \
-                                        PR_END_MACRO
+                                        } while (0)
 #define DMD_DESTROY_TLS_INDEX(i_)       TlsFree((i_))
 #define DMD_GET_TLS_DATA(i_)            TlsGetValue((i_))
 #define DMD_SET_TLS_DATA(i_, v_)        TlsSetValue((i_), (v_))
 
 #else
 
 #include <pthread.h>
 
--- a/memory/replace/dmd/Makefile.in
+++ b/memory/replace/dmd/Makefile.in
@@ -30,10 +30,14 @@ CPPSRCS 	+= HashFunctions.cpp
 EXPORTS 	= DMD.h
 
 # Disable mozglue.
 WRAP_LDFLAGS 	=
 MOZ_GLUE_LDFLAGS=
 
 STL_FLAGS 	=
 
+ifeq ($(OS_ARCH),WINNT)
+OS_LIBS         += $(call EXPAND_LIBNAME,dbghelp)
+endif
+
 include $(topsrcdir)/config/config.mk
 include $(topsrcdir)/config/rules.mk