2 #include "structdefs.h"
13 extern int classsize[];
14 jmp_buf error_handler;
19 float failurechance=0;
21 int injectinstructionfailures;
23 float instfailurechance=0;
31 void initializeexithandler() {
34 void exithandler(int sig, siginfo_t *info, void * uap) {
36 printf("exit in exithandler\n");
41 void initializeexithandler() {
43 sig.sa_sigaction=&exithandler;
44 sig.sa_flags=SA_SIGINFO;
45 sigemptyset(&sig.sa_mask);
46 sigaction(SIGUSR2, &sig, 0);
50 /* This function inject failures */
52 void injectinstructionfailure() {
54 // not supported in RAW version
58 if (injectinstructionfailures) {
61 instructioncount=failurecount;
62 instaccum+=failurecount;
63 if ((((double)random())/RAND_MAX)<instfailurechance) {
66 printf("FAILURE!!! %d\n",numfailures);
67 longjmp(error_handler,11);
72 if (injectinstructionfailures) {
75 instaccum+=failurecount;
76 if ((((double)random())/RAND_MAX)<instfailurechance) {
79 printf("FAILURE!!! %d\n",numfailures);
88 void CALL11(___System______exit____I,int ___status___, int ___status___) {
90 printf("exit in CALL11\n");
93 raw_test_done(___status___);
99 void CALL11(___System______printI____I,int ___status___, int ___status___) {
101 printf("printI in CALL11\n");
104 raw_test_pass(0x1111);
105 raw_test_pass_reg(___status___);
107 printf("%d\n", ___status___);
111 long CALL00(___System______currentTimeMillis____) {
113 // not supported in RAW version
116 struct timeval tv; long long retval;
117 gettimeofday(&tv, NULL);
118 retval = tv.tv_sec; /* seconds */
119 retval*=1000; /* milliseconds */
120 retval+= (tv.tv_usec/1000); /* adjust milliseconds & add them in */
125 void CALL01(___System______printString____L___String___,struct ___String___ * ___s___) {
128 struct ArrayObject * chararray=VAR(___s___)->___value___;
130 int offset=VAR(___s___)->___offset___;
131 for(i=0; i<VAR(___s___)->___count___; i++) {
132 short sc=((short *)(((char *)&chararray->___length___)+sizeof(int)))[i+offset];
138 /* Object allocation function */
141 void * allocate_new(void * ptr, int type) {
142 struct ___Object___ * v=(struct ___Object___ *) mygcmalloc((struct garbagelist *) ptr, classsize[type]);
154 /* Array allocation function */
156 struct ArrayObject * allocate_newarray(void * ptr, int type, int length) {
157 struct ArrayObject * v=mygcmalloc((struct garbagelist *) ptr, sizeof(struct ArrayObject)+length*classsize[type]);
163 printf("ERROR: negative array\n");
167 v->___length___=length;
177 void * allocate_new(int type) {
178 struct ___Object___ * v=FREEMALLOC(classsize[type]);
185 /* Array allocation function */
187 struct ArrayObject * allocate_newarray(int type, int length) {
188 struct ArrayObject * v=FREEMALLOC(sizeof(struct ArrayObject)+length*classsize[type]);
192 v->___length___=length;
198 /* Converts C character arrays into Java strings */
200 struct ___String___ * NewString(void * ptr, const char *str,int length) {
202 struct ___String___ * NewString(const char *str,int length) {
206 struct ArrayObject * chararray=allocate_newarray((struct garbagelist *)ptr, CHARARRAYTYPE, length);
207 int ptrarray[]={1, (int) ptr, (int) chararray};
208 struct ___String___ * strobj=allocate_new((struct garbagelist *) &ptrarray, STRINGTYPE);
209 chararray=(struct ArrayObject *) ptrarray[2];
211 struct ArrayObject * chararray=allocate_newarray(CHARARRAYTYPE, length);
212 struct ___String___ * strobj=allocate_new(STRINGTYPE);
214 strobj->___value___=chararray;
215 strobj->___count___=length;
216 strobj->___offset___=0;
218 for(i=0; i<length; i++) {
219 ((short *)(((char *)&chararray->___length___)+sizeof(int)))[i]=(short)str[i];
224 /* Generated code calls this if we fail a bounds check */
226 void failedboundschk() {
228 printf("Array out of bounds\n");
235 longjmp(error_handler,2);
239 /* Abort task call */
242 longjmp(error_handler,4);
244 printf("Aborting\n");