[llvm-commits] [poolalloc] r130077 - in /poolalloc/trunk: lib/AssistDS/TypeChecks.cpp runtime/DynamicTypeChecks/TypeRuntime.c
Arushi Aggarwal
aggarwa4 at illinois.edu
Sat Apr 23 17:34:39 PDT 2011
Author: aggarwa4
Date: Sat Apr 23 19:34:39 2011
New Revision: 130077
URL: http://llvm.org/viewvc/llvm-project?rev=130077&view=rev
Log:
Fix size variables to be int64.
Handle memset, by adding a new type.
Modified:
poolalloc/trunk/lib/AssistDS/TypeChecks.cpp
poolalloc/trunk/runtime/DynamicTypeChecks/TypeRuntime.c
Modified: poolalloc/trunk/lib/AssistDS/TypeChecks.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/AssistDS/TypeChecks.cpp?rev=130077&r1=130076&r2=130077&view=diff
==============================================================================
--- poolalloc/trunk/lib/AssistDS/TypeChecks.cpp (original)
+++ poolalloc/trunk/lib/AssistDS/TypeChecks.cpp Sat Apr 23 19:34:39 2011
@@ -246,9 +246,9 @@
std::vector<Value *> Args;
Args.push_back(GEP);
Args.push_back(ConstantInt::get(Int8Ty, UsedTypes[CAZ->getType()]));
- Args.push_back(ConstantInt::get(Int8Ty, TD->getTypeStoreSize(CAZ->getType())));
+ Args.push_back(ConstantInt::get(Int64Ty, TD->getTypeStoreSize(CAZ->getType())));
Args.push_back(ConstantInt::get(Int32Ty, tagCounter++));
- Constant *F = M.getOrInsertFunction("trackGlobal", VoidTy, VoidPtrTy, Int8Ty, Int8Ty, Int32Ty, NULL);
+ Constant *F = M.getOrInsertFunction("trackGlobal", VoidTy, VoidPtrTy, Int8Ty, Int64Ty, Int32Ty, NULL);
CallInst::Create(F, Args.begin(), Args.end(), "", &I);
}
}
@@ -263,9 +263,9 @@
std::vector<Value *> Args;
Args.push_back(GEP);
Args.push_back(ConstantInt::get(Int8Ty, UsedTypes[C->getType()]));
- Args.push_back(ConstantInt::get(Int8Ty, TD->getTypeStoreSize(C->getType())));
+ Args.push_back(ConstantInt::get(Int64Ty, TD->getTypeStoreSize(C->getType())));
Args.push_back(ConstantInt::get(Int32Ty, tagCounter++));
- Constant *F = M.getOrInsertFunction("trackGlobal", VoidTy, VoidPtrTy, Int8Ty, Int8Ty, Int32Ty, NULL);
+ Constant *F = M.getOrInsertFunction("trackGlobal", VoidTy, VoidPtrTy, Int8Ty, Int64Ty, Int32Ty, NULL);
CallInst::Create(F, Args.begin(), Args.end(), "", &I);
}
@@ -303,6 +303,13 @@
}
case Intrinsic::memset:
+ CastInst *BCI = BitCastInst::CreatePointerCast(I->getOperand(1), VoidPtrTy, "", I);
+ std::vector<Value *> Args;
+ Args.push_back(BCI);
+ Args.push_back(I->getOperand(3));
+ Args.push_back(ConstantInt::get(Int32Ty, tagCounter++));
+ Constant *F = M.getOrInsertFunction("trackInitInst", VoidTy, VoidPtrTy, Int64Ty, Int32Ty, NULL);
+ CallInst::Create(F, Args.begin(), Args.end(), "", I);
break;
}
} else if(F->getNameStr() == "realloc") {
@@ -332,12 +339,12 @@
std::vector<Value *> Args;
Args.push_back(BCI);
Args.push_back(ConstantInt::get(Int8Ty, UsedTypes[LI.getType()]));
- Args.push_back(ConstantInt::get(Int8Ty, TD->getTypeStoreSize(LI.getType())));
+ Args.push_back(ConstantInt::get(Int64Ty, TD->getTypeStoreSize(LI.getType())));
Args.push_back(ConstantInt::get(Int32Ty, tagCounter++));
// Create the call to the runtime check and place it before the load instruction.
- Constant *F = M.getOrInsertFunction("trackLoadInst", VoidTy, VoidPtrTy, Int8Ty, Int8Ty, Int32Ty, NULL);
+ Constant *F = M.getOrInsertFunction("trackLoadInst", VoidTy, VoidPtrTy, Int8Ty, Int64Ty, Int32Ty, NULL);
CallInst::Create(F, Args.begin(), Args.end(), "", &LI);
return true;
@@ -351,11 +358,11 @@
std::vector<Value *> Args;
Args.push_back(BCI);
Args.push_back(ConstantInt::get(Int8Ty, UsedTypes[SI.getOperand(0)->getType()])); // SI.getValueOperand()
- Args.push_back(ConstantInt::get(Int8Ty, TD->getTypeStoreSize(SI.getOperand(0)->getType())));
+ Args.push_back(ConstantInt::get(Int64Ty, TD->getTypeStoreSize(SI.getOperand(0)->getType())));
Args.push_back(ConstantInt::get(Int32Ty, tagCounter++));
// Create the call to the runtime check and place it before the store instruction.
- Constant *F = M.getOrInsertFunction("trackStoreInst", VoidTy, VoidPtrTy, Int8Ty, Int8Ty, Int32Ty, NULL);
+ Constant *F = M.getOrInsertFunction("trackStoreInst", VoidTy, VoidPtrTy, Int8Ty, Int64Ty, Int32Ty, NULL);
CallInst::Create(F, Args.begin(), Args.end(), "", &SI);
return true;
Modified: poolalloc/trunk/runtime/DynamicTypeChecks/TypeRuntime.c
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/runtime/DynamicTypeChecks/TypeRuntime.c?rev=130077&r1=130076&r2=130077&view=diff
==============================================================================
--- poolalloc/trunk/runtime/DynamicTypeChecks/TypeRuntime.c (original)
+++ poolalloc/trunk/runtime/DynamicTypeChecks/TypeRuntime.c Sat Apr 23 19:34:39 2011
@@ -19,35 +19,35 @@
* Initialize the shadow memory which records the 1:1 mapping of addresses to types.
*/
void shadowInit() {
- shadow_begin = (uint8_t *)mmap(0, SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON | MAP_NORESERVE, -1, 0);
+ shadow_begin = (uint8_t *)mmap(0, SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON | MAP_NORESERVE, -1, 0);
- if (shadow_begin == MAP_FAILED) {
- fprintf(stderr, "Failed to map the shadow memory!\n");
- fflush(stderr);
- assert(0 && "MAP_FAILED");
- }
+ if (shadow_begin == MAP_FAILED) {
+ fprintf(stderr, "Failed to map the shadow memory!\n");
+ fflush(stderr);
+ assert(0 && "MAP_FAILED");
+ }
}
/**
* Unmap the shadow memory which records the 1:1 mapping of addresses to types.
*/
void shadowUnmap() {
- if (munmap(shadow_begin, SIZE) == -1) {
- fprintf(stderr, "Failed to unmap the shadow memory!\n");
- fflush(stderr);
- }
+ if (munmap(shadow_begin, SIZE) == -1) {
+ fprintf(stderr, "Failed to unmap the shadow memory!\n");
+ fflush(stderr);
+ }
}
/**
* Record the global type and address in the shadow memory.
*/
void trackGlobal(void *ptr, uint8_t typeNumber, uint8_t size, uint32_t tag) {
- uintptr_t p = (uintptr_t)ptr;
- p &= 0xFFFFFFFF;
- shadow_begin[p] = typeNumber;
- memset(&shadow_begin[p + 1], 0, size - 1);
+ uintptr_t p = (uintptr_t)ptr;
+ p &= 0xFFFFFFFF;
+ shadow_begin[p] = typeNumber;
+ memset(&shadow_begin[p + 1], 0, size - 1);
#if DEBUG
- printf("Global: %p, %p = %u | %u bytes\n", ptr, (void *)p, typeNumber, size);
+ printf("Global: %p, %p = %u | %u bytes\n", ptr, (void *)p, typeNumber, size);
#endif
}
/**
@@ -64,53 +64,76 @@
}
/**
- * Check the loaded type against the type recorded in the shadow memory.
+ * Record the stored type and address in the shadow memory.
*/
-void trackLoadInst(void *ptr, uint8_t typeNumber, uint8_t size, uint32_t tag) {
- uint8_t i = 1;
- uintptr_t p = (uintptr_t)ptr;
- p &= 0xFFFFFFFF;
-
- if (typeNumber != shadow_begin[p]) {
- printf("Type mismatch: detecting %p %u, expecting %u! %u \n", ptr, typeNumber, shadow_begin[p], tag);
- i = size;
- }
-
- for (; i < size; ++i) {
- if (0 != shadow_begin[p + i]) {
- printf("Type mismatch: detecting %u, expecting %u (0 != %u)!\n", typeNumber, shadow_begin[p], shadow_begin[p + i]);
- break;
- }
- }
-
+void trackStoreInst(void *ptr, uint8_t typeNumber, uint64_t size, uint32_t tag) {
+ uintptr_t p = (uintptr_t)ptr;
+ p &= 0xFFFFFFFF;
+ shadow_begin[p] = typeNumber;
+ memset(&shadow_begin[p + 1], 0, size - 1);
#if DEBUG
- printf("Load: %p, %p = actual: %u, expect: %u | %u bytes\n", ptr, (void *)p, typeNumber, shadow_begin[p], size);
+ printf("Store: %p, %p = %u | %u %d bytes\n", ptr, (void *)p, typeNumber, size, tag);
#endif
}
/**
- * Record the stored type and address in the shadow memory.
+ * Check the loaded type against the type recorded in the shadow memory.
*/
-void trackStoreInst(void *ptr, uint8_t typeNumber, uint8_t size, uint32_t tag) {
- uintptr_t p = (uintptr_t)ptr;
- p &= 0xFFFFFFFF;
- shadow_begin[p] = typeNumber;
- memset(&shadow_begin[p + 1], 0, size - 1);
+void trackLoadInst(void *ptr, uint8_t typeNumber, uint64_t size, uint32_t tag) {
+ uint8_t i = 1;
+ uintptr_t p = (uintptr_t)ptr;
+ p &= 0xFFFFFFFF;
+
+ /* Check if this an initialized but untyped memory.*/
+ if (shadow_begin[p] != 0xFF) {
+ if (typeNumber != shadow_begin[p]) {
+ printf("Type mismatch: detecting %p %u, expecting %u! %u \n", ptr, typeNumber, shadow_begin[p], tag);
+ i = size;
+ }
+
+ for (; i < size; ++i) {
+ if (0 != shadow_begin[p + i]) {
+ printf("Type mismatch: detecting %u, expecting %u (0 != %u)!\n", typeNumber, shadow_begin[p], shadow_begin[p + i]);
+ break;
+ }
+ }
+ } else {
+ /* If so, set type to the type being read.
+ Check that none of the bytes are typed.*/
+ for (; i < size; ++i) {
+ if (0xFF != shadow_begin[p + i]) {
+ printf("Type mismatch: detecting %u, expecting %u (0 != %u)!\n", typeNumber, shadow_begin[p], shadow_begin[p + i]);
+ break;
+ }
+ }
+ trackStoreInst(ptr, typeNumber, size, tag);
+ }
+
#if DEBUG
- printf("Store: %p, %p = %u | %u %d bytes\n", ptr, (void *)p, typeNumber, size, tag);
+ printf("Load: %p, %p = actual: %u, expect: %u | %u bytes\n", ptr, (void *)p, typeNumber, shadow_begin[p], size);
#endif
}
/**
+ * For memset type instructions, that set values.
+ * 0xFF type indicates that any type can be read,
+ */
+void trackInitInst(void *ptr, uint64_t size, uint32_t tag) {
+ uintptr_t p = (uintptr_t)ptr;
+ p &= 0xFFFFFFFF;
+ memset(&shadow_begin[p], 0xFF, size);
+}
+
+/**
* Copy size bits of metadata from src ptr to dest ptr.
*/
void copyTypeInfo(void *dstptr, void *srcptr, uint64_t size, uint32_t tag) {
- uintptr_t d = (uintptr_t)dstptr;
- uintptr_t s = (uintptr_t)srcptr;
- d &= 0xFFFFFFFF;
- s &= 0xFFFFFFFF;
- memcpy(&shadow_begin[d], &shadow_begin[s], size);
+ uintptr_t d = (uintptr_t)dstptr;
+ uintptr_t s = (uintptr_t)srcptr;
+ d &= 0xFFFFFFFF;
+ s &= 0xFFFFFFFF;
+ memcpy(&shadow_begin[d], &shadow_begin[s], size);
#if DEBUG
- printf("Copy: %p, %p = %u | %u %d bytes\n", dstptr, (void *)d, shadow_begin[s], size, tag);
+ printf("Copy: %p, %p = %u | %u %d bytes\n", dstptr, (void *)d, shadow_begin[s], size, tag);
#endif
}
More information about the llvm-commits
mailing list