-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestkill.c
60 lines (55 loc) · 1.21 KB
/
testkill.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
#include "types.h"
#include "stat.h"
#include "user.h"
#include "fs.h"
#include "signal.h"
//in user handler change the value of registers which are stored in trapframe
void cont_handler(int signal){
__asm__ ("movl $0x0,%eax\n\t");
__asm__ ("movl $0x43,%ebx\n\t");
__asm__ ("movl $0x76,%ecx\n\t");
}
int main(){
int i = 0;
int pid = fork();
//child process
if(pid == 0) {
signal(SIGCONT, cont_handler);
register uint eax asm ("%eax");
register uint ebx asm ("%ebx");
register uint ecx asm ("%ecx");
__asm__ ("movl $0x21,%eax\n\t");
__asm__ ("movl $0x10,%ebx\n\t");
__asm__ ("movl $0x03,%ecx\n\t");
uint saved_eax = eax;
uint saved_ebx = ebx;
uint saved_ecx = ecx;
for(i = 0; i < 600; i++){
//printf (1, "eax %d ebx %d ecx %d\n", eax, ebx, ecx);
saved_eax = eax;
saved_ebx = ebx;
saved_ecx = ecx;
if (saved_eax != 33 || saved_ebx != 16 || saved_ecx != 3){
break;
}
else{
sleep(1);
continue;
}
}
if (i == 600){
printf (1, "test passed\n");
}
else{
printf (1, "test failed\n");
}
}
//parent process
else
{
sleep(200);
sendkill(pid, SIGCONT);
wait();
}
exit();
}