ClearBlue
SailfishChecker.h
1 //
2 // Created by yongchao on 12/20/22.
3 //
4 
5 #ifndef CLEARBLUE_YAPSACHECKER_H
6 #define CLEARBLUE_YAPSACHECKER_H
7 
8 #include <map>
9 #include <set>
10 
11 #include "Analysis/Bitcode/TSDataLayout.h"
12 #include "Analysis/CFG/CFGReachabilityAnalysis.h"
13 #include "Analysis/GVFA/NullPtrAnalysis.h"
14 #include "Analysis/Graph/DomTreePass.h"
15 #include "Analysis/TypeInference/TypeInference.h"
16 #include "Checker/PSA/PSAChecker.h"
17 #include "Checker/PSA/SymbolicSummary.h"
18 #include "Checker/PSA/TraceSummary.h"
19 #include "Checker/Sailfish/BotUpParallelPass.h"
20 #include "Checker/Sailfish/SummaryMapper.h"
21 #include "IR/SEG/SymbolicExprGraph.h"
22 #include "IR/SEG/SymbolicExprGraphBuilder.h"
23 #include "Report/BugReport/Reporter.h"
24 
25 typedef struct StatisticsEntry {
26  StringRef FunctionName;
27  StringRef TaskName;
28  size_t NumStartedPoints;
29  size_t NumProducedSummaries;
30  size_t RunningTime;
31 
32  StatisticsEntry(StringRef FN, StringRef TN, size_t NSP, size_t NPS, size_t RT)
33  : FunctionName(FN), TaskName(TN), NumStartedPoints(NSP),
34  NumProducedSummaries(NPS), RunningTime(RT) {}
36 
37 typedef struct ParallelThreadLocal {
38  std::vector<std::pair<int, std::shared_ptr<VulnerabilityTrace>>> VulnTraces;
39  std::vector<StatisticsEntry> Statistics;
41 
42 class SailfishChecker : public BotUpParallelPass, Reporter {
43  friend class SailfishFunctionChecker;
44 
45 private:
46  // SymbolicExprGraphBuilder *SEGBuilder = nullptr;
47  DomTreePass *DTP = nullptr;
48  // CBCallGraph *CG = nullptr;
49  NullPtrAnalysis *NPA = nullptr;
50  CFGReachabilityAnalysis *CRA = nullptr;
51  TSDataLayout *TDL = nullptr;
52  ExternalMemorySpec *MemSepc = nullptr;
53  ExternalIOSpec *IOSpec = nullptr;
54  ExternalTaintSpec *TaintSpec = nullptr;
55 
56  DebugInfoAnalysis *DIA = nullptr;
57  InstResolver *IResolver = nullptr;
58  ControlDependenceAnalysis *CDGs = nullptr;
59  TypeInference *Infer = nullptr;
60 
63  SMTAdvisor4Inlining SMTAdvisor;
64 
66  std::map<const Function *, SailfishSummary *> FuncSummaryMap;
67 
69  std::shared_ptr<VulnerabilityWrapper> Vuln;
70 
71 public:
72  static char ID;
74  virtual ~SailfishChecker();
75 
76 public:
77  /*==- interfaces extended from BotUpParallelPass -==*/
78 
79  virtual void getAnalysisUsage(AnalysisUsage &AU) const override;
80 
81  virtual bool runOnModule(Module &M) override;
82 
83  virtual bool internallyDepends(unsigned TaskAID, unsigned TaskBID) override;
84 
85  virtual bool externallyDepends(unsigned CallerTaskID,
86  unsigned CalleeTaskID) override;
87 
88  virtual bool runOnFunction(Function &F) override;
89 
90  virtual bool runOnFunction(Function &F, unsigned TaskID) override;
91 
92  virtual bool releaseMemory(Function &F) override;
93 
94  virtual std::string getName() { return "PSA-PPL"; }
95 
96  virtual SymbolicExprGraphBuilder *getSEGs() override { return SEGBuilder; }
97 
98  virtual CBCallGraph *getCG() override { return CG; }
99 
100  virtual DomTreePass *getDTP() override { return DTP; }
101 
102  virtual TSDataLayout *getDL() override { return TDL; };
103 
104  virtual DebugInfoAnalysis *getDIA() override { return DIA; };
105 
106  ExternalMemorySpec *getMemSpec() override { return MemSepc; };
107 
108  ExternalIOSpec *getIOSpec() override { return IOSpec; };
109 
110  ExternalTaintSpec *getTaintSpec() override { return TaintSpec; };
111 
112 private:
113  bool initialization(Module &);
114 
115  bool finalization(Module &);
116 
117  bool releaseMemory4Summary(SailfishSummary *Summary);
118 
119  void buildVFFromRet(Function &F);
120 
121  void buildVFFromParam(Function &F);
122 
123  void buildVFFromErSrc(Function &F);
124 
125  void buildVFFromSrcWp(Function &F);
126 
127  void buildVFFromCSOut(Function &F);
128 };
129 
130 #endif // CLEARBLUE_YAPSACHECKER_H
BotUpParallelPass
Definition: BotUpParallelPass.h:187
SymbolicExprGraphBuilder
Definition: SymbolicExprGraphBuilder.h:39
SailfishChecker::internallyDepends
virtual bool internallyDepends(unsigned TaskAID, unsigned TaskBID) override
Definition: SailfishChecker.cpp:226
StatisticsEntry
Definition: SailfishChecker.h:25
SailfishChecker::externallyDepends
virtual bool externallyDepends(unsigned CallerTaskID, unsigned CalleeTaskID) override
Definition: SailfishChecker.cpp:234
SailfishChecker::releaseMemory
virtual bool releaseMemory(Function &F) override
Definition: SailfishChecker.cpp:249
SailfishChecker
Definition: SailfishChecker.h:42
SailfishFunctionChecker
Definition: SailfishFunctionChecker.h:22
ParallelThreadLocal
Definition: SailfishChecker.h:37
SailfishFunctionChecker::F
Function * F
current function
Definition: SailfishFunctionChecker.h:28
SailfishSummary
Various summaries generated for each function in pipelined PSA checker.
Definition: SummaryMapper.h:19