Commit bac633d9 authored by treat@webkit.org's avatar treat@webkit.org

2009-06-23 Joe Mason <joe.mason@torchmobile.com>

        Reviewed by Adam Treat.

        Authors: Yong Li <yong.li@torchmobile.com>, Joe Mason <joe.mason@torchmobile.com>

        https://bugs.webkit.org/show_bug.cgi?id=26611
        Implement currentThreadStackBase on WINCE by adding a global,
        g_stackBase, which must be set to the address of a local variable
        by the caller before calling any WebKit function that invokes JSC.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@44993 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 4b7bc1ce
2009-06-23 Joe Mason <joe.mason@torchmobile.com>
Reviewed by Adam Treat.
Authors: Yong Li <yong.li@torchmobile.com>, Joe Mason <joe.mason@torchmobile.com>
https://bugs.webkit.org/show_bug.cgi?id=26611
Implement currentThreadStackBase on WINCE by adding a global,
g_stackBase, which must be set to the address of a local variable
by the caller before calling any WebKit function that invokes JSC.
* runtime/Collector.cpp:
(JSC::isPageWritable):
(JSC::getStackBase):
Starts at the top of the stack and returns the entire range of
consecutive writable pages as an estimate of the actual stack.
This will be much bigger than the actual stack range, so some
dead objects can't be collected, but it guarantees live objects
aren't collected prematurely.
(JSC::currentThreadStackBase):
On WinCE, returns g_stackBase if set or call getStackBase as a
fallback if not.
2009-06-23 Oliver Hunt <oliver@apple.com>
Reviewed by Alexey Proskuryakov.
......
......@@ -393,6 +393,63 @@ void* Heap::allocateNumber(size_t s)
return heapAllocate<NumberHeap>(s);
}
#if PLATFORM(WINCE)
void* g_stackBase = 0;
inline bool isPageWritable(void* page)
{
MEMORY_BASIC_INFORMATION memoryInformation;
DWORD result = VirtualQuery(page, &memoryInformation, sizeof(memoryInformation));
// return false on error, including ptr outside memory
if (result != sizeof(memoryInformation))
return false;
DWORD protect = memoryInformation.Protect & ~(PAGE_GUARD | PAGE_NOCACHE);
return protect == PAGE_READWRITE
|| protect == PAGE_WRITECOPY
|| protect == PAGE_EXECUTE_READWRITE
|| protect == PAGE_EXECUTE_WRITECOPY;
}
static void* getStackBase(void* previousFrame)
{
// find the address of this stack frame by taking the address of a local variable
bool isGrowingDownward;
void* thisFrame = (void*)(&isGrowingDownward);
isGrowingDownward = previousFrame < &thisFrame;
static DWORD pageSize = 0;
if (!pageSize) {
SYSTEM_INFO systemInfo;
GetSystemInfo(&systemInfo);
pageSize = systemInfo.dwPageSize;
}
// scan all of memory starting from this frame, and return the last writeable page found
register char* currentPage = (char*)((DWORD)thisFrame & ~(pageSize - 1));
if (isGrowingDownward) {
while (currentPage > 0) {
// check for underflow
if (currentPage >= (char*)pageSize)
currentPage -= pageSize;
else
currentPage = 0;
if (!isPageWritable(currentPage))
return currentPage + pageSize;
}
return 0;
} else {
while (true) {
// guaranteed to complete because isPageWritable returns false at end of memory
currentPage += pageSize;
if (!isPageWritable(currentPage))
return currentPage;
}
}
}
#endif
static inline void* currentThreadStackBase()
{
#if PLATFORM(DARWIN)
......@@ -458,6 +515,13 @@ static inline void* currentThreadStackBase()
stackThread = thread;
}
return static_cast<char*>(stackBase) + stackSize;
#elif PLATFORM(WINCE)
if (g_stackBase)
return g_stackBase;
else {
int dummy;
return getStackBase(&dummy);
}
#else
#error Need a way to get the stack base on this platform
#endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment