Ignore:
Timestamp:
Sep 4, 2019, 7:52:46 PM (6 years ago)
Author:
[email protected]
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):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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)
Note: See TracChangeset for help on using the changeset viewer.