Static Value-Flow Analysis
ExtAPI.h
Go to the documentation of this file.
1 //===- ExtAPI.h -- External functions -----------------------------------------//
2 //
3 // SVF: Static Value-Flow Analysis
4 //
5 // Copyright (C) <2013-2017> <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  * ExtAPI.h
25  *
26  * Created on: July 1, 2022
27  * Author: Shuangxiang Kan
28  */
29 
30 #ifndef __ExtAPI_H
31 #define __ExtAPI_H
32 
33 #include "SVFIR/SVFValue.h"
34 #include <Util/config.h>
35 #include <string>
36 #include <vector>
37 #include <map>
38 
40 
41 namespace SVF
42 {
43 
44 class ExtAPI
45 {
46  friend class LLVMModuleSet;
47 private:
48 
49  static ExtAPI *extOp;
50 
51  // Map SVFFunction to its annotations
53 
54  // extapi.bc file path
56 
57  ExtAPI() = default;
58 
59 public:
60 
61  static ExtAPI *getExtAPI();
62 
63  static void destory();
64 
65  // Set extapi.bc file path
66  static bool setExtBcPath(const std::string& path);
67 
68  // Get extapi.bc file path
70 
71  // Get the annotation of (F)
72  std::string getExtFuncAnnotation(const SVFFunction* fun, const std::string& funcAnnotation);
73 
74  const std::vector<std::string>& getExtFuncAnnotations(const SVFFunction* fun);
75 
76  // Does (F) have some annotation?
77  bool hasExtFuncAnnotation(const SVFFunction* fun, const std::string& funcAnnotation);
78 
79  // Does (F) have a static var X (unavailable to us) that its return points to?
80  bool has_static(const SVFFunction *F);
81 
82  // Does (F) have a memcpy_like operation?
83  bool is_memcpy(const SVFFunction *F);
84 
85  // Does (F) have a memset_like operation?
86  bool is_memset(const SVFFunction *F);
87 
88  // Does (F) allocate a new object and return it?
89  bool is_alloc(const SVFFunction *F);
90 
91  // Does (F) allocate a new object and assign it to one of its arguments?
92  bool is_arg_alloc(const SVFFunction *F);
93 
94  // Get the position of argument which holds the new object
96 
97  // Does (F) reallocate a new object?
98  bool is_realloc(const SVFFunction *F);
99 
100  // Should (F) be considered "external" (either not defined in the program
101  // or a user-defined version of a known alloc or no-op)?
102  bool is_ext(const SVFFunction *F);
103 
104 private:
105  // Set the annotation of (F)
106  void setExtFuncAnnotations(const SVFFunction* fun, const std::vector<std::string>& funcAnnotations);
107 };
108 } // End namespace SVF
109 
110 #endif
#define F(f)
const char *const string
Definition: cJSON.h:172
bool is_alloc(const SVFFunction *F)
Definition: ExtAPI.cpp:217
bool is_arg_alloc(const SVFFunction *F)
Definition: ExtAPI.cpp:223
bool hasExtFuncAnnotation(const SVFFunction *fun, const std::string &funcAnnotation)
Definition: ExtAPI.cpp:170
bool is_ext(const SVFFunction *F)
Definition: ExtAPI.cpp:253
std::string getExtBcPath()
Definition: ExtAPI.cpp:119
const std::vector< std::string > & getExtFuncAnnotations(const SVFFunction *fun)
Definition: ExtAPI.cpp:196
static std::string extBcPath
Definition: ExtAPI.h:55
static ExtAPI * extOp
Definition: ExtAPI.h:49
static ExtAPI * getExtAPI()
Definition: ExtAPI.cpp:42
std::string getExtFuncAnnotation(const SVFFunction *fun, const std::string &funcAnnotation)
Definition: ExtAPI.cpp:183
s32_t get_alloc_arg_pos(const SVFFunction *F)
Definition: ExtAPI.cpp:229
Map< const SVFFunction *, std::vector< std::string > > func2Annotations
Definition: ExtAPI.h:52
bool has_static(const SVFFunction *F)
bool is_memset(const SVFFunction *F)
Definition: ExtAPI.cpp:212
bool is_memcpy(const SVFFunction *F)
Definition: ExtAPI.cpp:205
ExtAPI()=default
static void destory()
Definition: ExtAPI.cpp:51
static bool setExtBcPath(const std::string &path)
Definition: ExtAPI.cpp:61
bool is_realloc(const SVFFunction *F)
Definition: ExtAPI.cpp:245
void setExtFuncAnnotations(const SVFFunction *fun, const std::vector< std::string > &funcAnnotations)
Definition: ExtAPI.cpp:164
for isBitcode
Definition: BasicTypes.h:68
std::unordered_map< Key, Value, Hash, KeyEqual, Allocator > Map
Definition: GeneralType.h:101
signed s32_t
Definition: GeneralType.h:47