From 23db0a41d8b178d6f3d2297834b28e015346bd43 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Thu, 5 May 2011 18:46:38 +0000 Subject: [PATCH] * syscalls.cc (readv): Add myfault handler. Don't check repeatedly open state of file handler. Streamline loop. (writev): Add myfault handler. --- winsup/cygwin/ChangeLog | 6 ++++ winsup/cygwin/syscalls.cc | 59 ++++++++++++++++----------------------- 2 files changed, 30 insertions(+), 35 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 6bd2b500c..a6ea390fe 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,9 @@ +2011-05-05 Corinna Vinschen + + * syscalls.cc (readv): Add myfault handler. Don't check repeatedly + open state of file handler. Streamline loop. + (writev): Add myfault handler. + 2011-05-05 Christopher Faylor * fhandler.cc (fhandler_base_overlapped::raw_read): Rename from diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc index 93be3ec03..b086554c5 100644 --- a/winsup/cygwin/syscalls.cc +++ b/winsup/cygwin/syscalls.cc @@ -962,60 +962,45 @@ readv (int fd, const struct iovec *const iov, const int iovcnt) { pthread_testcancel (); - extern int sigcatchers; - const int e = get_errno (); + myfault efault; + if (efault.faulted (EFAULT)) + return -1; ssize_t res = -1; - + const int e = get_errno (); const ssize_t tot = check_iovec_for_read (iov, iovcnt); + cygheap_fdget cfd (fd); + if (cfd < 0) + goto done; + if (tot <= 0) { res = tot; goto done; } + if ((cfd->get_flags () & O_ACCMODE) == O_WRONLY) + { + set_errno (EBADF); + goto done; + } + + /* Could block, so let user know we at least got here. */ + extern int sigcatchers; + syscall_printf ("readv (%d, %p, %d) %sblocking, sigcatchers %d", + fd, iov, iovcnt, cfd->is_nonblocking () ? "non" : "", + sigcatchers); + while (1) { - cygheap_fdget cfd (fd); - if (cfd < 0) - break; - - if ((cfd->get_flags () & O_ACCMODE) == O_WRONLY) - { - set_errno (EBADF); - break; - } - - /* Could block, so let user know we at least got here. */ - syscall_printf ("readv (%d, %p, %d) %sblocking, sigcatchers %d", - fd, iov, iovcnt, cfd->is_nonblocking () ? "non" : "", - sigcatchers); - - /* FIXME: This is not thread safe. We need some method to - ensure that an fd, closed in another thread, aborts I/O - operations. */ - if (!cfd.isopen ()) - break; - /* Check to see if this is a background read from a "tty", sending a SIGTTIN, if appropriate */ res = cfd->bg_check (SIGTTIN); - if (!cfd.isopen ()) - { - res = -1; - break; - } - if (res > bg_eof) { myself->process_state |= PID_TTYIN; - if (!cfd.isopen ()) - { - res = -1; - break; - } res = cfd->readv (iov, iovcnt, tot); myself->process_state &= ~PID_TTYIN; } @@ -1037,6 +1022,10 @@ writev (const int fd, const struct iovec *const iov, const int iovcnt) { pthread_testcancel (); + myfault efault; + if (efault.faulted (EFAULT)) + return -1; + int res = -1; const ssize_t tot = check_iovec_for_write (iov, iovcnt);