Changeset 275212 in webkit


Ignore:
Timestamp:
Mar 30, 2021 10:21:18 AM (3 years ago)
Author:
mark.lam@apple.com
Message:

Ensure that GlobalPropertyInfo is allocated on the stack.
https://bugs.webkit.org/show_bug.cgi?id=223911
rdar://75865742

Reviewed by Yusuke Suzuki.

Source/JavaScriptCore:

We rely on GlobalPropertyInfo being allocated on the stack to allow its JSValue
value to be scanned by the GC. Unfortunately, an ASAN compilation would choose
to allocate the GlobalPropertyInfo on a side buffer instead of directly on the
stack. This prevents the GC from doing the needed scan.

We'll fix this by suppressing ASAN on the functions that allocated GlobalPropertyInfo
arrays. Also added an ASSERT in the GlobalPropertyInfo constructor to assert that
it is allocated on the stack.

  • Scripts/wkbuiltins/builtins_generate_internals_wrapper_implementation.py:

(BuiltinsInternalsWrapperImplementationGenerator.generate_initialize_method):

  • runtime/JSGlobalObject.cpp:

(JSC::JSGlobalObject::initStaticGlobals):
(JSC::JSGlobalObject::init):
(JSC::JSGlobalObject::exposeDollarVM):

  • runtime/JSGlobalObject.h:

(JSC::JSGlobalObject::GlobalPropertyInfo::GlobalPropertyInfo):

Source/WebCore:

  • bindings/js/JSDOMGlobalObject.cpp:

(WebCore::JSDOMGlobalObject::addBuiltinGlobals):

  • bindings/js/JSDOMWindowBase.cpp:

(WebCore::JSDOMWindowBase::finishCreation):
(WebCore::JSDOMWindowBase::initStaticGlobals):

  • bindings/js/JSDOMWindowBase.h:
