Changeset 189517 in webkit


Ignore:
Timestamp:
Sep 8, 2015 5:19:15 PM (9 years ago)
Author:
mark.lam@apple.com
Message:

GC stack scan should include ABI red zone.
https://bugs.webkit.org/show_bug.cgi?id=148976

Reviewed by Geoffrey Garen and Benjamin Poulain.

Source/JavaScriptCore:

The x86_64 ABI section 3.2.2[1] and ARM64 ABI[2] both state that there is a
128 byte red zone below the stack pointer (reserved by the OS), and that
"functions may use this area for temporary data that is not needed across
function calls".

Hence, it is possible for a thread to store JSCell pointers in the red zone
area, and the conservative GC thread scanner needs to scan that area as well.

Note: the red zone should not be scanned for the GC thread itself (in
gatherFromCurrentThread()). This because we're guaranteed that there will
be GC frames below the lowest (top of stack) frame that we need to scan.
Hence, we are guaranteed that there are no red zone areas there containing
JSObject pointers of relevance.

No test added for this issue because the issue relies on:

  1. the compiler tool chain generating code that stores local variables containing the sole reference to a JS object (that needs to be kept alive) in the stack red zone, and
  2. GC has to run on another thread while that red zone containing the JS object reference is in use.

These conditions require a race that cannot be reliably reproduced.

[1]: http://people.freebsd.org/~obrien/amd64-elf-abi.pdf
[2]: https://developer.apple.com/library/ios/documentation/Xcode/Conceptual/iPhoneOSABIReference/Articles/ARM64FunctionCallingConventions.html#//apple_ref/doc/uid/TP40013702-SW7

  • heap/MachineStackMarker.cpp:

(JSC::MachineThreads::Thread::Thread):
(JSC::MachineThreads::Thread::createForCurrentThread):
(JSC::MachineThreads::Thread::freeRegisters):
(JSC::osRedZoneAdjustment):
(JSC::MachineThreads::Thread::captureStack):

Source/WTF:

  • wtf/StackBounds.h:

(WTF::StackBounds::origin):
(WTF::StackBounds::end):
(WTF::StackBounds::size):

