scratch/ffiTest: removed export
[mate.git] / scratch / ffiTest / mate_support.c
1 #include <stdio.h>
2 #include <stdlib.h>
3
4 /* TODO(bernhard): use {u,}int* types */
5
6 #define __USE_GNU
7 // Note by hs: my signal.h includes sys/uconctext which conflicts with
8 // asm/ucontext - this hack kinda solves the problem for me ;-) 
9 // so feel free to blame me for that s**t
10 #if defined __USE_XOPEN2K8
11 #undef __USE_XOPEN2K8
12 #define RESTORE
13 #warning hs-hack: undefining __USE_XOPEN2K8 for signal.h
14 #endif
15 #include <signal.h>
16 #ifdef RESTORE
17 #define __USE_XOPEN2K8
18 #endif
19
20 #include <sys/ucontext.h>
21
22 #include "prototypes.h"
23
24 void trap(int nSignal, siginfo_t *info, void *ctx)
25 {
26         printf("sig: %d\n", nSignal);
27         
28         mcontext_t *mctx = &((ucontext_t *) ctx)->uc_mcontext;
29         unsigned int from = (unsigned int) mctx->gregs[REG_EIP];
30
31         //mateTrapHandler(nSignal, info, ctx, from);
32
33         printf("from: 0x%08x\n", from);
34         exit(0);
35 }
36
37
38 void registerSignalHandlers2(void (*f)(int, siginfo_t*,void*))
39 {
40         printf("registering2\n");
41         struct sigaction illaction;
42         illaction.sa_sigaction = f;
43         sigemptyset(&illaction.sa_mask);
44         illaction.sa_flags = SA_SIGINFO | SA_RESTART | SA_NODEFER;
45         sigaction(SIGILL, &illaction, NULL);
46 }
47