This commit was manufactured by cvs2svn to create tag 'buildscript'.
[IRC.git] /
1 #include "runtime.h"
2 #include "structdefs.h"
3 #include <signal.h>
4 #include "mem.h"
5 #include<fcntl.h>
6 #include<errno.h>
7 #include<signal.h>
8 #include<stdio.h>
9 #include "option.h"
10
11 extern int classsize[];
12 jmp_buf error_handler;
13 int instructioncount;
14
15 char *options;
16 int injectfailures=0;
17 float failurechance=0;
18 int debugtask=0;
19 int injectinstructionfailures;
20 int failurecount;
21 float instfailurechance=0;
22 int numfailures;
23 int instaccum=0;
24 #ifdef DMALLOC
25 #include "dmalloc.h"
26 #endif
27
28
29
30
31 void exithandler(int sig, siginfo_t *info, void * uap) {
32   exit(0);
33 }
34
35 void initializeexithandler() {
36   struct sigaction sig;
37   sig.sa_sigaction=&exithandler;
38   sig.sa_flags=SA_SIGINFO;
39   sigemptyset(&sig.sa_mask);
40   sigaction(SIGUSR2, &sig, 0);
41 }
42
43
44 /* This function inject failures */
45
46 void injectinstructionfailure() {
47 #ifdef TASK
48   if (injectinstructionfailures) {
49     if (numfailures==0)
50       return;
51     instructioncount=failurecount;    
52     instaccum+=failurecount;
53     if ((((double)random())/RAND_MAX)<instfailurechance) {
54       if (numfailures>0)
55         numfailures--;
56       printf("FAILURE!!! %d\n",numfailures);
57       longjmp(error_handler,11);
58     }
59   }
60 #else
61 #ifdef THREADS
62   if (injectinstructionfailures) {
63     if (numfailures==0)
64       return;
65     instaccum+=failurecount;
66     if ((((double)random())/RAND_MAX)<instfailurechance) {
67       if (numfailures>0)
68         numfailures--;
69       printf("FAILURE!!! %d\n",numfailures);
70       threadexit();
71     }
72   }
73 #endif
74 #endif
75 }
76
77 void CALL01(___System______printString____L___String___,struct ___String___ * ___s___) {
78     struct ArrayObject * chararray=VAR(___s___)->___value___;
79     int i;
80     int offset=VAR(___s___)->___offset___;
81     for(i=0;i<VAR(___s___)->___count___;i++) {
82         short sc=((short *)(((char *)& chararray->___length___)+sizeof(int)))[i+offset];
83         putchar(sc);
84     }
85 }
86
87 /* Object allocation function */
88
89 #ifdef PRECISE_GC
90 void * allocate_new(void * ptr, int type) {
91   struct ___Object___ * v=(struct ___Object___ *) mygcmalloc((struct garbagelist *) ptr, classsize[type]);
92   v->type=type;
93 #ifdef THREADS
94   v->tid=0;
95   v->lockentry=0;
96   v->lockcount=0;
97 #endif
98   return v;
99 }
100
101 /* Array allocation function */
102
103 struct ArrayObject * allocate_newarray(void * ptr, int type, int length) {
104   struct ArrayObject * v=mygcmalloc((struct garbagelist *) ptr, sizeof(struct ArrayObject)+length*classsize[type]);
105   v->type=type;
106   if (length<0) {
107     printf("ERROR: negative array\n");
108     return NULL;
109   }
110   v->___length___=length;
111 #ifdef THREADS
112   v->tid=0;
113   v->lockentry=0;
114   v->lockcount=0;
115 #endif
116   return v;
117 }
118
119 #else
120 void * allocate_new(int type) {
121   void * v=FREEMALLOC(classsize[type]);
122   *((int *)v)=type;
123   return v;
124 }
125
126 /* Array allocation function */
127
128 struct ArrayObject * allocate_newarray(int type, int length) {
129   struct ArrayObject * v=FREEMALLOC(sizeof(struct ArrayObject)+length*classsize[type]);
130   v->type=type;
131   v->___length___=length;
132   return v;
133 }
134 #endif
135
136
137 /* Converts C character arrays into Java strings */
138 #ifdef PRECISE_GC
139 struct ___String___ * NewString(void * ptr, const char *str,int length) {
140 #else
141 struct ___String___ * NewString(const char *str,int length) {
142 #endif
143   int i;
144 #ifdef PRECISE_GC
145   struct ArrayObject * chararray=allocate_newarray((struct garbagelist *)ptr, CHARARRAYTYPE, length);
146   int ptrarray[]={1, (int) ptr, (int) chararray};
147   struct ___String___ * strobj=allocate_new((struct garbagelist *) &ptrarray, STRINGTYPE);
148   chararray=(struct ArrayObject *) ptrarray[2];
149 #else
150   struct ArrayObject * chararray=allocate_newarray(CHARARRAYTYPE, length);
151   struct ___String___ * strobj=allocate_new(STRINGTYPE);
152 #endif
153   strobj->___value___=chararray;
154   strobj->___count___=length;
155   strobj->___offset___=0;
156
157   for(i=0;i<length;i++) {
158     ((short *)(((char *)& chararray->___length___)+sizeof(int)))[i]=(short)str[i];  }
159   return strobj;
160 }
161
162 /* Generated code calls this if we fail a bounds check */
163
164 void failedboundschk() {
165 #ifndef TASK
166   printf("Array out of bounds\n");
167 #ifdef THREADS
168   threadexit();
169 #else
170   exit(-1);
171 #endif
172 #else
173   longjmp(error_handler,2);
174 #endif
175 }
176
177 /* Abort task call */
178 void abort_task() {
179 #ifdef TASK
180   longjmp(error_handler,4);
181 #else
182   printf("Aborting\n");
183   exit(-1);
184 #endif
185 }