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. _setitimer
  6. 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 
  15 #include <asm/segment.h>
  16 
  17 static unsigned long tvtojiffies(struct timeval *value)
     /* [previous][next][first][last][top][bottom][index][help] */
  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)
     /* [previous][next][first][last][top][bottom][index][help] */
  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)
     /* [previous][next][first][last][top][bottom][index][help] */
  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 asmlinkage int sys_getitimer(int which, struct itimerval *value)
     /* [previous][next][first][last][top][bottom][index][help] */
  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)
     /* [previous][next][first][last][top][bottom][index][help] */
  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                         if (j) {
  85                                 j += 1+itimer_ticks;
  86                                 if (j < itimer_next)
  87                                         itimer_next = j;
  88                         }
  89                         current->it_real_value = j;
  90                         current->it_real_incr = i;
  91                         break;
  92                 case ITIMER_VIRTUAL:
  93                         if (j)
  94                                 j++;
  95                         current->it_virt_value = j;
  96                         current->it_virt_incr = i;
  97                         break;
  98                 case ITIMER_PROF:
  99                         if (j)
 100                                 j++;
 101                         current->it_prof_value = j;
 102                         current->it_prof_incr = i;
 103                         break;
 104                 default:
 105                         return -EINVAL;
 106         }
 107         return 0;
 108 }
 109 
 110 asmlinkage int sys_setitimer(int which, struct itimerval *value, struct itimerval *ovalue)
     /* [previous][next][first][last][top][bottom][index][help] */
 111 {
 112         int error;
 113         struct itimerval set_buffer, get_buffer;
 114 
 115         if (!value)
 116                 memset((char *) &set_buffer, 0, sizeof(set_buffer));
 117         else
 118                 memcpy_fromfs(&set_buffer, value, sizeof(set_buffer));
 119         error = _setitimer(which, &set_buffer, ovalue ? &get_buffer : 0);
 120         if (error || !ovalue)
 121                 return error;
 122         error = verify_area(VERIFY_WRITE, ovalue, sizeof(struct itimerval));
 123         if (!error)
 124                 memcpy_tofs(ovalue, &get_buffer, sizeof(get_buffer));
 125         return error;
 126 }

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