wait4(2)/waitid(2): separate copying rusage to userland
New helpers: kernel_waitid() and kernel_wait4(). sys_waitid(), sys_wait4() and their compat variants switched to those. Copying struct rusage to userland is left to syscall itself. For compat_sys_wait4() that eliminates the use of set_fs() completely. For compat_sys_waitid() it's still needed (for siginfo handling); that will change shortly. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
16
kernel/sys.c
16
kernel/sys.c
@@ -1552,7 +1552,7 @@ static void accumulate_thread_rusage(struct task_struct *t, struct rusage *r)
|
||||
r->ru_oublock += task_io_get_oublock(t);
|
||||
}
|
||||
|
||||
static void k_getrusage(struct task_struct *p, int who, struct rusage *r)
|
||||
void getrusage(struct task_struct *p, int who, struct rusage *r)
|
||||
{
|
||||
struct task_struct *t;
|
||||
unsigned long flags;
|
||||
@@ -1626,20 +1626,16 @@ out:
|
||||
r->ru_maxrss = maxrss * (PAGE_SIZE / 1024); /* convert pages to KBs */
|
||||
}
|
||||
|
||||
int getrusage(struct task_struct *p, int who, struct rusage __user *ru)
|
||||
SYSCALL_DEFINE2(getrusage, int, who, struct rusage __user *, ru)
|
||||
{
|
||||
struct rusage r;
|
||||
|
||||
k_getrusage(p, who, &r);
|
||||
return copy_to_user(ru, &r, sizeof(r)) ? -EFAULT : 0;
|
||||
}
|
||||
|
||||
SYSCALL_DEFINE2(getrusage, int, who, struct rusage __user *, ru)
|
||||
{
|
||||
if (who != RUSAGE_SELF && who != RUSAGE_CHILDREN &&
|
||||
who != RUSAGE_THREAD)
|
||||
return -EINVAL;
|
||||
return getrusage(current, who, ru);
|
||||
|
||||
getrusage(current, who, &r);
|
||||
return copy_to_user(ru, &r, sizeof(r)) ? -EFAULT : 0;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_COMPAT
|
||||
@@ -1651,7 +1647,7 @@ COMPAT_SYSCALL_DEFINE2(getrusage, int, who, struct compat_rusage __user *, ru)
|
||||
who != RUSAGE_THREAD)
|
||||
return -EINVAL;
|
||||
|
||||
k_getrusage(current, who, &r);
|
||||
getrusage(current, who, &r);
|
||||
return put_compat_rusage(&r, ru);
|
||||
}
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user