diff mbox

[v4,8/9] epoll: Add compat version implementation of epoll_pwait1

Message ID 1425952155-27603-9-git-send-email-famz@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Fam Zheng March 10, 2015, 1:49 a.m. UTC
Signed-off-by: Fam Zheng <famz@redhat.com>
---
 fs/eventpoll.c         | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/compat.h |  6 ++++++
 2 files changed, 56 insertions(+)
diff mbox

Patch

diff --git a/fs/eventpoll.c b/fs/eventpoll.c
index 06a59fc..b837ea4 100644
--- a/fs/eventpoll.c
+++ b/fs/eventpoll.c
@@ -2178,6 +2178,56 @@  COMPAT_SYSCALL_DEFINE6(epoll_pwait, int, epfd,
 	return epoll_pwait_do(epfd, events, maxevents, CLOCK_MONOTONIC, kt,
 			      sigmask ? &ksigmask : NULL);
 }
+
+struct compat_epoll_wait_params {
+	int size;
+	int clockid;
+	compat_uptr_t timeout;
+	compat_uptr_t sigmask;
+	compat_size_t sigsetsize;
+} EPOLL_PACKED;
+
+COMPAT_SYSCALL_DEFINE5(epoll_pwait1, int, epfd, int, flags,
+		       struct epoll_event __user *, events,
+		       int, maxevents,
+		       struct compat_epoll_wait_params __user *, params)
+{
+	struct compat_epoll_wait_params p;
+
+	ktime_t kt = { 0 };
+	sigset_t sigmask;
+	compat_sigset_t compat_sigmask;
+	struct timespec timeout;
+
+	if (flags)
+		return -EINVAL;
+	if (!params)
+		return -EINVAL;
+	if (copy_from_user(&p, params, sizeof(p)))
+		return -EFAULT;
+	if (p.size != sizeof(p))
+		return -EINVAL;
+	if (p.sigmask) {
+		if (copy_from_user(&compat_sigmask, compat_ptr(p.sigmask),
+				   sizeof(sigmask)))
+			return -EFAULT;
+		if (p.sigsetsize != sizeof(p.sigmask))
+			return -EINVAL;
+		sigset_from_compat(&sigmask, &compat_sigmask);
+	}
+	if (p.timeout) {
+		if (compat_get_timespec(&timeout, compat_ptr(p.timeout)))
+			return -EFAULT;
+		if (!timespec_valid(&timeout))
+			return -EINVAL;
+		kt = timespec_to_ktime(timeout);
+	} else {
+		kt = ns_to_ktime(-1);
+	}
+
+	return epoll_pwait_do(epfd, events, maxevents, p.clockid,
+			      kt, p.sigmask ? &sigmask : NULL);
+}
 #endif
 
 static int __init eventpoll_init(void)
diff --git a/include/linux/compat.h b/include/linux/compat.h
index ab25814..649c5b2 100644
--- a/include/linux/compat.h
+++ b/include/linux/compat.h
@@ -452,6 +452,12 @@  asmlinkage long compat_sys_epoll_pwait(int epfd,
 			const compat_sigset_t __user *sigmask,
 			compat_size_t sigsetsize);
 
+struct compat_epoll_wait_params;
+asmlinkage long compat_sys_epoll_pwait1(int epfd, int flags,
+			struct epoll_event __user *events,
+			int maxevents,
+			struct compat_epoll_wait_params __user *params);
+
 asmlinkage long compat_sys_utime(const char __user *filename,
 				 struct compat_utimbuf __user *t);
 asmlinkage long compat_sys_utimensat(unsigned int dfd,