Changeset 233461 in webkit


Ignore:
Timestamp:
Jul 3, 2018 3:41:37 AM (6 years ago)
Author:
ddkilzer@apple.com
Message:

[iOS] Add assert to catch improper use of WebCore::Timer in UI Process
<https://webkit.org/b/185330>
<rdar://problem/32816079>

Reviewed by Darin Adler.

Source/WebCore:

  • platform/RuntimeApplicationChecks.cpp:

(WebCore::s_webKitProcessType): Add. Global to track process
type.
(WebCore::setWebKitProcessType): Implement new function that is
called when initializing Web, Network, and Storage processes.
(WebCore::isInNetworkProcess): Add.
(WebCore::isInStorageProcess): Add.
(WebCore::isInWebProcess): Add.

  • Check value in s_webKitProcessType to determine which process is currently running.
  • platform/RuntimeApplicationChecks.h:

(WebCore::isInNetworkProcess): Add.
(WebCore::isInStorageProcess): Add.
(WebCore::isInWebProcess):

  • Make available for all platforms.
  • platform/Timer.cpp:

(WebCore::TimerBase::TimerBase): Add assert and os_log_fault.
This catches the unwanted behavior on iOS using isAllowed().
(WebCore::TimerBase::isAllowed): Add implementation.

  • platform/Timer.h:

(WebCore::TimerBase::isAllowed): Add declaration.

  • platform/cocoa/RuntimeApplicationChecksCocoa.mm:

(WebCore::isInWebProcess): Delete. Replace with method in
RuntimeApplicationChecks.cpp.

Source/WebKit:

  • NetworkProcess/NetworkProcess.cpp:

(WebKit::NetworkProcess::NetworkProcess):

  • StorageProcess/StorageProcess.cpp:

(WebKit::StorageProcess::StorageProcess):

  • WebProcess/WebProcess.cpp:

(WebKit::m_nonVisibleProcessCleanupTimer):

  • Call setWebKitProcessType() to se the global for the current process.
