Really "fix" CTI mode on windows 2k3.
authoroliver@apple.com <oliver@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 23 Oct 2008 03:36:04 +0000 (03:36 +0000)
committeroliver@apple.com <oliver@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 23 Oct 2008 03:36:04 +0000 (03:36 +0000)
Reviewed my Maciej Stachowiak

This adds new methods fastMallocExecutable and fastFreeExecutable
to wrap allocation for cti code.  This still just makes fastMalloc
return executable memory all the time, which will be fixed in a
later patch.

However in windows debug builds all executable allocations will be
allocated on separate executable pages, which should resolve any
remaining 2k3 issues.  Conveniently the 2k3 bot will now also fail
if there are any fastFree vs. fastFreeExecutable errors.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@37804 268f45cc-cd09-0410-ab3c-d52691b4dbfc

JavaScriptCore/ChangeLog
JavaScriptCore/VM/CodeBlock.cpp
JavaScriptCore/kjs/regexp.cpp
JavaScriptCore/masm/X86Assembler.h
JavaScriptCore/wtf/FastMalloc.cpp
JavaScriptCore/wtf/FastMalloc.h

index 3fbfd0c..a8344b2 100644 (file)
@@ -1,3 +1,33 @@
+2008-10-22  Oliver Hunt  <oliver@apple.com>
+
+        Reviewed by Maciej Stachowiak.
+
+        Really "fix" CTI mode on windows 2k3.
+
+        This adds new methods fastMallocExecutable and fastFreeExecutable
+        to wrap allocation for cti code.  This still just makes fastMalloc
+        return executable memory all the time, which will be fixed in a
+        later patch.
+
+        However in windows debug builds all executable allocations will be
+        allocated on separate executable pages, which should resolve any
+        remaining 2k3 issues.  Conveniently the 2k3 bot will now also fail
+        if there are any fastFree vs. fastFreeExecutable errors.
+
+        * ChangeLog:
+        * VM/CodeBlock.cpp:
+        (JSC::CodeBlock::~CodeBlock):
+        * kjs/regexp.cpp:
+        (JSC::RegExp::~RegExp):
+        * masm/X86Assembler.h:
+        (JSC::JITCodeBuffer::copy):
+        * wtf/FastMalloc.cpp:
+        (WTF::fastMallocExecutable):
+        (WTF::fastFreeExecutable):
+        (WTF::TCMallocStats::fastMallocExecutable):
+        (WTF::TCMallocStats::fastFreeExecutable):
+        * wtf/FastMalloc.h:
+
 2008-10-22  Darin Adler  <darin@apple.com>
 
         Reviewed by Sam Weinig.
index b018efa..96ee1cd 100644 (file)
@@ -945,7 +945,7 @@ CodeBlock::~CodeBlock()
     for (size_t i = 0; i < size; ++i) {
         derefStructureIDs(&instructions[structureIDInstructions[i].opcodeIndex]);
         if (structureIDInstructions[i].stubRoutine)
-            fastFree(structureIDInstructions[i].stubRoutine);
+            WTF::fastFreeExecutable(structureIDInstructions[i].stubRoutine);
         if (CallLinkInfo* callLinkInfo = structureIDInstructions[i].linkInfoPtr) {
             callLinkInfo->callee->removeCaller(callLinkInfo);
             delete callLinkInfo;
@@ -956,7 +956,7 @@ CodeBlock::~CodeBlock()
     unlinkCallers();
 
     if (ctiCode)
-        fastFree(ctiCode);
+        WTF::fastFreeExecutable(ctiCode);
 #endif
 }
 
index e86ce89..7397232 100644 (file)
@@ -105,7 +105,7 @@ RegExp::~RegExp()
     jsRegExpFree(m_regExp);
 #if ENABLE(WREC)
     if (m_wrecFunction)
-        fastFree(m_wrecFunction);
+        WTF::fastFreeExecutable(m_wrecFunction);
 #endif
 }
 
index 406d723..6a45929 100644 (file)
@@ -30,6 +30,8 @@
 
 #include <wtf/Assertions.h>
 #include <wtf/AlwaysInline.h>
+#include <wtf/FastMalloc.h>
+
 #if HAVE(MMAN)
 #include <sys/mman.h>
 #endif
@@ -123,7 +125,7 @@ public:
         if (!m_index)
             return 0;
 
-        void* result = fastMalloc(m_index);
+        void* result = WTF::fastMallocExecutable(m_index);
 
         if (!result)
             return 0;
index aa1a108..a7c7f7c 100644 (file)
@@ -174,10 +174,12 @@ void* tryFastZeroedMalloc(size_t n)
 #include <stdlib.h>
 #if !PLATFORM(WIN_OS)
     #include <pthread.h>
+#else
+    #include "windows.h"
 #endif
 
 namespace WTF {
-    
+
 void* tryFastMalloc(size_t n) 
 {
     ASSERT(!isForbidden());
@@ -231,6 +233,28 @@ void* fastRealloc(void* p, size_t n)
 
 void releaseFastMallocFreeMemory() { }
 
+#if HAVE(VIRTUALALLOC)
+void* fastMallocExecutable(size_t n)
+{
+    return VirtualAlloc(0, n, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
+}
+
+void fastFreeExecutable(void* p)
+{ 
+    VirtualFree(p, 0, MEM_RELEASE); 
+}
+#else
+void* fastMallocExecutable(size_t n)
+{
+    return fastMalloc(n);
+}
+
+void fastFreeExecutable(void* p)
+{ 
+    fastFree(p);
+}
+#endif
+
 } // namespace WTF
 
 #if PLATFORM(DARWIN)
@@ -3361,6 +3385,16 @@ void* realloc(void* old_ptr, size_t new_size) {
   }
 }
 
+void* fastMallocExecutable(size_t n)
+{
+    return malloc<false>(n);
+}
+
+void fastFreeExecutable(void* p)
+{ 
+    free(p);
+}
+
 #ifdef WTF_CHANGES
 #undef do_malloc
 #else
index 770c7a2..fb2762c 100644 (file)
@@ -41,6 +41,9 @@ namespace WTF {
 
     void fastFree(void* p);
 
+    void* fastMallocExecutable(size_t n);
+    void fastFreeExecutable(void* p);
+
 #ifndef NDEBUG    
     void fastMallocForbid();
     void fastMallocAllow();