Changeset 84650 in webkit


Ignore:
Timestamp:
Apr 22, 2011 11:26:34 AM (13 years ago)
Author:
oliver@apple.com
Message:

2011-04-22 Oliver Hunt <oliver@apple.com>

Reviewed by Geoffrey Garen.

Make it harder to use HandleSlot incorrectly
https://bugs.webkit.org/show_bug.cgi?id=59205

Just add a little type fudging to make it harder to
incorrectly assign through a HandleSlot.

  • API/JSCallbackObjectFunctions.h: (JSC::::init):
  • JavaScriptCore.exp:
  • heap/Handle.h: (JSC::HandleBase::operator!): (JSC::HandleBase::operator UnspecifiedBoolType*): (JSC::HandleTypes::getFromSlot):
  • heap/HandleHeap.cpp: (JSC::HandleHeap::markStrongHandles): (JSC::HandleHeap::markWeakHandles): (JSC::HandleHeap::finalizeWeakHandles): (JSC::HandleHeap::writeBarrier): (JSC::HandleHeap::protectedGlobalObjectCount): (JSC::HandleHeap::isValidWeakNode):
  • heap/HandleHeap.h: (JSC::HandleHeap::copyWeak): (JSC::HandleHeap::makeWeak): (JSC::HandleHeap::Node::slot):
  • heap/HandleStack.cpp: (JSC::HandleStack::mark): (JSC::HandleStack::grow):
  • heap/HandleStack.h: (JSC::HandleStack::zapTo): (JSC::HandleStack::push):
  • heap/Heap.cpp: (JSC::HandleHeap::protectedObjectTypeCounts):
  • heap/Local.h: (JSC::::set):
  • heap/Strong.h: (JSC::Strong::set):
  • heap/Weak.h: (JSC::Weak::set):
  • runtime/StructureTransitionTable.h: (JSC::StructureTransitionTable::singleTransition): (JSC::StructureTransitionTable::setSingleTransition):
  • runtime/WeakGCMap.h: (JSC::WeakGCMap::add): (JSC::WeakGCMap::set):
  • runtime/WriteBarrier.h: (JSC::OpaqueJSValue::toJSValue): (JSC::OpaqueJSValue::toJSValueRef): (JSC::OpaqueJSValue::fromJSValue):
