This source file includes following definitions.
- tvtojiffies
- jiffiestotv
- _getitimer
- sys_getitimer
- _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
15 #include <asm/segment.h>
16
17 static unsigned long tvtojiffies(struct timeval *value)
18 {
19 return((unsigned long )value->tv_sec * HZ +
20 (unsigned long )(value->tv_usec + (1000000 / HZ - 1)) /
21 (1000000 / HZ));
22 }
23
24 static void jiffiestotv(unsigned long jiffies, struct timeval *value)
25 {
26 value->tv_usec = (jiffies % HZ) * (1000000 / HZ);
27 value->tv_sec = jiffies / HZ;
28 return;
29 }
30
31 int _getitimer(int which, struct itimerval *value)
32 {
33 register unsigned long val, interval;
34
35 switch (which) {
36 case ITIMER_REAL:
37 val = current->it_real_value;
38 interval = current->it_real_incr;
39 break;
40 case ITIMER_VIRTUAL:
41 val = current->it_virt_value;
42 interval = current->it_virt_incr;
43 break;
44 case ITIMER_PROF:
45 val = current->it_prof_value;
46 interval = current->it_prof_incr;
47 break;
48 default:
49 return(-EINVAL);
50 }
51 jiffiestotv(val, &value->it_value);
52 jiffiestotv(interval, &value->it_interval);
53 return(0);
54 }
55
56 int sys_getitimer(int which, struct itimerval *value)
57 {
58 int error;
59 struct itimerval get_buffer;
60
61 if (!value)
62 return -EFAULT;
63 error = _getitimer(which, &get_buffer);
64 if (error)
65 return error;
66 error = verify_area(VERIFY_WRITE, value, sizeof(struct itimerval));
67 if (error)
68 return error;
69 memcpy_tofs(value, &get_buffer, sizeof(get_buffer));
70 return 0;
71 }
72
73 int _setitimer(int which, struct itimerval *value, struct itimerval *ovalue)
74 {
75 register unsigned long i, j;
76 int k;
77
78 i = tvtojiffies(&value->it_interval);
79 j = tvtojiffies(&value->it_value);
80 if (ovalue && (k = _getitimer(which, ovalue)) < 0)
81 return k;
82 switch (which) {
83 case ITIMER_REAL:
84 current->it_real_value = j;
85 current->it_real_incr = i;
86 break;
87 case ITIMER_VIRTUAL:
88 current->it_virt_value = j;
89 current->it_virt_incr = i;
90 break;
91 case ITIMER_PROF:
92 current->it_prof_value = j;
93 current->it_prof_incr = i;
94 break;
95 default:
96 return -EINVAL;
97 }
98 return 0;
99 }
100
101 int sys_setitimer(int which, struct itimerval *value, struct itimerval *ovalue)
102 {
103 int error;
104 struct itimerval set_buffer, get_buffer;
105
106 if (!value)
107 memset((char *) &set_buffer, 0, sizeof(set_buffer));
108 else
109 memcpy_fromfs(&set_buffer, value, sizeof(set_buffer));
110 error = _setitimer(which, &set_buffer, ovalue ? &get_buffer : 0);
111 if (error || !ovalue)
112 return error;
113 error = verify_area(VERIFY_WRITE, ovalue, sizeof(struct itimerval));
114 if (!error)
115 memcpy_tofs(ovalue, &get_buffer, sizeof(get_buffer));
116 return error;
117 }