Re: [PATCH][COMPAT] compat_sys_futex 1/7 generic

From: Stephen Rothwell (sfr@canb.auug.org.au)
Date: Wed Feb 12 2003 - 01:28:18 EST


Hi Linus,

On Tue, 11 Feb 2003 21:26:54 -0800 (PST) Linus Torvalds <torvalds@transmeta.com> wrote:
>
> I'd prefer this much more if it just passed the timout around as jiffies
> (unconditionally), instead of converting them from one type of timespec to
> another, and then converting that other timespec to jiffies, and having
> multiple tests for NULL because of all that conversion confusion.
>
> Hmm?

How about this then. Just the generic part retransmitted.

/me mumbles "I will not ignore Rusty's suggestions ..."

-- 
Cheers,
Stephen Rothwell                    sfr@canb.auug.org.au
http://www.canb.auug.org.au/~sfr/

diff -ruN 2.5.60-32bit.1/kernel/compat.c 2.5.60-32bit.2/kernel/compat.c --- 2.5.60-32bit.1/kernel/compat.c 2003-01-17 14:01:08.000000000 +1100 +++ 2.5.60-32bit.2/kernel/compat.c 2003-02-12 17:22:18.000000000 +1100 @@ -16,6 +16,7 @@ #include <linux/errno.h> #include <linux/time.h> #include <linux/signal.h> +#include <linux/sched.h> /* for MAX_SCHEDULE_TIMEOUT */ #include <asm/uaccess.h> @@ -208,3 +209,19 @@ ret = put_user(s, oset); 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); +} diff -ruN 2.5.60-32bit.1/kernel/futex.c 2.5.60-32bit.2/kernel/futex.c --- 2.5.60-32bit.1/kernel/futex.c 2002-11-28 10:34:59.000000000 +1100 +++ 2.5.60-32bit.2/kernel/futex.c 2003-02-12 17:18:36.000000000 +1100 @@ -315,23 +315,6 @@ 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) { struct futex_q *q = filp->private_data; @@ -437,7 +420,7 @@ 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; int ret; @@ -445,12 +428,12 @@ pos_in_page = uaddr % PAGE_SIZE; /* Must be "naturally" aligned */ - if (pos_in_page % sizeof(int)) + if (pos_in_page % sizeof(u32)) return -EINVAL; switch (op) { case FUTEX_WAIT: - ret = futex_wait_utime(uaddr, pos_in_page, val, utime); + ret = futex_wait(uaddr, pos_in_page, val, timeout); break; case FUTEX_WAKE: ret = futex_wake(uaddr, pos_in_page, val); @@ -465,6 +448,20 @@ 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 * futexfs_get_sb(struct file_system_type *fs_type, int flags, char *dev_name, void *data) - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Sat Feb 15 2003 - 22:00:38 EST