Static Value-Flow Analysis
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
SVF::ExtAPI Class Reference

#include <ExtAPI.h>

Public Member Functions

std::string getExtBcPath ()
 
std::string getExtFuncAnnotation (const SVFFunction *fun, const std::string &funcAnnotation)
 
const std::vector< std::string > & getExtFuncAnnotations (const SVFFunction *fun)
 
bool hasExtFuncAnnotation (const SVFFunction *fun, const std::string &funcAnnotation)
 
bool has_static (const SVFFunction *F)
 
bool is_memcpy (const SVFFunction *F)
 
bool is_memset (const SVFFunction *F)
 
bool is_alloc (const SVFFunction *F)
 
bool is_arg_alloc (const SVFFunction *F)
 
bool is_alloc_stack_ret (const SVFFunction *F)
 
s32_t get_alloc_arg_pos (const SVFFunction *F)
 
bool is_realloc (const SVFFunction *F)
 
bool is_ext (const SVFFunction *F)
 

Static Public Member Functions

static ExtAPIgetExtAPI ()
 
static void destory ()
 
static bool setExtBcPath (const std::string &path)
 

Private Member Functions

 ExtAPI ()=default
 
void setExtFuncAnnotations (const SVFFunction *fun, const std::vector< std::string > &funcAnnotations)
 

Private Attributes

Map< const SVFFunction *, std::vector< std::string > > func2Annotations
 

Static Private Attributes

static ExtAPIextOp = nullptr
 
static std::string extBcPath = ""
 

Friends

class LLVMModuleSet
 

Detailed Description

Definition at line 44 of file ExtAPI.h.

Constructor & Destructor Documentation

◆ ExtAPI()

SVF::ExtAPI::ExtAPI ( )
privatedefault

Member Function Documentation

◆ destory()

void ExtAPI::destory ( )
static

Definition at line 51 of file ExtAPI.cpp.

52{
53 if (extOp != nullptr)
54 {
55 delete extOp;
56 extOp = nullptr;
57 }
58}
static ExtAPI * extOp
Definition ExtAPI.h:49

◆ get_alloc_arg_pos()

s32_t ExtAPI::get_alloc_arg_pos ( const SVFFunction F)

Definition at line 234 of file ExtAPI.cpp.

235{
236 std::string allocArg = getExtFuncAnnotation(F, "ALLOC_HEAP_ARG");
237 assert(!allocArg.empty() && "Not an alloc call via argument or incorrect extern function annotation!");
238
239 std::string number;
240 for (char c : allocArg)
241 {
242 if (isdigit(c))
243 number.push_back(c);
244 }
245 assert(!number.empty() && "Incorrect naming convention for svf external functions(ALLOC_HEAP_ARG + number)?");
246 return std::stoi(number);
247}
#define F(f)
const char *const const double number
Definition cJSON.h:268
std::string getExtFuncAnnotation(const SVFFunction *fun, const std::string &funcAnnotation)
Definition ExtAPI.cpp:183
int isdigit(int c)
Definition extapi.c:851
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:74

◆ getExtAPI()

ExtAPI * ExtAPI::getExtAPI ( )
static

Definition at line 42 of file ExtAPI.cpp.

43{
44 if (extOp == nullptr)
45 {
46 extOp = new ExtAPI;
47 }
48 return extOp;
49}
ExtAPI()=default

◆ getExtBcPath()

std::string ExtAPI::getExtBcPath ( )

Definition at line 119 of file ExtAPI.cpp.

