From bd400c93ad0c3be21401fb428e6474f9ea418b03 Mon Sep 17 00:00:00 2001 From: "oliver@apple.com" Date: Thu, 23 Oct 2008 03:36:04 +0000 Subject: [PATCH] Really "fix" CTI mode on windows 2k3. 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 | 30 ++++++++++++++++++++++++++++++ JavaScriptCore/VM/CodeBlock.cpp | 4 ++-- JavaScriptCore/kjs/regexp.cpp | 2 +- JavaScriptCore/masm/X86Assembler.h | 4 +++- JavaScriptCore/wtf/FastMalloc.cpp | 36 +++++++++++++++++++++++++++++++++++- JavaScriptCore/wtf/FastMalloc.h | 3 +++ 6 files changed, 74 insertions(+), 5 deletions(-) diff --git a/JavaScriptCore/ChangeLog b/JavaScriptCore/ChangeLog index 3fbfd0c..a8344b2 100644 --- a/JavaScriptCore/ChangeLog +++ b/JavaScriptCore/ChangeLog @@ -1,3 +1,33 @@ +2008-10-22 Oliver Hunt + + 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 Reviewed by Sam Weinig. diff --git a/JavaScriptCore/VM/CodeBlock.cpp b/JavaScriptCore/VM/CodeBlock.cpp index b018efa..96ee1cd 100644 --- a/JavaScriptCore/VM/CodeBlock.cpp +++ b/JavaScriptCore/VM/CodeBlock.cpp @@ -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 } diff --git a/JavaScriptCore/kjs/regexp.cpp b/JavaScriptCore/kjs/regexp.cpp index e86ce89..7397232 100644 --- a/JavaScriptCore/kjs/regexp.cpp +++ b/JavaScriptCore/kjs/regexp.cpp @@ -105,7 +105,7 @@ RegExp::~RegExp() jsRegExpFree(m_regExp); #if ENABLE(WREC) if (m_wrecFunction) - fastFree(m_wrecFunction); + WTF::fastFreeExecutable(m_wrecFunction); #endif } diff --git a/JavaScriptCore/masm/X86Assembler.h b/JavaScriptCore/masm/X86Assembler.h index 406d723..6a45929 100644 --- a/JavaScriptCore/masm/X86Assembler.h +++ b/JavaScriptCore/masm/X86Assembler.h @@ -30,6 +30,8 @@ #include #include +#include + #if HAVE(MMAN) #include #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; diff --git a/JavaScriptCore/wtf/FastMalloc.cpp b/JavaScriptCore/wtf/FastMalloc.cpp index aa1a108..a7c7f7c 100644 --- a/JavaScriptCore/wtf/FastMalloc.cpp +++ b/JavaScriptCore/wtf/FastMalloc.cpp @@ -174,10 +174,12 @@ void* tryFastZeroedMalloc(size_t n) #include #if !PLATFORM(WIN_OS) #include +#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(n); +} + +void fastFreeExecutable(void* p) +{ + free(p); +} + #ifdef WTF_CHANGES #undef do_malloc #else diff --git a/JavaScriptCore/wtf/FastMalloc.h b/JavaScriptCore/wtf/FastMalloc.h index 770c7a2..fb2762c 100644 --- a/JavaScriptCore/wtf/FastMalloc.h +++ b/JavaScriptCore/wtf/FastMalloc.h @@ -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(); -- 1.8.3.1