fdbdd5018fe78cdec1dbc3e3411e157ee6fc34df
[repair.git] / Repair / RepairCompiler / MCC / Runtime / instrument.cc
1 /* Defines interfaces for the applications and exports function calls that  
2    the applications should use instead of the standard ones. */
3
4 #include <stdlib.h>
5 #include <sys/time.h>
6 extern "C" {
7 #include "instrument.h"
8 }
9 #include <stdio.h>
10 #include "tmap.h"
11 #include "size.h"
12
13 typemap * memmap;
14
15 void *ourcalloc(size_t nmemb, size_t size) {
16   void *oc=calloc(nmemb,size);
17   memmap->allocate(oc,size*nmemb);
18   return oc;
19 }
20
21 void *ourmalloc(size_t size) {
22   void *oc=malloc(size);
23   memmap->allocate(oc,size);
24   return oc;
25 }
26
27 void ourfree(void *ptr) {
28   memmap->deallocate(ptr);
29   free(ptr);
30 }
31
32 void *ourrealloc(void *ptr, size_t size) {
33   void *orr=realloc(ptr,size);
34   if (size==0) {
35     memmap->deallocate(ptr);
36     return orr;
37   }
38   if (orr==NULL) {
39     return orr;
40   }
41   memmap->deallocate(ptr);
42   memmap->allocate(ptr,size);
43 }
44
45 void alloc(void *ptr,int size) {
46   memmap->allocate(ptr,size);
47 }
48
49 void dealloc(void *ptr) {
50   memmap->deallocate(ptr);
51 }
52
53 void initializemmap() {
54   typeobject *to=new typeobject();
55   memmap=new typemap(to);
56 }
57
58 typeobject * gettypeobject() {
59   return memmap->size;
60 }
61
62 void resettypemap() {
63   memmap->reset();
64 }
65
66 bool assertvalidtype(int ptr, int structure) {
67   return memmap->asserttype((void *)ptr, structure);
68 }
69 bool assertvalidmemory(int ptr, int structure) {
70   return memmap->assertvalidmemory((void *)ptr, structure);
71 }