Location:
trunk/Source/JavaScriptCore
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/API/JSCallbackObjectFunctions.h

    r84052 r84650  
    9797        HandleHeap::heapFor(slot)->makeWeak(slot, m_callbackObjectData.get(), classRef());
    9898        HandleHeap::heapFor(slot)->writeBarrier(slot, this);
    99         *slot = this;
     99        slot->fromJSValue(this);
    100100    }
    101101}
  • trunk/Source/JavaScriptCore/ChangeLog

    r84621 r84650  
     12011-04-22  Oliver Hunt  <oliver@apple.com>
     2
     3        Reviewed by Geoffrey Garen.
     4
     5        Make it harder to use HandleSlot incorrectly
     6        https://bugs.webkit.org/show_bug.cgi?id=59205
     7
     8        Just add a little type fudging to make it harder to
     9        incorrectly assign through a HandleSlot.
     10
     11        * API/JSCallbackObjectFunctions.h:
     12        (JSC::::init):
     13        * JavaScriptCore.exp:
     14        * heap/Handle.h:
     15        (JSC::HandleBase::operator!):
     16        (JSC::HandleBase::operator UnspecifiedBoolType*):
     17        (JSC::HandleTypes::getFromSlot):
     18        * heap/HandleHeap.cpp:
     19        (JSC::HandleHeap::markStrongHandles):
     20        (JSC::HandleHeap::markWeakHandles):
     21        (JSC::HandleHeap::finalizeWeakHandles):
     22        (JSC::HandleHeap::writeBarrier):
     23        (JSC::HandleHeap::protectedGlobalObjectCount):
     24        (JSC::HandleHeap::isValidWeakNode):
     25        * heap/HandleHeap.h:
     26        (JSC::HandleHeap::copyWeak):
     27        (JSC::HandleHeap::makeWeak):
     28        (JSC::HandleHeap::Node::slot):
     29        * heap/HandleStack.cpp:
     30        (JSC::HandleStack::mark):
     31        (JSC::HandleStack::grow):
     32        * heap/HandleStack.h:
     33        (JSC::HandleStack::zapTo):
     34        (JSC::HandleStack::push):
     35        * heap/Heap.cpp:
     36        (JSC::HandleHeap::protectedObjectTypeCounts):
     37        * heap/Local.h:
     38        (JSC::::set):
     39        * heap/Strong.h:
     40        (JSC::Strong::set):
     41        * heap/Weak.h:
     42        (JSC::Weak::set):
     43        * runtime/StructureTransitionTable.h:
     44        (JSC::StructureTransitionTable::singleTransition):
     45        (JSC::StructureTransitionTable::setSingleTransition):
     46        * runtime/WeakGCMap.h:
     47        (JSC::WeakGCMap::add):
     48        (JSC::WeakGCMap::set):
     49        * runtime/WriteBarrier.h:
     50        (JSC::OpaqueJSValue::toJSValue):
     51        (JSC::OpaqueJSValue::toJSValueRef):
     52        (JSC::OpaqueJSValue::fromJSValue):
     53
    1542011-04-22  Patrick Gansterer  <paroga@webkit.org>
    255
  • trunk/Source/JavaScriptCore/JavaScriptCore.exp

    r84556 r84650  
    9898_WTFReportFatalError
    9999__ZN14OpaqueJSString6createERKN3JSC7UStringE
    100 __ZN3JSC10HandleHeap12writeBarrierEPNS_7JSValueERKS1_
     100__ZN3JSC10HandleHeap12writeBarrierEPNS_13OpaqueJSValueERKNS_7JSValueE
    101101__ZN3JSC10HandleHeap4growEv
    102102__ZN3JSC10Identifier11addSlowCaseEPNS_12JSGlobalDataEPN3WTF10StringImplE
  • trunk/Source/JavaScriptCore/heap/Handle.h

    r84052 r84650  
    5454
    5555public:
    56     bool operator!() const { return !m_slot || !*m_slot; }
     56    bool operator!() const { return !m_slot || !m_slot->toJSValue(); }
    5757
    5858    // This conversion operator allows implicit conversion to bool but not to other integer types.
    5959    typedef JSValue (HandleBase::*UnspecifiedBoolType);
    60     operator UnspecifiedBoolType*() const { return (m_slot && *m_slot) ? reinterpret_cast<UnspecifiedBoolType*>(1) : 0; }
     60    operator UnspecifiedBoolType*() const { return (m_slot && m_slot->toJSValue()) ? reinterpret_cast<UnspecifiedBoolType*>(1) : 0; }
    6161
    6262protected:
     
    8080template <typename T> struct HandleTypes {
    8181    typedef T* ExternalType;
    82     static ExternalType getFromSlot(HandleSlot slot) { return (slot && *slot) ? reinterpret_cast<ExternalType>(slot->asCell()) : 0; }
     82    static ExternalType getFromSlot(HandleSlot slot) { return (slot && slot->toJSValue()) ? reinterpret_cast<ExternalType>(slot->toJSValue().asCell()) : 0; }
    8383    static JSValue toJSValue(T* cell) { return reinterpret_cast<JSCell*>(cell); }
    8484    template <typename U> static void validateUpcast() { T* temp; temp = (U*)0; }
     
    8787template <> struct HandleTypes<Unknown> {
    8888    typedef JSValue ExternalType;
    89     static ExternalType getFromSlot(HandleSlot slot) { return slot ? *slot : JSValue(); }
     89    static ExternalType getFromSlot(HandleSlot slot) { return slot ? slot->toJSValue() : JSValue(); }
    9090    static JSValue toJSValue(const JSValue& v) { return v; }
    9191    template <typename U> static void validateUpcast() {}
  • trunk/Source/JavaScriptCore/heap/HandleHeap.cpp

    r84556 r84650  
    6565    Node* end = m_strongList.end();
    6666    for (Node* node = m_strongList.begin(); node != end; node = node->next())
    67         heapRootMarker.mark(node->slot());
     67        heapRootMarker.mark(node->slot()->toJSValueRef());
    6868}
    6969
     
    7575    for (Node* node = m_weakList.begin(); node != end; node = node->next()) {
    7676        ASSERT(isValidWeakNode(node));
    77         JSCell* cell = node->slot()->asCell();
     77        JSCell* cell = node->slot()->toJSValue().asCell();
    7878        if (Heap::isMarked(cell))
    7979            continue;
     
    8686            continue;
    8787
    88         heapRootVisitor.mark(node->slot());
     88        heapRootVisitor.mark(node->slot()->toJSValueRef());
    8989    }
    9090}
     
    9797
    9898        ASSERT(isValidWeakNode(node));
    99         JSCell* cell = node->slot()->asCell();
     99        JSCell* cell = node->slot()->toJSValue().asCell();
    100100        if (Heap::isMarked(cell))
    101101            continue;
     
    107107        }
    108108
    109         *node->slot() = JSValue();
     109        node->slot()->fromJSValue(JSValue());
    110110        SentinelLinkedList<Node>::remove(node);
    111111        m_immediateList.push(node);
     
    119119    ASSERT(!m_nextToFinalize); // Forbid assignment to handles during the finalization phase, since it would violate many GC invariants.
    120120
    121     if (!value == !*slot && slot->isCell() == value.isCell())
     121    if (!value == !slot->toJSValue() && slot->toJSValue().isCell() == value.isCell())
    122122        return;
    123123
     
    142142    Node* end = m_strongList.end();
    143143    for (Node* node = m_strongList.begin(); node != end; node = node->next()) {
    144         JSValue value = *node->slot();
     144        JSValue value = node->slot()->toJSValue();
    145145        if (value.isObject() && asObject(value.asCell())->isGlobalObject())
    146146            count++;
     
    155155        return false;
    156156
    157     JSValue value = *node->slot();
     157    JSValue value = node->slot()->toJSValue();
    158158    if (!value || !value.isCell())
    159159        return false;
  • trunk/Source/JavaScriptCore/heap/HandleHeap.h

    r84556 r84650  
    174174    Node* node = toNode(allocate());
    175175    node->makeWeak(toNode(other)->weakOwner(), toNode(other)->weakOwnerContext());
    176     writeBarrier(node->slot(), *other);
    177     *node->slot() = *other;
     176    writeBarrier(node->slot(), other->toJSValue());
     177    node->slot()->fromJSValue(other->toJSValue());
    178178    return toHandle(node);
    179179}
     
    185185
    186186    SentinelLinkedList<Node>::remove(node);
    187     if (!*handle || !handle->isCell()) {
     187    if (!handle->toJSValue() || !handle->toJSValue().isCell()) {
    188188        m_immediateList.push(node);
    189189        return;
     
    216216inline HandleSlot HandleHeap::Node::slot()
    217217{
    218     return &m_value;
     218    return reinterpret_cast<HandleSlot>(&m_value);
    219219}
    220220
  • trunk/Source/JavaScriptCore/heap/HandleStack.cpp

    r84556 r84650  
    4242void HandleStack::mark(HeapRootVisitor& heapRootMarker)
    4343{
    44     const Vector<HandleSlot>& blocks = m_blockStack.blocks();
     44    const Vector<JSValue*>& blocks = m_blockStack.blocks();
    4545    size_t blockLength = m_blockStack.blockLength;
    4646
    4747    int end = blocks.size() - 1;
    4848    for (int i = 0; i < end; ++i) {
    49         HandleSlot block = blocks[i];
     49        JSValue* block = blocks[i];
    5050        heapRootMarker.mark(block, blockLength);
    5151    }
    52     HandleSlot block = blocks[end];
     52    JSValue* block = blocks[end];
    5353    heapRootMarker.mark(block, m_frame.m_next - block);
    5454}
     
    5656void HandleStack::grow()
    5757{
    58     HandleSlot block = m_blockStack.grow();
     58    JSValue* block = m_blockStack.grow();
    5959    m_frame.m_next = block;
    6060    m_frame.m_end = block + m_blockStack.blockLength;
  • trunk/Source/JavaScriptCore/heap/HandleStack.h

    r84556 r84650  
    4242    class Frame {
    4343    public:
    44         HandleSlot m_next;
    45         HandleSlot m_end;
     44        JSValue* m_next;
     45        JSValue* m_end;
    4646    };
    4747
     
    8383    UNUSED_PARAM(lastFrame);
    8484#else
    85     const Vector<HandleSlot>& blocks = m_blockStack.blocks();
     85    const Vector<JSValue*>& blocks = m_blockStack.blocks();
    8686   
    8787    if (lastFrame.m_end != m_frame.m_end) { // Zapping to a frame in a different block.
     
    9292        }
    9393       
    94         for (HandleSlot it = blocks[i] + m_blockStack.blockLength - 1; it != lastFrame.m_next - 1; --it)
     94        for (JSValue* it = blocks[i] + m_blockStack.blockLength - 1; it != lastFrame.m_next - 1; --it)
    9595            *it = JSValue();
    9696       
     
    9898    }
    9999   
    100     for (HandleSlot it = m_frame.m_next - 1; it != lastFrame.m_next - 1; --it)
     100    for (JSValue* it = m_frame.m_next - 1; it != lastFrame.m_next - 1; --it)
    101101        *it = JSValue();
    102102#endif
     
    122122    if (m_frame.m_next == m_frame.m_end)
    123123        grow();
    124     return m_frame.m_next++;
     124    return reinterpret_cast<HandleSlot>(m_frame.m_next++);
    125125}
    126126
  • trunk/Source/JavaScriptCore/heap/Heap.cpp

    r84556 r84650  
    364364    Node* end = m_strongList.end();
    365365    for (Node* node = m_strongList.begin(); node != end; node = node->next()) {
    366         JSValue value = *node->slot();
     366        JSValue value = node->slot()->toJSValue();
    367367        if (value && value.isCell())
    368368            typeCounter(value.asCell());
  • trunk/Source/JavaScriptCore/heap/Local.h

    r83773 r84650  
    9696    ASSERT(slot());
    9797    ASSERT(!HandleTypes<T>::toJSValue(externalType) || !HandleTypes<T>::toJSValue(externalType).isCell() || Heap::isMarked(HandleTypes<T>::toJSValue(externalType).asCell()));
    98     *slot() = externalType;
     98    slot()->fromJSValue(externalType);
    9999}
    100100
  • trunk/Source/JavaScriptCore/heap/Strong.h

    r84052 r84650  
    141141        JSValue value = HandleTypes<T>::toJSValue(externalType);
    142142        HandleHeap::heapFor(slot())->writeBarrier(slot(), value);
    143         *slot() = value;
     143        slot()->fromJSValue(value);
    144144    }
    145145};
  • trunk/Source/JavaScriptCore/heap/Weak.h

    r83773 r84650  
    132132        ASSERT(!value || !value.isCell() || Heap::isMarked(value.asCell()));
    133133        HandleHeap::heapFor(slot())->writeBarrier(slot(), value);
    134         *slot() = value;
     134        slot()->fromJSValue(value);
    135135    }
    136136};
  • trunk/Source/JavaScriptCore/runtime/StructureTransitionTable.h

    r84052 r84650  
    140140        ASSERT(isUsingSingleSlot());
    141141        if (HandleSlot slot = this->slot()) {
    142             if (*slot)
    143                 return reinterpret_cast<Structure*>(slot->asCell());
     142            if (slot->toJSValue())
     143                return reinterpret_cast<Structure*>(slot->toJSValue().asCell());
    144144        }
    145145        return 0;
     
    163163        }
    164164        HandleHeap::heapFor(slot)->writeBarrier(slot, reinterpret_cast<JSCell*>(structure));
    165         *slot = reinterpret_cast<JSCell*>(structure);
     165        slot->fromJSValue(reinterpret_cast<JSCell*>(structure));
    166166    }
    167167
  • trunk/Source/JavaScriptCore/runtime/WeakGCMap.h

    r84052 r84650  
    130130            HandleHeap::heapFor(slot)->makeWeak(slot, this, FinalizerCallback::finalizerContextFor(key));
    131131            HandleHeap::heapFor(slot)->writeBarrier(slot, value);
    132             *slot = value;
     132            slot->fromJSValue(value);
    133133        }
    134134        return iter;
     
    140140        ASSERT(slot);
    141141        HandleHeap::heapFor(slot)->writeBarrier(slot, value);
    142         *slot = value;
     142        slot->fromJSValue(value);
    143143    }
    144144
     
    153153        }
    154154        HandleHeap::heapFor(slot)->writeBarrier(slot, value);
    155         *slot = value;
     155        slot->fromJSValue(value);
    156156    }
    157157
  • trunk/Source/JavaScriptCore/runtime/WriteBarrier.h

    r84289 r84650  
    4242
    4343typedef enum { } Unknown;
    44 typedef JSValue* HandleSlot;
     44class OpaqueJSValue : private JSValue {
     45public:
     46    JSValue& toJSValue() { return *this; }
     47    JSValue* toJSValueRef() { return this; }
     48    void fromJSValue(const JSValue& value) { *this = static_cast<const OpaqueJSValue&>(value); }
     49};
     50typedef OpaqueJSValue* HandleSlot;
    4551
    4652template <typename T> struct JSValueChecker {
Note: See TracChangeset for help on using the changeset viewer.