[llvm-commits] [poolalloc] r128788 - in /poolalloc/trunk/runtime: Makefile TypeTrack/ TypeTrack/Makefile TypeTrack/TypeRuntime.c

Brice Lin Brice.Lin at gmail.com
Sun Apr 3 09:09:09 PDT 2011


Author: bglin2
Date: Sun Apr  3 11:09:09 2011
New Revision: 128788

URL: http://llvm.org/viewvc/llvm-project?rev=128788&view=rev
Log:
Initial commit for the 1:1 shadow memory (implemented with mmap) runtime used by the dynamic type checking pass.

Added:
    poolalloc/trunk/runtime/TypeTrack/
    poolalloc/trunk/runtime/TypeTrack/Makefile
    poolalloc/trunk/runtime/TypeTrack/TypeRuntime.c
Modified:
    poolalloc/trunk/runtime/Makefile

Modified: poolalloc/trunk/runtime/Makefile
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/runtime/Makefile?rev=128788&r1=128787&r2=128788&view=diff
==============================================================================
--- poolalloc/trunk/runtime/Makefile (original)
+++ poolalloc/trunk/runtime/Makefile Sun Apr  3 11:09:09 2011
@@ -6,6 +6,6 @@
 #
 # List all of the subdirectories that we will compile.
 #
-DIRS=FreeListAllocator FL2Allocator PreRT
+DIRS=FreeListAllocator FL2Allocator PreRT TypeTrack
 
 include $(LEVEL)/Makefile.common

Added: poolalloc/trunk/runtime/TypeTrack/Makefile
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/runtime/TypeTrack/Makefile?rev=128788&view=auto
==============================================================================
--- poolalloc/trunk/runtime/TypeTrack/Makefile (added)
+++ poolalloc/trunk/runtime/TypeTrack/Makefile Sun Apr  3 11:09:09 2011
@@ -0,0 +1,7 @@
+LEVEL = ../..
+
+SHARED_LIBRARY = 1
+LOADABLE_MODULE = 1
+LIBRARYNAME = typechecks_rt
+
+include $(LEVEL)/Makefile.common

Added: poolalloc/trunk/runtime/TypeTrack/TypeRuntime.c
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/runtime/TypeTrack/TypeRuntime.c?rev=128788&view=auto
==============================================================================
--- poolalloc/trunk/runtime/TypeTrack/TypeRuntime.c (added)
+++ poolalloc/trunk/runtime/TypeTrack/TypeRuntime.c Sun Apr  3 11:09:09 2011
@@ -0,0 +1,60 @@
+#include <assert.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <sys/mman.h>
+
+#define SIZE ((size_t)(sizeof(unsigned int)) * (size_t)(4294967296))
+
+unsigned int *shadow_begin;
+
+/**
+ * Initialize the shadow memory which records the 1:1 mapping of addresses to types.
+ */
+void shadowInit() {
+	shadow_begin = (unsigned int *)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!");
+		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!");
+		fflush(stderr);
+	}
+}
+
+/**
+ * Check the loaded type against the type recorded in the shadow memory.
+ *
+ * Note: currently does not handle GEPs.
+ */
+int trackLoadInst(void *ptr, unsigned int typeNumber) {
+	uintptr_t p = (uintptr_t)ptr;
+	p &= 0xFFFFFFFF;
+	printf("Load: %p, %p = %u | expecting %u\n", ptr, (void *)p, typeNumber, shadow_begin[p]);
+
+	return 0;
+}
+
+/**
+ * Record the stored type and address in the shadow memory.
+ *
+ * Note: currently does not handle GEPs.
+ */
+int trackStoreInst(void *ptr, unsigned int typeNumber) {
+	uintptr_t p = (uintptr_t)ptr;
+	p &= 0xFFFFFFFF;
+	shadow_begin[p] = typeNumber;
+#if 0
+	printf("Store: %p, %p = %u\n", ptr, (void *)p, typeNumber);
+#endif
+
+	return 0;
+}





More information about the llvm-commits mailing list