#ifndef MAGIC_PASS_H #define MAGIC_PASS_H #include #include #include #include #include #include #include #include #if MAGIC_USE_QPROF_INSTRUMENTATION #include #endif using namespace llvm; namespace llvm { #define magicPassLog(M) DEBUG(dbgs() << "MagicPass: " << M << "\n") #define magicPassErr(M) errs() << "MagicPass: " << M << "\n" class MagicPass : public ModulePass { public: static char ID; MagicPass(); std::vector getGlobalVariables() const; std::vector getGlobalVariableSizes() const; std::vector getShadowGlobalVariables() const; std::vector getFunctions() const; GlobalVariable* getMagicArray() const; GlobalVariable* getMagicTypeArray() const; GlobalVariable* getMagicFunctionArray() const; GlobalVariable* getMagicDsindexArray() const; virtual bool runOnModule(Module &M); private: std::vector globalVariables; std::set globalVariablesWithAddressTaken; std::vector globalVariableSizes; std::vector shadowGlobalVariables; std::vector functions; std::vector globalTypeInfos; std::map globalParentMap; std::map::iterator parentMapIt; std::map stringOwnerMap; std::map::iterator stringOwnerMapIt; std::map stringOwnerInvertedMap; std::map::iterator stringOwnerInvertedMapIt; GlobalVariable* magicArray; GlobalVariable* magicTypeArray; GlobalVariable* magicFunctionArray; GlobalVariable* magicDsindexArray; std::vector libPathRegexes; std::vector voidTypeAliases; std::set voidTypeAliasesSet; std::vector mmFuncPrefixes; std::set > mmFuncPairs; std::vector mmPoolFunctions; std::vector mmapCtlFunctions; std::set::iterator stringSetIt; std::set brkFunctions; std::set sbrkFunctions; std::vector magicDataSectionRegexes; std::vector magicFunctionSectionRegexes; std::vector extLibSectionRegexes; #if MAGIC_USE_QPROF_INSTRUMENTATION QProfConf *qprofConf; #endif void qprofInstrumentationInit(Module &M); void qprofInstrumentationApply(Module &M); bool checkPointerVariableIndexes(TYPECONST Type* type, std::vector &ptrVarIndexes, unsigned offset=0); void findPointerVariables(Function* function, Value *value, std::vector &ptrVars, std::vector > &ptrVarIndexes, Value *parent = NULL, bool isUser=false); TypeInfo* typeInfoFromPointerVariables(Module &M, TypeInfo *voidPtrTypeInfo, std::vector &ptrVars, std::vector > &ptrVarIndexes, std::string &allocName); TypeInfo* getAllocTypeInfo(Module &M, TypeInfo *voidPtrTypeInfo, const CallSite &CS, std::string &allocName, std::string &allocParentName); TypeInfo* fillTypeInfos(TypeInfo &sourceTypeInfo, std::vector &typeInfos); TypeInfo* fillExternalTypeInfos(TYPECONST Type* sourceType, GlobalValue *parent, std::vector &typeInfos); void printInterestingTypes(TYPECONST TypeInfo *aTypeInfo); unsigned getMaxRecursiveSequenceLength(TYPECONST TypeInfo *aTypeInfo); FunctionType* getFunctionType(TYPECONST FunctionType *baseType, std::vector selectedArgs); bool isCompatibleMagicMemFuncType(TYPECONST FunctionType *type, TYPECONST FunctionType* magicType); Function* findWrapper(Module &M, std::string *magicMemPrefixes, Function *f, std::string fName); void indexCasts(Module &M, User *U, std::vector &intCastTypes, std::vector &intCastValues, std::map > &bitcastMap); void fillStackInstrumentedFunctions(std::vector &stackIntrumentedFuncs, Function *deepestLLFunction); void indexLocalTypeInfos(Module &M, Function *F, std::map > &localMap); void addMagicStackDsentryFuncCalls(Module &M, Function *insertCallsInFunc, Function *localsFromFunc, Function *dsentryCreateFunc, Function *dsentryDestroyFunc, TYPECONST StructType *dsentryStructType, std::map > localTypeInfoMap, std::map &magicArrayTypePtrMap, TypeInfo *voidPtrTypeInfo, std::vector &typeInfoList, std::vector > &namesList, std::vector &flagsList); bool isExtLibrary(GlobalValue *GV, DIDescriptor *DID); bool isMagicGV(Module &M, GlobalVariable *GV); bool isMagicFunction(Module &M, Function *F); }; inline std::vector MagicPass::getGlobalVariables() const { return globalVariables; } inline std::vector MagicPass::getGlobalVariableSizes() const { return globalVariableSizes; } inline std::vector MagicPass::getShadowGlobalVariables() const { return shadowGlobalVariables; } inline std::vector MagicPass::getFunctions() const { return functions; } inline GlobalVariable* MagicPass::getMagicArray() const { return magicArray; } inline GlobalVariable* MagicPass::getMagicTypeArray() const { return magicTypeArray; } inline GlobalVariable* MagicPass::getMagicFunctionArray() const { return magicFunctionArray; } inline GlobalVariable* MagicPass::getMagicDsindexArray() const { return magicDsindexArray; } } #endif