Changeset 44993 in webkit


Ignore:
Timestamp:
Jun 23, 2009 8:45:12 AM (15 years ago)
Author:
treat@webkit.org
Message:

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.

Location:
trunk/JavaScriptCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r44984 r44993  
     12009-06-23  Joe Mason  <joe.mason@torchmobile.com>
     2
     3        Reviewed by Adam Treat.
     4
     5        Authors: Yong Li <yong.li@torchmobile.com>, Joe Mason <joe.mason@torchmobile.com>
     6
     7        https://bugs.webkit.org/show_bug.cgi?id=26611
     8        Implement currentThreadStackBase on WINCE by adding a global,
     9        g_stackBase, which must be set to the address of a local variable
     10        by the caller before calling any WebKit function that invokes JSC.
     11
     12        * runtime/Collector.cpp:
     13        (JSC::isPageWritable):
     14        (JSC::getStackBase):
     15          Starts at the top of the stack and returns the entire range of
     16          consecutive writable pages as an estimate of the actual stack.
     17          This will be much bigger than the actual stack range, so some
     18          dead objects can't be collected, but it guarantees live objects
     19          aren't collected prematurely.
     20
     21        (JSC::currentThreadStackBase):
     22          On WinCE, returns g_stackBase if set or call getStackBase as a
     23          fallback if not.
     24
    1252009-06-23  Oliver Hunt  <oliver@apple.com>
    226
  • 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.