add sandbox files
[IRC.git] / Robust / src / Runtime / STM / sandbox.c
1 #include "sandbox.h"
2
3 __thread int transaction_check_counter;
4 __thread jmp_buf aborttrans;
5 __thread int abortenabled;
6 __thread int * counter_reset_pointer;
7
8 void checkObjects() {
9   if (abortenabled&&checktrans()) {
10     transaction_check_counter=(*counter_reset_pointer=HIGH_CHECK_FREQUENCY);
11     longjmp(aborttrans, 1);
12   }
13   transaction_check_counter=*counter_reset_pointer;
14 }
15
16 /* Do sandboxing */
17 void errorhandler(int sig, struct sigcontext ctx) {
18   printf("Error\n");
19   if (abortenabled&&checktrans())
20     longjmp(aborttrans, 1);
21   threadhandler(sig, ctx);
22 }
23
24 int checktrans() {
25   /* Create info to keep track of objects that can be locked */
26   chashlistnode_t *curr = c_list;
27
28   /* Inner loop to traverse the linked list of the cache lookupTable */
29   while(likely(curr != NULL)) {
30     //if the first bin in hash table is empty
31     objheader_t * headeraddr=&((objheader_t *) curr->val)[-1];
32     objheader_t *header=(objheader_t *)(((char *)curr->key)-sizeof(objheader_t));
33     unsigned int version = headeraddr->version;
34     
35     if (header->lock==0) {
36       return 1;
37     }
38     CFENCE;
39     if (version!=header->version) {
40       return 1;
41     }
42     curr = curr->lnext;
43   }
44   return 0;
45 }