tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

NoNewThreadsChecker.cpp (1459B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 #include "NoNewThreadsChecker.h"
      6 #include "CustomMatchers.h"
      7 
      8 void NoNewThreadsChecker::registerMatchers(MatchFinder *AstMatcher) {
      9  // The checker looks for:
     10  // -Instances of NS_NewNamedThread that aren't in allowed files
     11  // -Instances of NS_NewNamedThread that use names that aren't recognized
     12  AstMatcher->addMatcher(
     13      callExpr(allOf(isFirstParty(),
     14                     callee(functionDecl(hasName("NS_NewNamedThread"))),
     15                     unless(isInAllowlistForThreads())))
     16          .bind("funcCall"),
     17      this);
     18 }
     19 
     20 void NoNewThreadsChecker::check(const MatchFinder::MatchResult &Result) {
     21  const CallExpr *FuncCall = Result.Nodes.getNodeAs<CallExpr>("funcCall");
     22 
     23  if (FuncCall) {
     24    diag(FuncCall->getBeginLoc(),
     25         "Thread name not recognized. Please use the background thread pool.",
     26         DiagnosticIDs::Error)
     27        << FuncCall->getDirectCallee()->getName();
     28    diag(
     29        FuncCall->getBeginLoc(),
     30        "NS_NewNamedThread has been deprecated in favor of background "
     31        "task dispatch via NS_DispatchBackgroundTask and "
     32        "NS_CreateBackgroundTaskQueue. If you must create a new ad-hoc thread, "
     33        "have your thread name added to ThreadAllows.txt.",
     34        DiagnosticIDs::Note);
     35  }
     36 }