Ignore:
Timestamp:
Jun 23, 2009, 8:45:12 AM (16 years ago)
Author:
[email protected]
Message:

2009-06-23 Joe Mason <[email protected]>

Reviewed by Adam Treat.

Authors: Yong Li <[email protected]>, Joe Mason <[email protected]>

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/runtime/Collector.cpp

    r44813 r44993  
    393393    return heapAllocate<NumberHeap>(s);
    394394}
     395
     396#if PLATFORM(WINCE)
     397void* g_stackBase = 0;
     398
     399inline bool isPageWritable(void* page)
     400{
     401    MEMORY_BASIC_INFORMATION memoryInformation;
     402    DWORD result = VirtualQuery(page, &memoryInformation, sizeof(memoryInformation));
     403
     404    // return false on error, including ptr outside memory
     405    if (result != sizeof(memoryInformation))
     406        return false;
     407
     408    DWORD protect = memoryInformation.Protect & ~(PAGE_GUARD | PAGE_NOCACHE);
     409    return protect == PAGE_READWRITE
     410        || protect == PAGE_WRITECOPY
     411        || protect == PAGE_EXECUTE_READWRITE
     412        || protect == PAGE_EXECUTE_WRITECOPY;
     413}
     414
     415static void* getStackBase(void* previousFrame)
     416{
     417    // find the address of this stack frame by taking the address of a local variable
     418    bool isGrowingDownward;
     419    void* thisFrame = (void*)(&isGrowingDownward);
     420
     421    isGrowingDownward = previousFrame < &thisFrame;
     422    static DWORD pageSize = 0;
     423    if (!pageSize) {
     424        SYSTEM_INFO systemInfo;
     425        GetSystemInfo(&systemInfo);
     426        pageSize = systemInfo.dwPageSize;
     427    }
     428
     429    // scan all of memory starting from this frame, and return the last writeable page found
     430    register char* currentPage = (char*)((DWORD)thisFrame & ~(pageSize - 1));
     431    if (isGrowingDownward) {
     432        while (currentPage > 0) {
     433            // check for underflow
     434            if (currentPage >= (char*)pageSize)
     435                currentPage -= pageSize;
     436            else
     437                currentPage = 0;
     438            if (!isPageWritable(currentPage))
     439                return currentPage + pageSize;
     440        }
     441        return 0;
     442    } else {
     443        while (true) {
     444            // guaranteed to complete because isPageWritable returns false at end of memory
     445            currentPage += pageSize;
     446            if (!isPageWritable(currentPage))
     447                return currentPage;
     448        }
     449    }
     450}
     451#endif
    395452
    396453static inline void* currentThreadStackBase()
     
    459516    }
    460517    return static_cast<char*>(stackBase) + stackSize;
     518#elif PLATFORM(WINCE)
     519    if (g_stackBase)
     520        return g_stackBase;
     521    else {
     522        int dummy;
     523        return getStackBase(&dummy);
     524    }
    461525#else
    462526#error Need a way to get the stack base on this platform
Note: See TracChangeset for help on using the changeset viewer.