Commit 424706ad authored by Stephen Rothwell's avatar Stephen Rothwell Committed by Jens Axboe

[PATCH] compat_sys_futex 1/3 generic, parisc, ppc64, s390x and x86_64

This is the generic part of the patch and the architecture specific parts
I have been asked to forward directly to you.
parent fcc21ee2
...@@ -320,7 +320,8 @@ tracesys_sigexit: ...@@ -320,7 +320,8 @@ tracesys_sigexit:
#ifdef __LP64__ #ifdef __LP64__
/* Use ENTRY_SAME for 32-bit syscalls which are the same on wide and /* Use ENTRY_SAME for 32-bit syscalls which are the same on wide and
* narrow palinux. Use ENTRY_DIFF for those where a 32-bit specific * narrow palinux. Use ENTRY_DIFF for those where a 32-bit specific
* implementation is required on wide palinux. * implementation is required on wide palinux. Use ENTRY_COMP where
* the compatability layer has a useful 32-bit implementation.
*/ */
#define ENTRY_SAME(_name_) .dword sys_##_name_ #define ENTRY_SAME(_name_) .dword sys_##_name_
#define ENTRY_DIFF(_name_) .dword sys32_##_name_ #define ENTRY_DIFF(_name_) .dword sys32_##_name_
...@@ -597,7 +598,7 @@ sys_call_table: ...@@ -597,7 +598,7 @@ sys_call_table:
ENTRY_SAME(ni_syscall) /* tkill */ ENTRY_SAME(ni_syscall) /* tkill */
ENTRY_SAME(sendfile64) ENTRY_SAME(sendfile64)
ENTRY_SAME(futex) /* 210 */ ENTRY_COMP(futex) /* 210 */
ENTRY_SAME(sched_setaffinity) ENTRY_SAME(sched_setaffinity)
ENTRY_SAME(sched_getaffinity) ENTRY_SAME(sched_getaffinity)
ENTRY_SAME(set_thread_area) ENTRY_SAME(set_thread_area)
......
...@@ -724,7 +724,7 @@ _GLOBAL(sys_call_table32) ...@@ -724,7 +724,7 @@ _GLOBAL(sys_call_table32)
.llong .sys_removexattr .llong .sys_removexattr
.llong .sys_lremovexattr .llong .sys_lremovexattr
.llong .sys_fremovexattr /* 220 */ .llong .sys_fremovexattr /* 220 */
.llong .sys_futex .llong .compat_sys_futex
.llong .sys32_sched_setaffinity .llong .sys32_sched_setaffinity
.llong .sys32_sched_getaffinity .llong .sys32_sched_getaffinity
.llong .sys_ni_syscall .llong .sys_ni_syscall
......
...@@ -629,7 +629,7 @@ sys_call_table: ...@@ -629,7 +629,7 @@ sys_call_table:
.long SYSCALL(sys_fremovexattr,sys32_fremovexattr_wrapper) /* 235 */ .long SYSCALL(sys_fremovexattr,sys32_fremovexattr_wrapper) /* 235 */
.long SYSCALL(sys_gettid,sys_gettid) .long SYSCALL(sys_gettid,sys_gettid)
.long SYSCALL(sys_tkill,sys_tkill) .long SYSCALL(sys_tkill,sys_tkill)
.long SYSCALL(sys_futex,sys32_futex_wrapper) .long SYSCALL(sys_futex,compat_sys_futex_wrapper)
.long SYSCALL(sys_sched_setaffinity,sys32_sched_setaffinity_wrapper) .long SYSCALL(sys_sched_setaffinity,sys32_sched_setaffinity_wrapper)
.long SYSCALL(sys_sched_getaffinity,sys32_sched_getaffinity_wrapper) /* 240 */ .long SYSCALL(sys_sched_getaffinity,sys32_sched_getaffinity_wrapper) /* 240 */
.long SYSCALL(sys_ni_syscall,sys_ni_syscall) .long SYSCALL(sys_ni_syscall,sys_ni_syscall)
......
...@@ -4049,28 +4049,6 @@ asmlinkage int sys32_sched_getaffinity(compat_pid_t pid, unsigned int len, ...@@ -4049,28 +4049,6 @@ asmlinkage int sys32_sched_getaffinity(compat_pid_t pid, unsigned int len,
return ret; return ret;
} }
asmlinkage int
sys_futex(void *uaddr, int op, int val, struct timespec *utime);
asmlinkage int
sys32_futex(void *uaddr, int op, int val,
struct compat_timespec *timeout32)
{
struct timespec tmp;
mm_segment_t old_fs;
int ret;
if (timeout32 && get_compat_timespec(&tmp, timeout32))
return -EINVAL;
old_fs = get_fs();
set_fs(KERNEL_DS);
ret = sys_futex(uaddr, op, val, timeout32 ? &tmp : NULL);
set_fs(old_fs);
return ret;
}
asmlinkage ssize_t sys_read(unsigned int fd, char * buf, size_t count); asmlinkage ssize_t sys_read(unsigned int fd, char * buf, size_t count);
asmlinkage compat_ssize_t sys32_read(unsigned int fd, char * buf, size_t count) asmlinkage compat_ssize_t sys32_read(unsigned int fd, char * buf, size_t count)
......
...@@ -1088,13 +1088,13 @@ sys32_fstat64_wrapper: ...@@ -1088,13 +1088,13 @@ sys32_fstat64_wrapper:
llgfr %r4,%r4 # long llgfr %r4,%r4 # long
jg sys32_fstat64 # branch to system call jg sys32_fstat64 # branch to system call
.globl sys32_futex_wrapper .globl compat_sys_futex_wrapper
sys32_futex_wrapper: compat_sys_futex_wrapper:
llgtr %r2,%r2 # void * llgtr %r2,%r2 # u32 *
lgfr %r3,%r3 # int lgfr %r3,%r3 # int
lgfr %r4,%r4 # int lgfr %r4,%r4 # int
llgtr %r5,%r5 # struct timespec * llgtr %r5,%r5 # struct compat_timespec *
jg sys32_futex # branch to system call jg compat_sys_futex # branch to system call
.globl sys32_setxattr_wrapper .globl sys32_setxattr_wrapper
sys32_setxattr_wrapper: sys32_setxattr_wrapper:
......
...@@ -440,7 +440,7 @@ ia32_sys_call_table: ...@@ -440,7 +440,7 @@ ia32_sys_call_table:
.quad sys_fremovexattr .quad sys_fremovexattr
.quad sys_tkill /* 238 */ .quad sys_tkill /* 238 */
.quad sys_sendfile64 .quad sys_sendfile64
.quad sys32_futex /* 240 */ .quad compat_sys_futex /* 240 */
.quad sys32_sched_setaffinity .quad sys32_sched_setaffinity
.quad sys32_sched_getaffinity .quad sys32_sched_getaffinity
.quad sys_set_thread_area .quad sys_set_thread_area
......
...@@ -2199,26 +2199,6 @@ long sys32_sched_getaffinity(pid_t pid, unsigned int len, ...@@ -2199,26 +2199,6 @@ long sys32_sched_getaffinity(pid_t pid, unsigned int len,
return err; return err;
} }
extern int sys_futex(unsigned long uaddr, int op, int val, struct timespec *t);
asmlinkage long
sys32_futex(unsigned long uaddr, int op, int val, struct compat_timespec *utime32)
{
struct timespec t;
mm_segment_t oldfs = get_fs();
int err;
if (utime32 && get_compat_timespec(&t, utime32))
return -EFAULT;
/* the set_fs is safe because futex doesn't use the seg limit
for valid page checking of uaddr. */
set_fs(KERNEL_DS);
err = sys_futex(uaddr, op, val, utime32 ? &t : NULL);
set_fs(oldfs);
return err;
}
extern long sys_io_setup(unsigned nr_reqs, aio_context_t *ctx); extern long sys_io_setup(unsigned nr_reqs, aio_context_t *ctx);
long sys32_io_setup(unsigned nr_reqs, u32 *ctx32p) long sys32_io_setup(unsigned nr_reqs, u32 *ctx32p)
......
...@@ -6,6 +6,6 @@ ...@@ -6,6 +6,6 @@
#define FUTEX_WAKE (1) #define FUTEX_WAKE (1)
#define FUTEX_FD (2) #define FUTEX_FD (2)
extern asmlinkage int sys_futex(unsigned long uaddr, int op, int val, struct timespec *utime); extern asmlinkage long sys_futex(u32 *uaddr, int op, int val, struct timespec *utime);
#endif #endif
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/time.h> #include <linux/time.h>
#include <linux/signal.h> #include <linux/signal.h>
#include <linux/sched.h> /* for MAX_SCHEDULE_TIMEOUT */
#include <asm/uaccess.h> #include <asm/uaccess.h>
...@@ -208,3 +209,19 @@ asmlinkage long compat_sys_sigprocmask(int how, compat_old_sigset_t *set, ...@@ -208,3 +209,19 @@ asmlinkage long compat_sys_sigprocmask(int how, compat_old_sigset_t *set,
ret = put_user(s, oset); ret = put_user(s, oset);
return ret; return ret;
} }
extern long do_futex(u32 *, int, int, unsigned long);
asmlinkage long compat_sys_futex(u32 *uaddr, int op, int val,
struct compat_timespec *utime)
{
struct timespec t;
unsigned long timeout = MAX_SCHEDULE_TIMEOUT;
if ((op == FUTEX_WAIT) && utime) {
if (get_compat_timespec(&t, utime))
return -EFAULT;
timeout = timespec_to_jiffies(t) + 1;
}
return do_futex((unsigned long)uaddr, op, val, timeout);
}
...@@ -315,23 +315,6 @@ static int futex_wait(unsigned long uaddr, ...@@ -315,23 +315,6 @@ static int futex_wait(unsigned long uaddr,
return ret; return ret;
} }
static inline int futex_wait_utime(unsigned long uaddr,
int offset,
int val,
struct timespec* utime)
{
unsigned long time = MAX_SCHEDULE_TIMEOUT;
if (utime) {
struct timespec t;
if (copy_from_user(&t, utime, sizeof(t)) != 0)
return -EFAULT;
time = timespec_to_jiffies(&t) + 1;
}
return futex_wait(uaddr, offset, val, time);
}
static int futex_close(struct inode *inode, struct file *filp) static int futex_close(struct inode *inode, struct file *filp)
{ {
struct futex_q *q = filp->private_data; struct futex_q *q = filp->private_data;
...@@ -437,7 +420,7 @@ static int futex_fd(unsigned long uaddr, int offset, int signal) ...@@ -437,7 +420,7 @@ static int futex_fd(unsigned long uaddr, int offset, int signal)
return ret; return ret;
} }
asmlinkage int sys_futex(unsigned long uaddr, int op, int val, struct timespec *utime) long do_futex(unsigned long uaddr, int op, int val, unsinged long timeout)
{ {
unsigned long pos_in_page; unsigned long pos_in_page;
int ret; int ret;
...@@ -445,12 +428,12 @@ asmlinkage int sys_futex(unsigned long uaddr, int op, int val, struct timespec * ...@@ -445,12 +428,12 @@ asmlinkage int sys_futex(unsigned long uaddr, int op, int val, struct timespec *
pos_in_page = uaddr % PAGE_SIZE; pos_in_page = uaddr % PAGE_SIZE;
/* Must be "naturally" aligned */ /* Must be "naturally" aligned */
if (pos_in_page % sizeof(int)) if (pos_in_page % sizeof(u32))
return -EINVAL; return -EINVAL;
switch (op) { switch (op) {
case FUTEX_WAIT: case FUTEX_WAIT:
ret = futex_wait_utime(uaddr, pos_in_page, val, utime); ret = futex_wait(uaddr, pos_in_page, val, timeout);
break; break;
case FUTEX_WAKE: case FUTEX_WAKE:
ret = futex_wake(uaddr, pos_in_page, val); ret = futex_wake(uaddr, pos_in_page, val);
...@@ -465,6 +448,20 @@ asmlinkage int sys_futex(unsigned long uaddr, int op, int val, struct timespec * ...@@ -465,6 +448,20 @@ asmlinkage int sys_futex(unsigned long uaddr, int op, int val, struct timespec *
return ret; return ret;
} }
asmlinkage long sys_futex(u32 *uaddr, int op, int val, struct timespec *utime)
{
struct timespec t;
unsigned long timeout = MAX_SCHEDULE_TIMEOUT;
if ((op == FUTEX_WAIT) && utime) {
if (copy_from_user(&t, utime, sizeof(t)) != 0)
return -EFAULT;
timeout = timespec_to_jiffies(t) + 1;
}
return do_futex((unsigned long)uaddr, op, val, timeout);
}
static struct super_block * static struct super_block *
futexfs_get_sb(struct file_system_type *fs_type, futexfs_get_sb(struct file_system_type *fs_type,
int flags, char *dev_name, void *data) int flags, char *dev_name, void *data)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment