]> rtime.felk.cvut.cz Git - frescor/fosa.git/blobdiff - src_partikle/fosa_long_jump.c
New way of handling long jumps
[frescor/fosa.git] / src_partikle / fosa_long_jump.c
index 3e502ce950d05c2dcbcc7bf7805eb6c0d5ad62a4..e59a69ff5d4a3dabaf2d03932179370bb749e4dd 100644 (file)
 #ifdef CONFIG_LONGJUMP
 
 #include <fosa_long_jump.h>
+#include <stdio.h>
 
-enum {
-  LONGJMP_MAGIC = 0x01234567,
-};
-
+#define LONGJMP_MAGIC 0x01234567
 int jmp_used_signals [LONGJMP_NSIG] = {[0 ... (LONGJMP_NSIG - 1)] = 0};
 pthread_mutex_t signal_pool_m = PTHREAD_MUTEX_INITIALIZER;
 
-
-int fosa_long_jump_save_context
-   (fosa_long_jump_context_t * context)
-{
-  if (!context)
-    return FOSA_EINVAL;
-
-  // Save the actual signal mask & mark the jump as still not performed
-  pthread_sigmask (SIG_SETMASK, NULL, &(context -> jmp_sigmask));
-  context -> jmp_hasexecuted  = false;
-
-  if (setjmp (context -> jmp_context) == LONGJMP_MAGIC) {
-#ifndef CONFIG_LONGJUMP_FREE_SIGNALS
-    pthread_sigmask (SIG_SETMASK, &(context -> jmp_sigmask), NULL);
-#endif 
-    context -> jmp_hasexecuted = true;
-  }
-  return 0;
-}
-
+extern void fosa_longjmp (fosa_long_jump_context_t ctx, unsigned long magic);
 
 int fosa_long_jump_was_performed
     (const fosa_long_jump_context_t * context, int * jumped)
@@ -101,7 +80,8 @@ int fosa_long_jump_was_performed
   if (!context && !jumped)
     return FOSA_EINVAL;
 
-  *jumped = context -> jmp_hasexecuted? 1:0;
+//   printf ("context [6]=%ld\n", (*(context))[6]);
+  *jumped = ((*(context))[6] == LONGJMP_MAGIC);
   return 0;
 }
 
@@ -110,11 +90,11 @@ void jmp_handler (int signo, siginfo_t *info, void *context)
 {
   fosa_long_jump_context_t *jmp_info = (fosa_long_jump_context_t *) info -> si_value.sival_ptr;
 
-#ifdef CONFIG_LONGJUMP_FREE_SIGNALS
+#ifdef CONFIG_LONGJUMP_FREE_SIGNAL
   sigset_t set;
 
   // Restore the signal mask
-  pthread_sigmask (SIG_SETMASK, &(context -> jmp_sigmask), NULL);
+//   pthread_sigmask (SIG_SETMASK, &(jmp_info -> jmp_sigmask), NULL);
 
   // Free this signal
   sigemptyset (&set);
@@ -126,8 +106,9 @@ void jmp_handler (int signo, siginfo_t *info, void *context)
   pthread_mutex_unlock (&signal_pool_m);
 #endif
 
+//   printf ("\t\t\t\t>>>  RESTORE CONTEXT  <<<\n\n");
   // Restore the saved context
-  longjmp (jmp_info -> jmp_context, LONGJMP_MAGIC);
+  fosa_longjmp (*jmp_info, LONGJMP_MAGIC);
   return;
 }