Bug 1791682 - [2/3] Allow multiple path-elements in ThreadFileAllows.txt r=andi

Filenames alone do not uniquely identify files in the Mozilla codebase.
Allow specification of path-elements alongside filenames.

Differential Revision: https://phabricator.services.mozilla.com/D157761
This commit is contained in:
Ray Kraesig 2022-09-30 00:11:22 +00:00
Родитель 99f55ae3f2
Коммит 55dd66f10d
2 изменённых файлов: 30 добавлений и 7 удалений

Просмотреть файл

@ -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<StringLiteral>(Node.getArg(0)->IgnoreImplicit());
if (nameArg) {

Просмотреть файл

@ -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