[llvm-commits] [poolalloc] r129663 - in /poolalloc/trunk: lib/AssistDS/TypeChecks.cpp runtime/DynamicTypeChecks/TypeRuntime.c
Brice Lin
Brice.Lin at gmail.com
Sun Apr 17 10:17:23 PDT 2011
Author: bglin2
Date: Sun Apr 17 12:17:23 2011
New Revision: 129663
URL: http://llvm.org/viewvc/llvm-project?rev=129663&view=rev
Log:
1. Record the size of stored values by writing the type to the starting byte and clearing the (size - 1) subsequent bytes.
2. Track globals separately from store instructions.
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=129663&r1=129662&r2=129663&view=diff
==============================================================================
--- poolalloc/trunk/lib/AssistDS/TypeChecks.cpp (original)
+++ poolalloc/trunk/lib/AssistDS/TypeChecks.cpp Sun Apr 17 12:17:23 2011
@@ -16,6 +16,7 @@
#include "llvm/DerivedTypes.h"
#include "llvm/Module.h"
#include "llvm/Assembly/Writer.h"
+#include "llvm/Support/Debug.h"
#include "llvm/Support/InstIterator.h"
#include "llvm/Support/raw_ostream.h"
@@ -173,17 +174,18 @@
}
bool TypeChecks::visitGlobal(Module &M, GlobalVariable &GV, Instruction &I) {
-
CastInst *BCI = BitCastInst::CreatePointerCast(&GV, VoidPtrTy, "", &I);
std::vector<Value *> Args;
Args.push_back(BCI);
const PointerType *PTy = GV.getType();
Args.push_back(ConstantInt::get(Int8Ty, UsedTypes[PTy->getElementType()]));
- Constant *F = M.getOrInsertFunction("trackStoreInst", VoidTy, VoidPtrTy, Int8Ty, NULL);
+ Args.push_back(ConstantInt::get(Int8Ty, TD->getTypeStoreSize(PTy->getElementType())));
+ Constant *F = M.getOrInsertFunction("trackGlobal", VoidTy, VoidPtrTy, Int8Ty, Int8Ty, NULL);
CallInst::Create(F, Args.begin(), Args.end(), "", &I);
return true;
}
+
// Insert runtime checks before all load instructions.
bool TypeChecks::visitLoadInst(Module &M, LoadInst &LI) {
// Cast the pointer operand to i8* for the runtime function.
@@ -192,9 +194,10 @@
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())));
// Create the call to the runtime check and place it before the load instruction.
- Constant *F = M.getOrInsertFunction("trackLoadInst", VoidTy, VoidPtrTy, Int8Ty, NULL);
+ Constant *F = M.getOrInsertFunction("trackLoadInst", VoidTy, VoidPtrTy, Int8Ty, Int8Ty, NULL);
CallInst::Create(F, Args.begin(), Args.end(), "", &LI);
return true;
@@ -208,9 +211,10 @@
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())));
// Create the call to the runtime check and place it before the store instruction.
- Constant *F = M.getOrInsertFunction("trackStoreInst", VoidTy, VoidPtrTy, Int8Ty, NULL);
+ Constant *F = M.getOrInsertFunction("trackStoreInst", VoidTy, VoidPtrTy, Int8Ty, Int8Ty, NULL);
CallInst::Create(F, Args.begin(), Args.end(), "", &SI);
return true;
@@ -227,7 +231,7 @@
Args.push_back(BCI_Src);
Args.push_back(ConstantInt::get(Int8Ty, TD->getTypeStoreSize(SI.getOperand(0)->getType())));
- // Create the call to the runtime check and place it before the store instruction.
+ // Create the call to the runtime check and place it before the copying store instruction.
Constant *F = M.getOrInsertFunction("copyTypeInfo", VoidTy, VoidPtrTy, VoidPtrTy, Int8Ty, NULL);
CallInst::Create(F, Args.begin(), Args.end(), "", &SI);
Modified: poolalloc/trunk/runtime/DynamicTypeChecks/TypeRuntime.c
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/runtime/DynamicTypeChecks/TypeRuntime.c?rev=129663&r1=129662&r2=129663&view=diff
==============================================================================
--- poolalloc/trunk/runtime/DynamicTypeChecks/TypeRuntime.c (original)
+++ poolalloc/trunk/runtime/DynamicTypeChecks/TypeRuntime.c Sun Apr 17 12:17:23 2011
@@ -1,7 +1,7 @@
#include <assert.h>
-#include <string.h>
#include <stdint.h>
#include <stdio.h>
+#include <string.h>
#include <sys/mman.h>
#define DEBUG (0)
@@ -39,30 +39,55 @@
}
/**
+ * Record the global type and address in the shadow memory.
+ */
+void trackGlobal(void *ptr, uint8_t typeNumber, uint8_t size) {
+ 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);
+#endif
+}
+
+/**
* Check the loaded type against the type recorded in the shadow memory.
*/
-void trackLoadInst(void *ptr, uint8_t typeNumber) {
+void trackLoadInst(void *ptr, uint8_t typeNumber, uint8_t size) {
+ uint8_t i = 1;
uintptr_t p = (uintptr_t)ptr;
p &= 0xFFFFFFFF;
if (typeNumber != shadow_begin[p]) {
printf("Type mismatch: detecting %u, expecting %u!\n", typeNumber, shadow_begin[p]);
+ 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;
+ }
}
#if DEBUG
- printf("Load: %p, %p = %u | expecting %u\n", ptr, (void *)p, typeNumber, shadow_begin[p]);
+ printf("Load: %p, %p = actual: %u, expect: %u | %u bytes\n", ptr, (void *)p, typeNumber, shadow_begin[p], size);
#endif
}
/**
* Record the stored type and address in the shadow memory.
*/
-void trackStoreInst(void *ptr, uint8_t typeNumber) {
+void trackStoreInst(void *ptr, uint8_t typeNumber, uint8_t size) {
uintptr_t p = (uintptr_t)ptr;
p &= 0xFFFFFFFF;
shadow_begin[p] = typeNumber;
+ memset(&shadow_begin[p + 1], 0, size - 1);
+
#if DEBUG
- printf("Store: %p, %p = %u\n", ptr, (void *)p, typeNumber);
+ printf("Store: %p, %p = %u | %u bytes\n", ptr, (void *)p, typeNumber, size);
#endif
}
@@ -74,5 +99,5 @@
uintptr_t s = (uintptr_t)srcptr;
d &= 0xFFFFFFFF;
s &= 0xFFFFFFFF;
- memcpy(&shadow_begin[d], &shadow_begin[s], size);
+ memcpy(&shadow_begin[d], &shadow_begin[s], size);
}
More information about the llvm-commits
mailing list