[llvm-commits] [poolalloc] r134206 - in /poolalloc/trunk: lib/AssistDS/TypeChecks.cpp runtime/DynamicTypeChecks/TypeRuntime.cpp
Arushi Aggarwal
aggarwa4 at illinois.edu
Thu Jun 30 16:44:55 PDT 2011
Author: aggarwa4
Date: Thu Jun 30 18:44:55 2011
New Revision: 134206
URL: http://llvm.org/viewvc/llvm-project?rev=134206&view=rev
Log:
Add more library functions.
Do not instrument stores if they come from
PHI, Select, Bitcasts, already instrumented through loads.
Modified:
poolalloc/trunk/lib/AssistDS/TypeChecks.cpp
poolalloc/trunk/runtime/DynamicTypeChecks/TypeRuntime.cpp
Modified: poolalloc/trunk/lib/AssistDS/TypeChecks.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/AssistDS/TypeChecks.cpp?rev=134206&r1=134205&r2=134206&view=diff
==============================================================================
--- poolalloc/trunk/lib/AssistDS/TypeChecks.cpp (original)
+++ poolalloc/trunk/lib/AssistDS/TypeChecks.cpp Thu Jun 30 18:44:55 2011
@@ -1531,6 +1531,15 @@
Constant *F = M.getOrInsertFunction("trackgetaddrinfo", VoidTy, VoidPtrTy, Int32Ty, NULL);
CallInst *CI = CallInst::Create(F, Args.begin(), Args.end());
CI->insertAfter(BCI);
+ } else if (F->getNameStr() == std::string("mmap")) {
+ CastInst *BCI = BitCastInst::CreatePointerCast(I, VoidPtrTy);
+ BCI->insertAfter(I);
+ std::vector<Value *> Args;
+ Args.push_back(BCI);
+ Args.push_back(CS.getArgument(1));
+ Args.push_back(getTagCounter());
+ CallInst *CI = CallInst::Create(trackInitInst, Args.begin(), Args.end());
+ CI->insertAfter(BCI);
} else if (F->getNameStr() == std::string("__strdup")) {
CastInst *BCI_Dest = BitCastInst::CreatePointerCast(I, VoidPtrTy);
BCI_Dest->insertAfter(I);
@@ -1590,6 +1599,16 @@
Args.push_back(getTagCounter());
CallInst *CI = CallInst::Create(trackInitInst, Args.begin(), Args.end());
CI->insertAfter(BCI);
+ } else if (F->getNameStr() == std::string("gethostbyname") ||
+ F->getNameStr() == std::string("gethostbyaddr")) {
+ CastInst *BCI = BitCastInst::CreatePointerCast(I, VoidPtrTy);
+ BCI->insertAfter(I);
+ std::vector<Value*>Args;
+ Args.push_back(BCI);
+ Args.push_back(getTagCounter());
+ Constant *F = M.getOrInsertFunction("trackgethostbyname", VoidTy, VoidPtrTy, Int32Ty, NULL);
+ CallInst *CI = CallInst::Create(F, Args.begin(), Args.end());
+ CI->insertAfter(BCI);
} else if (F->getNameStr() == std::string("gethostname")) {
CastInst *BCI = BitCastInst::CreatePointerCast(CS.getArgument(0), VoidPtrTy);
BCI->insertAfter(I);
@@ -1599,7 +1618,8 @@
Constant *F = M.getOrInsertFunction("trackgethostname", VoidTy, VoidPtrTy, Int32Ty, NULL);
CallInst *CI = CallInst::Create(F, Args.begin(), Args.end());
CI->insertAfter(BCI);
- } else if (F->getNameStr() == std::string("getenv")) {
+ } else if (F->getNameStr() == std::string("getenv") ||
+ F->getNameStr() == std::string("strerror")) {
CastInst *BCI = BitCastInst::CreatePointerCast(I, VoidPtrTy);
BCI->insertAfter(I);
std::vector<Value *>Args;
@@ -1723,15 +1743,26 @@
Constant *F = M.getOrInsertFunction("trackReadLink", VoidTy, VoidPtrTy, I->getType(), Int32Ty, NULL);
CallInst *CI = CallInst::Create(F, Args.begin(), Args.end());
CI->insertAfter(I);
+ } else if (F->getNameStr() == std::string("pipe")) {
+ CastInst *BCI = BitCastInst::CreatePointerCast(CS.getArgument(0), VoidPtrTy, "", I);
+ std::vector<Value*> Args;
+ Args.push_back(BCI);
+ Args.push_back(getTagCounter());
+ Constant *F = M.getOrInsertFunction("trackpipe", VoidTy, VoidPtrTy, Int32Ty, NULL);
+ CallInst::Create(F, Args.begin(), Args.end(), "", I);
+ return true;
} else if (F->getNameStr() == std::string("getsockname")) {
- CastInst *BCI = BitCastInst::CreatePointerCast(CS.getArgument(1), VoidPtrTy, "", I);
- const PointerType *PTy = cast<PointerType>(CS.getArgument(1)->getType());
- const Type * ElementType = PTy->getElementType();
+ CastInst *BCI = BitCastInst::CreatePointerCast(CS.getArgument(1), VoidPtrTy);
+ BCI->insertAfter(I);
+ CastInst *BCI_Size = BitCastInst::CreatePointerCast(CS.getArgument(2), VoidPtrTy);
+ BCI_Size->insertAfter(I);
std::vector<Value *> Args;
Args.push_back(BCI);
- Args.push_back(getSizeConstant(ElementType));
+ Args.push_back(BCI_Size);
Args.push_back(getTagCounter());
- CallInst::Create(trackInitInst, Args.begin(), Args.end(), "", I);
+ Constant *F = M.getOrInsertFunction("trackgetsockname", VoidTy, VoidPtrTy, VoidPtrTy, Int32Ty, NULL);
+ CallInst *CI = CallInst::Create(F, Args.begin(), Args.end());
+ CI->insertAfter(BCI);
return true;
} else if (F->getNameStr() == std::string("readdir")) {
CastInst *BCI = BitCastInst::CreatePointerCast(I, VoidPtrTy);
@@ -2013,7 +2044,6 @@
continue;
}
}
-
std::vector<Value *> Args;
Args.push_back(getTypeMarkerConstant(I));
Args.push_back(getSizeConstant(I->getType()));
@@ -2106,9 +2136,14 @@
}
}
} else if(BitCastInst *BI = dyn_cast<BitCastInst>(II)) {
+ BitCast_MD_Map[BI] = AI;
visitUses(BI, AI, BCI);
//CallInst::Create(checkTypeInst, Args.begin(), Args.end(), "", cast<Instruction>(II.getUse().getUser()));
- } else {
+ /*} else if(PtrToIntInst *P2I = dyn_cast<PtrToIntInst>(II)) {
+ visitUses(P2I, AI, BCI);
+ } else if(IntToPtrInst *I2P = dyn_cast<IntToPtrInst>(II)) {
+ visitUses(I2P, AI, BCI);*/
+ }else {
CallInst::Create(checkTypeInst, Args.begin(), Args.end(), "", cast<Instruction>(II.getUse().getUser()));
}
}
@@ -2117,6 +2152,18 @@
// Insert runtime checks before all store instructions.
bool TypeChecks::visitStoreInst(Module &M, StoreInst &SI) {
+ if(PHINode *PH = dyn_cast<PHINode>(SI.getOperand(0)->stripPointerCasts())) {
+ if(PHINode_MD_Map.find(PH) != PHINode_MD_Map.end())
+ return false;
+ }
+ if(SelectInst *SelI = dyn_cast<SelectInst>(SI.getOperand(0)->stripPointerCasts())) {
+ if(SelectInst_MD_Map.find(SelI) != SelectInst_MD_Map.end())
+ return false;
+ }
+ if(BitCastInst *BI = dyn_cast<BitCastInst>(SI.getOperand(0)->stripPointerCasts())) {
+ if(BitCast_MD_Map.find(BI) != BitCast_MD_Map.end())
+ return false;
+ }
// Cast the pointer operand to i8* for the runtime function.
CastInst *BCI = BitCastInst::CreatePointerCast(SI.getPointerOperand(), VoidPtrTy, "", &SI);
Modified: poolalloc/trunk/runtime/DynamicTypeChecks/TypeRuntime.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/runtime/DynamicTypeChecks/TypeRuntime.cpp?rev=134206&r1=134205&r2=134206&view=diff
==============================================================================
--- poolalloc/trunk/runtime/DynamicTypeChecks/TypeRuntime.cpp (original)
+++ poolalloc/trunk/runtime/DynamicTypeChecks/TypeRuntime.cpp Thu Jun 30 18:44:55 2011
@@ -80,9 +80,12 @@
void trackgetcwd(void *ptr, uint32_t tag) ;
void trackgetpwuid(void *ptr, uint32_t tag) ;
void trackgethostname(void *ptr, uint32_t tag) ;
+ void trackgethostbyname(void *ptr, uint32_t tag) ;
void trackgetaddrinfo(void *ptr, uint32_t tag) ;
void trackaccept(void *ptr, void *size,uint32_t tag) ;
+ void trackgetsockname(void *ptr, void *size,uint32_t tag) ;
void trackpoll(void *ptr, uint64_t nfds, uint32_t tag) ;
+ void trackpipe(void *ptr, uint32_t tag) ;
void trackReadLink(void *ptr, int64_t val, uint32_t tag) ;
}
@@ -390,6 +393,24 @@
void trackgethostname(void *ptr, uint32_t tag) {
trackInitInst(ptr, strlen((const char *)ptr) + 1, tag);
}
+void trackgethostbyname(void *ptr, uint32_t tag) {
+ struct hostent *hn = (struct hostent *)ptr;
+ trackInitInst(hn->h_name, strlen(hn->h_name) + 1, tag);
+ unsigned i;
+ for(i =0; hn->h_aliases[i] != NULL; i++) {
+ trackInitInst(&hn->h_aliases[i], sizeof(char*), tag);
+ trackInitInst(hn->h_aliases[i], hn->h_length, tag);
+ }
+ trackInitInst(&hn->h_aliases[i], sizeof(char*), tag);
+ trackInitInst(hn->h_aliases[i], hn->h_length, tag);
+ for(i = 0; hn->h_addr_list[i] != NULL; i++) {
+ trackInitInst(&hn->h_addr_list[i], sizeof(char*), tag);
+ trackInitInst(hn->h_addr_list[i], hn->h_length, tag);
+ }
+ trackInitInst(&hn->h_addr_list[i], sizeof(char*), tag);
+ trackInitInst(hn->h_addr_list[i], hn->h_length, tag);
+ trackInitInst(ptr, sizeof(struct hostent), tag);
+}
void trackgetaddrinfo(void *ptr, uint32_t tag) {
struct addrinfo *res;
@@ -407,6 +428,15 @@
trackInitInst(ptr, (uint64_t)bytes, tag);
}
+void trackgetsockname(void *ptr, void *size, uint32_t tag) {
+ int32_t bytes = *((int32_t*)size);
+ trackInitInst(ptr, (uint64_t)bytes, tag);
+}
+
+void trackpipe(void *ptr, uint32_t tag) {
+ trackInitInst(ptr, sizeof(int) * 2, tag);
+}
+
void trackpoll(void *ptr, uint64_t nfds, uint32_t tag) {
struct pollfd *fds = (struct pollfd *)ptr;
unsigned i = 0;
More information about the llvm-commits
mailing list