From: bdemsky Date: Fri, 5 Mar 2004 05:26:51 +0000 (+0000) Subject: Runtime for checker... X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=38a2bde899fd10aa21ba2961beac1726fc5f5ec3;p=repair.git Runtime for checker... --- diff --git a/Repair/RepairCompiler/MCC/Runtime/buildruntime b/Repair/RepairCompiler/MCC/Runtime/buildruntime new file mode 100755 index 0000000..ca76f74 --- /dev/null +++ b/Repair/RepairCompiler/MCC/Runtime/buildruntime @@ -0,0 +1,5 @@ +#!/bin/bash +g++ -c SimpleHash.cc +g++ -c tmap.cc +g++ -c instrument.cc +gcc -c libredblack/redblack.c \ No newline at end of file diff --git a/Repair/RepairCompiler/MCC/Runtime/instrument.cc b/Repair/RepairCompiler/MCC/Runtime/instrument.cc new file mode 100755 index 0000000..f3f4d90 --- /dev/null +++ b/Repair/RepairCompiler/MCC/Runtime/instrument.cc @@ -0,0 +1,50 @@ +/* Defines interfaces for the applications and exports function calls that + the applications should use instead of the standard ones. */ + +#include +#include +extern "C" { +#include "instrument.h" +} +#include +#include "tmap.h" + +typemap * memmap; + +void *ourcalloc(size_t nmemb, size_t size) { + void *oc=calloc(nmemb,size); + memmap->allocate(oc,size*nmemb); + return oc; +} + +void *ourmalloc(size_t size) { + void *oc=malloc(size); + memmap->allocate(oc,size); + return oc; +} + +void ourfree(void *ptr) { + memmap->deallocate(ptr); + free(ptr); +} + +void *ourrealloc(void *ptr, size_t size) { + void *orr=realloc(ptr,size); + if (size==0) { + memmap->deallocate(ptr); + return orr; + } + if (orr==NULL) { + return orr; + } + memmap->deallocate(ptr); + memmap->allocate(ptr,size); +} + +void alloc(void *ptr,int size) { + memmap->allocate(ptr,size); +} + +void dealloc(void *ptr) { + memmap->deallocate(ptr); +} diff --git a/Repair/RepairCompiler/MCC/Runtime/instrument.h b/Repair/RepairCompiler/MCC/Runtime/instrument.h new file mode 100755 index 0000000..d08f364 --- /dev/null +++ b/Repair/RepairCompiler/MCC/Runtime/instrument.h @@ -0,0 +1,13 @@ +/* Defines interfaces for the applications and exports function calls that + the applications should use instead of the standard ones. */ + +#ifndef INSTRUMENT_H +#define INSTUMENT_H + +void alloc(void *ptr,int size); +void dealloc(void *ptr); +void *ourcalloc(size_t nmemb, size_t size); +void *ourmalloc(size_t size); +void ourfree(void *ptr); +void *ourrealloc(void *ptr, size_t size); +#endif diff --git a/Repair/RepairCompiler/MCC/Runtime/memory.h b/Repair/RepairCompiler/MCC/Runtime/memory.h new file mode 100755 index 0000000..e97f0e5 --- /dev/null +++ b/Repair/RepairCompiler/MCC/Runtime/memory.h @@ -0,0 +1,8 @@ +#ifndef MEMORY_H +#define MEMORY_H +#include "instument.h" +#define malloc(size) ourmalloc(size) +#define calloc(memb,size) ourcalloc(memb,size) +#define realloc(ptr,size) ourrealloc(ptr,size) +#define free(size) ourfree(size) +#endif diff --git a/Repair/RepairCompiler/MCC/Runtime/size.h b/Repair/RepairCompiler/MCC/Runtime/size.h new file mode 100755 index 0000000..7c57bce --- /dev/null +++ b/Repair/RepairCompiler/MCC/Runtime/size.h @@ -0,0 +1,11 @@ +class typeobject { + public: + typeobject(); + int getfield(int type, int fieldindex); //returns type + int isArray(int type, int fieldindex); //returns if array + int numElements(int type, int fieldindex); //returns number of elements + int size(int type); + int getnumfields(int type); + bool issubtype(int subtype, int type); + void reset(); +}; diff --git a/Repair/RepairCompiler/MCC/Runtime/tmap.cc b/Repair/RepairCompiler/MCC/Runtime/tmap.cc new file mode 100755 index 0000000..2b626ad --- /dev/null +++ b/Repair/RepairCompiler/MCC/Runtime/tmap.cc @@ -0,0 +1,189 @@ +#include +#include "tmap.h" +#include "size.h" +extern "C" { +#include "libredblack/redblack.h" +} + +#define CHECKTYPE +#define CHECKMEMORY + +typemap::typemap(typeobject * size) { + alloctree=rbinit(); + typetree=rbinit(); + this->size=size; +} + +void freefunction(void *ptr) { + if(ptr!=NULL) { + delete((structuremap *)ptr); + } +} + +typemap::~typemap() { + rbdestroy(typetree,freefunction); + rbdestroy(alloctree,freefunction); +} + +void typemap::reset() { + rbdestroy(typetree,freefunction); + typetree=rbinit(); + size->reset(); +} + +structuremap::structuremap(int s) { + str=s; + typetree=rbinit(); +} + +structuremap::~structuremap() { + rbdestroy(typetree,freefunction); +} + +bool typemap::asserttype(void *ptr, void *high, int s) { +#ifdef CHECKTYPE + bool b=checktype(true,ptr,s); + if (!b) { + printf("Assertion failure\n"); + bool testb=checktype(true,ptr,s); + } + return b; +#endif + return assertvalidmemory(ptr, high); +} + +bool typemap::assertvalidmemory(void* low, void* high) { +#ifdef CHECKMEMORY + return checkmemory(low, high); +#endif + return true; +} + +bool typemap::istype(void *ptr, void *high, int s) { +#ifdef CHECKTYPE + bool b=checktype(false,ptr,s); + if (!b) { + printf("Verify failure\n"); + bool testb=checktype(false,ptr,s); + } + return b; +#endif + return assertvalidmemory(ptr, high); +} + +void typemap::allocate(void *ptr, int size) { + void *low=ptr; + void *high=((char *)ptr)+size; + int val=rbinsert(low,high,NULL,alloctree); + if (val==0) + printf("Error\n"); +} + +int typemap::findoffsetstructure(int s, int offset) { + int count=0; + for(int i=0;igetnumfields(s);i++) { + int mult=1; + int ttype=size->getfield(s,i); + if (size->isArray(s,i)) { + mult=size->numElements(s,i); + } + int increment=size->size(ttype); + int delt=offset-count; + if (delt low) || (allocp.high < high)) { /* make sure this block is used */ + return false; + } else { + return true; + } +} + + +bool typemap::checktype(bool doaction,void *ptr, int structure) { + int ssize=size->size(structure); + void *low=ptr; + void *high=((char *)low)+ssize; + struct pair allocp=rbfind(low,high,alloctree); + if (allocp.low==NULL) + return false; + if (allocp.low>low||allocp.highissubtype(structure,smap->str)) { + /* narrowing cast */ + if (!doaction) + return true; + smap->str=structure; + return true; + } else if (size->issubtype(smap->str,structure)) { + /* widening cast */ + return true; + } else + return false; /* incompatible types */ + } else if (typep.low<=low&&typep.high>=high) { + /* See if it matches up with structure inside typep */ + if (rbsearch(low,high,smap->typetree)) { + /* recurse */ + return checktype(doaction,low,high, structure, smap->typetree); + } else { + /* check to see if data lines up correctly */ + int offset=((char *)low)-((char *)typep.low); + int st=findoffsetstructure(smap->str,offset); + if (st==-1) + return false; + if (size->issubtype(structure,st)) { + if (!doaction) + return true; + structuremap *newsm=new structuremap(structure); + int flag=rbinsert(low, high, newsm, smap->typetree); + return (flag==1); + } else if (size->issubtype(st,structure)) { + if (!doaction) + return true; + structuremap *newsm=new structuremap(st); + int flag=rbinsert(low, high, newsm, smap->typetree); + return (flag==1); + } else + return false; + } + } else + return false; +} diff --git a/Repair/RepairCompiler/MCC/Runtime/tmap.h b/Repair/RepairCompiler/MCC/Runtime/tmap.h new file mode 100755 index 0000000..87da756 --- /dev/null +++ b/Repair/RepairCompiler/MCC/Runtime/tmap.h @@ -0,0 +1,32 @@ +#ifndef TMAP_H +#define TMAP_H +class typeobject; + +class typemap { + public: + typemap(typeobject *); + ~typemap(); + void allocate(void *, int); + void deallocate(void *); + bool assertvalidmemory(void* low, void* high); + bool asserttype(void *ptr, void *high, int structure); + bool istype(void *ptr, void *high, int structure); + void reset(); + private: + bool checkmemory(void* low, void* high); + bool checktype(bool doaction,void *ptr, int structure); + bool checktype(bool doaction, void *low, void *high,int structure, struct rbtree *ttree); + int findoffsetstructure(int s, int offset); + typeobject *size; + struct rbtree *alloctree; + struct rbtree *typetree; +}; + +class structuremap { + public: + structuremap(int s); + ~structuremap(); + int str; + struct rbtree *typetree; +}; +#endif