[llvm-commits] [poolalloc] r131071 - /poolalloc/trunk/runtime/DynamicTypeChecks/TypeRuntime.c
Brice Lin
Brice.Lin at gmail.com
Sun May 8 11:45:00 PDT 2011
Author: bglin2
Date: Sun May 8 13:45:00 2011
New Revision: 131071
URL: http://llvm.org/viewvc/llvm-project?rev=131071&view=rev
Log:
1. Address into shadow memory with 2^47 bits.
2. Fixed printf() format strings for uint64_t.
Modified:
poolalloc/trunk/runtime/DynamicTypeChecks/TypeRuntime.c
Modified: poolalloc/trunk/runtime/DynamicTypeChecks/TypeRuntime.c
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/runtime/DynamicTypeChecks/TypeRuntime.c?rev=131071&r1=131070&r2=131071&view=diff
==============================================================================
--- poolalloc/trunk/runtime/DynamicTypeChecks/TypeRuntime.c (original)
+++ poolalloc/trunk/runtime/DynamicTypeChecks/TypeRuntime.c Sun May 8 13:45:00 2011
@@ -1,25 +1,34 @@
#include <assert.h>
+#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <sys/mman.h>
#define DEBUG (0)
+#define SIZE ((size_t)(70368744177664))
-#define SIZE ((size_t)(4294967296))
+uint8_t *shadow_begin;
-#if 0
-/* 2^47 bits */
-#define SIZE ((size_t)(140737488355328))
-#endif
+uintptr_t maskAddress(void *ptr) {
+ uintptr_t p = (uintptr_t)ptr;
-uint8_t *shadow_begin;
+ if ((p & 0x600000000000) == 0x600000000000) {
+ return (p & 0x3FFFFFFFFFFF);
+ } else if ((p | 0x1FFFFFFFFFFF) == 0x1FFFFFFFFFFF) {
+ return p;
+ } else {
+ fprintf(stderr, "Address out of range!\n");
+ fflush(stderr);
+ assert(0 && "MAP_FAILED");
+ }
+}
/**
* 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 = mmap(0, SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, -1, 0);
if (shadow_begin == MAP_FAILED) {
fprintf(stderr, "Failed to map the shadow memory!\n");
@@ -42,24 +51,24 @@
* Record the global type and address in the shadow memory.
*/
void trackGlobal(void *ptr, uint8_t typeNumber, uint64_t size, uint32_t tag) {
- uintptr_t p = (uintptr_t)ptr;
- p &= 0xFFFFFFFF;
+ uintptr_t p = maskAddress(ptr);
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 | %" PRIu64 " bytes\n", ptr, (void *)p, typeNumber, size);
#endif
}
/**
* Record the type stored at ptr(of size size) and replicate it
*/
void trackGlobalArray(void *ptr, uint64_t size, uint64_t count, uint32_t tag) {
- unsigned i;
- uintptr_t p = (uintptr_t)ptr;
- uintptr_t p1 = (uintptr_t)ptr;
- for(i =1; i<count;i++) {
+ uintptr_t p = maskAddress(ptr);
+ uintptr_t p1 = maskAddress(ptr);
+ uint64_t i;
+
+ for (i = 1; i < count; ++i) {
p += size;
- memcpy(&shadow_begin[p & 0xFFFFFFFF], &shadow_begin[p1 & 0xFFFFFFFF] , size);
+ memcpy(&shadow_begin[p], &shadow_begin[p1], size);
}
}
@@ -67,12 +76,11 @@
* Record the stored type and address in the shadow memory.
*/
void trackStoreInst(void *ptr, uint8_t typeNumber, uint64_t size, uint32_t tag) {
- uintptr_t p = (uintptr_t)ptr;
- p &= 0xFFFFFFFF;
+ uintptr_t p = maskAddress(ptr);
shadow_begin[p] = typeNumber;
memset(&shadow_begin[p + 1], 0, size - 1);
#if DEBUG
- printf("Store: %p, %p = %u | %u %d bytes\n", ptr, (void *)p, typeNumber, size, tag);
+ printf("Store: %p, %p = %u | %" PRIu64 " bytes | %d\n", ptr, (void *)p, typeNumber, size, tag);
#endif
}
@@ -81,8 +89,7 @@
*/
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;
+ uintptr_t p = maskAddress(ptr);
/* Check if this an initialized but untyped memory.*/
if (shadow_begin[p] != 0xFF) {
@@ -110,7 +117,7 @@
}
#if DEBUG
- printf("Load: %p, %p = actual: %u, expect: %u | %u bytes\n", ptr, (void *)p, typeNumber, shadow_begin[p], size);
+ printf("Load: %p, %p = actual: %u, expect: %u | %" PRIu64 " bytes\n", ptr, (void *)p, typeNumber, shadow_begin[p], size);
#endif
}
@@ -119,13 +126,11 @@
* 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;
+ uintptr_t p = maskAddress(ptr);
memset(&shadow_begin[p], 0xFF, size);
}
void trackUnInitInst(void *ptr, uint64_t size, uint32_t tag) {
- uintptr_t p = (uintptr_t)ptr;
- p &= 0xFFFFFFFF;
+ uintptr_t p = maskAddress(ptr);
memset(&shadow_begin[p], 0x00, size);
}
@@ -133,12 +138,10 @@
* 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;
+ uintptr_t d = maskAddress(dstptr);
+ uintptr_t s = maskAddress(srcptr);
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 | %" PRIu64 " bytes | %d\n", dstptr, (void *)d, shadow_begin[s], size, tag);
#endif
}
More information about the llvm-commits
mailing list