[PATCH 1/3] Add generic compat_sys_sendfile andcompat_sys_sendfile64

From: Catalin Marinas
Date: Thu Sep 13 2012 - 04:51:10 EST


These functions are used by other architectures requiring compat
support, so just make them generic.

Signed-off-by: Catalin Marinas <catalin.marinas@xxxxxxx>
Cc: Arnd Bergmann <arnd@xxxxxxxx>
---
include/linux/compat.h | 5 +++++
kernel/compat.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 49 insertions(+), 0 deletions(-)

diff --git a/include/linux/compat.h b/include/linux/compat.h
index c4be3f5..e2f5e9a 100644
--- a/include/linux/compat.h
+++ b/include/linux/compat.h
@@ -594,6 +594,11 @@ asmlinkage ssize_t compat_sys_process_vm_writev(compat_pid_t pid,
unsigned long liovcnt, const struct compat_iovec __user *rvec,
unsigned long riovcnt, unsigned long flags);

+asmlinkage int compat_sys_sendfile(int out_fd, int in_fd,
+ compat_off_t __user *offset, s32 count);
+asmlinkage int compat_sys_sendfile64(int out_fd, int in_fd,
+ compat_loff_t __user *offset, s32 count);
+
#else

#define is_compat_task() (0)
diff --git a/kernel/compat.c b/kernel/compat.c
index c28a306..5f07388 100644
--- a/kernel/compat.c
+++ b/kernel/compat.c
@@ -1215,6 +1215,50 @@ compat_sys_sysinfo(struct compat_sysinfo __user *info)
return 0;
}

+#ifdef __ARCH_WANT_COMPAT_SYS_SENDFILE
+asmlinkage int compat_sys_sendfile(int out_fd, int in_fd,
+ compat_off_t __user *offset, s32 count)
+{
+ mm_segment_t old_fs = get_fs();
+ int ret;
+ off_t of;
+
+ if (offset && get_user(of, offset))
+ return -EFAULT;
+
+ set_fs(KERNEL_DS);
+ ret = sys_sendfile(out_fd, in_fd,
+ offset ? (off_t __user *)&of : NULL, count);
+ set_fs(old_fs);
+
+ if (offset && put_user(of, offset))
+ return -EFAULT;
+ return ret;
+}
+#endif /* __ARCH_WANT_COMPAT_SYS_SENDFILE */
+
+#ifdef __ARCH_WANT_COMPAT_SYS_SENDFILE64
+asmlinkage int compat_sys_sendfile64(int out_fd, int in_fd,
+ compat_loff_t __user *offset, s32 count)
+{
+ mm_segment_t old_fs = get_fs();
+ int ret;
+ loff_t of;
+
+ if (offset && get_user(of, offset))
+ return -EFAULT;
+
+ set_fs(KERNEL_DS);
+ ret = sys_sendfile(out_fd, in_fd,
+ offset ? (loff_t __user *)&of : NULL, count);
+ set_fs(old_fs);
+
+ if (offset && put_user(of, offset))
+ return -EFAULT;
+ return ret;
+}
+#endif /* __ARCH_WANT_COMPAT_SYS_SENDFILE64 */
+
/*
* Allocate user-space memory for the duration of a single system call,
* in order to marshall parameters inside a compat thunk.