root/kernel/sys.c

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

DEFINITIONS

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

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

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