Location:
trunk/Source
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r189516 r189517  
     12015-09-08  Mark Lam  <mark.lam@apple.com>
     2
     3        GC stack scan should include ABI red zone.
     4        https://bugs.webkit.org/show_bug.cgi?id=148976
     5
     6        Reviewed by Geoffrey Garen and Benjamin Poulain.
     7
     8        The x86_64 ABI section 3.2.2[1] and ARM64 ABI[2] both state that there is a
     9        128 byte red zone below the stack pointer (reserved by the OS), and that
     10        "functions may use this area for temporary data that is not needed across
     11        function calls".
     12
     13        Hence, it is possible for a thread to store JSCell pointers in the red zone
     14        area, and the conservative GC thread scanner needs to scan that area as well.
     15
     16        Note: the red zone should not be scanned for the GC thread itself (in
     17        gatherFromCurrentThread()).  This because we're guaranteed that there will
     18        be GC frames below the lowest (top of stack) frame that we need to scan.
     19        Hence, we are guaranteed that there are no red zone areas there containing
     20        JSObject pointers of relevance.
     21
     22        No test added for this issue because the issue relies on:
     23        1. the compiler tool chain generating code that stores local variables
     24           containing the sole reference to a JS object (that needs to be kept
     25           alive) in the stack red zone, and
     26        2. GC has to run on another thread while that red zone containing the
     27           JS object reference is in use.
     28
     29        These conditions require a race that cannot be reliably reproduced.
     30
     31        [1]: http://people.freebsd.org/~obrien/amd64-elf-abi.pdf
     32        [2]: https://developer.apple.com/library/ios/documentation/Xcode/Conceptual/iPhoneOSABIReference/Articles/ARM64FunctionCallingConventions.html#//apple_ref/doc/uid/TP40013702-SW7
     33
     34        * heap/MachineStackMarker.cpp:
     35        (JSC::MachineThreads::Thread::Thread):
     36        (JSC::MachineThreads::Thread::createForCurrentThread):
     37        (JSC::MachineThreads::Thread::freeRegisters):
     38        (JSC::osRedZoneAdjustment):
     39        (JSC::MachineThreads::Thread::captureStack):
     40
    1412015-09-08  Geoffrey Garen  <ggaren@apple.com>
    242
  • trunk/Source/JavaScriptCore/heap/MachineStackMarker.cpp

    r188499 r189517  
    161161    WTF_MAKE_FAST_ALLOCATED;
    162162
    163     Thread(const PlatformThread& platThread, void* base)
     163    Thread(const PlatformThread& platThread, void* base, void* end)
    164164        : platformThread(platThread)
    165165        , stackBase(base)
     166        , stackEnd(end)
    166167    {
    167168#if USE(PTHREADS) && !OS(WINDOWS) && !OS(DARWIN) && defined(SA_RESTART)
     
    196197    static Thread* createForCurrentThread()
    197198    {
    198         return new Thread(getCurrentPlatformThread(), wtfThreadData().stack().origin());
     199        auto stackBounds = wtfThreadData().stack();
     200        return new Thread(getCurrentPlatformThread(), stackBounds.origin(), stackBounds.end());
    199201    }
    200202
     
    242244    PlatformThread platformThread;
    243245    void* stackBase;
     246    void* stackEnd;
    244247#if OS(WINDOWS)
    245248    HANDLE platformThreadHandle;
     
    511514}
    512515
     516static inline int osRedZoneAdjustment()
     517{
     518    int redZoneAdjustment = 0;
     519#if !OS(WINDOWS)
     520#if CPU(X86_64)
     521    // See http://people.freebsd.org/~obrien/amd64-elf-abi.pdf Section 3.2.2.
     522    redZoneAdjustment = -128;
     523#elif CPU(ARM64)
     524    // See https://developer.apple.com/library/ios/documentation/Xcode/Conceptual/iPhoneOSABIReference/Articles/ARM64FunctionCallingConventions.html#//apple_ref/doc/uid/TP40013702-SW7
     525    redZoneAdjustment = -128;
     526#endif
     527#endif // OS(DARWIN)
     528    return redZoneAdjustment;
     529}
     530
    513531std::pair<void*, size_t> MachineThreads::Thread::captureStack(void* stackTop)
    514532{
    515     void* begin = stackBase;
    516     void* end = reinterpret_cast<void*>(
    517         WTF::roundUpToMultipleOf<sizeof(void*)>(reinterpret_cast<uintptr_t>(stackTop)));
    518     if (begin > end)
    519         std::swap(begin, end);
    520     return std::make_pair(begin, static_cast<char*>(end) - static_cast<char*>(begin));
     533    char* begin = reinterpret_cast_ptr<char*>(stackBase);
     534    char* end = reinterpret_cast_ptr<char*>(WTF::roundUpToMultipleOf<sizeof(void*)>(reinterpret_cast<uintptr_t>(stackTop)));
     535    ASSERT(begin >= end);
     536
     537    char* endWithRedZone = end + osRedZoneAdjustment();
     538    ASSERT(WTF::roundUpToMultipleOf<sizeof(void*)>(reinterpret_cast<uintptr_t>(endWithRedZone)) == reinterpret_cast<uintptr_t>(endWithRedZone));
     539
     540    if (endWithRedZone < stackEnd)
     541        endWithRedZone = reinterpret_cast_ptr<char*>(stackEnd);
     542
     543    std::swap(begin, endWithRedZone);
     544    return std::make_pair(begin, endWithRedZone - begin);
    521545}
    522546
  • trunk/Source/WTF/ChangeLog

    r189367 r189517  
     12015-09-08  Mark Lam  <mark.lam@apple.com>
     2
     3        GC stack scan should include ABI red zone.
     4        https://bugs.webkit.org/show_bug.cgi?id=148976
     5
     6        Reviewed by Geoffrey Garen and Benjamin Poulain.
     7
     8        * wtf/StackBounds.h:
     9        (WTF::StackBounds::origin):
     10        (WTF::StackBounds::end):
     11        (WTF::StackBounds::size):
     12
    1132015-09-04  Csaba Osztrogonác  <ossy@webkit.org>
    214
  • trunk/Source/WTF/wtf/StackBounds.h

    r173949 r189517  
    5555    }
    5656
     57    void* end() const
     58    {
     59        ASSERT(m_bound);
     60        return m_bound;
     61    }
     62   
    5763    size_t size() const
    5864    {
Note: See TracChangeset for help on using the changeset viewer.