This source file includes following definitions.
- tvtojiffies
- jiffiestotv
- _getitimer
- sys_getitimer
- it_real_fn
- _setitimer
- sys_setitimer
1
2
3
4
5
6
7
8
9 #include <linux/signal.h>
10 #include <linux/sched.h>
11 #include <linux/string.h>
12 #include <linux/errno.h>
13 #include <linux/time.h>
14 #include <linux/mm.h>
15
16 #include <asm/segment.h>
17
18 static unsigned long tvtojiffies(struct timeval *value)
19 {
20 return((unsigned long )value->tv_sec * HZ +
21 (unsigned long )(value->tv_usec + (1000000 / HZ - 1)) /
22 (1000000 / HZ));
23 }
24
25 static void jiffiestotv(unsigned long jiffies, struct timeval *value)
26 {
27 value->tv_usec = (jiffies % HZ) * (1000000 / HZ);
28 value->tv_sec = jiffies / HZ;
29 return;
30 }
31
32 static int _getitimer(int which, struct itimerval *value)
33 {
34 register long val, interval;
35
36 switch (which) {
37 case ITIMER_REAL:
38 interval = current->it_real_incr;
39 val = 0;
40 if (del_timer(¤t->real_timer)) {
41 val = current->real_timer.expires;
42 add_timer(¤t->real_timer);
43 if (val <= 0)
44 val = interval;
45 }
46 break;
47 case ITIMER_VIRTUAL:
48 val = current->it_virt_value;
49 interval = current->it_virt_incr;
50 break;
51 case ITIMER_PROF:
52 val = current->it_prof_value;
53 interval = current->it_prof_incr;
54 break;
55 default:
56 return(-EINVAL);
57 }
58 jiffiestotv(val, &value->it_value);
59 jiffiestotv(interval, &value->it_interval);
60 return 0;
61 }
62
63 asmlinkage int sys_getitimer(int which, struct itimerval *value)
64 {
65 int error;
66 struct itimerval get_buffer;
67
68 if (!value)
69 return -EFAULT;
70 error = _getitimer(which, &get_buffer);
71 if (error)
72 return error;
73 error = verify_area(VERIFY_WRITE, value, sizeof(struct itimerval));
74 if (error)
75 return error;
76 memcpy_tofs(value, &get_buffer, sizeof(get_buffer));
77 return 0;
78 }
79
80 void it_real_fn(unsigned long __data)
81 {
82 struct task_struct * p = (struct task_struct *) __data;
83
84 send_sig(SIGALRM, p, 1);
85 if (p->it_real_incr) {
86 p->real_timer.expires = p->it_real_incr;
87 add_timer(&p->real_timer);
88 }
89 }
90
91 int _setitimer(int which, struct itimerval *value, struct itimerval *ovalue)
92 {
93 register unsigned long i, j;
94 int k;
95
96 i = tvtojiffies(&value->it_interval);
97 j = tvtojiffies(&value->it_value);
98 if (ovalue && (k = _getitimer(which, ovalue)) < 0)
99 return k;
100 switch (which) {
101 case ITIMER_REAL:
102 del_timer(¤t->real_timer);
103 if (j) {
104 current->real_timer.expires = j;
105 add_timer(¤t->real_timer);
106 }
107 current->it_real_value = j;
108 current->it_real_incr = i;
109 break;
110 case ITIMER_VIRTUAL:
111 if (j)
112 j++;
113 current->it_virt_value = j;
114 current->it_virt_incr = i;
115 break;
116 case ITIMER_PROF:
117 if (j)
118 j++;
119 current->it_prof_value = j;
120 current->it_prof_incr = i;
121 break;
122 default:
123 return -EINVAL;
124 }
125 return 0;
126 }
127
128 asmlinkage int sys_setitimer(int which, struct itimerval *value, struct itimerval *ovalue)
129 {
130 int error;
131 struct itimerval set_buffer, get_buffer;
132
133 if (value) {
134 error = verify_area(VERIFY_READ, value, sizeof(*value));
135 if (error)
136 return error;
137 memcpy_fromfs(&set_buffer, value, sizeof(set_buffer));
138 } else
139 memset((char *) &set_buffer, 0, sizeof(set_buffer));
140
141 if (ovalue) {
142 error = verify_area(VERIFY_WRITE, ovalue, sizeof(struct itimerval));
143 if (error)
144 return error;
145 }
146
147 error = _setitimer(which, &set_buffer, ovalue ? &get_buffer : 0);
148 if (error || !ovalue)
149 return error;
150
151 memcpy_tofs(ovalue, &get_buffer, sizeof(get_buffer));
152 return error;
153 }