add sandbox files
authorbdemsky <bdemsky>
Fri, 9 Oct 2009 07:07:58 +0000 (07:07 +0000)
committerbdemsky <bdemsky>
Fri, 9 Oct 2009 07:07:58 +0000 (07:07 +0000)
Robust/src/Runtime/STM/sandbox.c [new file with mode: 0644]
Robust/src/Runtime/STM/sandbox.h [new file with mode: 0644]

diff --git a/Robust/src/Runtime/STM/sandbox.c b/Robust/src/Runtime/STM/sandbox.c
new file mode 100644 (file)
index 0000000..bf7504f
--- /dev/null
@@ -0,0 +1,45 @@
+#include "sandbox.h"
+
+__thread int transaction_check_counter;
+__thread jmp_buf aborttrans;
+__thread int abortenabled;
+__thread int * counter_reset_pointer;
+
+void checkObjects() {
+  if (abortenabled&&checktrans()) {
+    transaction_check_counter=(*counter_reset_pointer=HIGH_CHECK_FREQUENCY);
+    longjmp(aborttrans, 1);
+  }
+  transaction_check_counter=*counter_reset_pointer;
+}
+
+/* Do sandboxing */
+void errorhandler(int sig, struct sigcontext ctx) {
+  printf("Error\n");
+  if (abortenabled&&checktrans())
+    longjmp(aborttrans, 1);
+  threadhandler(sig, ctx);
+}
+
+int checktrans() {
+  /* Create info to keep track of objects that can be locked */
+  chashlistnode_t *curr = c_list;
+
+  /* Inner loop to traverse the linked list of the cache lookupTable */
+  while(likely(curr != NULL)) {
+    //if the first bin in hash table is empty
+    objheader_t * headeraddr=&((objheader_t *) curr->val)[-1];
+    objheader_t *header=(objheader_t *)(((char *)curr->key)-sizeof(objheader_t));
+    unsigned int version = headeraddr->version;
+    
+    if (header->lock==0) {
+      return 1;
+    }
+    CFENCE;
+    if (version!=header->version) {
+      return 1;
+    }
+    curr = curr->lnext;
+  }
+  return 0;
+}
diff --git a/Robust/src/Runtime/STM/sandbox.h b/Robust/src/Runtime/STM/sandbox.h
new file mode 100644 (file)
index 0000000..a93321d
--- /dev/null
@@ -0,0 +1,18 @@
+#ifndef SANDBOX_H
+#define SANDBOX_H
+
+#include <setjmp.h>
+#include <signal.h>
+extern __thread jmp_buf aborttrans;
+extern __thread int abortenabled;
+extern __thread int* counter_reset_pointer;
+extern __thread int transaction_check_counter;
+void checkObjects();
+#define LOW_CHECK_FREQUENCY 1000000
+#define HIGH_CHECK_FREQUENCY 100000
+int checktrans();
+void errorhandler(int sig, struct sigcontext ctx);
+
+#endif
+
+