Skip to content

Commit 7e95a22

Browse files
author
Al Viro
committed
move compat wait4 and waitid next to native variants
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent a8c3954 commit 7e95a22

File tree

2 files changed

+69
-66
lines changed

2 files changed

+69
-66
lines changed

kernel/compat.c

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -543,72 +543,6 @@ int put_compat_rusage(const struct rusage *r, struct compat_rusage __user *ru)
543543
return 0;
544544
}
545545

546-
COMPAT_SYSCALL_DEFINE4(wait4,
547-
compat_pid_t, pid,
548-
compat_uint_t __user *, stat_addr,
549-
int, options,
550-
struct compat_rusage __user *, ru)
551-
{
552-
if (!ru) {
553-
return sys_wait4(pid, stat_addr, options, NULL);
554-
} else {
555-
struct rusage r;
556-
int ret;
557-
unsigned int status;
558-
mm_segment_t old_fs = get_fs();
559-
560-
set_fs (KERNEL_DS);
561-
ret = sys_wait4(pid,
562-
(stat_addr ?
563-
(unsigned int __user *) &status : NULL),
564-
options, (struct rusage __user *) &r);
565-
set_fs (old_fs);
566-
567-
if (ret > 0) {
568-
if (put_compat_rusage(&r, ru))
569-
return -EFAULT;
570-
if (stat_addr && put_user(status, stat_addr))
571-
return -EFAULT;
572-
}
573-
return ret;
574-
}
575-
}
576-
577-
COMPAT_SYSCALL_DEFINE5(waitid,
578-
int, which, compat_pid_t, pid,
579-
struct compat_siginfo __user *, uinfo, int, options,
580-
struct compat_rusage __user *, uru)
581-
{
582-
siginfo_t info;
583-
struct rusage ru;
584-
long ret;
585-
mm_segment_t old_fs = get_fs();
586-
587-
memset(&info, 0, sizeof(info));
588-
589-
set_fs(KERNEL_DS);
590-
ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
591-
uru ? (struct rusage __user *)&ru : NULL);
592-
set_fs(old_fs);
593-
594-
if ((ret < 0) || (info.si_signo == 0))
595-
return ret;
596-
597-
if (uru) {
598-
/* sys_waitid() overwrites everything in ru */
599-
if (COMPAT_USE_64BIT_TIME)
600-
ret = copy_to_user(uru, &ru, sizeof(ru));
601-
else
602-
ret = put_compat_rusage(&ru, uru);
603-
if (ret)
604-
return -EFAULT;
605-
}
606-
607-
BUG_ON(info.si_code & __SI_MASK);
608-
info.si_code |= __SI_CHLD;
609-
return copy_siginfo_to_user32(uinfo, &info);
610-
}
611-
612546
static int compat_get_user_cpu_mask(compat_ulong_t __user *user_mask_ptr,
613547
unsigned len, struct cpumask *new_mask)
614548
{

kernel/exit.c

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
#include <linux/kcov.h>
6363
#include <linux/random.h>
6464
#include <linux/rcuwait.h>
65+
#include <linux/compat.h>
6566

6667
#include <linux/uaccess.h>
6768
#include <asm/unistd.h>
@@ -1735,3 +1736,71 @@ SYSCALL_DEFINE3(waitpid, pid_t, pid, int __user *, stat_addr, int, options)
17351736
}
17361737

17371738
#endif
1739+
1740+
#ifdef CONFIG_COMPAT
1741+
COMPAT_SYSCALL_DEFINE4(wait4,
1742+
compat_pid_t, pid,
1743+
compat_uint_t __user *, stat_addr,
1744+
int, options,
1745+
struct compat_rusage __user *, ru)
1746+
{
1747+
if (!ru) {
1748+
return sys_wait4(pid, stat_addr, options, NULL);
1749+
} else {
1750+
struct rusage r;
1751+
int ret;
1752+
unsigned int status;
1753+
mm_segment_t old_fs = get_fs();
1754+
1755+
set_fs (KERNEL_DS);
1756+
ret = sys_wait4(pid,
1757+
(stat_addr ?
1758+
(unsigned int __user *) &status : NULL),
1759+
options, (struct rusage __user *) &r);
1760+
set_fs (old_fs);
1761+
1762+
if (ret > 0) {
1763+
if (put_compat_rusage(&r, ru))
1764+
return -EFAULT;
1765+
if (stat_addr && put_user(status, stat_addr))
1766+
return -EFAULT;
1767+
}
1768+
return ret;
1769+
}
1770+
}
1771+
1772+
COMPAT_SYSCALL_DEFINE5(waitid,
1773+
int, which, compat_pid_t, pid,
1774+
struct compat_siginfo __user *, infop, int, options,
1775+
struct compat_rusage __user *, uru)
1776+
{
1777+
siginfo_t info;
1778+
struct rusage ru;
1779+
long ret;
1780+
mm_segment_t old_fs = get_fs();
1781+
1782+
memset(&info, 0, sizeof(info));
1783+
1784+
set_fs(KERNEL_DS);
1785+
ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
1786+
uru ? (struct rusage __user *)&ru : NULL);
1787+
set_fs(old_fs);
1788+
1789+
if ((ret < 0) || (info.si_signo == 0))
1790+
return ret;
1791+
1792+
if (uru) {
1793+
/* sys_waitid() overwrites everything in ru */
1794+
if (COMPAT_USE_64BIT_TIME)
1795+
ret = copy_to_user(uru, &ru, sizeof(ru));
1796+
else
1797+
ret = put_compat_rusage(&ru, uru);
1798+
if (ret)
1799+
return -EFAULT;
1800+
}
1801+
1802+
BUG_ON(info.si_code & __SI_MASK);
1803+
info.si_code |= __SI_CHLD;
1804+
return copy_siginfo_to_user32(infop, &info);
1805+
}
1806+
#endif

0 commit comments

Comments
 (0)