Hacks to allow repairs of fields used to define layouts of arrays.
[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 #include <string.h>
12
13 struct typemap * memmap;
14
15 void *ourcalloc(size_t nmemb, size_t size) {
16   void *oc=calloc(nmemb,size);
17   typemapallocate(memmap, oc,size*nmemb);
18   return oc;
19 }
20
21 void *ourmalloc(size_t size) {
22   void *oc=malloc(size);
23   typemapallocate(memmap, oc,size);
24   return oc;
25 }
26
27 void ourfree(void *ptr) {
28   if (ptr!=NULL) {
29     typemapdeallocate(memmap, ptr);
30   }
31   free(ptr);
32 }
33
34 void *ourrealloc(void *ptr, size_t size) {
35   void *orr=realloc(ptr,size);
36   if (size==0) {
37     typemapdeallocate(memmap, ptr);
38     return orr;
39   }
40   if (orr==NULL) {
41     return orr;
42   }
43   typemapdeallocate(memmap, ptr);
44   typemapallocate(memmap, orr,size);
45   return orr;
46 }
47
48 char *ourstrdup(const char *ptr) {
49   char *new_ptr=strdup(ptr);
50   int length=strlen(ptr)+1;
51   typemapallocate(memmap,new_ptr,length);
52   return new_ptr;
53 }
54
55
56 void alloc(void *ptr,int size) {
57   typemapallocate(memmap, ptr,size);
58 }
59
60 void dealloc(void *ptr) {
61   typemapdeallocate(memmap, ptr);
62 }
63
64 void initializemmap() {
65   memmap=allocatetypemap();
66 }
67
68 void resettypemap() {
69   typemapreset(memmap);
70 }
71
72 bool assertvalidtype(int ptr, int structure) {
73   return typemapasserttype(memmap, (void *)ptr, structure);
74 }
75 bool assertvalidmemory(int ptr, int structure) {
76   return typemapassertvalidmemory(memmap, (void *)ptr, structure);
77 }
78
79 bool assertexactmemory(int ptr, int structure) {
80   return typemapassertexactmemory(memmap, (void *)ptr, structure);
81 }
82
83 void * getendofblock(int ptr) {
84   return typemapgetendofblock(memmap, (void *)ptr);
85 }
86
87 void initializestack(void *high) {
88   initializetypemapstack(memmap, high);
89 }