Annotation of linux/kernel/itimer.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.