check_iovec cleanup

Brian Ford Brian.Ford@flightsafety.com
Wed Jul 26 22:53:00 GMT 2006


I think this removes some redundancy and a questionable check while being
more straight forward and covering more possible fault cases.  Please let
me know if I missed a reason it had to be that way.

2006-07-26  Brian Ford  <Brian.Ford@FlightSafety.com>

	* miscfuncs.cc (dummytest): Delete.
	(check_iovec): Remove forwrite argument.  Let caller setup fault
	handler and don't explicitly test for valid buffers.
	* winsup.h (check_iovec_for_read): Delete define.
	(check_iovec_for_write): Likewise.
	(check_iovec): Adjust prototype.
	* net.cc (cygwin_recvmsg): Adjust for above.
	(cygwin_sendmsg): Likewise.
	* syscalls.cc (readv): Setup fault handling here and adjust for
	above.
	(writev): Likewise.

-- 
Brian Ford
Lead Realtime Software Engineer
VITAL - Visual Simulation Systems
FlightSafety International
the best safety device in any aircraft is a well-trained crew...
-------------- next part --------------
Index: miscfuncs.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/miscfuncs.cc,v
retrieving revision 1.41
diff -u -p -r1.41 miscfuncs.cc
--- miscfuncs.cc	28 May 2006 15:50:14 -0000	1.41
+++ miscfuncs.cc	26 Jul 2006 22:28:53 -0000
@@ -159,13 +159,8 @@ check_invalid_virtual_addr (const void *
   return 0;
 }
 
-static char __attribute__ ((noinline))
-dummytest (volatile char *p)
-{
-  return *p;
-}
 ssize_t
-check_iovec (const struct iovec *iov, int iovcnt, bool forwrite)
+check_iovec (const struct iovec *iov, int iovcnt)
 {
   if (iovcnt <= 0 || iovcnt > IOV_MAX)
     {
@@ -173,10 +168,6 @@ check_iovec (const struct iovec *iov, in
       return -1;
     }
 
-  myfault efault;
-  if (efault.faulted (EFAULT))
-    return -1;
-
   size_t tot = 0;
 
   while (iovcnt != 0)
@@ -187,21 +178,13 @@ check_iovec (const struct iovec *iov, in
 	  return -1;
 	}
 
-      volatile char *p = ((char *) iov->iov_base) + iov->iov_len - 1;
-      if (!iov->iov_len)
-	/* nothing to do */;
-      else if (!forwrite)
-	*p  = dummytest (p);
-      else
-	dummytest (p);
-
       iov++;
       iovcnt--;
     }
 
   assert (tot <= SSIZE_MAX);
 
-  return (ssize_t) tot;
+  return tot;
 }
 
 UINT
Index: net.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/net.cc,v
retrieving revision 1.214
diff -u -p -r1.214 net.cc
--- net.cc	25 Jul 2006 19:23:23 -0000	1.214
+++ net.cc	26 Jul 2006 22:28:55 -0000
@@ -2068,7 +2068,7 @@ cygwin_recvmsg (int fd, struct msghdr *m
     res = -1;
   else
     {
-      res = check_iovec_for_read (msg->msg_iov, msg->msg_iovlen);
+      res = check_iovec (msg->msg_iov, msg->msg_iovlen);
       if (res > 0)
 	res = fh->recvmsg (msg, flags, res); // res == iovec tot
     }
@@ -2091,7 +2091,7 @@ cygwin_sendmsg (int fd, const struct msg
     res = -1;
   else
     {
-      res = check_iovec_for_write (msg->msg_iov, msg->msg_iovlen);
+      res = check_iovec (msg->msg_iov, msg->msg_iovlen);
       res = fh->sendmsg (msg, flags, res); // res == iovec tot
     }
 
Index: syscalls.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/syscalls.cc,v
retrieving revision 1.404
diff -u -p -r1.404 syscalls.cc
--- syscalls.cc	25 Jul 2006 19:23:23 -0000	1.404
+++ syscalls.cc	26 Jul 2006 22:28:55 -0000
@@ -445,7 +445,14 @@ readv (int fd, const struct iovec *const
 
   int res = -1;
 
-  const ssize_t tot = check_iovec_for_read (iov, iovcnt);
+  myfault efault;
+  if (efault.faulted (EFAULT))
+    {
+      res = -1;
+      goto done;
+    }
+
+  const ssize_t tot = check_iovec (iov, iovcnt);
 
   if (tot <= 0)
     {
@@ -527,11 +534,17 @@ writev (const int fd, const struct iovec
 {
   int res = -1;
   sig_dispatch_pending ();
-  const ssize_t tot = check_iovec_for_write (iov, iovcnt);
 
   cygheap_fdget cfd (fd);
-  if (cfd < 0)
-    goto done;
+  myfault efault;
+
+  if (efault.faulted (EFAULT) || cfd < 0)
+    {
+      res = -1;
+      goto done;
+    }
+
+  const ssize_t tot = check_iovec (iov, iovcnt);
 
   if (tot <= 0)
     {
Index: winsup.h
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/winsup.h,v
retrieving revision 1.190
diff -u -p -r1.190 winsup.h
--- winsup.h	25 Jul 2006 19:23:23 -0000	1.190
+++ winsup.h	26 Jul 2006 22:28:55 -0000
@@ -263,9 +263,7 @@ void init_global_security ();
 
 int __stdcall check_invalid_virtual_addr (const void *s, unsigned sz) __attribute__ ((regparm(2)));
 
-ssize_t check_iovec (const struct iovec *, int, bool) __attribute__ ((regparm(3)));
-#define check_iovec_for_read(a, b) check_iovec ((a), (b), false)
-#define check_iovec_for_write(a, b) check_iovec ((a), (b), true)
+ssize_t check_iovec (const struct iovec *, int) __attribute__ ((regparm(2)));
 
 #define set_winsock_errno() __set_winsock_errno (__FUNCTION__, __LINE__)
 void __set_winsock_errno (const char *fn, int ln) __attribute__ ((regparm(2)));


More information about the Cygwin-patches mailing list