ab5db1e8aa85c78a50ec6d14066d2e86894325f6
[repair.git] / Repair / RepairCompiler / MCC / CRuntime / instrument.c
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
7 #include "instrument.h"
8 #include <stdio.h>
9 #include "tmap.h"
10 #include "size.h"
11
12 struct typemap * memmap;
13
14 void *ourcalloc(size_t nmemb, size_t size) {
15   void *oc=calloc(nmemb,size);
16   typemapallocate(memmap, oc,size*nmemb);
17   return oc;
18 }
19
20 void *ourmalloc(size_t size) {
21   void *oc=malloc(size);
22   typemapallocate(memmap, oc,size);
23   return oc;
24 }
25
26 void ourfree(void *ptr) {
27   typemapdeallocate(memmap, ptr);
28   free(ptr);
29 }
30
31 void *ourrealloc(void *ptr, size_t size) {
32   void *orr=realloc(ptr,size);
33   if (size==0) {
34     typemapdeallocate(memmap, ptr);
35     return orr;
36   }
37   if (orr==NULL) {
38     return orr;
39   }
40   typemapdeallocate(memmap, ptr);
41   typemapallocate(memmap, orr,size);
42   return orr;
43 }
44
45 void alloc(void *ptr,int size) {
46   typemapallocate(memmap, ptr,size);
47 }
48
49 void dealloc(void *ptr) {
50   typemapdeallocate(memmap, ptr);
51 }
52
53 void initializemmap() {
54   memmap=allocatetypemap();
55 }
56
57 void resettypemap() {
58   typemapreset(memmap);
59 }
60
61 bool assertvalidtype(int ptr, int structure) {
62   return typemapasserttype(memmap, (void *)ptr, structure);
63 }
64 bool assertvalidmemory(int ptr, int structure) {
65   return typemapassertvalidmemory(memmap, (void *)ptr, structure);
66 }
67
68 void initializestack(void *high) {
69   initializetypemapstack(memmap, high);
70 }