2017-08-11 06:09:22 +08:00
|
|
|
//===--- CloexecCheck.h - clang-tidy-----------------------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2017-08-11 06:09:22 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
///
|
|
|
|
/// \file
|
|
|
|
/// This file contains the declaration of the CloexecCheck class, which is the
|
|
|
|
/// base class for all of the close-on-exec checks in Android module.
|
|
|
|
///
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_H
|
|
|
|
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_H
|
|
|
|
|
2019-03-25 20:38:26 +08:00
|
|
|
#include "../ClangTidyCheck.h"
|
2017-08-11 06:09:22 +08:00
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace tidy {
|
|
|
|
namespace android {
|
|
|
|
|
Remove \brief commands from doxygen comments.
Summary:
We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.
Patch produced by
for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done
[This is analogous to LLVM r331272 and CFE r331834]
Subscribers: srhines, nemanjai, javed.absar, kbarton, MaskRay, jkorous, arphaman, jfb, kadircet, jsji, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D66578
llvm-svn: 369643
2019-08-22 19:32:57 +08:00
|
|
|
/// The base class for all close-on-exec checks in Android module.
|
2017-08-11 06:09:22 +08:00
|
|
|
/// To be specific, there are some functions that need the close-on-exec flag to
|
|
|
|
/// prevent the file descriptor leakage on fork+exec and this class provides
|
|
|
|
/// utilities to identify and fix these C functions.
|
|
|
|
class CloexecCheck : public ClangTidyCheck {
|
|
|
|
public:
|
|
|
|
CloexecCheck(StringRef Name, ClangTidyContext *Context)
|
|
|
|
: ClangTidyCheck(Name, Context) {}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void
|
|
|
|
registerMatchersImpl(ast_matchers::MatchFinder *Finder,
|
|
|
|
ast_matchers::internal::Matcher<FunctionDecl> Function);
|
|
|
|
|
|
|
|
/// Currently, we have three types of fixes.
|
|
|
|
///
|
|
|
|
/// Type1 is to insert the necessary macro flag in the flag argument. For
|
|
|
|
/// example, 'O_CLOEXEC' is required in function 'open()', so
|
|
|
|
/// \code
|
|
|
|
/// open(file, O_RDONLY);
|
|
|
|
/// \endcode
|
|
|
|
/// should be
|
|
|
|
/// \code
|
|
|
|
/// open(file, O_RDONLY | O_CLOEXE);
|
|
|
|
/// \endcode
|
|
|
|
///
|
|
|
|
/// \param [out] Result MatchResult from AST matcher.
|
|
|
|
/// \param MacroFlag The macro name of the flag.
|
|
|
|
/// \param ArgPos The 0-based position of the flag argument.
|
|
|
|
void insertMacroFlag(const ast_matchers::MatchFinder::MatchResult &Result,
|
2017-08-13 02:50:53 +08:00
|
|
|
StringRef MacroFlag, int ArgPos);
|
2017-08-11 06:09:22 +08:00
|
|
|
|
|
|
|
/// Type2 is to replace the API to another function that has required the
|
|
|
|
/// ability. For example:
|
|
|
|
/// \code
|
|
|
|
/// creat(path, mode);
|
|
|
|
/// \endcode
|
|
|
|
/// should be
|
|
|
|
/// \code
|
|
|
|
/// open(path, O_CREAT | O_WRONLY | O_TRUNC | O_CLOEXEC, mode)
|
|
|
|
/// \endcode
|
|
|
|
///
|
|
|
|
/// \param [out] Result MatchResult from AST matcher.
|
|
|
|
/// \param WarningMsg The warning message.
|
|
|
|
/// \param FixMsg The fix message.
|
|
|
|
void replaceFunc(const ast_matchers::MatchFinder::MatchResult &Result,
|
|
|
|
StringRef WarningMsg, StringRef FixMsg);
|
|
|
|
|
|
|
|
/// Type3 is also to add a flag to the corresponding argument, but this time,
|
|
|
|
/// the flag is some string and each char represents a mode rather than a
|
|
|
|
/// macro. For example, 'fopen' needs char 'e' in its mode argument string, so
|
|
|
|
/// \code
|
|
|
|
/// fopen(in_file, "r");
|
|
|
|
/// \endcode
|
|
|
|
/// should be
|
|
|
|
/// \code
|
|
|
|
/// fopen(in_file, "re");
|
|
|
|
/// \endcode
|
|
|
|
///
|
|
|
|
/// \param [out] Result MatchResult from AST matcher.
|
|
|
|
/// \param Mode The required mode char.
|
|
|
|
/// \param ArgPos The 0-based position of the flag argument.
|
|
|
|
void insertStringFlag(const ast_matchers::MatchFinder::MatchResult &Result,
|
|
|
|
const char Mode, const int ArgPos);
|
2017-08-15 01:04:16 +08:00
|
|
|
|
|
|
|
/// Helper function to get the spelling of a particular argument.
|
|
|
|
StringRef getSpellingArg(const ast_matchers::MatchFinder::MatchResult &Result,
|
|
|
|
int N) const;
|
2017-08-17 00:59:26 +08:00
|
|
|
|
|
|
|
/// Binding name of the FuncDecl of a function call.
|
2017-08-17 03:13:35 +08:00
|
|
|
static const char *FuncDeclBindingStr;
|
2017-08-17 00:59:26 +08:00
|
|
|
|
|
|
|
/// Binding name of the function call expression.
|
2017-08-17 03:13:35 +08:00
|
|
|
static const char *FuncBindingStr;
|
2017-08-11 06:09:22 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace android
|
|
|
|
} // namespace tidy
|
|
|
|
} // namespace clang
|
|
|
|
|
|
|
|
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_H
|