From 8c5a329e1f567500004566ca4482c5269a0ac439 Mon Sep 17 00:00:00 2001 From: bdemsky Date: Thu, 24 Aug 2006 19:53:02 +0000 Subject: [PATCH] checkpointing code bug fixes long jump signal handlers --- Robust/src/Runtime/checkpoint.c | 49 ++++++++++++++++++----------- Robust/src/Runtime/runtime.c | 55 +++++++++++++++++++++++++++++++-- Robust/src/Runtime/runtime.h | 3 +- 3 files changed, 86 insertions(+), 21 deletions(-) diff --git a/Robust/src/Runtime/checkpoint.c b/Robust/src/Runtime/checkpoint.c index 0dceb860..86c885ce 100644 --- a/Robust/src/Runtime/checkpoint.c +++ b/Robust/src/Runtime/checkpoint.c @@ -3,12 +3,21 @@ #include "structdefs.h" #include -void ** makecheckpoint(int numparams, void ** pointerarray, struct SimpleHash * forward, struct SimpleHash * reverse) { +void ** makecheckpoint(int numparams, void ** srcpointer, struct SimpleHash * forward, struct SimpleHash * reverse) { void **newarray=RUNMALLOC(sizeof(void *)*numparams); struct SimpleHash *todo=allocateSimpleHash(100); int i; for(i=0;i___length___; - int size=sizeof(struct ArrayObject)+length*elementsize; - void *newobj=RUNMALLOC(size); - memcpy(newobj, orig, size); - return newobj; + if (orig==0) + return 0; + else { + int type=((int *)orig)[0]; + if (type___length___; + int size=sizeof(struct ArrayObject)+length*elementsize; + void *newobj=RUNMALLOC(size); + memcpy(newobj, orig, size); + return newobj; + } } } diff --git a/Robust/src/Runtime/runtime.c b/Robust/src/Runtime/runtime.c index 818c6ac7..7353d931 100644 --- a/Robust/src/Runtime/runtime.c +++ b/Robust/src/Runtime/runtime.c @@ -1,14 +1,24 @@ #include "runtime.h" #include "structdefs.h" #include +#include +#include "mem.h" +#include +#include +#include +#include +#include +#include extern int classsize[]; -#include "mem.h" +jmp_buf error_handler; #ifdef TASK +#include "checkpoint.h" #include "Queue.h" #include "SimpleHash.h" #include "task.h" + struct SimpleHash * activetasks; struct parameterwrapper * objectqueues[NUMCLASSES]; @@ -77,8 +87,29 @@ void flagorand(void * ptr, int ormask, int andmask) { } } +/* Handler for signals */ +void myhandler(int sig, struct __siginfo *info, void *uap) { + printf("sig=%d\n",sig); + printf("signal\n"); + longjmp(error_handler,1); +} + void executetasks() { void * pointerarray[MAXTASKPARAMS]; + /* Set up signal handlers */ + struct sigaction sig; + sig.sa_sigaction=&myhandler; + sig.sa_flags=SA_SIGINFO; + sig.sa_mask=0; + + /* Catch bus errors, segmentation faults, and floating point exceptions*/ + sigaction(SIGBUS,&sig,0); + sigaction(SIGSEGV,&sig,0); + sigaction(SIGFPE,&sig,0); + + /* Map first block of memory to protected, anonymous page */ + mmap(0, 0x1000, 0, MAP_SHARED|MAP_FIXED|MAP_ANON, -1, 0); + newtask: while(SimpleHashcountset(activetasks)!=0) { struct taskdescriptor * task=(struct taskdescriptor *) SimpleHashfirstkey(activetasks); @@ -92,7 +123,19 @@ void executetasks() { } pointerarray[i]=getTail(queue)->objectptr; } - ((void (*) (void **)) task->taskptr)(pointerarray); + { + struct SimpleHash * forward=allocateSimpleHash(100); + struct SimpleHash * reverse=allocateSimpleHash(100); + void ** checkpoint=makecheckpoint(task->numParameters, pointerarray, forward, reverse); + if (setjmp(error_handler)) { + /* Recover */ + restorecheckpoint(task->numParameters, pointerarray, checkpoint, forward, reverse); + /* TODO: REMOVE TASK FROM QUEUE */ + } else { + /* Actually call task */ + ((void (*) (void **)) task->taskptr)(pointerarray); + } + } } } @@ -158,11 +201,19 @@ struct ___String___ * NewString(char *str,int length) { } void failedboundschk() { +#ifndef TASK printf("Array out of bounds\n"); exit(-1); +#else + longjmp(error_handler,2); +#endif } void failednullptr() { +#ifndef TASK printf("Dereferenced a null pointer\n"); exit(-1); +#else + longjmp(error_handler,3); +#endif } diff --git a/Robust/src/Runtime/runtime.h b/Robust/src/Runtime/runtime.h index 7bbc2de1..e17e18a5 100644 --- a/Robust/src/Runtime/runtime.h +++ b/Robust/src/Runtime/runtime.h @@ -1,6 +1,7 @@ #ifndef RUNTIME #define RUNTIME - +#include +extern jmp_buf error_handler; void * allocate_new(int type); struct ArrayObject * allocate_newarray(int type, int length); -- 2.34.1