root/kernel/itimer.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. tvtojiffies
  2. jiffiestotv
  3. _getitimer
  4. sys_getitimer
  5. it_real_fn
  6. _setitimer
  7. sys_setitimer

   1 /*
   2  * linux/kernel/itimer.c
   3  *
   4  * Copyright (C) 1992 Darren Senn
   5  */
   6 
   7 /* These are all the functions necessary to implement itimers */
   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)
     /* [previous][next][first][last][top][bottom][index][help] */
  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)
     /* [previous][next][first][last][top][bottom][index][help] */
  26 {
  27         value->tv_usec = (jiffies % HZ) * (1000000 / HZ);
  28         value->tv_sec = jiffies / HZ;
  29         return;
  30 }
  31 
  32 int _getitimer(int which, struct itimerval *value)
     /* [previous][next][first][last][top][bottom][index][help] */
  33 {
  34         register unsigned long val, interval;
  35 
  36         switch (which) {
  37         case ITIMER_REAL:
  38                 val = current->it_real_value;
  39                 interval = current->it_real_incr;
  40                 break;
  41         case ITIMER_VIRTUAL:
  42                 val = current->it_virt_value;
  43                 interval = current->it_virt_incr;
  44                 break;
  45         case ITIMER_PROF:
  46                 val = current->it_prof_value;
  47                 interval = current->it_prof_incr;
  48                 break;
  49         default:
  50                 return(-EINVAL);
  51         }
  52         jiffiestotv(val, &value->it_value);
  53         jiffiestotv(interval, &value->it_interval);
  54         return(0);
  55 }
  56 
  57 asmlinkage int sys_getitimer(int which, struct itimerval *value)
     /* [previous][next][first][last][top][bottom][index][help] */
  58 {
  59         int error;
  60         struct itimerval get_buffer;
  61 
  62         if (!value)
  63                 return -EFAULT;
  64         error = _getitimer(which, &get_buffer);
  65         if (error)
  66                 return error;
  67         error = verify_area(VERIFY_WRITE, value, sizeof(struct itimerval));
  68         if (error)
  69                 return error;
  70         memcpy_tofs(value, &get_buffer, sizeof(get_buffer));
  71         return 0;
  72 }
  73 
  74 void it_real_fn(unsigned long __data)
     /* [previous][next][first][last][top][bottom][index][help] */
  75 {
  76         struct task_struct * p = (struct task_struct *) __data;
  77 
  78         send_sig(SIGALRM, p, 1);
  79         if (p->it_real_incr) {
  80                 p->real_timer.expires = p->it_real_incr;
  81                 add_timer(&p->real_timer);
  82         }
  83 }
  84 
  85 int _setitimer(int which, struct itimerval *value, struct itimerval *ovalue)
     /* [previous][next][first][last][top][bottom][index][help] */
  86 {
  87         register unsigned long i, j;
  88         int k;
  89 
  90         i = tvtojiffies(&value->it_interval);
  91         j = tvtojiffies(&value->it_value);
  92         if (ovalue && (k = _getitimer(which, ovalue)) < 0)
  93                 return k;
  94         switch (which) {
  95                 case ITIMER_REAL:
  96                         del_timer(&current->real_timer);
  97                         if (j) {
  98                                 current->real_timer.expires = j;
  99                                 add_timer(&current->real_timer);
 100                         }
 101                         current->it_real_value = j;
 102                         current->it_real_incr = i;
 103                         break;
 104                 case ITIMER_VIRTUAL:
 105                         if (j)
 106                                 j++;
 107                         current->it_virt_value = j;
 108                         current->it_virt_incr = i;
 109                         break;
 110                 case ITIMER_PROF:
 111                         if (j)
 112                                 j++;
 113                         current->it_prof_value = j;
 114                         current->it_prof_incr = i;
 115                         break;
 116                 default:
 117                         return -EINVAL;
 118         }
 119         return 0;
 120 }
 121 
 122 asmlinkage int sys_setitimer(int which, struct itimerval *value, struct itimerval *ovalue)
     /* [previous][next][first][last][top][bottom][index][help] */
 123 {
 124         int error;
 125         struct itimerval set_buffer, get_buffer;
 126 
 127         if (value) {
 128                 error = verify_area(VERIFY_READ, value, sizeof(*value));
 129                 if (error)
 130                         return error;
 131                 memcpy_fromfs(&set_buffer, value, sizeof(set_buffer));
 132         } else
 133                 memset((char *) &set_buffer, 0, sizeof(set_buffer));
 134 
 135         if (ovalue) {
 136                 error = verify_area(VERIFY_WRITE, ovalue, sizeof(struct itimerval));
 137                 if (error)
 138                         return error;
 139         }
 140 
 141         error = _setitimer(which, &set_buffer, ovalue ? &get_buffer : 0);
 142         if (error || !ovalue)
 143                 return error;
 144 
 145         memcpy_tofs(ovalue, &get_buffer, sizeof(get_buffer));
 146         return error;
 147 }

/* [previous][next][first][last][top][bottom][index][help] */