#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)
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;
}
{
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);
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;
}