120{
121 // Default ways of retrieving extapi.bc (in order of precedence):
122 // 1. Set `path/to/extapi.bc` through `setExtBcPath()`
123 // 2. Set `path/to/extapi.bc` through the command line argument `-extapi=path/to/extapi.bc`
124 // 3. Get location generated by CMakeLists.txt from `config.h` header file (if SVF was installed)
125 // 4. Get location in build tree based from `config.h` header file (if SVF was only built)
126 // 5. Get location based on environment variable $ENV{SVF_DIR}
127 // 6. Search for `extapi.bc` from root directory for npm installation (iff SVF installed through npm)
128
129 // 1. Set `path/to/extapi.bc` through `setExtBcPath()`
130 if (!extBcPath.empty())
131 return extBcPath;
132
133 // 2. Set `path/to/extapi.bc` through the command line argument `-extapi=path/to/extapi.bc`
135 return extBcPath;
136
137 // 3. Get location generated by CMakeLists.txt from `config.h` header file (if SVF was installed)
138 if (setExtBcPath(SVF_EXTAPI_BC)) // Full path is available (for custom file names)
139 return extBcPath;
140 if (setExtBcPath(SVF_EXTAPI_DIR "/extapi.bc")) // Based on directory & default filename
141 return extBcPath;
142
143 // 4. Get location in build tree based from `config.h` header file (if SVF was only built)
144 if (setExtBcPath(SVF_BUILD_DIR "/lib/extapi.bc"))
145 return extBcPath;
146
147 // 5. Get location based on environment variable $ENV{SVF_DIR}
148 if (setExtBcPath(getFilePath("SVF_DIR")))
149 return extBcPath;
150
151 // 6. Search for `extapi.bc` from root directory for npm installation (iff SVF installed through npm)
152 if (setExtBcPath(getFilePath("npm root")))
153 return extBcPath;
154
155 SVFUtil::errs() << "ERROR: Failed to find \"extapi.bc\" LLVM bitcode file in " << extBcPath << std::endl
156 << "To override the default locations for \"extapi.bc\", you can:" << std::endl
157 << "\t1. Use the command line argument \"-extapi=path/to/extapi.bc\"" << std::endl
158 << "\t2. Use the \"setExtBcPath()\" function *BEFORE* calling \"buildSVFModule()\"" << std::endl
159 << "\t3. Override the paths in \"svf/Util/config.h\" (WARNING: will be overwritten when "
160 << "rebuilding SVF (generated by CMakeLists.txt))" << std::endl;
161 abort();
162}
static std::string getFilePath(const std::string &path)
Definition ExtAPI.cpp:97
static std::string extBcPath
Definition ExtAPI.h:55
static bool setExtBcPath(const std::string &path)
Definition ExtAPI.cpp:61
static const Option< std::string > ExtAPIPath
Definition Options.h:220
std::ostream & errs()
Overwrite llvm::errs()
Definition SVFUtil.h:56

◆ getExtFuncAnnotation()

std::string ExtAPI::getExtFuncAnnotation ( const SVFFunction fun,
const std::string &  funcAnnotation 
)

Definition at line 183 of file ExtAPI.cpp.

184{
185 assert(fun && "Null SVFFunction* pointer");
186 auto it = func2Annotations.find(fun);
187 if (it != func2Annotations.end())
188 {
189 for (const std::string& annotation : it->second)
190 if (annotation.find(funcAnnotation) != std::string::npos)
192 }
193 return "";
194}
if(prebuffer< 0)
Definition cJSON.cpp:1269
return(char *) p.buffer
const char *const string
Definition cJSON.h:172
Map< const SVFFunction *, std::vector< std::string > > func2Annotations
Definition ExtAPI.h:52

◆ getExtFuncAnnotations()

const std::vector< std::string > & ExtAPI::getExtFuncAnnotations ( const SVFFunction fun)

Definition at line 196 of file ExtAPI.cpp.

197{
198 assert(fun && "Null SVFFunction* pointer");
199 auto it = func2Annotations.find(fun);
200 if (it != func2Annotations.end())
201 return it->second;
202 return func2Annotations[fun];
203}

◆ has_static()

bool SVF::ExtAPI::has_static ( const SVFFunction F)

◆ hasExtFuncAnnotation()

bool ExtAPI::hasExtFuncAnnotation ( const SVFFunction fun,
const std::string &  funcAnnotation 
)

Definition at line 170 of file ExtAPI.cpp.

