From 35bea9cef8055d413c852d167816c1288635b48d Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Thu, 7 Nov 2024 15:51:02 +0100 Subject: tools/syz-declextract: enumerate io_uring operations --- tools/syz-declextract/syz-declextract.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'tools') diff --git a/tools/syz-declextract/syz-declextract.cpp b/tools/syz-declextract/syz-declextract.cpp index 8c08fb39c..f9b08eef5 100644 --- a/tools/syz-declextract/syz-declextract.cpp +++ b/tools/syz-declextract/syz-declextract.cpp @@ -863,6 +863,33 @@ private: } }; +class IouringMatcher : public MatchFinder::MatchCallback { +public: + IouringMatcher(MatchFinder &Finder) { + Finder.addMatcher( + translationUnitDecl(forEachDescendant( + varDecl(hasType(constantArrayType(hasElementType(hasDeclaration(recordDecl(hasName("io_issue_def")))))), + isDefinition()) + .bind("io_issue_defs"))), + this); + } + +private: + void run(const MatchFinder::MatchResult &Result) override { + const auto *ioIssueDefs = Result.Nodes.getNodeAs("io_issue_defs"); + if (!ioIssueDefs) { + return; + } + auto elements = extractDesignatedInitConsts(*Result.Context, *ioIssueDefs); + // TODO: if .prep callback is set to io_eopnotsupp_prep, the operations is not really supported. + // TODO: use the .issue callback to find the root function of the interface, + // also the file where the callback is defined is better file than io_uring/opdef.c. + for (const auto &[_, op] : elements) { + emitInterface("IOURING", op.name, op.name); + } + } +}; + int main(int argc, const char **argv) { llvm::cl::OptionCategory SyzDeclExtractOptionCategory("syz-declextract options"); auto ExpectedParser = clang::tooling::CommonOptionsParser::create(argc, argv, SyzDeclExtractOptionCategory); @@ -874,6 +901,7 @@ int main(int argc, const char **argv) { MatchFinder Finder; SyscallMatcher SyscallMatcher(Finder); NetlinkPolicyMatcher NetlinkPolicyMatcher(Finder); + IouringMatcher IouringMatcher(Finder); clang::tooling::CommonOptionsParser &OptionsParser = ExpectedParser.get(); clang::tooling::ClangTool Tool(OptionsParser.getCompilations(), OptionsParser.getSourcePathList()); -- cgit mrf-deployment