-
Notifications
You must be signed in to change notification settings - Fork 22
/
signal_test.c
executable file
·51 lines (40 loc) · 999 Bytes
/
signal_test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "types.h"
#include "stat.h"
#include "user.h"
void
fpf_handler(void){
printf(1, "---------------------------------\n");
printf(1, "fpf handled!!!!!\n");
printf(1, "---------------------------------\n\n");
return;
}
void
segv_handler(void){
printf(1, "---------------------------------\n");
printf(1, "segv handled!!!!!\n");
printf(1, "---------------------------------\n\n");
}
void segment_fault()
{
int *ptr = (void*)0x8000001;
*ptr = 1;
}
int
main(int argc, char *argv[])
{
int a = 10;
int b = 0;
int c;
printf(1, "fpf_handler: %x\n", fpf_handler);
printf(1, "fpf_handler: %x\n", &fpf_handler);
printf(1, "segv_handler: %x\n", segv_handler);
printf(1, "segv_handler: %x\n", &segv_handler);
signal(SIGFPE, (sighandler_t)fpf_handler);
signal(SIGSEGV, (sighandler_t)segv_handler);
//segment fault
segment_fault();
//fpr trap
c = a / b;
printf(1, "finished $d%d!\n", b, c);
exit();
}