Location:
trunk/Source
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r275190 r275212  
     12021-03-30  Mark Lam  <mark.lam@apple.com>
     2
     3        Ensure that GlobalPropertyInfo is allocated on the stack.
     4        https://bugs.webkit.org/show_bug.cgi?id=223911
     5        rdar://75865742
     6
     7        Reviewed by Yusuke Suzuki.
     8
     9        We rely on GlobalPropertyInfo being allocated on the stack to allow its JSValue
     10        value to be scanned by the GC.  Unfortunately, an ASAN compilation would choose
     11        to allocate the GlobalPropertyInfo on a side buffer instead of directly on the
     12        stack.  This prevents the GC from doing the needed scan.
     13
     14        We'll fix this by suppressing ASAN on the functions that allocated GlobalPropertyInfo
     15        arrays.  Also added an ASSERT in the GlobalPropertyInfo constructor to assert that
     16        it is allocated on the stack.
     17
     18        * Scripts/wkbuiltins/builtins_generate_internals_wrapper_implementation.py:
     19        (BuiltinsInternalsWrapperImplementationGenerator.generate_initialize_method):
     20        * runtime/JSGlobalObject.cpp:
     21        (JSC::JSGlobalObject::initStaticGlobals):
     22        (JSC::JSGlobalObject::init):
     23        (JSC::JSGlobalObject::exposeDollarVM):
     24        * runtime/JSGlobalObject.h:
     25        (JSC::JSGlobalObject::GlobalPropertyInfo::GlobalPropertyInfo):
     26
    1272021-03-29  Xan López  <xan@igalia.com>
    228
  • trunk/Source/JavaScriptCore/Scripts/wkbuiltins/builtins_generate_internals_wrapper_implementation.py

    r273138 r275212  
    144144
    145145    def generate_initialize_method(self):
    146         lines = ["void JSBuiltinInternalFunctions::initialize(JSDOMGlobalObject& globalObject)",
     146        lines = ["SUPPRESS_ASAN void JSBuiltinInternalFunctions::initialize(JSDOMGlobalObject& globalObject)",
    147147                "{",
    148148                "    UNUSED_PARAM(globalObject);"]
  • trunk/Source/JavaScriptCore/runtime/JSGlobalObject.cpp

    r274893 r275212  
    581581}
    582582
     583SUPPRESS_ASAN inline void JSGlobalObject::initStaticGlobals(VM& vm)
     584{
     585    GlobalPropertyInfo staticGlobals[] = {
     586        GlobalPropertyInfo(vm.propertyNames->NaN, jsNaN(), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
     587        GlobalPropertyInfo(vm.propertyNames->Infinity, jsNumber(std::numeric_limits<double>::infinity()), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
     588        GlobalPropertyInfo(vm.propertyNames->undefinedKeyword, jsUndefined(), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
     589#if ASSERT_ENABLED
     590        GlobalPropertyInfo(vm.propertyNames->builtinNames().assertPrivateName(), JSFunction::create(vm, this, 1, String(), assertCall), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
     591#endif
     592    };
     593    addStaticGlobals(staticGlobals, WTF_ARRAY_LENGTH(staticGlobals));
     594}
     595
    583596void JSGlobalObject::init(VM& vm)
    584597{
     
    13581371    }
    13591372
    1360     GlobalPropertyInfo staticGlobals[] = {
    1361         GlobalPropertyInfo(vm.propertyNames->NaN, jsNaN(), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
    1362         GlobalPropertyInfo(vm.propertyNames->Infinity, jsNumber(std::numeric_limits<double>::infinity()), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
    1363         GlobalPropertyInfo(vm.propertyNames->undefinedKeyword, jsUndefined(), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
    1364 #if ASSERT_ENABLED
    1365         GlobalPropertyInfo(vm.propertyNames->builtinNames().assertPrivateName(), JSFunction::create(vm, this, 1, String(), assertCall), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
    1366 #endif
    1367     };
    1368     addStaticGlobals(staticGlobals, WTF_ARRAY_LENGTH(staticGlobals));
     1373    initStaticGlobals(vm);
    13691374   
    13701375    if (UNLIKELY(Options::useDollarVM()))
     
    21092114}
    21102115
    2111 void JSGlobalObject::exposeDollarVM(VM& vm)
     2116SUPPRESS_ASAN void JSGlobalObject::exposeDollarVM(VM& vm)
    21122117{
    21132118    RELEASE_ASSERT(g_jscConfig.restrictedOptionsEnabled && Options::useDollarVM());
  • trunk/Source/JavaScriptCore/runtime/JSGlobalObject.h

    r274609 r275212  
    11171117            , attributes(a)
    11181118        {
     1119            ASSERT(Thread::current().stack().contains(this));
    11191120        }
    11201121
     
    11391140
    11401141    JS_EXPORT_PRIVATE void init(VM&);
     1142    void initStaticGlobals(VM&);
    11411143    void fixupPrototypeChainWithObjectPrototype(VM&);
    11421144
  • trunk/Source/WebCore/ChangeLog

    r275206 r275212  
     12021-03-30  Mark Lam  <mark.lam@apple.com>
     2
     3        Ensure that GlobalPropertyInfo is allocated on the stack.
     4        https://bugs.webkit.org/show_bug.cgi?id=223911
     5        rdar://75865742
     6
     7        Reviewed by Yusuke Suzuki.
     8
     9        * bindings/js/JSDOMGlobalObject.cpp:
     10        (WebCore::JSDOMGlobalObject::addBuiltinGlobals):
     11        * bindings/js/JSDOMWindowBase.cpp:
     12        (WebCore::JSDOMWindowBase::finishCreation):
     13        (WebCore::JSDOMWindowBase::initStaticGlobals):
     14        * bindings/js/JSDOMWindowBase.h:
     15
    1162021-03-30  Sam Weinig  <weinig@apple.com>
    217
  • trunk/Source/WebCore/bindings/js/JSDOMGlobalObject.cpp

    r275151 r275212  
    174174}
    175175
    176 void JSDOMGlobalObject::addBuiltinGlobals(VM& vm)
     176SUPPRESS_ASAN void JSDOMGlobalObject::addBuiltinGlobals(VM& vm)
    177177{
    178178    m_builtinInternalFunctions.initialize(*this);
  • trunk/Source/WebCore/bindings/js/JSDOMWindowBase.cpp

    r273203 r275212  
    22 *  Copyright (C) 2000 Harri Porten (porten@kde.org)
    33 *  Copyright (C) 2006 Jon Shier (jshier@iastate.edu)
    4  *  Copyright (C) 2003-2020 Apple Inc. All rights reseved.
     4 *  Copyright (C) 2003-2021 Apple Inc. All rights reseved.
    55 *  Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org)
    66 *  Copyright (c) 2015 Canon Inc. All rights reserved.
     
    101101}
    102102
    103 void JSDOMWindowBase::finishCreation(VM& vm, JSWindowProxy* proxy)
    104 {
    105     Base::finishCreation(vm, proxy);
    106     ASSERT(inherits(vm, info()));
    107 
     103SUPPRESS_ASAN inline void JSDOMWindowBase::initStaticGlobals(JSC::VM& vm)
     104{
    108105    auto& builtinNames = static_cast<JSVMClientData*>(vm.clientData)->builtinNames();
    109106
     
    114111
    115112    addStaticGlobals(staticGlobals, WTF_ARRAY_LENGTH(staticGlobals));
     113}
     114
     115void JSDOMWindowBase::finishCreation(VM& vm, JSWindowProxy* proxy)
     116{
     117    Base::finishCreation(vm, proxy);
     118    ASSERT(inherits(vm, info()));
     119
     120    initStaticGlobals(vm);
    116121
    117122    if (m_wrapped && m_wrapped->frame() && m_wrapped->frame()->settings().needsSiteSpecificQuirks())
  • trunk/Source/WebCore/bindings/js/JSDOMWindowBase.h

    r273203 r275212  
    11/*
    22 *  Copyright (C) 2000 Harri Porten (porten@kde.org)
    3  *  Copyright (C) 2003-2017 Apple Inc. All rights reseved.
     3 *  Copyright (C) 2003-2021 Apple Inc. All rights reseved.
    44 *
    55 *  This library is free software; you can redistribute it and/or
     
    9494    JSDOMWindowBase(JSC::VM&, JSC::Structure*, RefPtr<DOMWindow>&&, JSWindowProxy*);
    9595    void finishCreation(JSC::VM&, JSWindowProxy*);
     96    void initStaticGlobals(JSC::VM&);
    9697
    9798    RefPtr<JSC::WatchpointSet> m_windowCloseWatchpoints;
Note: See TracChangeset for help on using the changeset viewer.