4 * Copyright (C) 1991, 1992 Linus Torvalds
7 #include <linux/errno.h>
8 #include <linux/sched.h>
9 #include <linux/kernel.h>
10 #include <linux/times.h>
11 #include <linux/utsname.h>
12 #include <linux/param.h>
13 #include <linux/resource.h>
14 #include <linux/signal.h>
15 #include <linux/string.h>
16 #include <linux/ptrace.h>
17 #include <linux/stat.h>
18 #include <linux/mman.h>
20 #include <linux/fcntl.h>
21 #include <linux/acct.h>
22 #include <linux/tty.h>
23 #include <linux/smp.h>
24 #include <linux/smp_lock.h>
25 #include <linux/notifier.h>
26 #include <linux/reboot.h>
28 #include <asm/uaccess.h>
32 * this indicates whether you can reboot with ctrl-alt-del: the default is yes
39 * Notifier list for kernel code which wants to be called
40 * at shutdown. This is used to stop any idling DMA operations
44 struct notifier_block
*reboot_notifier_list
= NULL
;
46 int register_reboot_notifier(struct notifier_block
* nb
)
48 return notifier_chain_register(&reboot_notifier_list
, nb
);
51 int unregister_reboot_notifier(struct notifier_block
* nb
)
53 return notifier_chain_unregister(&reboot_notifier_list
, nb
);
58 extern void adjust_clock(void);
60 asmlinkage
int sys_ni_syscall(void)
65 static int proc_sel(struct task_struct
*p
, int which
, int who
)
71 if (!who
&& p
== current
)
73 return(p
->pid
== who
);
77 return(p
->pgrp
== who
);
81 return(p
->uid
== who
);
87 asmlinkage
int sys_setpriority(int which
, int who
, int niceval
)
89 struct task_struct
*p
;
90 unsigned int priority
;
93 if (which
> 2 || which
< 0)
96 /* normalize: avoid signed division (rounding problems) */
103 priority
= (priority
* DEF_PRIORITY
+ 10) / 20 + DEF_PRIORITY
;
106 priority
= 2*DEF_PRIORITY
- priority
;
111 read_lock(&tasklist_lock
);
113 if (!proc_sel(p
, which
, who
))
115 if (p
->uid
!= current
->euid
&&
116 p
->uid
!= current
->uid
&& !suser()) {
122 if (priority
> p
->priority
&& !suser())
125 p
->priority
= priority
;
127 read_unlock(&tasklist_lock
);
133 * Ugh. To avoid negative return values, "getpriority()" will
134 * not return the normal nice-value, but a value that has been
135 * offset by 20 (ie it returns 0..40 instead of -20..20)
137 asmlinkage
int sys_getpriority(int which
, int who
)
139 struct task_struct
*p
;
140 long max_prio
= -ESRCH
;
142 if (which
> 2 || which
< 0)
145 read_lock(&tasklist_lock
);
147 if (!proc_sel(p
, which
, who
))
149 if (p
->priority
> max_prio
)
150 max_prio
= p
->priority
;
152 read_unlock(&tasklist_lock
);
154 /* scale the priority from timeslice to 0..40 */
156 max_prio
= (max_prio
* 20 + DEF_PRIORITY
/2) / DEF_PRIORITY
;
163 * Why do these exist? Binary compatibility with some other standard?
164 * If so, maybe they should be moved into the appropriate arch
168 asmlinkage
int sys_profil(void)
173 asmlinkage
int sys_ftime(void)
178 asmlinkage
int sys_break(void)
183 asmlinkage
int sys_stty(void)
188 asmlinkage
int sys_gtty(void)
193 asmlinkage
int sys_prof(void)
200 extern asmlinkage
int sys_kill(int, int);
203 * Reboot system call: for obvious reasons only root may call it,
204 * and even root needs to set up some magic numbers in the registers
205 * so that some mistake won't make this reboot the whole machine.
206 * You can also set the meaning of the ctrl-alt-del-key here.
208 * reboot doesn't sync: do that yourself before calling this.
211 asmlinkage
int sys_reboot(int magic1
, int magic2
, int cmd
, void * arg
)
215 /* We only trust the superuser with rebooting the system. */
219 /* For safety, we require "magic" arguments. */
220 if (magic1
!= LINUX_REBOOT_MAGIC1
||
221 (magic2
!= LINUX_REBOOT_MAGIC2
&& magic2
!= LINUX_REBOOT_MAGIC2A
))
226 case LINUX_REBOOT_CMD_RESTART
:
227 notifier_call_chain(&reboot_notifier_list
, SYS_RESTART
, NULL
);
228 printk(KERN_EMERG
"Restarting system.\n");
229 machine_restart(NULL
);
232 case LINUX_REBOOT_CMD_CAD_ON
:
236 case LINUX_REBOOT_CMD_CAD_OFF
:
240 case LINUX_REBOOT_CMD_HALT
:
241 notifier_call_chain(&reboot_notifier_list
, SYS_HALT
, NULL
);
242 printk(KERN_EMERG
"System halted.\n");
247 case LINUX_REBOOT_CMD_POWER_OFF
:
248 notifier_call_chain(&reboot_notifier_list
, SYS_POWER_OFF
, NULL
);
249 printk(KERN_EMERG
"Power down.\n");
254 case LINUX_REBOOT_CMD_RESTART2
:
255 if (strncpy_from_user(&buffer
[0], (char *)arg
, sizeof(buffer
) - 1) < 0) {
259 buffer
[sizeof(buffer
) - 1] = '\0';
261 notifier_call_chain(&reboot_notifier_list
, SYS_RESTART
, buffer
);
262 printk(KERN_EMERG
"Restarting system with command '%s'.\n", buffer
);
263 machine_restart(buffer
);
276 * This function gets called by ctrl-alt-del - ie the keyboard interrupt.
277 * As it's called within an interrupt, it may NOT sync: the only choice
278 * is whether to reboot at once, or just ignore the ctrl-alt-del.
280 void ctrl_alt_del(void)
283 notifier_call_chain(&reboot_notifier_list
, SYS_RESTART
, NULL
);
284 machine_restart(NULL
);
286 kill_proc(1, SIGINT
, 1);
291 * Unprivileged users may change the real gid to the effective gid
292 * or vice versa. (BSD-style)
294 * If you set the real gid at all, or set the effective gid to a value not
295 * equal to the real gid, then the saved gid is set to the new effective gid.
297 * This makes it possible for a setgid program to completely drop its
298 * privileges, which is often a useful assertion to make when you are doing
299 * a security audit over a program.
301 * The general idea is that a program which uses just setregid() will be
302 * 100% compatible with BSD. A program which uses just setgid() will be
303 * 100% compatible with POSIX w/ Saved ID's.
305 * SMP: There are not races, the gid's are checked only by filesystem
306 * operations (as far as semantic preservation is concerned).
308 asmlinkage
int sys_setregid(gid_t rgid
, gid_t egid
)
310 int old_rgid
= current
->gid
;
311 int old_egid
= current
->egid
;
313 if (rgid
!= (gid_t
) -1) {
314 if ((old_rgid
== rgid
) ||
315 (current
->egid
==rgid
) ||
321 if (egid
!= (gid_t
) -1) {
322 if ((old_rgid
== egid
) ||
323 (current
->egid
== egid
) ||
324 (current
->sgid
== egid
) ||
326 current
->fsgid
= current
->egid
= egid
;
328 current
->gid
= old_rgid
;
332 if (rgid
!= (gid_t
) -1 ||
333 (egid
!= (gid_t
) -1 && egid
!= old_rgid
))
334 current
->sgid
= current
->egid
;
335 current
->fsgid
= current
->egid
;
336 if (current
->egid
!= old_egid
)
337 current
->dumpable
= 0;
342 * setgid() is implemented like SysV w/ SAVED_IDS
344 * SMP: Same implicit races as above.
346 asmlinkage
int sys_setgid(gid_t gid
)
348 int old_egid
= current
->egid
;
351 current
->gid
= current
->egid
= current
->sgid
= current
->fsgid
= gid
;
352 else if ((gid
== current
->gid
) || (gid
== current
->sgid
))
353 current
->egid
= current
->fsgid
= gid
;
357 if (current
->egid
!= old_egid
)
358 current
->dumpable
= 0;
362 static char acct_active
= 0;
363 static struct file acct_file
;
365 int acct_process(long exitcode
)
371 strncpy(ac
.ac_comm
, current
->comm
, ACCT_COMM
);
372 ac
.ac_comm
[ACCT_COMM
-1] = '\0';
373 ac
.ac_utime
= current
->utime
;
374 ac
.ac_stime
= current
->stime
;
375 ac
.ac_btime
= CT_TO_SECS(current
->start_time
) + (xtime
.tv_sec
- (jiffies
/ HZ
));
376 ac
.ac_etime
= CURRENT_TIME
- ac
.ac_btime
;
377 ac
.ac_uid
= current
->uid
;
378 ac
.ac_gid
= current
->gid
;
379 ac
.ac_tty
= (current
)->tty
== NULL
? -1 :
380 kdev_t_to_nr(current
->tty
->device
);
382 if (current
->flags
& PF_FORKNOEXEC
)
384 if (current
->flags
& PF_SUPERPRIV
)
386 if (current
->flags
& PF_DUMPCORE
)
388 if (current
->flags
& PF_SIGNALED
)
390 ac
.ac_minflt
= current
->min_flt
;
391 ac
.ac_majflt
= current
->maj_flt
;
392 ac
.ac_exitcode
= exitcode
;
394 /* Kernel segment override */
398 acct_file
.f_op
->write(acct_file
.f_inode
, &acct_file
,
399 (char *)&ac
, sizeof(struct acct
));
406 asmlinkage
int sys_acct(const char *name
)
408 struct inode
*inode
= (struct inode
*)0;
416 if (name
== (char *)0) {
418 if (acct_file
.f_op
->release
)
419 acct_file
.f_op
->release(acct_file
.f_inode
, &acct_file
);
421 if (acct_file
.f_inode
!= (struct inode
*) 0)
422 iput(acct_file
.f_inode
);
430 if ((error
= getname(name
, &tmp
)) != 0)
433 error
= open_namei(tmp
, O_RDWR
, 0600, &inode
, 0);
439 if (!S_ISREG(inode
->i_mode
)) {
445 if (!inode
->i_op
|| !inode
->i_op
->default_file_ops
||
446 !inode
->i_op
->default_file_ops
->write
) {
451 acct_file
.f_mode
= 3;
452 acct_file
.f_flags
= 0;
453 acct_file
.f_count
= 1;
454 acct_file
.f_inode
= inode
;
455 acct_file
.f_pos
= inode
->i_size
;
456 acct_file
.f_reada
= 0;
457 acct_file
.f_op
= inode
->i_op
->default_file_ops
;
459 if(acct_file
.f_op
->open
)
460 if(acct_file
.f_op
->open(acct_file
.f_inode
, &acct_file
)) {
477 * Why do these exist? Binary compatibility with some other standard?
478 * If so, maybe they should be moved into the appropriate arch
482 asmlinkage
int sys_phys(void)
487 asmlinkage
int sys_lock(void)
492 asmlinkage
int sys_mpx(void)
497 asmlinkage
int sys_ulimit(void)
502 asmlinkage
int sys_old_syscall(void)
510 * Unprivileged users may change the real uid to the effective uid
511 * or vice versa. (BSD-style)
513 * If you set the real uid at all, or set the effective uid to a value not
514 * equal to the real uid, then the saved uid is set to the new effective uid.
516 * This makes it possible for a setuid program to completely drop its
517 * privileges, which is often a useful assertion to make when you are doing
518 * a security audit over a program.
520 * The general idea is that a program which uses just setreuid() will be
521 * 100% compatible with BSD. A program which uses just setuid() will be
522 * 100% compatible with POSIX w/ Saved ID's.
524 asmlinkage
int sys_setreuid(uid_t ruid
, uid_t euid
)
529 old_ruid
= current
->uid
;
530 old_euid
= current
->euid
;
531 if (ruid
!= (uid_t
) -1) {
532 if ((old_ruid
== ruid
) ||
533 (current
->euid
==ruid
) ||
539 if (euid
!= (uid_t
) -1) {
540 if ((old_ruid
== euid
) ||
541 (current
->euid
== euid
) ||
542 (current
->suid
== euid
) ||
544 current
->fsuid
= current
->euid
= euid
;
546 current
->uid
= old_ruid
;
550 if (ruid
!= (uid_t
) -1 ||
551 (euid
!= (uid_t
) -1 && euid
!= old_ruid
))
552 current
->suid
= current
->euid
;
553 current
->fsuid
= current
->euid
;
554 if (current
->euid
!= old_euid
)
555 current
->dumpable
= 0;
560 * setuid() is implemented like SysV w/ SAVED_IDS
562 * Note that SAVED_ID's is deficient in that a setuid root program
563 * like sendmail, for example, cannot set its uid to be a normal
564 * user and then switch back, because if you're root, setuid() sets
565 * the saved uid too. If you don't like this, blame the bright people
566 * in the POSIX committee and/or USG. Note that the BSD-style setreuid()
567 * will allow a root program to temporarily drop privileges and be able to
568 * regain them by swapping the real and effective uid.
570 asmlinkage
int sys_setuid(uid_t uid
)
572 int old_euid
= current
->euid
;
575 current
->uid
= current
->euid
= current
->suid
= current
->fsuid
= uid
;
576 else if ((uid
== current
->uid
) || (uid
== current
->suid
))
577 current
->fsuid
= current
->euid
= uid
;
581 if (current
->euid
!= old_euid
)
582 current
->dumpable
= 0;
588 * This function implementes a generic ability to update ruid, euid,
589 * and suid. This allows you to implement the 4.4 compatible seteuid().
591 asmlinkage
int sys_setresuid(uid_t ruid
, uid_t euid
, uid_t suid
)
593 uid_t old_ruid
, old_euid
, old_suid
;
595 old_ruid
= current
->uid
;
596 old_euid
= current
->euid
;
597 old_suid
= current
->suid
;
599 if ((ruid
!= (uid_t
) -1) && (ruid
!= current
->uid
) &&
600 (ruid
!= current
->euid
) && (ruid
!= current
->suid
))
602 if ((euid
!= (uid_t
) -1) && (euid
!= current
->uid
) &&
603 (euid
!= current
->euid
) && (euid
!= current
->suid
))
605 if ((suid
!= (uid_t
) -1) && (suid
!= current
->uid
) &&
606 (suid
!= current
->euid
) && (suid
!= current
->suid
))
608 if (ruid
!= (uid_t
) -1)
610 if (euid
!= (uid_t
) -1)
611 current
->euid
= euid
;
612 if (suid
!= (uid_t
) -1)
613 current
->suid
= suid
;
617 asmlinkage
int sys_getresuid(uid_t
*ruid
, uid_t
*euid
, uid_t
*suid
)
621 if (!(retval
= put_user(current
->uid
, ruid
)) &&
622 !(retval
= put_user(current
->euid
, euid
)))
623 retval
= put_user(current
->suid
, suid
);
630 * "setfsuid()" sets the fsuid - the uid used for filesystem checks. This
631 * is used for "access()" and for the NFS daemon (letting nfsd stay at
632 * whatever uid it wants to). It normally shadows "euid", except when
633 * explicitly set by setfsuid() or for access..
635 asmlinkage
int sys_setfsuid(uid_t uid
)
639 old_fsuid
= current
->fsuid
;
640 if (uid
== current
->uid
|| uid
== current
->euid
||
641 uid
== current
->suid
|| uid
== current
->fsuid
|| suser())
642 current
->fsuid
= uid
;
643 if (current
->fsuid
!= old_fsuid
)
644 current
->dumpable
= 0;
650 * Samma på svenska..
652 asmlinkage
int sys_setfsgid(gid_t gid
)
656 old_fsgid
= current
->fsgid
;
657 if (gid
== current
->gid
|| gid
== current
->egid
||
658 gid
== current
->sgid
|| gid
== current
->fsgid
|| suser())
659 current
->fsgid
= gid
;
660 if (current
->fsgid
!= old_fsgid
)
661 current
->dumpable
= 0;
666 asmlinkage
long sys_times(struct tms
* tbuf
)
669 * In the SMP world we might just be unlucky and have one of
670 * the times increment as we use it. Since the value is an
671 * atomically safe type this is just fine. Conceptually its
672 * as if the syscall took an instant longer to occur.
676 /* ?? use copy_to_user() */
677 if(!access_ok(VERIFY_READ
, tbuf
, sizeof(struct tms
)) ||
678 __put_user(current
->utime
,&tbuf
->tms_utime
)||
679 __put_user(current
->stime
,&tbuf
->tms_stime
) ||
680 __put_user(current
->cutime
,&tbuf
->tms_cutime
) ||
681 __put_user(current
->cstime
,&tbuf
->tms_cstime
))
688 * This needs some heavy checking ...
689 * I just haven't the stomach for it. I also don't fully
690 * understand sessions/pgrp etc. Let somebody who does explain it.
692 * OK, I think I have the protection semantics right.... this is really
693 * only important on a multi-user system anyway, to make sure one user
694 * can't send a signal to a process owned by another. -TYT, 12/12/91
696 * Auch. Had to add the 'did_exec' flag to conform completely to POSIX.
700 asmlinkage
int sys_setpgid(pid_t pid
, pid_t pgid
)
702 struct task_struct
* p
;
712 read_lock(&tasklist_lock
);
715 /* NOTE: I haven't dropped tasklist_lock, this is
721 read_unlock(&tasklist_lock
);
725 /* From this point forward we keep holding onto the tasklist lock
726 * so that our parent does not change from under us. -DaveM
729 if (p
->p_pptr
== current
|| p
->p_opptr
== current
) {
731 if (p
->session
!= current
->session
)
736 } else if (p
!= current
)
742 struct task_struct
* tmp
;
743 for_each_task (tmp
) {
744 if (tmp
->pgrp
== pgid
&&
745 tmp
->session
== current
->session
)
755 /* All paths lead to here, thus we are safe. -DaveM */
756 read_unlock(&tasklist_lock
);
760 asmlinkage
int sys_getpgid(pid_t pid
)
763 return current
->pgrp
;
765 struct task_struct
*p
;
768 read_lock(&tasklist_lock
);
775 read_unlock(&tasklist_lock
);
780 asmlinkage
int sys_getpgrp(void)
782 /* SMP - assuming writes are word atomic this is fine */
783 return current
->pgrp
;
786 asmlinkage
int sys_getsid(pid_t pid
)
788 struct task_struct
* p
;
791 /* SMP: The 'self' case requires no lock */
793 ret
= current
->session
;
797 read_lock(&tasklist_lock
);
804 read_unlock(&tasklist_lock
);
809 asmlinkage
int sys_setsid(void)
811 struct task_struct
* p
;
814 read_lock(&tasklist_lock
);
816 if (p
->pgrp
== current
->pid
)
821 current
->session
= current
->pgrp
= current
->pid
;
823 current
->tty_old_pgrp
= 0;
826 read_unlock(&tasklist_lock
);
831 * Supplementary group ID's
833 asmlinkage
int sys_getgroups(int gidsetsize
, gid_t
*grouplist
)
838 * SMP: Nobody else can change our grouplist. Thus we are
844 i
= current
->ngroups
;
848 if (copy_to_user(grouplist
, current
->groups
, sizeof(gid_t
)*i
))
855 * SMP: Our groups are not shared. We can copy to/from them safely
856 * without another task interfering.
859 asmlinkage
int sys_setgroups(int gidsetsize
, gid_t
*grouplist
)
863 if ((unsigned) gidsetsize
> NGROUPS
)
865 if(copy_from_user(current
->groups
, grouplist
, gidsetsize
* sizeof(gid_t
)))
867 current
->ngroups
= gidsetsize
;
871 int in_group_p(gid_t grp
)
873 if (grp
!= current
->fsgid
) {
874 int i
= current
->ngroups
;
876 gid_t
*groups
= current
->groups
;
890 asmlinkage
int sys_newuname(struct new_utsname
* name
)
894 if (copy_to_user(name
,&system_utsname
,sizeof *name
))
902 * Move these to arch dependent dir since they are for
903 * backward compatibility only?
907 asmlinkage
int sys_uname(struct old_utsname
* name
)
909 if (name
&& !copy_to_user(name
, &system_utsname
, sizeof (*name
)))
915 asmlinkage
int sys_olduname(struct oldold_utsname
* name
)
921 if (!access_ok(VERIFY_WRITE
,name
,sizeof(struct oldold_utsname
)))
924 error
= __copy_to_user(&name
->sysname
,&system_utsname
.sysname
,__OLD_UTS_LEN
);
925 error
-= __put_user(0,name
->sysname
+__OLD_UTS_LEN
);
926 error
-= __copy_to_user(&name
->nodename
,&system_utsname
.nodename
,__OLD_UTS_LEN
);
927 error
-= __put_user(0,name
->nodename
+__OLD_UTS_LEN
);
928 error
-= __copy_to_user(&name
->release
,&system_utsname
.release
,__OLD_UTS_LEN
);
929 error
-= __put_user(0,name
->release
+__OLD_UTS_LEN
);
930 error
-= __copy_to_user(&name
->version
,&system_utsname
.version
,__OLD_UTS_LEN
);
931 error
-= __put_user(0,name
->version
+__OLD_UTS_LEN
);
932 error
-= __copy_to_user(&name
->machine
,&system_utsname
.machine
,__OLD_UTS_LEN
);
933 error
= __put_user(0,name
->machine
+__OLD_UTS_LEN
);
934 error
= error
? -EFAULT
: 0;
941 asmlinkage
int sys_sethostname(char *name
, int len
)
945 if (len
< 0 || len
> __NEW_UTS_LEN
)
947 if(copy_from_user(system_utsname
.nodename
, name
, len
))
949 system_utsname
.nodename
[len
] = 0;
953 asmlinkage
int sys_gethostname(char *name
, int len
)
959 i
= 1 + strlen(system_utsname
.nodename
);
962 return copy_to_user(name
, system_utsname
.nodename
, i
) ? -EFAULT
: 0;
966 * Only setdomainname; getdomainname can be implemented by calling
969 asmlinkage
int sys_setdomainname(char *name
, int len
)
973 if (len
< 0 || len
> __NEW_UTS_LEN
)
975 if(copy_from_user(system_utsname
.domainname
, name
, len
))
977 system_utsname
.domainname
[len
] = 0;
981 asmlinkage
int sys_getrlimit(unsigned int resource
, struct rlimit
*rlim
)
983 if (resource
>= RLIM_NLIMITS
)
986 return copy_to_user(rlim
, current
->rlim
+ resource
, sizeof(*rlim
))
990 asmlinkage
int sys_setrlimit(unsigned int resource
, struct rlimit
*rlim
)
992 struct rlimit new_rlim
, *old_rlim
;
994 if (resource
>= RLIM_NLIMITS
)
996 if(copy_from_user(&new_rlim
, rlim
, sizeof(*rlim
)))
998 old_rlim
= current
->rlim
+ resource
;
999 if (((new_rlim
.rlim_cur
> old_rlim
->rlim_max
) ||
1000 (new_rlim
.rlim_max
> old_rlim
->rlim_max
)) &&
1003 if (resource
== RLIMIT_NOFILE
) {
1004 if (new_rlim
.rlim_cur
> NR_OPEN
|| new_rlim
.rlim_max
> NR_OPEN
)
1007 *old_rlim
= new_rlim
;
1012 * It would make sense to put struct rusage in the task_struct,
1013 * except that would make the task_struct be *really big*. After
1014 * task_struct gets moved into malloc'ed memory, it would
1015 * make sense to do this. It will make moving the rest of the information
1016 * a lot simpler! (Which we're not doing right now because we're not
1017 * measuring them yet).
1019 * This is SMP safe. Either we are called from sys_getrusage on ourselves
1020 * below (we know we aren't going to exit/disappear and only we change our
1021 * rusage counters), or we are called from wait4() on a process which is
1022 * either stopped or zombied. In the zombied case the task won't get
1023 * reaped till shortly after the call to getrusage(), in both cases the
1024 * task being examined is in a frozen state so the counters won't change.
1026 int getrusage(struct task_struct
*p
, int who
, struct rusage
*ru
)
1030 memset((char *) &r
, 0, sizeof(r
));
1033 r
.ru_utime
.tv_sec
= CT_TO_SECS(p
->utime
);
1034 r
.ru_utime
.tv_usec
= CT_TO_USECS(p
->utime
);
1035 r
.ru_stime
.tv_sec
= CT_TO_SECS(p
->stime
);
1036 r
.ru_stime
.tv_usec
= CT_TO_USECS(p
->stime
);
1037 r
.ru_minflt
= p
->min_flt
;
1038 r
.ru_majflt
= p
->maj_flt
;
1039 r
.ru_nswap
= p
->nswap
;
1041 case RUSAGE_CHILDREN
:
1042 r
.ru_utime
.tv_sec
= CT_TO_SECS(p
->cutime
);
1043 r
.ru_utime
.tv_usec
= CT_TO_USECS(p
->cutime
);
1044 r
.ru_stime
.tv_sec
= CT_TO_SECS(p
->cstime
);
1045 r
.ru_stime
.tv_usec
= CT_TO_USECS(p
->cstime
);
1046 r
.ru_minflt
= p
->cmin_flt
;
1047 r
.ru_majflt
= p
->cmaj_flt
;
1048 r
.ru_nswap
= p
->cnswap
;
1051 r
.ru_utime
.tv_sec
= CT_TO_SECS(p
->utime
+ p
->cutime
);
1052 r
.ru_utime
.tv_usec
= CT_TO_USECS(p
->utime
+ p
->cutime
);
1053 r
.ru_stime
.tv_sec
= CT_TO_SECS(p
->stime
+ p
->cstime
);
1054 r
.ru_stime
.tv_usec
= CT_TO_USECS(p
->stime
+ p
->cstime
);
1055 r
.ru_minflt
= p
->min_flt
+ p
->cmin_flt
;
1056 r
.ru_majflt
= p
->maj_flt
+ p
->cmaj_flt
;
1057 r
.ru_nswap
= p
->nswap
+ p
->cnswap
;
1060 return copy_to_user(ru
, &r
, sizeof(r
)) ? -EFAULT
: 0;
1063 asmlinkage
int sys_getrusage(int who
, struct rusage
*ru
)
1065 if (who
!= RUSAGE_SELF
&& who
!= RUSAGE_CHILDREN
)
1067 return getrusage(current
, who
, ru
);
1070 asmlinkage
int sys_umask(int mask
)
1072 mask
= xchg(¤t
->fs
->umask
, mask
& S_IRWXUGO
);