Static Value-Flow Analysis
Loading...
Searching...
No Matches
SaberCheckerAPI.h
Go to the documentation of this file.
1//===- SaberCheckerAPI.h -- API for checkers in Saber-------------------------//
2//
3// SVF: Static Value-Flow Analysis
4//
5// Copyright (C) <2013-> <Yulei Sui>
6//
7
8// This program is free software: you can redistribute it and/or modify
9// it under the terms of the GNU Affero General Public License as published by
10// the Free Software Foundation, either version 3 of the License, or
11// (at your option) any later version.
12
13// This program is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16// GNU Affero General Public License for more details.
17
18// You should have received a copy of the GNU Affero General Public License
19// along with this program. If not, see <http://www.gnu.org/licenses/>.
20//
21//===----------------------------------------------------------------------===//
22
23/*
24 * SaberCheckerAPI.h
25 *
26 * Created on: Apr 23, 2014
27 * Author: Yulei Sui
28 */
29
30#ifndef SABERCHECKERAPI_H_
31#define SABERCHECKERAPI_H_
32
33#include "Util/SVFUtil.h"
34#include "Graphs/ICFGNode.h"
35
36namespace SVF
37{
38
39/*
40 * Saber Checker API class contains interfaces for various bug checking
41 * memory leak detection e.g., alloc free
42 * incorrect file operation detection, e.g., fopen, fclose
43 */
45{
46
47public:
56
58
59private:
62
65 {
66 init();
67 }
68
70 void init();
71
74
76 inline CHECKER_TYPE getType(const SVFFunction* F) const
77 {
78 if(F)
79 {
80 TDAPIMap::const_iterator it= tdAPIMap.find(F->getName());
81 if(it != tdAPIMap.end())
82 return it->second;
83 }
84 return CK_DUMMY;
85 }
86
87public:
90 {
91 if(ckAPI == nullptr)
92 {
93 ckAPI = new SaberCheckerAPI();
94 }
95 return ckAPI;
96 }
97
99
100 inline bool isMemAlloc(const SVFFunction* fun) const
101 {
102 return getType(fun) == CK_ALLOC;
103 }
104 inline bool isMemAlloc(const CallICFGNode* cs) const
105 {
106 return isMemAlloc(cs->getCalledFunction());
107 }
109
111
112 inline bool isMemDealloc(const SVFFunction* fun) const
113 {
114 return getType(fun) == CK_FREE;
115 }
116 inline bool isMemDealloc(const CallICFGNode* cs) const
117 {
118 return isMemDealloc(cs->getCalledFunction());
119 }
121
123
124 inline bool isFOpen(const SVFFunction* fun) const
125 {
126 return getType(fun) == CK_FOPEN;
127 }
128 inline bool isFOpen(const CallICFGNode* cs) const
129 {
130 return isFOpen(cs->getCalledFunction());
131 }
133
135
136 inline bool isFClose(const SVFFunction* fun) const
137 {
138 return getType(fun) == CK_FCLOSE;
139 }
140 inline bool isFClose(const CallICFGNode* cs) const
141 {
142 return isFClose(cs->getCalledFunction());
143 }
145
146};
147
148} // End namespace SVF
149
150#endif /* SABERCHECKERAPI_H_ */
#define F(f)
const SVFFunction * getCalledFunction() const
Definition ICFGNode.h:518
bool isFOpen(const SVFFunction *fun) const
Return true if this call is a file open.
@ CK_FREE
memory allocation
@ CK_FOPEN
memory deallocation
static SaberCheckerAPI * ckAPI
Static reference.
bool isFClose(const CallICFGNode *cs) const
void init()
Initialize the map.
bool isFOpen(const CallICFGNode *cs) const
TDAPIMap tdAPIMap
API map, from a string to threadAPI type.
bool isMemDealloc(const CallICFGNode *cs) const
bool isMemAlloc(const SVFFunction *fun) const
Return true if this call is a memory allocation.
Map< std::string, CHECKER_TYPE > TDAPIMap
bool isFClose(const SVFFunction *fun) const
Return true if this call is a file close.
CHECKER_TYPE getType(const SVFFunction *F) const
Get the function type of a function.
bool isMemDealloc(const SVFFunction *fun) const
Return true if this call is a memory deallocation.
bool isMemAlloc(const CallICFGNode *cs) const
SaberCheckerAPI()
Constructor.
static SaberCheckerAPI * getCheckerAPI()
Return a static reference.
for isBitcode
Definition BasicTypes.h:68
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:74