klee
SpecialFunctionHandler.h
Go to the documentation of this file.
1//===-- SpecialFunctionHandler.h --------------------------------*- C++ -*-===//
2//
3// The KLEE Symbolic Virtual Machine
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef KLEE_SPECIALFUNCTIONHANDLER_H
11#define KLEE_SPECIALFUNCTIONHANDLER_H
12
13#include "klee/Config/config.h"
14
15#include <iterator>
16#include <map>
17#include <vector>
18#include <string>
19
20namespace llvm {
21 class Function;
22}
23
24namespace klee {
25 class Executor;
26 class Expr;
27 class ExecutionState;
28 struct KInstruction;
29 template<typename T> class ref;
30
32 public:
34 KInstruction *target,
35 std::vector<ref<Expr> >
36 &arguments);
37 typedef std::map<const llvm::Function*,
38 std::pair<Handler,bool> > handlers_ty;
39
42
43 struct HandlerInfo {
44 const char *name;
49 };
50
51 // const_iterator to iterate over stored HandlerInfo
52 // FIXME: Implement >, >=, <=, < operators
53 class const_iterator : public std::iterator<std::random_access_iterator_tag, HandlerInfo>
54 {
55 private:
56 value_type* base;
57 int index;
58 public:
59 const_iterator(value_type* hi) : base(hi), index(0) {};
60 const_iterator& operator++(); // pre-fix
61 const_iterator operator++(int); // post-fix
62 const value_type& operator*() { return base[index];}
63 const value_type* operator->() { return &(base[index]);}
64 const value_type& operator[](int i) { return base[i];}
65 bool operator==(const_iterator& rhs) { return (rhs.base + rhs.index) == (this->base + this->index);}
66 bool operator!=(const_iterator& rhs) { return !(*this == rhs);}
67 };
68
69 static const_iterator begin();
70 static const_iterator end();
71 static int size();
72
73
74
75 public:
77
85 void prepare(std::vector<const char *> &preservedFunctions);
86
89 void bind();
90
91 bool handle(ExecutionState &state,
92 llvm::Function *f,
93 KInstruction *target,
94 std::vector< ref<Expr> > &arguments);
95
96 /* Convenience routines */
97
98 std::string readStringAtAddress(ExecutionState &state, ref<Expr> address);
99
100 /* Handlers */
101
102#define HANDLER(name) void name(ExecutionState &state, \
103 KInstruction *target, \
104 std::vector< ref<Expr> > &arguments)
105 HANDLER(handleAbort);
106 HANDLER(handleAssert);
107 HANDLER(handleAssertFail);
108 HANDLER(handleAssume);
109 HANDLER(handleCalloc);
110 HANDLER(handleCheckMemoryAccess);
111 HANDLER(handleDefineFixedObject);
112 HANDLER(handleDelete);
113 HANDLER(handleDeleteArray);
114#ifdef SUPPORT_KLEE_EH_CXX
115 HANDLER(handleEhUnwindRaiseExceptionImpl);
116 HANDLER(handleEhTypeid);
117#endif
118 HANDLER(handleErrnoLocation);
119 HANDLER(handleExit);
120 HANDLER(handleFree);
121 HANDLER(handleGetErrno);
122 HANDLER(handleGetObjSize);
123 HANDLER(handleGetValue);
124 HANDLER(handleIsSymbolic);
125 HANDLER(handleMakeSymbolic);
126 HANDLER(handleMalloc);
127 HANDLER(handleMemalign);
128 HANDLER(handleMarkGlobal);
129 HANDLER(handleOpenMerge);
130 HANDLER(handleCloseMerge);
131 HANDLER(handleNew);
132 HANDLER(handleNewArray);
133 HANDLER(handlePreferCex);
134 HANDLER(handlePosixPreferCex);
135 HANDLER(handlePrintExpr);
136 HANDLER(handlePrintRange);
137 HANDLER(handleRange);
138 HANDLER(handleRealloc);
139 HANDLER(handleReportError);
140 HANDLER(handleRevirtObjects);
141 HANDLER(handleSetForking);
142 HANDLER(handleSilentExit);
143 HANDLER(handleStackTrace);
144 HANDLER(handleUnderConstrained);
145 HANDLER(handleWarning);
146 HANDLER(handleWarningOnce);
147 HANDLER(handleAddOverflow);
148 HANDLER(handleMulOverflow);
149 HANDLER(handleSubOverflow);
150 HANDLER(handleDivRemOverflow);
151#undef HANDLER
152 };
153} // End klee namespace
154
155#endif /* KLEE_SPECIALFUNCTIONHANDLER_H */
#define Expr
Definition: STPBuilder.h:19
ExecutionState representing a path under exploration.
void(SpecialFunctionHandler::* Handler)(ExecutionState &state, KInstruction *target, std::vector< ref< Expr > > &arguments)
HANDLER(handleErrnoLocation)
HANDLER(handlePosixPreferCex)
HANDLER(handleMakeSymbolic)
HANDLER(handleSubOverflow)
HANDLER(handleSetForking)
HANDLER(handleStackTrace)
HANDLER(handleCheckMemoryAccess)
HANDLER(handleDeleteArray)
HANDLER(handleAddOverflow)
HANDLER(handleRevirtObjects)
HANDLER(handleCloseMerge)
HANDLER(handleWarningOnce)
HANDLER(handleSilentExit)
HANDLER(handleDivRemOverflow)
HANDLER(handlePrintRange)
HANDLER(handleUnderConstrained)
std::string readStringAtAddress(ExecutionState &state, ref< Expr > address)
HANDLER(handleReportError)
HANDLER(handleMarkGlobal)
HANDLER(handleIsSymbolic)
std::map< const llvm::Function *, std::pair< Handler, bool > > handlers_ty
SpecialFunctionHandler(Executor &_executor)
HANDLER(handleMulOverflow)
HANDLER(handleGetObjSize)
bool handle(ExecutionState &state, llvm::Function *f, KInstruction *target, std::vector< ref< Expr > > &arguments)
HANDLER(handleAssertFail)
HANDLER(handleDefineFixedObject)
void prepare(std::vector< const char * > &preservedFunctions)
Definition: main.cpp:291
bool hasReturnValue
Intrinsic terminates the process.
bool doNotOverride
Intrinsic has a return value.