Location:
trunk/Source
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r233452 r233461  
     12018-07-03  David Kilzer  <ddkilzer@apple.com>
     2
     3        [iOS] Add assert to catch improper use of WebCore::Timer in UI Process
     4        <https://webkit.org/b/185330>
     5        <rdar://problem/32816079>
     6
     7        Reviewed by Darin Adler.
     8
     9        * platform/RuntimeApplicationChecks.cpp:
     10        (WebCore::s_webKitProcessType): Add. Global to track process
     11        type.
     12        (WebCore::setWebKitProcessType): Implement new function that is
     13        called when initializing Web, Network, and Storage processes.
     14        (WebCore::isInNetworkProcess): Add.
     15        (WebCore::isInStorageProcess): Add.
     16        (WebCore::isInWebProcess): Add.
     17        - Check value in s_webKitProcessType to determine which process
     18          is currently running.
     19        * platform/RuntimeApplicationChecks.h:
     20        (WebCore::isInNetworkProcess): Add.
     21        (WebCore::isInStorageProcess): Add.
     22        (WebCore::isInWebProcess):
     23        - Make available for all platforms.
     24
     25        * platform/Timer.cpp:
     26        (WebCore::TimerBase::TimerBase): Add assert and os_log_fault.
     27        This catches the unwanted behavior on iOS using isAllowed().
     28        (WebCore::TimerBase::isAllowed): Add implementation.
     29        * platform/Timer.h:
     30        (WebCore::TimerBase::isAllowed): Add declaration.
     31
     32        * platform/cocoa/RuntimeApplicationChecksCocoa.mm:
     33        (WebCore::isInWebProcess): Delete.  Replace with method in
     34        RuntimeApplicationChecks.cpp.
     35
    1362018-07-02  Antti Koivisto  <antti@apple.com>
    237
  • trunk/Source/WebCore/platform/RuntimeApplicationChecks.cpp

    r216903 r233461  
    4747}
    4848
     49#if !PLATFORM(WIN)
     50static WebKitProcessType s_webKitProcessType { WebKitProcessType::UIProcess };
     51
     52void setWebKitProcessType(WebKitProcessType type)
     53{
     54    s_webKitProcessType = type;
     55}
     56
     57bool isInNetworkProcess()
     58{
     59    return s_webKitProcessType == WebKitProcessType::NetworkProcess;
     60}
     61
     62bool isInStorageProcess()
     63{
     64    return s_webKitProcessType == WebKitProcessType::StorageProcess;
     65}
     66
     67bool isInWebProcess()
     68{
     69    return s_webKitProcessType == WebKitProcessType::WebProcess;
     70}
     71#endif
     72
    4973int presentingApplicationPID()
    5074{
  • trunk/Source/WebCore/platform/RuntimeApplicationChecks.h

    r232969 r233461  
    3434
    3535#if PLATFORM(WIN)
     36inline bool isInNetworkProcess() { return false; }
     37inline bool isInStorageProcess() { return false; }
    3638inline bool isInWebProcess() { return false; }
    37 #elif !PLATFORM(COCOA)
    38 inline bool isInWebProcess() { return true; }
     39#else
     40enum class WebKitProcessType { UIProcess = 0, NetworkProcess, StorageProcess, WebProcess };
     41WEBCORE_EXPORT void setWebKitProcessType(WebKitProcessType);
     42bool isInNetworkProcess();
     43bool isInStorageProcess();
     44bool isInWebProcess();
    3945#endif
    4046
    4147#if PLATFORM(COCOA)
    42 
    43 bool isInWebProcess();
    4448
    4549WEBCORE_EXPORT void setApplicationBundleIdentifier(const String&);
  • trunk/Source/WebCore/platform/Timer.cpp

    r229209 r233461  
    2828#include "Timer.h"
    2929
     30#include "Logging.h"
     31#include "RuntimeApplicationChecks.h"
    3032#include "SharedTimer.h"
    3133#include "ThreadGlobalData.h"
     
    3436#include <limits>
    3537#include <math.h>
     38#include <wtf/Compiler.h>
    3639#include <wtf/MainThread.h>
    3740#include <wtf/Vector.h>
     41
     42#if USE(WEB_THREAD)
     43#include "WebCoreThread.h"
     44#endif
    3845
    3946namespace WebCore {
     
    187194TimerBase::TimerBase()
    188195{
     196#if PLATFORM(IOS)
     197    if (UNLIKELY(!isAllowed())) {
     198#define WEBCORE_TIMERBASE_ASSERTION_MESSAGE "WebCore::Timer should not be used in UI Process."
     199        ASSERT_WITH_MESSAGE(false, WEBCORE_TIMERBASE_ASSERTION_MESSAGE);
     200        RELEASE_LOG_FAULT(Threading, WEBCORE_TIMERBASE_ASSERTION_MESSAGE);
     201#undef WEBCORE_TIMERBASE_ASSERTION_MESSAGE
     202    }
     203#endif
    189204}
    190205
     
    241256    if (inHeap())
    242257        checkHeapIndex();
     258}
     259
     260bool TimerBase::isAllowed()
     261{
     262#if PLATFORM(IOS)
     263    if (isInWebProcess() || isInNetworkProcess() || isInStorageProcess())
     264        return true;
     265
     266#if USE(WEB_THREAD)
     267    if (WebThreadIsEnabled() && (WebThreadIsCurrent() || WebThreadIsLocked()))
     268        return true;
     269#endif
     270
     271    return false;
     272#else
     273    return true;
     274#endif
    243275}
    244276
  • trunk/Source/WebCore/platform/Timer.h

    r233435 r233461  
    7979    void checkHeapIndex() const;
    8080
     81    static bool isAllowed();
     82
    8183    void setNextFireTime(MonotonicTime);
    8284
  • trunk/Source/WebCore/platform/cocoa/RuntimeApplicationChecksCocoa.mm

    r233122 r233461  
    6666}
    6767
    68 bool isInWebProcess()
    69 {
    70     static bool mainBundleIsWebProcess = [[[NSBundle mainBundle] bundleIdentifier] isEqualToString:@"com.apple.WebKit.WebContent.Development"]
    71         || [[[NSBundle mainBundle] bundleIdentifier] isEqualToString:@"com.apple.WebKit.WebContent"]
    72         || [[[NSBundle mainBundle] bundleIdentifier] isEqualToString:@"com.apple.WebProcess"];
    73     return mainBundleIsWebProcess;
    74 }
    75 
    7668static bool applicationBundleIsEqualTo(const String& bundleIdentifierString)
    7769{
  • trunk/Source/WebKit/ChangeLog

    r233460 r233461  
     12018-07-03  David Kilzer  <ddkilzer@apple.com>
     2
     3        [iOS] Add assert to catch improper use of WebCore::Timer in UI Process
     4        <https://webkit.org/b/185330>
     5        <rdar://problem/32816079>
     6
     7        Reviewed by Darin Adler.
     8
     9        * NetworkProcess/NetworkProcess.cpp:
     10        (WebKit::NetworkProcess::NetworkProcess):
     11        * StorageProcess/StorageProcess.cpp:
     12        (WebKit::StorageProcess::StorageProcess):
     13        * WebProcess/WebProcess.cpp:
     14        (WebKit::m_nonVisibleProcessCleanupTimer):
     15        - Call setWebKitProcessType() to se the global for the current
     16          process.
     17
    1182018-07-03  Frederic Wang  <fred.wang@free.fr>
    219
  • trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp

    r233180 r233461  
    129129            webProcessConnection->setOnLineState(isOnLine);
    130130    });
     131
     132    WebCore::setWebKitProcessType(WebKitProcessType::NetworkProcess);
    131133}
    132134
  • trunk/Source/WebKit/StorageProcess/StorageProcess.cpp

    r232891 r233461  
    4141#include <WebCore/IDBKeyData.h>
    4242#include <WebCore/NotImplemented.h>
     43#include <WebCore/RuntimeApplicationChecks.h>
    4344#include <WebCore/SWServerWorker.h>
    4445#include <WebCore/SecurityOrigin.h>
     
    7374    // FIXME: https://bugs.webkit.org/show_bug.cgi?id=135365 - Need a more explicit way of doing this besides accessing the UTF8Encoding.
    7475    UTF8Encoding();
     76
     77    WebCore::setWebKitProcessType(WebKitProcessType::StorageProcess);
    7578}
    7679
  • trunk/Source/WebKit/WebProcess/WebProcess.cpp

    r233162 r233461  
    210210   
    211211    Gigacage::disableDisablingPrimitiveGigacageIfShouldBeEnabled();
     212
     213    WebCore::setWebKitProcessType(WebKitProcessType::WebProcess);
    212214}
    213215
Note: See TracChangeset for help on using the changeset viewer.