171{
172 assert(fun && "Null SVFFunction* pointer");
173 auto it = func2Annotations.find(fun);
174 if (it != func2Annotations.end())
175 {
176 for (const std::string& annotation : it->second)
177 if (annotation.find(funcAnnotation) != std::string::npos)
178 return true;
179 }
180 return false;
181}
#define true
Definition cJSON.cpp:65

◆ is_alloc()

bool ExtAPI::is_alloc ( const SVFFunction F)

Definition at line 217 of file ExtAPI.cpp.

218{
219 return F && hasExtFuncAnnotation(F, "ALLOC_HEAP_RET");
220}
bool hasExtFuncAnnotation(const SVFFunction *fun, const std::string &funcAnnotation)
Definition ExtAPI.cpp:170

◆ is_alloc_stack_ret()

bool ExtAPI::is_alloc_stack_ret ( const SVFFunction F)

Definition at line 228 of file ExtAPI.cpp.

229{
230 return F && hasExtFuncAnnotation(F, "ALLOC_STACK_RET");
231}

◆ is_arg_alloc()

bool ExtAPI::is_arg_alloc ( const SVFFunction F)

Definition at line 223 of file ExtAPI.cpp.

224{
225 return F && hasExtFuncAnnotation(F, "ALLOC_HEAP_ARG");
226}

◆ is_ext()

bool ExtAPI::is_ext ( const SVFFunction F)

Definition at line 258 of file ExtAPI.cpp.

259{
260 assert(F && "Null SVFFunction* pointer");
261 if (F->isDeclaration() || F->isIntrinsic())
262 return true;
263 else if (hasExtFuncAnnotation(F, "OVERWRITE") && getExtFuncAnnotations(F).size() == 1)
264 return false;
265 else
266 return !getExtFuncAnnotations(F).empty();
267}
const std::vector< std::string > & getExtFuncAnnotations(const SVFFunction *fun)
Definition ExtAPI.cpp:196

◆ is_memcpy()

bool ExtAPI::is_memcpy ( const SVFFunction F)

Definition at line 205 of file ExtAPI.cpp.

206{
207 return F &&
208 (hasExtFuncAnnotation(F, "MEMCPY") || hasExtFuncAnnotation(F, "STRCPY")
209 || hasExtFuncAnnotation(F, "STRCAT"));
210}

◆ is_memset()

bool ExtAPI::is_memset ( const SVFFunction F)

Definition at line 212 of file ExtAPI.cpp.

213{
214 return F && hasExtFuncAnnotation(F, "MEMSET");
215}

◆ is_realloc()

bool ExtAPI::is_realloc ( const SVFFunction F)

Definition at line 250 of file ExtAPI.cpp.

251{
252 return F && hasExtFuncAnnotation(F, "REALLOC_HEAP_RET");
253}

◆ setExtBcPath()

bool ExtAPI::setExtBcPath ( const std::string &  path)
static

Definition at line 61 of file ExtAPI.cpp.

62{
63 struct stat statbuf;
64 if (!path.empty() && !stat(path.c_str(), &statbuf))
65 {
67 return true;
68 }
69 return false;
70}

◆ setExtFuncAnnotations()

void ExtAPI::setExtFuncAnnotations ( const SVFFunction fun,
const std::vector< std::string > &  funcAnnotations 
)
private

Definition at line 164 of file ExtAPI.cpp.

165{
166 assert(fun && "Null SVFFunction* pointer");
168}

Friends And Related Symbol Documentation

◆ LLVMModuleSet

Definition at line 46 of file ExtAPI.h.

Member Data Documentation

◆ extBcPath

std::string ExtAPI::extBcPath = ""
staticprivate

Definition at line 55 of file ExtAPI.h.

◆ extOp

ExtAPI * ExtAPI::extOp = nullptr
staticprivate

Definition at line 49 of file ExtAPI.h.

◆ func2Annotations

Map<const SVFFunction*, std::vector<std::string> > SVF::ExtAPI::func2Annotations
private

Definition at line 52 of file ExtAPI.h.


The documentation for this class was generated from the following files: