drm: reorganise drm tree to be more future proof.
[safe/jmp/linux-2.6] / fs / select.c
index 41c3571..da0e882 100644 (file)
@@ -21,6 +21,7 @@
 #include <linux/poll.h>
 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
 #include <linux/file.h>
+#include <linux/fdtable.h>
 #include <linux/fs.h>
 #include <linux/rcupdate.h>
 
@@ -177,11 +178,6 @@ get_max:
        return max;
 }
 
-#define BIT(i)         (1UL << ((i)&(__NFDBITS-1)))
-#define MEM(i,m)       ((m)+(unsigned)(i)/__NFDBITS)
-#define ISSET(i,m)     (((i)&*(m)) != 0)
-#define SET(i,m)       (*(m) |= (i))
-
 #define POLLIN_SET (POLLRDNORM | POLLRDBAND | POLLIN | POLLHUP | POLLERR)
 #define POLLOUT_SET (POLLWRBAND | POLLWRNORM | POLLOUT | POLLERR)
 #define POLLEX_SET (POLLPRI)
@@ -253,7 +249,6 @@ int do_select(int n, fd_set_bits *fds, s64 *timeout)
                                                retval++;
                                        }
                                }
-                               cond_resched();
                        }
                        if (res_in)
                                *rinp = res_in;
@@ -261,11 +256,12 @@ int do_select(int n, fd_set_bits *fds, s64 *timeout)
                                *routp = res_out;
                        if (res_ex)
                                *rexp = res_ex;
+                       cond_resched();
                }
                wait = NULL;
                if (retval || !*timeout || signal_pending(current))
                        break;
-               if(table.error) {
+               if (table.error) {
                        retval = table.error;
                        break;
                }
@@ -303,7 +299,7 @@ int do_select(int n, fd_set_bits *fds, s64 *timeout)
 #define MAX_SELECT_SECONDS \
        ((unsigned long) (MAX_SCHEDULE_TIMEOUT / HZ)-1)
 
-static int core_sys_select(int n, fd_set __user *inp, fd_set __user *outp,
+int core_sys_select(int n, fd_set __user *inp, fd_set __user *outp,
                           fd_set __user *exp, s64 *timeout)
 {
        fd_set_bits fds;
@@ -430,7 +426,7 @@ sticky:
        return ret;
 }
 
-#ifdef TIF_RESTORE_SIGMASK
+#ifdef HAVE_SET_RESTORE_SIGMASK
 asmlinkage long sys_pselect7(int n, fd_set __user *inp, fd_set __user *outp,
                fd_set __user *exp, struct timespec __user *tsp,
                const sigset_t __user *sigmask, size_t sigsetsize)
@@ -503,7 +499,7 @@ sticky:
                if (sigmask) {
                        memcpy(&current->saved_sigmask, &sigsaved,
                                        sizeof(sigsaved));
-                       set_thread_flag(TIF_RESTORE_SIGMASK);
+                       set_restore_sigmask();
                }
        } else if (sigmask)
                sigprocmask(SIG_SETMASK, &sigsaved, NULL);
@@ -533,7 +529,7 @@ asmlinkage long sys_pselect6(int n, fd_set __user *inp, fd_set __user *outp,
 
        return sys_pselect7(n, inp, outp, exp, tsp, up, sigsetsize);
 }
-#endif /* TIF_RESTORE_SIGMASK */
+#endif /* HAVE_SET_RESTORE_SIGMASK */
 
 struct poll_list {
        struct poll_list *next;
@@ -586,7 +582,7 @@ static int do_poll(unsigned int nfds,  struct poll_list *list,
        /* Optimise the no-wait case */
        if (!(*timeout))
                pt = NULL;
+
        for (;;) {
                struct poll_list *walk;
                long __timeout;
@@ -616,10 +612,12 @@ static int do_poll(unsigned int nfds,  struct poll_list *list,
                 * a poll_table to them on the next loop iteration.
                 */
                pt = NULL;
-               if (count || !*timeout || signal_pending(current))
-                       break;
-               count = wait->error;
-               if (count)
+               if (!count) {
+                       count = wait->error;
+                       if (signal_pending(current))
+                               count = -EINTR;
+               }
+               if (count || !*timeout)
                        break;
 
                if (*timeout < 0) {
@@ -689,8 +687,6 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds, s64 *timeout)
 
        poll_initwait(&table);
        fdcount = do_poll(nfds, head, &table, timeout);
-       if (!fdcount && signal_pending(current))
-               fdcount = -EINTR;
        poll_freewait(&table);
 
        for (walk = head; walk; walk = walk->next) {
@@ -714,10 +710,28 @@ out_fds:
        return err;
 }
 
+static long do_restart_poll(struct restart_block *restart_block)
+{
+       struct pollfd __user *ufds = (struct pollfd __user*)restart_block->arg0;
+       int nfds = restart_block->arg1;
+       s64 timeout = ((s64)restart_block->arg3<<32) | (s64)restart_block->arg2;
+       int ret;
+
+       ret = do_sys_poll(ufds, nfds, &timeout);
+       if (ret == -EINTR) {
+               restart_block->fn = do_restart_poll;
+               restart_block->arg2 = timeout & 0xFFFFFFFF;
+               restart_block->arg3 = (u64)timeout >> 32;
+               ret = -ERESTART_RESTARTBLOCK;
+       }
+       return ret;
+}
+
 asmlinkage long sys_poll(struct pollfd __user *ufds, unsigned int nfds,
                        long timeout_msecs)
 {
        s64 timeout_jiffies;
+       int ret;
 
        if (timeout_msecs > 0) {
 #if HZ > 1000
@@ -726,16 +740,27 @@ asmlinkage long sys_poll(struct pollfd __user *ufds, unsigned int nfds,
                        timeout_jiffies = -1;
                else
 #endif
-                       timeout_jiffies = msecs_to_jiffies(timeout_msecs);
+                       timeout_jiffies = msecs_to_jiffies(timeout_msecs) + 1;
        } else {
                /* Infinite (< 0) or no (0) timeout */
                timeout_jiffies = timeout_msecs;
        }
 
-       return do_sys_poll(ufds, nfds, &timeout_jiffies);
+       ret = do_sys_poll(ufds, nfds, &timeout_jiffies);
+       if (ret == -EINTR) {
+               struct restart_block *restart_block;
+               restart_block = &current_thread_info()->restart_block;
+               restart_block->fn = do_restart_poll;
+               restart_block->arg0 = (unsigned long)ufds;
+               restart_block->arg1 = nfds;
+               restart_block->arg2 = timeout_jiffies & 0xFFFFFFFF;
+               restart_block->arg3 = (u64)timeout_jiffies >> 32;
+               ret = -ERESTART_RESTARTBLOCK;
+       }
+       return ret;
 }
 
-#ifdef TIF_RESTORE_SIGMASK
+#ifdef HAVE_SET_RESTORE_SIGMASK
 asmlinkage long sys_ppoll(struct pollfd __user *ufds, unsigned int nfds,
        struct timespec __user *tsp, const sigset_t __user *sigmask,
        size_t sigsetsize)
@@ -781,7 +806,7 @@ asmlinkage long sys_ppoll(struct pollfd __user *ufds, unsigned int nfds,
                if (sigmask) {
                        memcpy(&current->saved_sigmask, &sigsaved,
                                        sizeof(sigsaved));
-                       set_thread_flag(TIF_RESTORE_SIGMASK);
+                       set_restore_sigmask();
                }
                ret = -ERESTARTNOHAND;
        } else if (sigmask)
@@ -815,4 +840,4 @@ asmlinkage long sys_ppoll(struct pollfd __user *ufds, unsigned int nfds,
 
        return ret;
 }
-#endif /* TIF_RESTORE_SIGMASK */
+#endif /* HAVE_SET_RESTORE_SIGMASK */