home *** CD-ROM | disk | FTP | other *** search
/ Whiteline: Alpha / Whiteline Alpha.iso / linux / atari / source / source.lzh / atari-linux-0.01pl3 / kernel / itimer.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-05  |  2.8 KB  |  124 lines

  1. /*
  2.  * linux/kernel/itimer.c
  3.  *
  4.  * Copyright (C) 1992 Darren Senn
  5.  *
  6.  * This file is subject to the terms and conditions of the GNU General Public
  7.  * License.  See the file README.legal in the main directory of this archive
  8.  * for more details.
  9.  */
  10.  
  11. /* These are all the functions necessary to implement itimers */
  12.  
  13. #include <asm/system.h>
  14. #include <asm/segment.h>
  15.  
  16. #include <linux/signal.h>
  17. #include <linux/sched.h>
  18. #include <linux/kernel.h>
  19. #include <linux/string.h>
  20. #include <linux/errno.h>
  21. #include <linux/time.h>
  22.  
  23. static unsigned long tvtojiffies(struct timeval *value)
  24. {
  25.     return((unsigned long )value->tv_sec * HZ +
  26.         (unsigned long )(value->tv_usec + (1000000 / HZ - 1)) /
  27.         (1000000 / HZ));
  28. }
  29.  
  30. static void jiffiestotv(unsigned long jiffies, struct timeval *value)
  31. {
  32.     value->tv_usec = (jiffies % HZ) * (1000000 / HZ);
  33.     value->tv_sec = jiffies / HZ;
  34.     return;
  35. }
  36.  
  37. int _getitimer(int which, struct itimerval *value)
  38. {
  39.     register unsigned long val, interval;
  40.  
  41.     switch (which) {
  42.     case ITIMER_REAL:
  43.         val = current->it_real_value;
  44.         interval = current->it_real_incr;
  45.         break;
  46.     case ITIMER_VIRTUAL:
  47.         val = current->it_virt_value;
  48.         interval = current->it_virt_incr;
  49.         break;
  50.     case ITIMER_PROF:
  51.         val = current->it_prof_value;
  52.         interval = current->it_prof_incr;
  53.         break;
  54.     default:
  55.         return(-EINVAL);
  56.     }
  57.     jiffiestotv(val, &value->it_value);
  58.     jiffiestotv(interval, &value->it_interval);
  59.     return(0);
  60. }
  61.  
  62. asmlinkage int sys_getitimer(int which, struct itimerval *value)
  63. {
  64.     int error;
  65.     struct itimerval get_buffer;
  66.  
  67.     if (!value)
  68.         return -EFAULT;
  69.     error = _getitimer(which, &get_buffer);
  70.     if (error)
  71.         return error;
  72.     error = verify_area(VERIFY_WRITE, value, sizeof(struct itimerval));
  73.     if (error)
  74.         return error;
  75.     memcpy_tofs(value, &get_buffer, sizeof(get_buffer));
  76.     return 0;
  77. }
  78.  
  79. int _setitimer(int which, struct itimerval *value, struct itimerval *ovalue)
  80. {
  81.     register unsigned long i, j;
  82.     int k;
  83.  
  84.     i = tvtojiffies(&value->it_interval);
  85.     j = tvtojiffies(&value->it_value);
  86.     if (ovalue && (k = _getitimer(which, ovalue)) < 0)
  87.         return k;
  88.     switch (which) {
  89.         case ITIMER_REAL:
  90.             current->it_real_value = j;
  91.             current->it_real_incr = i;
  92.             break;
  93.         case ITIMER_VIRTUAL:
  94.             current->it_virt_value = j;
  95.             current->it_virt_incr = i;
  96.             break;
  97.         case ITIMER_PROF:
  98.             current->it_prof_value = j;
  99.             current->it_prof_incr = i;
  100.             break;
  101.         default:
  102.             return -EINVAL;
  103.     }
  104.     return 0;
  105. }
  106.  
  107. asmlinkage int sys_setitimer(int which, struct itimerval *value, struct itimerval *ovalue)
  108. {
  109.     int error;
  110.     struct itimerval set_buffer, get_buffer;
  111.  
  112.     if (!value)
  113.         memset((char *) &set_buffer, 0, sizeof(set_buffer));
  114.     else
  115.         memcpy_fromfs(&set_buffer, value, sizeof(set_buffer));
  116.     error = _setitimer(which, &set_buffer, ovalue ? &get_buffer : 0);
  117.     if (error || !ovalue)
  118.         return error;
  119.     error = verify_area(VERIFY_WRITE, ovalue, sizeof(struct itimerval));
  120.     if (!error)
  121.         memcpy_tofs(ovalue, &get_buffer, sizeof(get_buffer));
  122.     return error;
  123. }
  124.