-
Notifications
You must be signed in to change notification settings - Fork 0
/
alarm.txt
79 lines (75 loc) · 1.58 KB
/
alarm.txt
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
1.按之前的系统调用的操作步骤:int sigreturn(void);
int sigalarm(int,void*);。。。。等等
2.proc.h
struct proc {
......
int interval; // interval of alarm
int since_interval; // last call until now
void (*handler)(); // function pointer
int running_hand; // flag of running
struct trapframe trapframe_cp; //copy of trapframe_cp
};
3.
sysproc.c
uint64
sys_sigreturn(void)
{
struct proc *p = myproc();
p->since_interval = 0;
*(p->trapframe) = p->trapframe_cp;
p->running_hand = 0;
return 0;
}
uint64
sys_sigalarm(void)
{
int interval;
uint64 pointer;
if(argint(0, &interval) < 0)
return -1;
if(interval == 0)
return 0;
if(argaddr(1, &pointer) < 0)
return -1;
myproc()->handler = (void *)pointer;
myproc()->since_interval = 0;
myproc()->running_hand = 0;
myproc()->interval = interval;
return 0;
}
proc.c
static struct proc*
allocproc(void)
{
....
found:
p->pid = allocpid();
p->interval = 0;
p->since_interval = 0;
p->handler = 0;
....
}
trap.c
void
usertrap(void)
{
.......
// give up the CPU if this is a timer interrupt.
if(which_dev == 2)
{
if(p->interval != 0)
{
if(!p->running_hand)
p->since_interval = p->since_interval + 1;
if(!p->running_hand && p->since_interval == p->interval)
{
printf("alarm!\n");
p->running_hand = 1;
p->trapframe_cp = *(p->trapframe);
p->trapframe->epc = (uint64)p->handler;
}
}
yield();
}
......
}