diff --git a/build/clang-plugin/CustomMatchers.h b/build/clang-plugin/CustomMatchers.h index 5a74c155707b..ece717e79918 100644 --- a/build/clang-plugin/CustomMatchers.h +++ b/build/clang-plugin/CustomMatchers.h @@ -194,17 +194,34 @@ AST_MATCHER(CallExpr, isInWhiteListForPrincipalGetUri) { /// code or names of existing threads that we would like to ignore. AST_MATCHER(CallExpr, isInAllowlistForThreads) { - // Get the source location of the call + // Get the source location of the call. SourceLocation Loc = Node.getRParenLoc(); StringRef FileName = getFilename(Finder->getASTContext().getSourceManager(), Loc); + + const auto rbegin = [](StringRef s) { return llvm::sys::path::rbegin(s); }; + const auto rend = [](StringRef s) { return llvm::sys::path::rend(s); }; + + // Files in the allowlist are (definitionally) explicitly permitted to create + // new threads. for (auto thread_file : allow_thread_files) { - if (llvm::sys::path::rbegin(FileName)->equals(thread_file)) { + // All the provided path-elements must match. + const bool match = [&] { + auto it1 = rbegin(FileName), it2 = rbegin(thread_file), + end1 = rend(FileName), end2 = rend(thread_file); + for (; it2 != end2; ++it1, ++it2) { + if (it1 == end1 || !it1->equals(*it2)) { + return false; + } + } + return true; + }(); + if (match) { return true; } } - // Now we get the first arg (the name of the thread) and we check it. + // Check the first arg (the name of the thread). const StringLiteral *nameArg = dyn_cast(Node.getArg(0)->IgnoreImplicit()); if (nameArg) { diff --git a/build/clang-plugin/ThreadFileAllows.txt b/build/clang-plugin/ThreadFileAllows.txt index dcdb218ca761..ed51dbd4cfd8 100644 --- a/build/clang-plugin/ThreadFileAllows.txt +++ b/build/clang-plugin/ThreadFileAllows.txt @@ -1,18 +1,23 @@ # This file is ingested by `ThreadAllows.py` to produce a list of files which # our clang plugin will allow to use `NS_NewNamedThread`. # -# Note that this file contains a list of _files_, not _paths_. +# Files may be specified with any number of slash-separated path-elements; all +# provided path-elements must match. (Because we often move and/or symlink +# header files, this means headers will usually have no path-elements.) +# +# Note that this file contains a list of _files_, not _paths_. The clang plugin +# has no notion of $TOPSRCDIR. ###### # Release files # declaration and definition of `NS_NewNamedThread` nsThreadUtils.h -nsThreadUtils.cpp +xpcom/threads/nsThreadUtils.cpp # Thread-pools are permitted to make dynamically many threads, using dynamic # thread names with explicit numbering. -nsThreadPool.cpp +xpcom/threads/nsThreadPool.cpp ###### # Unsorted files @@ -20,7 +25,8 @@ nsThreadPool.cpp # Files below this point are grandfathered in. Please do not add new files to # this list -- and please remove any that you can, whether by documenting and # moving them or by confirming that they are no longer required. -ActorsParent.cpp +dom/indexedDB/ActorsParent.cpp +dom/quota/ActorsParent.cpp DecodePool.cpp GeckoChildProcessHost.cpp LazyIdleThread.cpp