]> sourceware.org Git - glibc.git/commitdiff
hurd: Make recv* cancellation points
authorSamuel Thibault <samuel.thibault@ens-lyon.org>
Sun, 14 Jun 2020 00:19:35 +0000 (00:19 +0000)
committerSamuel Thibault <samuel.thibault@ens-lyon.org>
Sun, 14 Jun 2020 00:19:35 +0000 (00:19 +0000)
* sysdeps/mach/hurd/recv.c (__recv): Make the __socket_recv call
cancellable.
* sysdeps/mach/hurd/recvfrom.c (__recvfrom): Make the __socket_recv and
__socket_whatis_address calls cancellable.
* sysdeps/mach/hurd/recvmsg.c (__libc_recvmsg): Make the __socket_recv,
__socket_whatis_address, __io_reauthenticate, and __auth_user_authenticate calls
cancellable.

sysdeps/mach/hurd/recv.c
sysdeps/mach/hurd/recvfrom.c
sysdeps/mach/hurd/recvmsg.c

index 6dd556cc1241ac73bab69e20556838a315b6e5e6..b9ed067265dce22e78ca4eb1070ea14b8f7655de 100644 (file)
@@ -21,6 +21,7 @@
 #include <hurd/fd.h>
 #include <hurd/socket.h>
 #include <string.h>
+#include <sysdep-cancel.h>
 
 /* Read N bytes into BUF from socket FD.
    Returns the number read or -1 for errors.  */
@@ -36,13 +37,17 @@ __recv (int fd, void *buf, size_t n, int flags)
   mach_msg_type_number_t nports = 0;
   char *cdata = NULL;
   mach_msg_type_number_t clen = 0;
+  int cancel_oldtype;
 
+  cancel_oldtype = LIBC_CANCEL_ASYNC();
   err = HURD_DPORT_USE (fd, __socket_recv (port, &addrport,
                                               flags, &bufp, &nread,
                                               &ports, &nports,
                                               &cdata, &clen,
                                               &flags,
                                               n));
+  LIBC_CANCEL_RESET (cancel_oldtype);
+
   if (err == MIG_BAD_ID || err == EOPNOTSUPP)
     /* The file did not grok the socket protocol.  */
     err = ENOTSOCK;
index 4479158d7019e03de87e6b8e4ea7d1fb47ec9c8a..ed3d9707227a9b0f6649b2a7afb5549772a51c30 100644 (file)
@@ -21,6 +21,7 @@
 #include <hurd.h>
 #include <hurd/fd.h>
 #include <hurd/socket.h>
+#include <sysdep-cancel.h>
 
 /* Read N bytes into BUF through socket FD.
    If ADDR is not NULL, fill in *ADDR_LEN bytes of it with tha address of
@@ -39,13 +40,18 @@ __recvfrom (int fd, void *buf, size_t n, int flags, __SOCKADDR_ARG addrarg,
   char *cdata = NULL;
   mach_msg_type_number_t clen = 0;
   struct sockaddr *addr = addrarg.__sockaddr__;
-
-  if (err = HURD_DPORT_USE (fd, __socket_recv (port, &addrport,
-                                              flags, &bufp, &nread,
-                                              &ports, &nports,
-                                              &cdata, &clen,
-                                              &flags,
-                                              n)))
+  int cancel_oldtype;
+
+  cancel_oldtype = LIBC_CANCEL_ASYNC();
+  err = HURD_DPORT_USE (fd, __socket_recv (port, &addrport,
+                                          flags, &bufp, &nread,
+                                          &ports, &nports,
+                                          &cdata, &clen,
+                                          &flags,
+                                          n));
+  LIBC_CANCEL_RESET (cancel_oldtype);
+
+  if (err)
     return __hurd_sockfail (fd, flags, err);
 
   /* Get address data for the returned address port if requested.  */
@@ -55,7 +61,9 @@ __recvfrom (int fd, void *buf, size_t n, int flags, __SOCKADDR_ARG addrarg,
       mach_msg_type_number_t buflen = *addr_len;
       int type;
 
+      cancel_oldtype = LIBC_CANCEL_ASYNC();
       err = __socket_whatis_address (addrport, &type, &buf, &buflen);
+      LIBC_CANCEL_RESET (cancel_oldtype);
       if (err == EOPNOTSUPP)
        /* If the protocol server can't tell us the address, just return a
           zero-length one.  */
index 4297a90b32982b609773cc5c6a0b6a78a56aa945..75c5f37f0ec06ffdd4ae73025a23b8fee059328b 100644 (file)
@@ -22,6 +22,7 @@
 #include <hurd.h>
 #include <hurd/fd.h>
 #include <hurd/socket.h>
+#include <sysdep-cancel.h>
 
 /* Receive a message as described by MESSAGE from socket FD.
    Returns the number of bytes read or -1 for errors.  */
@@ -42,12 +43,16 @@ __libc_recvmsg (int fd, struct msghdr *message, int flags)
   int nfds, *opened_fds = NULL;
   int i, ii, j;
   int newfds;
+  int cancel_oldtype;
 
   error_t reauthenticate (mach_port_t port, mach_port_t *result)
     {
       error_t err;
       mach_port_t ref;
       ref = __mach_reply_port ();
+      int cancel_oldtype;
+
+      cancel_oldtype = LIBC_CANCEL_ASYNC();
       do
        err = __io_reauthenticate (port, ref, MACH_MSG_TYPE_MAKE_SEND);
       while (err == EINTR);
@@ -57,6 +62,8 @@ __libc_recvmsg (int fd, struct msghdr *message, int flags)
                                          ref, MACH_MSG_TYPE_MAKE_SEND,
                                          result));
        while (err == EINTR);
+      LIBC_CANCEL_RESET (cancel_oldtype);
+
       __mach_port_destroy (__mach_task_self (), ref);
       return err;
     }
@@ -78,11 +85,14 @@ __libc_recvmsg (int fd, struct msghdr *message, int flags)
     }
 
   buf = data;
-  if (err = HURD_DPORT_USE (fd, __socket_recv (port, &aport,
-                                              flags, &data, &len,
-                                              &ports, &nports,
-                                              &cdata, &clen,
-                                              &message->msg_flags, amount)))
+  cancel_oldtype = LIBC_CANCEL_ASYNC();
+  err = HURD_DPORT_USE (fd, __socket_recv (port, &aport,
+                                          flags, &data, &len,
+                                          &ports, &nports,
+                                          &cdata, &clen,
+                                          &message->msg_flags, amount));
+  LIBC_CANCEL_RESET (cancel_oldtype);
+  if (err)
     return __hurd_sockfail (fd, flags, err);
 
   if (message->msg_name != NULL && aport != MACH_PORT_NULL)
@@ -91,7 +101,10 @@ __libc_recvmsg (int fd, struct msghdr *message, int flags)
       mach_msg_type_number_t buflen = message->msg_namelen;
       int type;
 
+      cancel_oldtype = LIBC_CANCEL_ASYNC();
       err = __socket_whatis_address (aport, &type, &buf, &buflen);
+      LIBC_CANCEL_RESET (cancel_oldtype);
+
       if (err == EOPNOTSUPP)
        /* If the protocol server can't tell us the address, just return a
           zero-length one.  */
This page took 0.052567 seconds and 5 git commands to generate.