Changeset 75180 in webkit


Ignore:
Timestamp:
Jan 6, 2011 12:39:55 PM (13 years ago)
Author:
Patrick Gansterer
Message:

2011-01-06 Patrick Gansterer <Patrick Gansterer>

Reviewed by Gavin Barraclough.

[WINCE] Determine stack extent
https://bugs.webkit.org/show_bug.cgi?id=26276

Scan the stack for writeable pages and use the limits.

  • wtf/StackBounds.cpp: (WTF::detectGrowingDownward): (WTF::isPageWritable): (WTF::getLowerStackBound): (WTF::getUpperStackBound): (WTF::StackBounds::initialize):
Location:
trunk/Source/JavaScriptCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r75141 r75180  
     12011-01-06  Patrick Gansterer  <paroga@webkit.org>
     2
     3        Reviewed by Gavin Barraclough.
     4
     5        [WINCE] Determine stack extent
     6        https://bugs.webkit.org/show_bug.cgi?id=26276
     7
     8        Scan the stack for writeable pages and use the limits.
     9
     10        * wtf/StackBounds.cpp:
     11        (WTF::detectGrowingDownward):
     12        (WTF::isPageWritable):
     13        (WTF::getLowerStackBound):
     14        (WTF::getUpperStackBound):
     15        (WTF::StackBounds::initialize):
     16
    1172011-01-05  Steve Falkenburg  <sfalken@apple.com>
    218
  • trunk/Source/JavaScriptCore/wtf/StackBounds.cpp

    • Property svn:eol-style set to native
    r74595 r75180  
    6666//
    6767// FIXME: remove this! - this code unsafely guesses at stack sizes!
    68 #if OS(WINDOWS) || OS(SOLARIS) || OS(OPENBSD) || OS(SYMBIAN) || OS(HAIKU) || OS(WINCE)
     68#if OS(WINDOWS) || OS(SOLARIS) || OS(OPENBSD) || OS(SYMBIAN) || OS(HAIKU)
    6969// Based on the current limit used by the JSC parser, guess the stack size.
    7070static const ptrdiff_t estimatedStackSize = 128 * sizeof(void*) * 1024;
     
    185185namespace WTF {
    186186
    187 inline bool isPageWritable(void* page)
     187static bool detectGrowingDownward(void* previousFrame)
     188{
     189    // Find the address of this stack frame by taking the address of a local variable.
     190    int thisFrame;
     191    return previousFrame > &thisFrame;
     192}
     193
     194static inline bool isPageWritable(void* page)
    188195{
    189196    MEMORY_BASIC_INFORMATION memoryInformation;
     
    201208}
    202209
    203 static void* getStackMax(void* previousFrame, bool& isGrowingDownward)
     210static inline void* getLowerStackBound(char* currentPage, DWORD pageSize)
     211{
     212    while (currentPage > 0) {
     213        // check for underflow
     214        if (currentPage >= reinterpret_cast<char*>(pageSize))
     215            currentPage -= pageSize;
     216        else
     217            currentPage = 0;
     218
     219        if (!isPageWritable(currentPage))
     220            return currentPage + pageSize;
     221    }
     222
     223    return 0;
     224}
     225
     226static inline void* getUpperStackBound(char* currentPage, DWORD pageSize)
     227{
     228    do {
     229        // guaranteed to complete because isPageWritable returns false at end of memory
     230        currentPage += pageSize;
     231    } while (isPageWritable(currentPage));
     232
     233    return currentPage - pageSize;
     234}
     235
     236void StackBounds::initialize()
    204237{
    205238    // find the address of this stack frame by taking the address of a local variable
    206239    void* thisFrame = &thisFrame;
    207     isGrowingDownward = previousFrame < &thisFrame;
    208 
    209     if (JSC::g_stackBase)
    210         return JSC::g_stackBase;
     240    bool isGrowingDownward = detectGrowingDownward(thisFrame);
    211241
    212242    SYSTEM_INFO systemInfo;
     
    215245
    216246    // scan all of memory starting from this frame, and return the last writeable page found
    217     register char* currentPage = (char*)((DWORD)thisFrame & ~(pageSize - 1));
    218     if (isGrowingDownward) {
    219         while (currentPage > 0) {
    220             // check for underflow
    221             if (currentPage >= (char*)pageSize)
    222                 currentPage -= pageSize;
    223             else
    224                 currentPage = 0;
    225             if (!isPageWritable(currentPage))
    226                 return currentPage + pageSize;
    227         }
    228         return 0;
    229     } else {
    230         while (true) {
    231             // guaranteed to complete because isPageWritable returns false at end of memory
    232             currentPage += pageSize;
    233             if (!isPageWritable(currentPage))
    234                 return currentPage;
    235         }
    236     }
    237 }
    238 
    239 void StackBounds::initialize()
    240 {
    241     int dummy;
    242     bool isGrowingDownward;
    243     m_origin = getStackMax(&dummy, isGrowingDownward);
    244     m_bound = isGrowingDownward
    245         ? static_cast<char*>(m_origin) - estimatedStackSize
    246         : static_cast<char*>(m_origin) + estimatedStackSize;
     247    char* currentPage = reinterpret_cast<char*>(reinterpret_cast<DWORD>(thisFrame) & ~(pageSize - 1));
     248    void* lowerStackBound = getLowerStackBound(currentPage, pageSize);
     249    void* upperStackBound = getUpperStackBound(currentPage, pageSize);
     250
     251    m_origin = isGrowingDownward ? upperStackBound : lowerStackBound;
     252    m_bound = isGrowingDownward ? lowerStackBound : upperStackBound;
    247253}
    248254
Note: See TracChangeset for help on using the changeset viewer.