public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
To: libc-alpha@sourceware.org
Subject: [RFC 14/14] linux: Add recvvmsg fallback for 64-bit time_t SO_TIMESTAMP{NS}
Date: Tue,  8 Sep 2020 11:57:38 -0300	[thread overview]
Message-ID: <20200908145738.640039-14-adhemerval.zanella@linaro.org> (raw)
In-Reply-To: <20200908145738.640039-1-adhemerval.zanella@linaro.org>

Handle the SO_TIMESTAMP{NS} similar to recvmsg: for
!__ASSUME_TIME64_SYSCALLS it converts the first 32-bit time SO_TIMESTAMP
or SO_TIMESTAMPNS and appends it to the control buffer if has extra
space or returns MSG_CTRUNC otherwise.  The 32-bit time field is kept
as-is.

Also for !__ASSUME_TIME64_SYSCALLS it limits the maximum number of
'struct mmsghdr *' to IOV_MAX (and also increases the stack size
requirement to IOV_MAX times sizeof (socklen_t)).  The Linux imposes
a similar limit to sendmmsg, so bound the array size on recvmmsg is not
unreasonable.  And this will be used only on older when building with
32-bit time support.

Checked on x86_64-linux-gnu and i686-linux-gnu (on 5.4 and on 4.15
kernel).
---
 include/sys/socket.h               |  3 +++
 sysdeps/unix/sysv/linux/recvmmsg.c | 17 +++++++++++++++--
 sysdeps/unix/sysv/linux/recvmsg.c  |  6 +++---
 3 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/include/sys/socket.h b/include/sys/socket.h
index c551c8fa87..171440ab14 100644
--- a/include/sys/socket.h
+++ b/include/sys/socket.h
@@ -171,6 +171,9 @@ libc_hidden_proto (__libc_sa_len)
 #define SCM_TIMESTAMPNS_NEW   SO_TIMESTAMPNS_NEW
 #define SCM_TIMESTAMPING_NEW  SO_TIMESTAMPING_NEW
 
+extern void __convert_scm_timestamps (struct msghdr *msg, socklen_t msgsize)
+  attribute_hidden;
+
 libc_hidden_proto (__cmsg_nxthdr)
 
 #endif
diff --git a/sysdeps/unix/sysv/linux/recvmmsg.c b/sysdeps/unix/sysv/linux/recvmmsg.c
index a29c91fb76..0f67e2dcac 100644
--- a/sysdeps/unix/sysv/linux/recvmmsg.c
+++ b/sysdeps/unix/sysv/linux/recvmmsg.c
@@ -44,13 +44,26 @@ __recvmmsg64 (int fd, struct mmsghdr *vmessages, unsigned int vlen, int flags,
       ts32 = valid_timespec64_to_timespec (*timeout);
       pts32 = &ts32;
     }
+
+  socklen_t csize[IOV_MAX];
+  if (vlen > IOV_MAX)
+    vlen = IOV_MAX;
+  for (int i = 0; i < vlen; i++)
+    csize[i] = vmessages[i].msg_hdr.msg_controllen;
+
 # ifdef __ASSUME_RECVMMSG_SYSCALL
   r = SYSCALL_CANCEL (recvmmsg, fd, vmessages, vlen, flags, pts32);
 # else
   r = SOCKETCALL_CANCEL (recvmmsg, fd, vmessages, vlen, flags, pts32);
 # endif
-  if (r >= 0 && timeout != NULL)
-    *timeout = valid_timespec_to_timespec64 (ts32);
+  if (r >= 0)
+    {
+      if (timeout != NULL)
+        *timeout = valid_timespec_to_timespec64 (ts32);
+
+      for (int i=0; i < r; i++)
+        __convert_scm_timestamps (&vmessages[i].msg_hdr, csize[i]);
+    }
 #endif /* __ASSUME_TIME64_SYSCALLS  */
   return r;
 }
diff --git a/sysdeps/unix/sysv/linux/recvmsg.c b/sysdeps/unix/sysv/linux/recvmsg.c
index c6d1d10b05..510ed04ea5 100644
--- a/sysdeps/unix/sysv/linux/recvmsg.c
+++ b/sysdeps/unix/sysv/linux/recvmsg.c
@@ -32,8 +32,8 @@
    original message as a spurious control ones of unknown typ while running
    on kernel with native 64-bit time support will only see the time64 version
    of the control message.  */
-static void
-convert_scm_timestamps (struct msghdr *msg, socklen_t msgsize)
+void
+__convert_scm_timestamps (struct msghdr *msg, socklen_t msgsize)
 {
   if (msg->msg_control == NULL || msg->msg_controllen == 0)
     return;
@@ -108,7 +108,7 @@ __libc_recvmsg (int fd, struct msghdr *msg, int flags)
 
 #ifndef __ASSUME_TIME64_SYSCALLS
   if (r >= 0)
-    convert_scm_timestamps (msg, orig_controllen);
+    __convert_scm_timestamps (msg, orig_controllen);
 #endif
 
   return r;
-- 
2.25.1


  parent reply	other threads:[~2020-09-08 14:58 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-08 14:57 [PATCH v2 01/14] linux: Simplify clock_getres Adhemerval Zanella
2020-09-08 14:57 ` [PATCH v2 02/14] linux: Add ppoll time64 optimization Adhemerval Zanella
2020-09-10 19:21   ` Alistair Francis
2020-09-08 14:57 ` [PATCH v2 03/14] linux: Add time64 semtimedop support Adhemerval Zanella
2020-09-10 19:23   ` Alistair Francis
2020-09-08 14:57 ` [PATCH v2 04/14] linux: Add time64 pselect support Adhemerval Zanella
2020-09-10 19:35   ` Alistair Francis
2020-09-12  1:22   ` H.J. Lu
2020-09-08 14:57 ` [PATCH v2 05/14] linux: Add time64 select support Adhemerval Zanella
2020-09-11 20:44   ` Alistair Francis
2020-09-08 14:57 ` [PATCH v2 06/14] linux: Add time64 sigtimedwait support Adhemerval Zanella
2020-09-11 20:56   ` Alistair Francis
2020-09-08 14:57 ` [PATCH v2 07/14] linux: Use 64-bit time_t syscall on clock_getcputclockid Adhemerval Zanella
2020-09-16 15:26   ` Alistair Francis
2020-09-08 14:57 ` [PATCH v2 08/14] linux: Consolidate utimes Adhemerval Zanella
2020-09-16 15:30   ` Alistair Francis
2020-09-08 14:57 ` [PATCH v2 09/14] linux: Fix time64 support for futimesat Adhemerval Zanella
2020-09-08 14:57 ` [PATCH v2 10/14] linux: Add time64 support for nanosleep Adhemerval Zanella
2020-09-16 17:16   ` Alistair Francis
2020-09-08 14:57 ` [PATCH v2 11/14] linux: Add time64 recvmmsg support Adhemerval Zanella
2020-09-25 21:18   ` Alistair Francis
2020-09-08 14:57 ` [RFC 12/14] linux: Add fallback for 64-bit time_t SO_{RCV,SND}TIMEO Adhemerval Zanella
2020-09-08 14:57 ` [RFC 13/14] linux: Add fallback for 64-bit time_t SO_TIMESTAMP{NS} Adhemerval Zanella
2020-09-08 14:57 ` Adhemerval Zanella [this message]
2020-09-10 19:20 ` [PATCH v2 01/14] linux: Simplify clock_getres Alistair Francis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200908145738.640039-14-adhemerval.zanella@linaro.org \
    --to=adhemerval.zanella@linaro.org \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).