root/kernel/sys.c

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

DEFINITIONS

This source file includes following definitions.
  1. proc_sel
  2. sys_setpriority
  3. sys_getpriority
  4. sys_profil
  5. sys_ftime
  6. sys_break
  7. sys_stty
  8. sys_gtty
  9. sys_prof
  10. save_v86_state
  11. mark_screen_rdonly
  12. sys_vm86
  13. sys_reboot
  14. ctrl_alt_del
  15. sys_setregid
  16. sys_setgid
  17. sys_acct
  18. sys_phys
  19. sys_lock
  20. sys_mpx
  21. sys_ulimit
  22. sys_time
  23. sys_setreuid
  24. sys_setuid
  25. sys_stime
  26. sys_times
  27. sys_brk
  28. sys_setpgid
  29. sys_getpgrp
  30. sys_setsid
  31. sys_getgroups
  32. sys_setgroups
  33. in_group_p
  34. sys_newuname
  35. sys_uname
  36. sys_sethostname
  37. sys_getrlimit
  38. sys_setrlimit
  39. getrusage
  40. sys_getrusage
  41. sys_gettimeofday
  42. sys_settimeofday
  43. adjust_clock
  44. sys_umask

   1 /*
   2  *  linux/kernel/sys.c
   3  *
   4  *  Copyright (C) 1991, 1992  Linus Torvalds
   5  */
   6 
   7 #include <linux/errno.h>
   8 #include <linux/sched.h>
   9 #include <linux/tty.h>
  10 #include <linux/kernel.h>
  11 #include <linux/config.h>
  12 #include <linux/times.h>
  13 #include <linux/utsname.h>
  14 #include <linux/param.h>
  15 #include <linux/resource.h>
  16 #include <linux/signal.h>
  17 #include <linux/string.h>
  18 #include <linux/ptrace.h>
  19 
  20 #include <asm/segment.h>
  21 
  22 /*
  23  * this indicates wether you can reboot with ctrl-alt-del: the default is yes
  24  */
  25 static int C_A_D = 1;
  26 
  27 /* 
  28  * The timezone where the local system is located.  Used as a default by some
  29  * programs who obtain this value by using gettimeofday.
  30  */
  31 struct timezone sys_tz = { 0, 0};
  32 
  33 extern int session_of_pgrp(int pgrp);
  34 
  35 #define PZERO   15
  36 
  37 static int proc_sel(struct task_struct *p, int which, int who)
     /* [previous][next][first][last][top][bottom][index][help] */
  38 {
  39         switch (which) {
  40                 case PRIO_PROCESS:
  41                         if (!who && p == current)
  42                                 return 1;
  43                         return(p->pid == who);
  44                 case PRIO_PGRP:
  45                         if (!who)
  46                                 who = current->pgrp;
  47                         return(p->pgrp == who);
  48                 case PRIO_USER:
  49                         if (!who)
  50                                 who = current->uid;
  51                         return(p->uid == who);
  52         }
  53         return 0;
  54 }
  55 
  56 int sys_setpriority(int which, int who, int niceval)
     /* [previous][next][first][last][top][bottom][index][help] */
  57 {
  58         struct task_struct **p;
  59         int error = ESRCH;
  60         int priority;
  61 
  62         if (which > 2 || which < 0)
  63                 return -EINVAL;
  64 
  65         if ((priority = PZERO - niceval) <= 0)
  66                 priority = 1;
  67 
  68         for(p = &LAST_TASK; p > &FIRST_TASK; --p) {
  69                 if (!*p || !proc_sel(*p, which, who))
  70                         continue;
  71                 if ((*p)->uid != current->euid &&
  72                         (*p)->uid != current->uid && !suser()) {
  73                         error = EPERM;
  74                         continue;
  75                 }
  76                 if (error == ESRCH)
  77                         error = 0;
  78                 if (priority > (*p)->priority && !suser())
  79                         error = EACCES;
  80                 else
  81                         (*p)->priority = priority;
  82         }
  83         return -error;
  84 }
  85 
  86 int sys_getpriority(int which, int who)
     /* [previous][next][first][last][top][bottom][index][help] */
  87 {
  88         struct task_struct **p;
  89         int max_prio = 0;
  90 
  91         if (which > 2 || which < 0)
  92                 return -EINVAL;
  93 
  94         for(p = &LAST_TASK; p > &FIRST_TASK; --p) {
  95                 if (!*p || !proc_sel(*p, which, who))
  96                         continue;
  97                 if ((*p)->priority > max_prio)
  98                         max_prio = (*p)->priority;
  99         }
 100         return(max_prio ? max_prio : -ESRCH);
 101 }
 102 
 103 int sys_profil()
     /* [previous][next][first][last][top][bottom][index][help] */
 104 {
 105         return -ENOSYS;
 106 }
 107 
 108 int sys_ftime()
     /* [previous][next][first][last][top][bottom][index][help] */
 109 {
 110         return -ENOSYS;
 111 }
 112 
 113 int sys_break()
     /* [previous][next][first][last][top][bottom][index][help] */
 114 {
 115         return -ENOSYS;
 116 }
 117 
 118 int sys_stty()
     /* [previous][next][first][last][top][bottom][index][help] */
 119 {
 120         return -ENOSYS;
 121 }
 122 
 123 int sys_gtty()
     /* [previous][next][first][last][top][bottom][index][help] */
 124 {
 125         return -ENOSYS;
 126 }
 127 
 128 int sys_prof()
     /* [previous][next][first][last][top][bottom][index][help] */
 129 {
 130         return -ENOSYS;
 131 }
 132 
 133 unsigned long save_v86_state(int signr,struct vm86_regs * regs)
     /* [previous][next][first][last][top][bottom][index][help] */
 134 {
 135         unsigned long stack;
 136 
 137         if (!current->vm86_info) {
 138                 printk("no vm86_info: BAD\n");
 139                 do_exit(SIGSEGV);
 140         }
 141         memcpy_tofs(&(current->vm86_info->regs),regs,sizeof(*regs));
 142         put_fs_long(current->screen_bitmap,&(current->vm86_info->screen_bitmap));
 143         stack = current->tss.esp0;
 144         current->tss.esp0 = current->saved_kernel_stack;
 145         current->saved_kernel_stack = 0;
 146         return stack;
 147 }
 148 
 149 static void mark_screen_rdonly(struct task_struct * tsk)
     /* [previous][next][first][last][top][bottom][index][help] */
 150 {
 151         unsigned long tmp;
 152         unsigned long *pg_table;
 153 
 154         if ((tmp = tsk->tss.cr3) != 0) {
 155                 tmp = *(unsigned long *) tmp;
 156                 if (tmp & PAGE_PRESENT) {
 157                         tmp &= 0xfffff000;
 158                         pg_table = (0xA0000 >> PAGE_SHIFT) + (unsigned long *) tmp;
 159                         tmp = 32;
 160                         while (tmp--) {
 161                                 if (PAGE_PRESENT & *pg_table)
 162                                         *pg_table &= ~PAGE_RW;
 163                                 pg_table++;
 164                         }
 165                 }
 166         }
 167 }
 168 
 169 int sys_vm86(struct vm86_struct * v86)
     /* [previous][next][first][last][top][bottom][index][help] */
 170 {
 171         struct vm86_struct info;
 172         struct pt_regs * pt_regs = (struct pt_regs *) &v86;
 173 
 174         if (current->saved_kernel_stack)
 175                 return -EPERM;
 176         memcpy_fromfs(&info,v86,sizeof(info));
 177 /*
 178  * make sure the vm86() system call doesn't try to do anything silly
 179  */
 180         info.regs.__null_ds = 0;
 181         info.regs.__null_es = 0;
 182         info.regs.__null_fs = 0;
 183         info.regs.__null_gs = 0;
 184 /*
 185  * The eflags register is also special: we cannot trust that the user
 186  * has set it up safely, so this makes sure interrupt etc flags are
 187  * inherited from protected mode.
 188  */
 189         info.regs.eflags &= 0x00000dd5;
 190         info.regs.eflags |= 0xfffff22a & pt_regs->eflags;
 191         info.regs.eflags |= VM_MASK;
 192         current->saved_kernel_stack = current->tss.esp0;
 193         current->tss.esp0 = (unsigned long) pt_regs;
 194         current->vm86_info = v86;
 195         current->screen_bitmap = info.screen_bitmap;
 196         if (info.flags & VM86_SCREEN_BITMAP)
 197                 mark_screen_rdonly(current);
 198         __asm__ __volatile__("movl %0,%%esp\n\t"
 199                 "pushl $ret_from_sys_call\n\t"
 200                 "ret"::"g" ((long) &(info.regs)),"a" (info.regs.eax));
 201         return 0;
 202 }
 203 
 204 extern void hard_reset_now(void);
 205 
 206 /*
 207  * Reboot system call: for obvious reasons only root may call it,
 208  * and even root needs to set up some magic numbers in the registers
 209  * so that some mistake won't make this reboot the whole machine.
 210  * You can also set the meaning of the ctrl-alt-del-key here.
 211  *
 212  * reboot doesn't sync: do that yourself before calling this.
 213  */
 214 int sys_reboot(int magic, int magic_too, int flag)
     /* [previous][next][first][last][top][bottom][index][help] */
 215 {
 216         if (!suser())
 217                 return -EPERM;
 218         if (magic != 0xfee1dead || magic_too != 672274793)
 219                 return -EINVAL;
 220         if (flag == 0x01234567)
 221                 hard_reset_now();
 222         else if (flag == 0x89ABCDEF)
 223                 C_A_D = 1;
 224         else if (!flag)
 225                 C_A_D = 0;
 226         else
 227                 return -EINVAL;
 228         return (0);
 229 }
 230 
 231 /*
 232  * This function gets called by ctrl-alt-del - ie the keyboard interrupt.
 233  * As it's called within an interrupt, it may NOT sync: the only choice
 234  * is wether to reboot at once, or just ignore the ctrl-alt-del.
 235  */
 236 void ctrl_alt_del(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 237 {
 238         if (C_A_D)
 239                 hard_reset_now();
 240         else
 241                 send_sig(SIGINT,task[1],1);
 242 }
 243         
 244 
 245 /*
 246  * This is done BSD-style, with no consideration of the saved gid, except
 247  * that if you set the effective gid, it sets the saved gid too.  This 
 248  * makes it possible for a setgid program to completely drop its privileges,
 249  * which is often a useful assertion to make when you are doing a security
 250  * audit over a program.
 251  *
 252  * The general idea is that a program which uses just setregid() will be
 253  * 100% compatible with BSD.  A program which uses just setgid() will be
 254  * 100% compatible with POSIX w/ Saved ID's. 
 255  */
 256 int sys_setregid(gid_t rgid, gid_t egid)
     /* [previous][next][first][last][top][bottom][index][help] */
 257 {
 258         int old_rgid = current->gid;
 259 
 260         if (rgid != (gid_t) -1) {
 261                 if ((current->egid==rgid) ||
 262                     (old_rgid == rgid) || 
 263                     suser())
 264                         current->gid = rgid;
 265                 else
 266                         return(-EPERM);
 267         }
 268         if (egid != (gid_t) -1) {
 269                 if ((old_rgid == egid) ||
 270                     (current->egid == egid) ||
 271                     suser()) {
 272                         current->egid = egid;
 273                         current->sgid = egid;
 274                 } else {
 275                         current->gid = old_rgid;
 276                         return(-EPERM);
 277                 }
 278         }
 279         return 0;
 280 }
 281 
 282 /*
 283  * setgid() is implemeneted like SysV w/ SAVED_IDS 
 284  */
 285 int sys_setgid(gid_t gid)
     /* [previous][next][first][last][top][bottom][index][help] */
 286 {
 287         if (suser())
 288                 current->gid = current->egid = current->sgid = gid;
 289         else if ((gid == current->gid) || (gid == current->sgid))
 290                 current->egid = gid;
 291         else
 292                 return -EPERM;
 293         return 0;
 294 }
 295 
 296 int sys_acct()
     /* [previous][next][first][last][top][bottom][index][help] */
 297 {
 298         return -ENOSYS;
 299 }
 300 
 301 int sys_phys()
     /* [previous][next][first][last][top][bottom][index][help] */
 302 {
 303         return -ENOSYS;
 304 }
 305 
 306 int sys_lock()
     /* [previous][next][first][last][top][bottom][index][help] */
 307 {
 308         return -ENOSYS;
 309 }
 310 
 311 int sys_mpx()
     /* [previous][next][first][last][top][bottom][index][help] */
 312 {
 313         return -ENOSYS;
 314 }
 315 
 316 int sys_ulimit()
     /* [previous][next][first][last][top][bottom][index][help] */
 317 {
 318         return -ENOSYS;
 319 }
 320 
 321 int sys_time(long * tloc)
     /* [previous][next][first][last][top][bottom][index][help] */
 322 {
 323         int i;
 324 
 325         i = CURRENT_TIME;
 326         if (tloc) {
 327                 verify_area(tloc,4);
 328                 put_fs_long(i,(unsigned long *)tloc);
 329         }
 330         return i;
 331 }
 332 
 333 /*
 334  * Unprivileged users may change the real user id to the effective uid
 335  * or vice versa.  (BSD-style)
 336  *
 337  * When you set the effective uid, it sets the saved uid too.  This 
 338  * makes it possible for a setuid program to completely drop its privileges,
 339  * which is often a useful assertion to make when you are doing a security
 340  * audit over a program.
 341  *
 342  * The general idea is that a program which uses just setreuid() will be
 343  * 100% compatible with BSD.  A program which uses just setuid() will be
 344  * 100% compatible with POSIX w/ Saved ID's. 
 345  */
 346 int sys_setreuid(uid_t ruid, uid_t euid)
     /* [previous][next][first][last][top][bottom][index][help] */
 347 {
 348         int old_ruid = current->uid;
 349         
 350         if (ruid != (uid_t) -1) {
 351                 if ((current->euid==ruid) ||
 352                     (old_ruid == ruid) ||
 353                     suser())
 354                         current->uid = ruid;
 355                 else
 356                         return(-EPERM);
 357         }
 358         if (euid != (uid_t) -1) {
 359                 if ((old_ruid == euid) ||
 360                     (current->euid == euid) ||
 361                     suser()) {
 362                         current->euid = euid;
 363                         current->suid = euid;
 364                 } else {
 365                         current->uid = old_ruid;
 366                         return(-EPERM);
 367                 }
 368         }
 369         return 0;
 370 }
 371 
 372 /*
 373  * setuid() is implemeneted like SysV w/ SAVED_IDS 
 374  * 
 375  * Note that SAVED_ID's is deficient in that a setuid root program
 376  * like sendmail, for example, cannot set its uid to be a normal 
 377  * user and then switch back, because if you're root, setuid() sets
 378  * the saved uid too.  If you don't like this, blame the bright people
 379  * in the POSIX commmittee and/or USG.  Note that the BSD-style setreuid()
 380  * will allow a root program to temporarily drop privileges and be able to
 381  * regain them by swapping the real and effective uid.  
 382  */
 383 int sys_setuid(uid_t uid)
     /* [previous][next][first][last][top][bottom][index][help] */
 384 {
 385         if (suser())
 386                 current->uid = current->euid = current->suid = uid;
 387         else if ((uid == current->uid) || (uid == current->suid))
 388                 current->euid = uid;
 389         else
 390                 return -EPERM;
 391         return(0);
 392 }
 393 
 394 int sys_stime(long * tptr)
     /* [previous][next][first][last][top][bottom][index][help] */
 395 {
 396         if (!suser())
 397                 return -EPERM;
 398         startup_time = get_fs_long((unsigned long *)tptr) - jiffies/HZ;
 399         jiffies_offset = 0;
 400         return 0;
 401 }
 402 
 403 int sys_times(struct tms * tbuf)
     /* [previous][next][first][last][top][bottom][index][help] */
 404 {
 405         if (tbuf) {
 406                 verify_area(tbuf,sizeof *tbuf);
 407                 put_fs_long(current->utime,(unsigned long *)&tbuf->tms_utime);
 408                 put_fs_long(current->stime,(unsigned long *)&tbuf->tms_stime);
 409                 put_fs_long(current->cutime,(unsigned long *)&tbuf->tms_cutime);
 410                 put_fs_long(current->cstime,(unsigned long *)&tbuf->tms_cstime);
 411         }
 412         return jiffies;
 413 }
 414 
 415 int sys_brk(unsigned long end_data_seg)
     /* [previous][next][first][last][top][bottom][index][help] */
 416 {
 417         unsigned long rlim;
 418 
 419         rlim = current->rlim[RLIMIT_DATA].rlim_cur;
 420         if (rlim >= RLIM_INFINITY)
 421                 rlim = 0xffffffff;
 422         if (end_data_seg >= current->end_code &&
 423             end_data_seg-current->end_code <= rlim &&
 424             end_data_seg < current->start_stack - 16384)
 425                 current->brk = end_data_seg;
 426         return current->brk;
 427 }
 428 
 429 /*
 430  * This needs some heave checking ...
 431  * I just haven't get the stomach for it. I also don't fully
 432  * understand sessions/pgrp etc. Let somebody who does explain it.
 433  *
 434  * OK, I think I have the protection semantics right.... this is really
 435  * only important on a multi-user system anyway, to make sure one user
 436  * can't send a signal to a process owned by another.  -TYT, 12/12/91
 437  */
 438 int sys_setpgid(pid_t pid, pid_t pgid)
     /* [previous][next][first][last][top][bottom][index][help] */
 439 {
 440         int i; 
 441 
 442         if (!pid)
 443                 pid = current->pid;
 444         if (!pgid)
 445                 pgid = current->pid;
 446         if (pgid < 0)
 447                 return -EINVAL;
 448         for (i=0 ; i<NR_TASKS ; i++)
 449                 if (task[i] && (task[i]->pid == pid) &&
 450                     ((task[i]->p_pptr == current) || 
 451                      (task[i] == current))) {
 452                         if (task[i]->leader)
 453                                 return -EPERM;
 454                         if ((task[i]->session != current->session) ||
 455                             ((pgid != pid) && 
 456                              (session_of_pgrp(pgid) != current->session)))
 457                                 return -EPERM;
 458                         task[i]->pgrp = pgid;
 459                         return 0;
 460                 }
 461         return -ESRCH;
 462 }
 463 
 464 int sys_getpgrp(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 465 {
 466         return current->pgrp;
 467 }
 468 
 469 int sys_setsid(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 470 {
 471         if (current->leader && !suser())
 472                 return -EPERM;
 473         current->leader = 1;
 474         current->session = current->pgrp = current->pid;
 475         current->tty = -1;
 476         return current->pgrp;
 477 }
 478 
 479 /*
 480  * Supplementary group ID's
 481  */
 482 int sys_getgroups(int gidsetsize, gid_t *grouplist)
     /* [previous][next][first][last][top][bottom][index][help] */
 483 {
 484         int     i;
 485 
 486         if (gidsetsize)
 487                 verify_area(grouplist, sizeof(gid_t) * gidsetsize);
 488 
 489         for (i = 0; (i < NGROUPS) && (current->groups[i] != NOGROUP);
 490              i++, grouplist++) {
 491                 if (gidsetsize) {
 492                         if (i >= gidsetsize)
 493                                 return -EINVAL;
 494                         put_fs_word(current->groups[i], (short *) grouplist);
 495                 }
 496         }
 497         return(i);
 498 }
 499 
 500 int sys_setgroups(int gidsetsize, gid_t *grouplist)
     /* [previous][next][first][last][top][bottom][index][help] */
 501 {
 502         int     i;
 503 
 504         if (!suser())
 505                 return -EPERM;
 506         if (gidsetsize > NGROUPS)
 507                 return -EINVAL;
 508         for (i = 0; i < gidsetsize; i++, grouplist++) {
 509                 current->groups[i] = get_fs_word((unsigned short *) grouplist);
 510         }
 511         if (i < NGROUPS)
 512                 current->groups[i] = NOGROUP;
 513         return 0;
 514 }
 515 
 516 int in_group_p(gid_t grp)
     /* [previous][next][first][last][top][bottom][index][help] */
 517 {
 518         int     i;
 519 
 520         if (grp == current->egid)
 521                 return 1;
 522 
 523         for (i = 0; i < NGROUPS; i++) {
 524                 if (current->groups[i] == NOGROUP)
 525                         break;
 526                 if (current->groups[i] == grp)
 527                         return 1;
 528         }
 529         return 0;
 530 }
 531 
 532 int sys_newuname(struct new_utsname * name)
     /* [previous][next][first][last][top][bottom][index][help] */
 533 {
 534         if (!name)
 535                 return -EFAULT;
 536         verify_area(name, sizeof *name);
 537         memcpy_tofs(name,&system_utsname,sizeof *name);
 538         return 0;
 539 }
 540 
 541 int sys_uname(struct old_utsname * name)
     /* [previous][next][first][last][top][bottom][index][help] */
 542 {
 543         if (!name)
 544                 return -EINVAL;
 545         verify_area(name,sizeof *name);
 546         memcpy_tofs(&name->sysname,&system_utsname.sysname,__OLD_UTS_LEN);
 547         put_fs_byte(0,name->sysname+__OLD_UTS_LEN);
 548         memcpy_tofs(&name->nodename,&system_utsname.nodename,__OLD_UTS_LEN);
 549         put_fs_byte(0,name->nodename+__OLD_UTS_LEN);
 550         memcpy_tofs(&name->release,&system_utsname.release,__OLD_UTS_LEN);
 551         put_fs_byte(0,name->release+__OLD_UTS_LEN);
 552         memcpy_tofs(&name->version,&system_utsname.version,__OLD_UTS_LEN);
 553         put_fs_byte(0,name->version+__OLD_UTS_LEN);
 554         memcpy_tofs(&name->machine,&system_utsname.machine,__OLD_UTS_LEN);
 555         put_fs_byte(0,name->machine+__OLD_UTS_LEN);
 556         return 0;
 557 }
 558 
 559 /*
 560  * Only sethostname; gethostname can be implemented by calling uname()
 561  */
 562 int sys_sethostname(char *name, int len)
     /* [previous][next][first][last][top][bottom][index][help] */
 563 {
 564         int     i;
 565         
 566         if (!suser())
 567                 return -EPERM;
 568         if (len > __NEW_UTS_LEN)
 569                 return -EINVAL;
 570         for (i=0; i < len; i++) {
 571                 if ((system_utsname.nodename[i] = get_fs_byte(name+i)) == 0)
 572                         return 0;
 573         }
 574         system_utsname.nodename[i] = 0;
 575         return 0;
 576 }
 577 
 578 int sys_getrlimit(unsigned int resource, struct rlimit *rlim)
     /* [previous][next][first][last][top][bottom][index][help] */
 579 {
 580         if (resource >= RLIM_NLIMITS)
 581                 return -EINVAL;
 582         verify_area(rlim,sizeof *rlim);
 583         put_fs_long(current->rlim[resource].rlim_cur, 
 584                     (unsigned long *) rlim);
 585         put_fs_long(current->rlim[resource].rlim_max, 
 586                     ((unsigned long *) rlim)+1);
 587         return 0;       
 588 }
 589 
 590 int sys_setrlimit(unsigned int resource, struct rlimit *rlim)
     /* [previous][next][first][last][top][bottom][index][help] */
 591 {
 592         struct rlimit new, *old;
 593 
 594         if (resource >= RLIM_NLIMITS)
 595                 return -EINVAL;
 596         old = current->rlim + resource;
 597         new.rlim_cur = get_fs_long((unsigned long *) rlim);
 598         new.rlim_max = get_fs_long(((unsigned long *) rlim)+1);
 599         if (((new.rlim_cur > old->rlim_max) ||
 600              (new.rlim_max > old->rlim_max)) &&
 601             !suser())
 602                 return -EPERM;
 603         *old = new;
 604         return 0;
 605 }
 606 
 607 /*
 608  * It would make sense to put struct rusuage in the task_struct,
 609  * except that would make the task_struct be *really big*.  After
 610  * task_struct gets moved into malloc'ed memory, it would
 611  * make sense to do this.  It will make moving the rest of the information
 612  * a lot simpler!  (Which we're not doing right now because we're not
 613  * measuring them yet).
 614  */
 615 void getrusage(struct task_struct *p, int who, struct rusage *ru)
     /* [previous][next][first][last][top][bottom][index][help] */
 616 {
 617         struct rusage r;
 618         unsigned long   *lp, *lpend, *dest;
 619 
 620         verify_area(ru, sizeof *ru);
 621         memset((char *) &r, 0, sizeof(r));
 622         switch (who) {
 623                 case RUSAGE_SELF:
 624                         r.ru_utime.tv_sec = CT_TO_SECS(p->utime);
 625                         r.ru_utime.tv_usec = CT_TO_USECS(p->utime);
 626                         r.ru_stime.tv_sec = CT_TO_SECS(p->stime);
 627                         r.ru_stime.tv_usec = CT_TO_USECS(p->stime);
 628                         r.ru_minflt = p->min_flt;
 629                         r.ru_majflt = p->maj_flt;
 630                         break;
 631                 case RUSAGE_CHILDREN:
 632                         r.ru_utime.tv_sec = CT_TO_SECS(p->cutime);
 633                         r.ru_utime.tv_usec = CT_TO_USECS(p->cutime);
 634                         r.ru_stime.tv_sec = CT_TO_SECS(p->cstime);
 635                         r.ru_stime.tv_usec = CT_TO_USECS(p->cstime);
 636                         r.ru_minflt = p->cmin_flt;
 637                         r.ru_majflt = p->cmaj_flt;
 638                         break;
 639                 default:
 640                         r.ru_utime.tv_sec = CT_TO_SECS(p->utime + p->cutime);
 641                         r.ru_utime.tv_usec = CT_TO_USECS(p->utime + p->cutime);
 642                         r.ru_stime.tv_sec = CT_TO_SECS(p->stime + p->cstime);
 643                         r.ru_stime.tv_usec = CT_TO_USECS(p->stime + p->cstime);
 644                         r.ru_minflt = p->min_flt + p->cmin_flt;
 645                         r.ru_majflt = p->maj_flt + p->cmaj_flt;
 646                         break;
 647         }
 648         lp = (unsigned long *) &r;
 649         lpend = (unsigned long *) (&r+1);
 650         dest = (unsigned long *) ru;
 651         for (; lp < lpend; lp++, dest++) 
 652                 put_fs_long(*lp, dest);
 653 }
 654 
 655 int sys_getrusage(int who, struct rusage *ru)
     /* [previous][next][first][last][top][bottom][index][help] */
 656 {
 657         if (who != RUSAGE_SELF && who != RUSAGE_CHILDREN)
 658                 return -EINVAL;
 659         getrusage(current, who, ru);
 660         return(0);
 661 }
 662 
 663 int sys_gettimeofday(struct timeval *tv, struct timezone *tz)
     /* [previous][next][first][last][top][bottom][index][help] */
 664 {
 665         if (tv) {
 666                 unsigned long nowtime = jiffies+jiffies_offset;
 667                 verify_area(tv, sizeof *tv);
 668                 put_fs_long(startup_time + CT_TO_SECS(nowtime),
 669                             (unsigned long *) tv);
 670                 put_fs_long(CT_TO_USECS(nowtime), 
 671                             ((unsigned long *) tv)+1);
 672         }
 673         if (tz) {
 674                 verify_area(tz, sizeof *tz);
 675                 put_fs_long(sys_tz.tz_minuteswest, (unsigned long *) tz);
 676                 put_fs_long(sys_tz.tz_dsttime, ((unsigned long *) tz)+1);
 677         }
 678         return 0;
 679 }
 680 
 681 /*
 682  * The first time we set the timezone, we will warp the clock so that
 683  * it is ticking GMT time instead of local time.  Presumably, 
 684  * if someone is setting the timezone then we are running in an
 685  * environment where the programs understand about timezones.
 686  * This should be done at boot time in the /etc/rc script, as
 687  * soon as possible, so that the clock can be set right.  Otherwise,
 688  * various programs will get confused when the clock gets warped.
 689  */
 690 int sys_settimeofday(struct timeval *tv, struct timezone *tz)
     /* [previous][next][first][last][top][bottom][index][help] */
 691 {
 692         static int      firsttime = 1;
 693         void            adjust_clock();
 694 
 695         if (!suser())
 696                 return -EPERM;
 697         if (tz) {
 698                 sys_tz.tz_minuteswest = get_fs_long((unsigned long *) tz);
 699                 sys_tz.tz_dsttime = get_fs_long(((unsigned long *) tz)+1);
 700                 if (firsttime) {
 701                         firsttime = 0;
 702                         if (!tv)
 703                                 adjust_clock();
 704                 }
 705         }
 706         if (tv) {
 707                 int sec, usec;
 708 
 709                 sec = get_fs_long((unsigned long *)tv);
 710                 usec = get_fs_long(((unsigned long *)tv)+1);
 711         
 712                 startup_time = sec - jiffies/HZ;
 713                 jiffies_offset = usec * HZ / 1000000 - jiffies%HZ;
 714         }
 715         return 0;
 716 }
 717 
 718 /*
 719  * Adjust the time obtained from the CMOS to be GMT time instead of
 720  * local time.
 721  * 
 722  * This is ugly, but preferable to the alternatives.  Otherwise we
 723  * would either need to write a program to do it in /etc/rc (and risk
 724  * confusion if the program gets run more than once; it would also be 
 725  * hard to make the program warp the clock precisely n hours)  or
 726  * compile in the timezone information into the kernel.  Bad, bad....
 727  *
 728  * XXX Currently does not adjust for daylight savings time.  May not
 729  * need to do anything, depending on how smart (dumb?) the BIOS
 730  * is.  Blast it all.... the best thing to do not depend on the CMOS
 731  * clock at all, but get the time via NTP or timed if you're on a 
 732  * network....                          - TYT, 1/1/92
 733  */
 734 void adjust_clock()
     /* [previous][next][first][last][top][bottom][index][help] */
 735 {
 736         startup_time += sys_tz.tz_minuteswest*60;
 737 }
 738 
 739 int sys_umask(int mask)
     /* [previous][next][first][last][top][bottom][index][help] */
 740 {
 741         int old = current->umask;
 742 
 743         current->umask = mask & 0777;
 744         return (old);
 745 }
 746 

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