-
Notifications
You must be signed in to change notification settings - Fork 0
/
hooks.c
101 lines (92 loc) · 2.92 KB
/
hooks.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "xinu.h"
extern int TEST;
extern unsigned int TEST5_PAGE;
extern unsigned char* TEST5_PTR;
extern unsigned char* TEST6_PTR;
extern int TEST5_pagefault;
extern int TEST6_pagefault;
void hook_ptable_create(unsigned int pagenum){
switch( TEST ){
case 5:
kprintf("GRADING : Test 5 creates a new page table at frame %d as expected\r\n", pagenum );
/*if( pagenum == TEST5_PAGE ){
kprintf("GRADING : Test 5 creates a new page table %d as expected\r\n", pagenum );
}else{
kprintf("GRADING : Test 5 creates a new page table %d which is not expected. Expect %d\r\n", pagenum, TEST5_PAGE );
}*/
case 6:
kprintf("GRADING : Test 6 creates a new page table at frame %d as expected\r\n", pagenum );
break;
}
}
void hook_ptable_delete(unsigned int pagenum){
switch( TEST ){
case 1:
case 2:
case 3:
case 4:
case 5:
kprintf("GRADING : page table %d is unexpectedly deleted in test %d \r\n", pagenum, TEST );
break;
case 51:
kprintf("GRADING : page table %d is deleted in test %d xmunmap() \r\n", pagenum, TEST );
break;
case 6:
kprintf("GRADING : page table %d is unexpectedly deleted in test %d \r\n", pagenum, TEST );
break;
case 61:
break;
case 62:
kprintf("GRADING : page table %d is deleted in test %d xmunmap() \r\n", pagenum, TEST );
break;
}
}
void hook_pfault(char *addr){
switch( TEST ){
case 5:
if( addr == TEST5_PTR ){
kprintf("GRADING : Test 5 cause page fault at address: 0x%0X as expected\r\n", addr);
TEST5_pagefault = 1;
}else{
TEST5_pagefault = 1;
kprintf("GRADING : Test 5 cause page fault at unexpected address: expect 0x%0X but instead 0x%0X\r\n", TEST5_PTR, addr);
}
break;
case 6:
if( addr == TEST6_PTR ){
kprintf("GRADING : Test 6 cause page fault at address: 0x%0X as expected\r\n", addr);
TEST6_pagefault = 1;
}else{
TEST6_pagefault = 1;
kprintf("GRADING : Test 6 cause page fault at unexpected address: expect 0x%0X but instead 0x%0X\r\n", TEST6_PTR, addr);
}
break;
case 61:
kprintf("GRADING : Test 6 failed because the new process accessing the memory location should not trigger a page fault.\r\n");
break;
case 12:
break;
case 13:
break;
/*default:
kprintf("page fault at an unknown test!\r\n");*/
break;
}
}
void hook_pswap_out(unsigned int pagenum, int framenb){
switch( TEST ){
case 1:
case 2:
case 3:
case 4:
case 5:
kprintf("GRADING : page %d is unexpectedly swapped out in test %d \r\n", pagenum, TEST );
break;
case 12:
kprintf("GRADING : page %d is swapped out in test %d \r\n", pagenum, TEST );
break;
case 13:
kprintf("GRADING : page %d is swapped out in test %d \r\n", pagenum, TEST );
break;
}
}