Changeset 249518 in webkit


Ignore:
Timestamp:
Sep 4, 2019 7:52:46 PM (5 years ago)
Author:
ysuzuki@apple.com
Message:

[JSC] FunctionOverrides should have a lock to ensure concurrent access to hash table does not happen
https://bugs.webkit.org/show_bug.cgi?id=201485

Reviewed by Tadeu Zagallo.

FunctionOverrides is a per-process singleton for registering overrides information. But we are accessing
it without taking a lock. If multiple threads with multiple VMs are accessing this concurrently, we have
a race issue like,

  1. While one thread is adding overrides information,
  2. Another thread is accessing this hash table.

This patch adds a lock to make sure that only one thread can access this registry.

  • tools/FunctionOverrides.cpp:

(JSC::FunctionOverrides::FunctionOverrides):
(JSC::FunctionOverrides::reinstallOverrides):
(JSC::FunctionOverrides::initializeOverrideFor):
(JSC::FunctionOverrides::parseOverridesInFile):

  • tools/FunctionOverrides.h:

(JSC::FunctionOverrides::clear):

Location:
trunk/Source/JavaScriptCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r249509 r249518  
     12019-09-04  Yusuke Suzuki  <ysuzuki@apple.com>
     2
     3        [JSC] FunctionOverrides should have a lock to ensure concurrent access to hash table does not happen
     4        https://bugs.webkit.org/show_bug.cgi?id=201485
     5
     6        Reviewed by Tadeu Zagallo.
     7
     8        FunctionOverrides is a per-process singleton for registering overrides information. But we are accessing
     9        it without taking a lock. If multiple threads with multiple VMs are accessing this concurrently, we have
     10        a race issue like,
     11
     12        1. While one thread is adding overrides information,
     13        2. Another thread is accessing this hash table.
     14
     15        This patch adds a lock to make sure that only one thread can access this registry.
     16
     17        * tools/FunctionOverrides.cpp:
     18        (JSC::FunctionOverrides::FunctionOverrides):
     19        (JSC::FunctionOverrides::reinstallOverrides):
     20        (JSC::FunctionOverrides::initializeOverrideFor):
     21        (JSC::FunctionOverrides::parseOverridesInFile):
     22        * tools/FunctionOverrides.h:
     23        (JSC::FunctionOverrides::clear):
     24
    1252019-09-04  Yusuke Suzuki  <ysuzuki@apple.com>
    226
  • trunk/Source/JavaScriptCore/tools/FunctionOverrides.cpp

    r248552 r249518  
    103103FunctionOverrides::FunctionOverrides(const char* overridesFileName)
    104104{
    105     parseOverridesInFile(overridesFileName);
     105    parseOverridesInFile(holdLock(m_lock), overridesFileName);
    106106}
    107107
     
    109109{
    110110    FunctionOverrides& overrides = FunctionOverrides::overrides();
     111    auto locker = holdLock(overrides.m_lock);
    111112    const char* overridesFileName = Options::functionOverrides();
    112     overrides.clear();
    113     overrides.parseOverridesInFile(overridesFileName);
     113    overrides.clear(locker);
     114    overrides.parseOverridesInFile(locker, overridesFileName);
    114115}
    115116
     
    152153    String sourceBodyString = sourceString.substring(sourceBodyStart);
    153154
    154     auto it = overrides.m_entries.find(sourceBodyString);
    155     if (it == overrides.m_entries.end())
    156         return false;
    157 
    158     initializeOverrideInfo(origCode, it->value, result);
     155    String newBody;
     156    {
     157        auto locker = holdLock(overrides.m_lock);
     158        auto it = overrides.m_entries.find(sourceBodyString.isolatedCopy());
     159        if (it == overrides.m_entries.end())
     160            return false;
     161        newBody = it->value.isolatedCopy();
     162    }
     163
     164    initializeOverrideInfo(origCode, newBody, result);
    159165    return true;
    160166}
     
    228234}
    229235
    230 void FunctionOverrides::parseOverridesInFile(const char* fileName)
     236void FunctionOverrides::parseOverridesInFile(const AbstractLocker&, const char* fileName)
    231237{
    232238    if (!fileName)
  • trunk/Source/JavaScriptCore/tools/FunctionOverrides.h

    r243365 r249518  
    2828#include "SourceCode.h"
    2929#include <wtf/HashMap.h>
     30#include <wtf/Lock.h>
    3031#include <wtf/text/WTFString.h>
    3132
     
    5758
    5859private:
    59     void parseOverridesInFile(const char* fileName);
    60     void clear() { m_entries.clear(); }
     60    void parseOverridesInFile(const AbstractLocker&, const char* fileName);
     61    void clear(const AbstractLocker&) { m_entries.clear(); }
    6162
    6263    HashMap<String, String> m_entries;
     64    Lock m_lock;
    6365};
    6466
Note: See TracChangeset for help on using the changeset viewer.