|
@@ -7,6 +7,17 @@
|
7
|
7
|
*
|
8
|
8
|
*/
|
9
|
9
|
|
|
10
|
+/**
|
|
11
|
+ * Hooked interrupt count
|
|
12
|
+ *
|
|
13
|
+ * At exit, after unhooking all possible interrupts, this counter
|
|
14
|
+ * should be examined. If it is non-zero, it means that we failed to
|
|
15
|
+ * unhook at least one interrupt vector, and so must not free up the
|
|
16
|
+ * memory we are using. (Note that this also implies that we should
|
|
17
|
+ * re-hook INT 15 in order to hide ourselves from the memory map).
|
|
18
|
+ */
|
|
19
|
+int hooked_bios_interrupts = 0;
|
|
20
|
+
|
10
|
21
|
/**
|
11
|
22
|
* Hook INT vector
|
12
|
23
|
*
|
|
@@ -26,9 +37,15 @@ void hook_bios_interrupt ( unsigned int interrupt, unsigned int handler,
|
26
|
37
|
.offset = handler,
|
27
|
38
|
};
|
28
|
39
|
|
|
40
|
+ if ( ( chain_vector->segment != 0 ) ||
|
|
41
|
+ ( chain_vector->offset != 0 ) ) {
|
|
42
|
+ /* Already hooked; do nothing */
|
|
43
|
+ return;
|
|
44
|
+ }
|
29
|
45
|
copy_from_real ( chain_vector, 0, ( interrupt * 4 ),
|
30
|
46
|
sizeof ( *chain_vector ) );
|
31
|
47
|
copy_to_real ( 0, ( interrupt * 4 ), &vector, sizeof ( vector ) );
|
|
48
|
+ hooked_bios_interrupts++;
|
32
|
49
|
}
|
33
|
50
|
|
34
|
51
|
/**
|
|
@@ -53,5 +70,8 @@ int unhook_bios_interrupt ( unsigned int interrupt, unsigned int handler,
|
53
|
70
|
return -EBUSY;
|
54
|
71
|
copy_to_real ( 0, ( interrupt * 4 ), chain_vector,
|
55
|
72
|
sizeof ( *chain_vector ) );
|
|
73
|
+ chain_vector->segment = 0;
|
|
74
|
+ chain_vector->offset = 0;
|
|
75
|
+ hooked_bios_interrupts--;
|
56
|
76
|
return 0;
|
57
|
77
|
}
|