2 #include "structdefs.h"
13 extern int classsize[];
14 jmp_buf error_handler;
19 float failurechance=0;
22 int injectinstructionfailures;
24 float instfailurechance=0;
32 void initializeexithandler() {
35 void exithandler(int sig, siginfo_t *info, void * uap) {
37 printf("exit in exithandler\n");
42 void initializeexithandler() {
44 sig.sa_sigaction=&exithandler;
45 sig.sa_flags=SA_SIGINFO;
46 sigemptyset(&sig.sa_mask);
47 sigaction(SIGUSR2, &sig, 0);
51 /* This function inject failures */
53 void injectinstructionfailure() {
55 // not supported in RAW version
59 if (injectinstructionfailures) {
62 instructioncount=failurecount;
63 instaccum+=failurecount;
64 if ((((double)random())/RAND_MAX)<instfailurechance) {
67 printf("FAILURE!!! %d\n",numfailures);
68 longjmp(error_handler,11);
73 if (injectinstructionfailures) {
76 instaccum+=failurecount;
77 if ((((double)random())/RAND_MAX)<instfailurechance) {
80 printf("FAILURE!!! %d\n",numfailures);
89 void CALL11(___System______exit____I,int ___status___, int ___status___) {
91 printf("exit in CALL11\n");
94 raw_test_done(___status___);
100 void CALL11(___System______printI____I,int ___status___, int ___status___) {
102 printf("printI in CALL11\n");
105 raw_test_pass(0x1111);
106 raw_test_pass_reg(___status___);
108 printf("%d\n", ___status___);
112 long CALL00(___System______currentTimeMillis____) {
114 // not supported in RAW version
117 struct timeval tv; long long retval;
118 gettimeofday(&tv, NULL);
119 retval = tv.tv_sec; /* seconds */
120 retval*=1000; /* milliseconds */
121 retval+= (tv.tv_usec/1000); /* adjust milliseconds & add them in */
126 void CALL01(___System______printString____L___String___,struct ___String___ * ___s___) {
129 struct ArrayObject * chararray=VAR(___s___)->___value___;
131 int offset=VAR(___s___)->___offset___;
132 for(i=0; i<VAR(___s___)->___count___; i++) {
133 short sc=((short *)(((char *)&chararray->___length___)+sizeof(int)))[i+offset];
139 /* Object allocation function */
142 void * allocate_new(void * ptr, int type) {
143 struct ___Object___ * v=(struct ___Object___ *) mygcmalloc((struct garbagelist *) ptr, classsize[type]);
157 /* Array allocation function */
159 struct ArrayObject * allocate_newarray(void * ptr, int type, int length) {
160 struct ArrayObject * v=mygcmalloc((struct garbagelist *) ptr, sizeof(struct ArrayObject)+length*classsize[type]);
168 printf("ERROR: negative array\n");
172 v->___length___=length;
182 void * allocate_new(int type) {
183 struct ___Object___ * v=FREEMALLOC(classsize[type]);
192 /* Array allocation function */
194 struct ArrayObject * allocate_newarray(int type, int length) {
195 struct ArrayObject * v=FREEMALLOC(sizeof(struct ArrayObject)+length*classsize[type]);
201 v->___length___=length;
207 /* Converts C character arrays into Java strings */
209 struct ___String___ * NewString(void * ptr, const char *str,int length) {
211 struct ___String___ * NewString(const char *str,int length) {
215 struct ArrayObject * chararray=allocate_newarray((struct garbagelist *)ptr, CHARARRAYTYPE, length);
216 int ptrarray[]={1, (int) ptr, (int) chararray};
217 struct ___String___ * strobj=allocate_new((struct garbagelist *) &ptrarray, STRINGTYPE);
218 chararray=(struct ArrayObject *) ptrarray[2];
220 struct ArrayObject * chararray=allocate_newarray(CHARARRAYTYPE, length);
221 struct ___String___ * strobj=allocate_new(STRINGTYPE);
223 strobj->___value___=chararray;
224 strobj->___count___=length;
225 strobj->___offset___=0;
227 for(i=0; i<length; i++) {
228 ((short *)(((char *)&chararray->___length___)+sizeof(int)))[i]=(short)str[i];
233 /* Generated code calls this if we fail a bounds check */
235 void failedboundschk() {
237 printf("Array out of bounds\n");
244 longjmp(error_handler,2);
248 /* Abort task call */
251 longjmp(error_handler,4);
253 printf("Aborting\n");