xenomai.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/9] y2038: Finalize and enable y2038 support
@ 2023-09-27 13:50 Florian Bezdeka
  2023-09-27 13:50 ` [PATCH v2 1/9] y2038: kernel/drivers: Implement SO_RCVTIMEO_NEW and SO_SNDTIMEO_NEW Florian Bezdeka
                   ` (9 more replies)
  0 siblings, 10 replies; 17+ messages in thread
From: Florian Bezdeka @ 2023-09-27 13:50 UTC (permalink / raw)
  To: xenomai, jan.kiszka; +Cc: Florian Bezdeka

Hi all,
    
this is the final y2038 related patch series. With this series applied
y2038 support will be enabled by default for all affected
builds/architectures.

There is a kill switch (--disable-y2038) available in case unexpected
problems come up after merge but that is not expected. The y2038 queue
was regularly tested over the last two years now.
    
Short summary:
  - Implement y2038 safe ioctls around SO_RCVTIMEO and SO_SNDTIMEO
  - Enable additional function wrapping
  - Fix some smokey tests (reading of reference clocks)

Fingers crossed, seems the y2038 issue is solved now.

Best regards,
Florian

Signed-off-by: Florian Bezdeka <florian.bezdeka@siemens.com>
---
Changes in v2:
- Rebase on current next
- Take care of review comments from Jan 
- Reworked function wrapping, no additional __wrap_ implementations for
  time64 based services
- Added cleanup patches 
- Link to v1: https://lore.kernel.org/r/20230809-florian-y2038-2-v1-0-d1cfe2f394a3@siemens.com

---
Florian Bezdeka (9):
      y2038: kernel/drivers: Implement SO_RCVTIMEO_NEW and SO_SNDTIMEO_NEW
      y2038: lib/cobalt: Switch vdso to gettime64
      y2038: testsuite/clocktest: Fix reading of reference clock
      y2038: build: Introduce new build parameter --disable-y2038
      y2038: lib/cobalt: Split function name and interface in COBALT_DECL()
      y2038: lib/cobalt: Implement necessary wrappers for y2038 support
      y2038: testsuite/smokey: Add some function wrapping tests
      lib/cobalt: Cleanup includes
      lib/cobalt/wrappers.h: Remove duplicate definition of __stringify()

 configure.ac                                     | 63 ++++++++++++++++++-
 include/cobalt/fcntl.h                           | 10 +--
 include/cobalt/mqueue.h                          | 49 ++++++---------
 include/cobalt/pthread.h                         | 77 ++++++++++++------------
 include/cobalt/sched.h                           | 12 ++--
 include/cobalt/semaphore.h                       | 24 ++++----
 include/cobalt/signal.h                          | 16 ++---
 include/cobalt/stdio.h                           | 33 +++++-----
 include/cobalt/stdlib.h                          |  4 +-
 include/cobalt/sys/ioctl.h                       |  3 +-
 include/cobalt/sys/mman.h                        | 10 +--
 include/cobalt/sys/select.h                      |  8 +--
 include/cobalt/sys/socket.h                      | 70 +++++++++++----------
 include/cobalt/sys/time.h                        |  4 +-
 include/cobalt/sys/timerfd.h                     | 11 ++--
 include/cobalt/syslog.h                          | 12 ++--
 include/cobalt/time.h                            | 50 ++++++++-------
 include/cobalt/unistd.h                          | 10 +--
 include/cobalt/wrappers.h                        | 34 ++++++++---
 kernel/drivers/ipc/bufp.c                        | 34 +++++++++++
 kernel/drivers/ipc/iddp.c                        | 34 +++++++++++
 kernel/drivers/ipc/internal.h                    | 27 +++++++++
 kernel/drivers/ipc/rtipc.c                       | 29 +++++++++
 kernel/drivers/ipc/xddp.c                        | 18 ++++++
 kernel/drivers/net/stack/ipv4/tcp/tcp.c          | 31 ++++++++++
 lib/cobalt/Makefile.am                           |  2 +
 lib/cobalt/arch/arm/include/asm/xenomai/time.h   |  5 ++
 lib/cobalt/arch/arm64/include/asm/xenomai/time.h |  5 ++
 lib/cobalt/arch/x86/features.c                   |  1 -
 lib/cobalt/arch/x86/include/asm/xenomai/time.h   |  5 ++
 lib/cobalt/attr.c                                |  4 --
 lib/cobalt/clock.c                               | 33 +++++-----
 lib/cobalt/cobalt-glibc-time64.wrappers          | 23 +++++++
 lib/cobalt/cond.c                                |  7 ++-
 lib/cobalt/current.c                             |  3 +-
 lib/cobalt/init.c                                |  2 -
 lib/cobalt/internal.c                            |  4 +-
 lib/cobalt/malloc-nowrap.c                       |  1 +
 lib/cobalt/malloc.c                              |  1 +
 lib/cobalt/mq.c                                  | 17 +++---
 lib/cobalt/mutex.c                               |  6 +-
 lib/cobalt/parse_vdso.c                          |  2 -
 lib/cobalt/rtdm.c                                | 19 +++---
 lib/cobalt/sched.c                               |  5 --
 lib/cobalt/select.c                              | 60 ++++++++++++++++--
 lib/cobalt/semaphore.c                           |  4 +-
 lib/cobalt/signal.c                              |  9 ++-
 lib/cobalt/sigshadow.c                           |  1 +
 lib/cobalt/thread.c                              |  2 -
 lib/cobalt/ticks.c                               |  1 +
 lib/cobalt/timer.c                               | 12 ++--
 lib/cobalt/timerfd.c                             | 11 ++--
 lib/cobalt/umm.c                                 |  7 +--
 lib/cobalt/umm.h                                 |  2 -
 scripts/xeno-config-cobalt.in                    |  5 ++
 testsuite/clocktest/clocktest.c                  | 11 +++-
 testsuite/smokey/y2038/syscall-tests.c           | 47 +++++++++++++++
 57 files changed, 671 insertions(+), 319 deletions(-)
---
base-commit: 335e2aaf4e4f048ecd83cab75a7471ad8e93b97b
change-id: 20230809-florian-y2038-2-23303aa750cf

Best regards,
-- 
Florian Bezdeka <florian.bezdeka@siemens.com>


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH v2 1/9] y2038: kernel/drivers: Implement SO_RCVTIMEO_NEW and SO_SNDTIMEO_NEW
  2023-09-27 13:50 [PATCH v2 0/9] y2038: Finalize and enable y2038 support Florian Bezdeka
@ 2023-09-27 13:50 ` Florian Bezdeka
  2023-09-28 17:00   ` Jan Kiszka
  2023-09-27 13:50 ` [PATCH v2 2/9] y2038: lib/cobalt: Switch vdso to gettime64 Florian Bezdeka
                   ` (8 subsequent siblings)
  9 siblings, 1 reply; 17+ messages in thread
From: Florian Bezdeka @ 2023-09-27 13:50 UTC (permalink / raw)
  To: xenomai, jan.kiszka; +Cc: Florian Bezdeka

When requesting y2038 support from recent glibc versions SO_RCVTIMEO and
SO_SNDTIMEO will be auto-converted to the _NEW variants to make clear
that we have to deal with a different (now y2038 safe) ABI.

Implementing SO_RCVTIMEO_NEW and SO_SNDTIMEO_NEW where necessary.

Signed-off-by: Florian Bezdeka <florian.bezdeka@siemens.com>
---
 kernel/drivers/ipc/bufp.c               | 34 +++++++++++++++++++++++++++++++++
 kernel/drivers/ipc/iddp.c               | 34 +++++++++++++++++++++++++++++++++
 kernel/drivers/ipc/internal.h           | 27 ++++++++++++++++++++++++++
 kernel/drivers/ipc/rtipc.c              | 29 ++++++++++++++++++++++++++++
 kernel/drivers/ipc/xddp.c               | 18 +++++++++++++++++
 kernel/drivers/net/stack/ipv4/tcp/tcp.c | 31 ++++++++++++++++++++++++++++++
 6 files changed, 173 insertions(+)

diff --git a/kernel/drivers/ipc/bufp.c b/kernel/drivers/ipc/bufp.c
index 565409dd6..f1936d846 100644
--- a/kernel/drivers/ipc/bufp.c
+++ b/kernel/drivers/ipc/bufp.c
@@ -824,6 +824,7 @@ static int __bufp_setsockopt(struct bufp_socket *sk,
 			     void *arg)
 {
 	struct _rtdm_setsockopt_args sopt;
+	struct __kernel_sock_timeval stv;
 	struct rtipc_port_label plabel;
 	struct __kernel_old_timeval tv;
 	rtdm_lockctx_t s;
@@ -844,6 +845,14 @@ static int __bufp_setsockopt(struct bufp_socket *sk,
 			sk->rx_timeout = rtipc_timeval_to_ns(&tv);
 			break;
 
+		case SO_RCVTIMEO_NEW:
+			ret = rtipc_get_sock_timeval(fd, &stv, sopt.optval,
+						     sopt.optlen);
+			if (ret)
+				return ret;
+			sk->rx_timeout = rtipc_sock_timeval_to_ns(&stv);
+			break;
+
 		case SO_SNDTIMEO_OLD:
 			ret = rtipc_get_timeval(fd, &tv, sopt.optval, sopt.optlen);
 			if (ret)
@@ -851,6 +860,14 @@ static int __bufp_setsockopt(struct bufp_socket *sk,
 			sk->tx_timeout = rtipc_timeval_to_ns(&tv);
 			break;
 
+		case SO_SNDTIMEO_NEW:
+			ret = rtipc_get_sock_timeval(fd, &stv, sopt.optval,
+						     sopt.optlen);
+			if (ret)
+				return ret;
+			sk->tx_timeout = rtipc_sock_timeval_to_ns(&stv);
+			break;
+
 		default:
 			ret = -EINVAL;
 		}
@@ -913,6 +930,7 @@ static int __bufp_getsockopt(struct bufp_socket *sk,
 			     void *arg)
 {
 	struct _rtdm_getsockopt_args sopt;
+	struct __kernel_sock_timeval stv;
 	struct rtipc_port_label plabel;
 	struct __kernel_old_timeval tv;
 	rtdm_lockctx_t s;
@@ -936,6 +954,14 @@ static int __bufp_getsockopt(struct bufp_socket *sk,
 				return ret;
 			break;
 
+		case SO_RCVTIMEO_NEW:
+			rtipc_ns_to_sock_timeval(&stv, sk->rx_timeout);
+			ret = rtipc_put_sock_timeval(fd, sopt.optval, &stv,
+						     len);
+			if (ret)
+				return ret;
+			break;
+
 		case SO_SNDTIMEO_OLD:
 			rtipc_ns_to_timeval(&tv, sk->tx_timeout);
 			ret = rtipc_put_timeval(fd, sopt.optval, &tv, len);
@@ -943,6 +969,14 @@ static int __bufp_getsockopt(struct bufp_socket *sk,
 				return ret;
 			break;
 
+		case SO_SNDTIMEO_NEW:
+			rtipc_ns_to_sock_timeval(&stv, sk->tx_timeout);
+			ret = rtipc_put_sock_timeval(fd, sopt.optval, &stv,
+						     len);
+			if (ret)
+				return ret;
+			break;
+
 		default:
 			ret = -EINVAL;
 		}
diff --git a/kernel/drivers/ipc/iddp.c b/kernel/drivers/ipc/iddp.c
index 05d019339..e4893a378 100644
--- a/kernel/drivers/ipc/iddp.c
+++ b/kernel/drivers/ipc/iddp.c
@@ -704,6 +704,7 @@ static int __iddp_setsockopt(struct iddp_socket *sk,
 			     void *arg)
 {
 	struct _rtdm_setsockopt_args sopt;
+	struct __kernel_sock_timeval stv;
 	struct rtipc_port_label plabel;
 	struct __kernel_old_timeval tv;
 	rtdm_lockctx_t s;
@@ -724,6 +725,14 @@ static int __iddp_setsockopt(struct iddp_socket *sk,
 			sk->rx_timeout = rtipc_timeval_to_ns(&tv);
 			break;
 
+		case SO_RCVTIMEO_NEW:
+			ret = rtipc_get_sock_timeval(fd, &stv, sopt.optval,
+						     sopt.optlen);
+			if (ret)
+				return ret;
+			sk->rx_timeout = rtipc_sock_timeval_to_ns(&stv);
+			break;
+
 		case SO_SNDTIMEO_OLD:
 			ret = rtipc_get_timeval(fd, &tv, sopt.optval, sopt.optlen);
 			if (ret)
@@ -731,6 +740,14 @@ static int __iddp_setsockopt(struct iddp_socket *sk,
 			sk->tx_timeout = rtipc_timeval_to_ns(&tv);
 			break;
 
+		case SO_SNDTIMEO_NEW:
+			ret = rtipc_get_sock_timeval(fd, &stv, sopt.optval,
+						     sopt.optlen);
+			if (ret)
+				return ret;
+			sk->tx_timeout = rtipc_sock_timeval_to_ns(&stv);
+			break;
+
 		default:
 			ret = -EINVAL;
 		}
@@ -793,6 +810,7 @@ static int __iddp_getsockopt(struct iddp_socket *sk,
 			     void *arg)
 {
 	struct _rtdm_getsockopt_args sopt;
+	struct __kernel_sock_timeval stv;
 	struct rtipc_port_label plabel;
 	struct __kernel_old_timeval tv;
 	rtdm_lockctx_t s;
@@ -817,6 +835,14 @@ static int __iddp_getsockopt(struct iddp_socket *sk,
 				return ret;
 			break;
 
+		case SO_RCVTIMEO_NEW:
+			rtipc_ns_to_sock_timeval(&stv, sk->rx_timeout);
+			ret = rtipc_put_sock_timeval(fd, sopt.optval, &stv,
+						     len);
+			if (ret)
+				return ret;
+			break;
+
 		case SO_SNDTIMEO_OLD:
 			rtipc_ns_to_timeval(&tv, sk->tx_timeout);
 			ret = rtipc_put_timeval(fd, sopt.optval, &tv, len);
@@ -824,6 +850,14 @@ static int __iddp_getsockopt(struct iddp_socket *sk,
 				return ret;
 			break;
 
+		case SO_SNDTIMEO_NEW:
+			rtipc_ns_to_sock_timeval(&stv, sk->tx_timeout);
+			ret = rtipc_put_sock_timeval(fd, sopt.optval, &stv,
+						     len);
+			if (ret)
+				return ret;
+			break;
+
 		default:
 			ret = -EINVAL;
 		}
diff --git a/kernel/drivers/ipc/internal.h b/kernel/drivers/ipc/internal.h
index 919a5d978..f29ba2204 100644
--- a/kernel/drivers/ipc/internal.h
+++ b/kernel/drivers/ipc/internal.h
@@ -76,6 +76,17 @@ static inline nanosecs_rel_t rtipc_timeval_to_ns(const struct __kernel_old_timev
 	return ns;
 }
 
+static inline nanosecs_rel_t
+rtipc_sock_timeval_to_ns(const struct __kernel_sock_timeval *tv)
+{
+	nanosecs_rel_t ns = tv->tv_usec * 1000;
+
+	if (tv->tv_sec)
+		ns += (nanosecs_rel_t)tv->tv_sec * 1000000000UL;
+
+	return ns;
+}
+
 static inline void rtipc_ns_to_timeval(struct __kernel_old_timeval *tv, nanosecs_rel_t ns)
 {
 	unsigned long nsecs;
@@ -84,6 +95,15 @@ static inline void rtipc_ns_to_timeval(struct __kernel_old_timeval *tv, nanosecs
 	tv->tv_usec = nsecs / 1000;
 }
 
+static inline void rtipc_ns_to_sock_timeval(struct __kernel_sock_timeval *tv,
+					    nanosecs_rel_t ns)
+{
+	unsigned long nsecs;
+
+	tv->tv_sec = xnclock_divrem_billion(ns, &nsecs);
+	tv->tv_usec = nsecs / 1000;
+}
+
 int rtipc_get_sockaddr(struct rtdm_fd *fd,
 		       struct sockaddr_ipc **saddrp,
 		       const void *arg);
@@ -105,9 +125,16 @@ int rtipc_get_sockoptin(struct rtdm_fd *fd,
 int rtipc_get_timeval(struct rtdm_fd *fd, struct __kernel_old_timeval *tv,
 		      const void *arg, size_t arglen);
 
+int rtipc_get_sock_timeval(struct rtdm_fd *fd, struct __kernel_sock_timeval *tv,
+			   const void *arg, size_t arglen);
+
 int rtipc_put_timeval(struct rtdm_fd *fd, void *arg,
 		      const struct __kernel_old_timeval *tv, size_t arglen);
 
+int rtipc_put_sock_timeval(struct rtdm_fd *fd, void *arg,
+			   const struct __kernel_sock_timeval *tv,
+			   size_t arglen);
+
 int rtipc_get_length(struct rtdm_fd *fd, size_t *lenp,
 		     const void *arg, size_t arglen);
 
diff --git a/kernel/drivers/ipc/rtipc.c b/kernel/drivers/ipc/rtipc.c
index 211b496ec..66176adad 100644
--- a/kernel/drivers/ipc/rtipc.c
+++ b/kernel/drivers/ipc/rtipc.c
@@ -290,6 +290,20 @@ int rtipc_get_timeval(struct rtdm_fd *fd, struct __kernel_old_timeval *tv,
 	return rtdm_safe_copy_from_user(fd, tv, arg, sizeof(*tv));
 }
 
+int rtipc_get_sock_timeval(struct rtdm_fd *fd, struct __kernel_sock_timeval *tv,
+			   const void *arg, size_t arglen)
+{
+	if (arglen != sizeof(*tv))
+		return -EINVAL;
+
+	if (!rtdm_fd_is_user(fd)) {
+		*tv = *(struct __kernel_sock_timeval *)arg;
+		return 0;
+	}
+
+	return rtdm_safe_copy_from_user(fd, tv, arg, sizeof(*tv));
+}
+
 int rtipc_put_timeval(struct rtdm_fd *fd, void *arg,
 		      const struct __kernel_old_timeval *tv, size_t arglen)
 {
@@ -312,6 +326,21 @@ int rtipc_put_timeval(struct rtdm_fd *fd, void *arg,
 	return rtdm_safe_copy_to_user(fd, arg, tv, sizeof(*tv));
 }
 
+int rtipc_put_sock_timeval(struct rtdm_fd *fd, void *arg,
+			   const struct __kernel_sock_timeval *tv,
+			   size_t arglen)
+{
+	if (arglen != sizeof(*tv))
+		return -EINVAL;
+
+	if (!rtdm_fd_is_user(fd)) {
+		*(struct __kernel_sock_timeval *)arg = *tv;
+		return 0;
+	}
+
+	return rtdm_safe_copy_to_user(fd, arg, tv, sizeof(*tv));
+}
+
 int rtipc_get_length(struct rtdm_fd *fd, size_t *lenp,
 		     const void *arg, size_t arglen)
 {
diff --git a/kernel/drivers/ipc/xddp.c b/kernel/drivers/ipc/xddp.c
index 2ca0da5fd..8f1b2ece7 100644
--- a/kernel/drivers/ipc/xddp.c
+++ b/kernel/drivers/ipc/xddp.c
@@ -859,6 +859,7 @@ static int __xddp_setsockopt(struct xddp_socket *sk,
 {
 	int (*monitor)(struct rtdm_fd *fd, int event, long arg);
 	struct _rtdm_setsockopt_args sopt;
+	struct __kernel_sock_timeval stv;
 	struct rtipc_port_label plabel;
 	struct __kernel_old_timeval tv;
 	rtdm_lockctx_t s;
@@ -879,6 +880,14 @@ static int __xddp_setsockopt(struct xddp_socket *sk,
 			sk->timeout = rtipc_timeval_to_ns(&tv);
 			break;
 
+		case SO_RCVTIMEO_NEW:
+			ret = rtipc_get_sock_timeval(fd, &stv, sopt.optval,
+						     sopt.optlen);
+			if (ret)
+				return ret;
+
+			sk->timeout = rtipc_sock_timeval_to_ns(&stv);
+			break;
 		default:
 			ret = -EINVAL;
 		}
@@ -965,6 +974,7 @@ static int __xddp_getsockopt(struct xddp_socket *sk,
 			     void *arg)
 {
 	struct _rtdm_getsockopt_args sopt;
+	struct __kernel_sock_timeval stv;
 	struct rtipc_port_label plabel;
 	struct __kernel_old_timeval tv;
 	rtdm_lockctx_t s;
@@ -988,6 +998,14 @@ static int __xddp_getsockopt(struct xddp_socket *sk,
 				return ret;
 			break;
 
+		case SO_RCVTIMEO_NEW:
+			rtipc_ns_to_sock_timeval(&stv, sk->timeout);
+			ret = rtipc_put_sock_timeval(fd, sopt.optval, &stv,
+						     len);
+			if (ret)
+				return ret;
+			break;
+
 		default:
 			ret = -EINVAL;
 		}
diff --git a/kernel/drivers/net/stack/ipv4/tcp/tcp.c b/kernel/drivers/net/stack/ipv4/tcp/tcp.c
index 71628ba03..5bd114530 100644
--- a/kernel/drivers/net/stack/ipv4/tcp/tcp.c
+++ b/kernel/drivers/net/stack/ipv4/tcp/tcp.c
@@ -1743,6 +1743,7 @@ static int rt_tcp_setsockopt(struct rtdm_fd *fd, struct tcp_socket *ts,
 			     socklen_t optlen)
 {
 	/* uint64_t val; */
+	struct __kernel_sock_timeval stv;
 	struct __kernel_old_timeval tv;
 	rtdm_lockctx_t context;
 
@@ -1793,6 +1794,36 @@ static int rt_tcp_setsockopt(struct rtdm_fd *fd, struct tcp_socket *ts,
 
 		return 0;
 
+	case SO_SNDTIMEO_NEW:
+		if (optlen < sizeof(stv))
+			return -EINVAL;
+		if (rtdm_copy_from_user(fd, &stv, optval, sizeof(stv)))
+			return -EFAULT;
+		if (stv.tv_usec < 0 || stv.tv_usec >= 1000000)
+			return -EDOM;
+
+		rtdm_lock_get_irqsave(&ts->socket_lock, context);
+
+		if (stv.tv_sec < 0) {
+			ts->sk_sndtimeo = RTDM_TIMEOUT_NONE;
+			rtdm_lock_put_irqrestore(&ts->socket_lock, context);
+			return 0;
+		}
+
+		ts->sk_sndtimeo = RTDM_TIMEOUT_INFINITE;
+		if (stv.tv_sec == 0 && stv.tv_usec == 0) {
+			rtdm_lock_put_irqrestore(&ts->socket_lock, context);
+			return 0;
+		}
+
+		if (stv.tv_sec < (MAX_SCHEDULE_TIMEOUT / 1000000000ull - 1))
+			ts->sk_sndtimeo =
+				(stv.tv_sec * 1000000 + stv.tv_usec) * 1000;
+
+		rtdm_lock_put_irqrestore(&ts->socket_lock, context);
+
+		return 0;
+
 	case SO_REUSEADDR:
 		/* to implement */
 		return -EOPNOTSUPP;

-- 
2.39.2


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH v2 2/9] y2038: lib/cobalt: Switch vdso to gettime64
  2023-09-27 13:50 [PATCH v2 0/9] y2038: Finalize and enable y2038 support Florian Bezdeka
  2023-09-27 13:50 ` [PATCH v2 1/9] y2038: kernel/drivers: Implement SO_RCVTIMEO_NEW and SO_SNDTIMEO_NEW Florian Bezdeka
@ 2023-09-27 13:50 ` Florian Bezdeka
  2023-09-27 13:50 ` [PATCH v2 3/9] y2038: testsuite/clocktest: Fix reading of reference clock Florian Bezdeka
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 17+ messages in thread
From: Florian Bezdeka @ 2023-09-27 13:50 UTC (permalink / raw)
  To: xenomai, jan.kiszka; +Cc: Florian Bezdeka

In case y2038 support was requested we have to switch to the gettime64
variant of the vdso interface.

Signed-off-by: Florian Bezdeka <florian.bezdeka@siemens.com>
---
 lib/cobalt/arch/arm/include/asm/xenomai/time.h   | 5 +++++
 lib/cobalt/arch/arm64/include/asm/xenomai/time.h | 5 +++++
 lib/cobalt/arch/x86/include/asm/xenomai/time.h   | 5 +++++
 3 files changed, 15 insertions(+)

diff --git a/lib/cobalt/arch/arm/include/asm/xenomai/time.h b/lib/cobalt/arch/arm/include/asm/xenomai/time.h
index 34df7e9df..1b4947b2d 100644
--- a/lib/cobalt/arch/arm/include/asm/xenomai/time.h
+++ b/lib/cobalt/arch/arm/include/asm/xenomai/time.h
@@ -11,6 +11,11 @@
 #define _LIB_COBALT_ARM_TIME_H
 
 #define COBALT_VDSO_VERSION	"LINUX_2.6"
+
+#ifdef __USE_TIME_BITS64
+#define COBALT_VDSO_GETTIME	"__vdso_clock_gettime64"
+#else
 #define COBALT_VDSO_GETTIME	"__vdso_clock_gettime"
+#endif
 
 #endif /* !_LIB_COBALT_ARM_TIME_H */
diff --git a/lib/cobalt/arch/arm64/include/asm/xenomai/time.h b/lib/cobalt/arch/arm64/include/asm/xenomai/time.h
index d0dad6d88..9577aa773 100644
--- a/lib/cobalt/arch/arm64/include/asm/xenomai/time.h
+++ b/lib/cobalt/arch/arm64/include/asm/xenomai/time.h
@@ -11,6 +11,11 @@
 #define _LIB_COBALT_ARM64_TIME_H
 
 #define COBALT_VDSO_VERSION	"LINUX_2.6.39"
+
+#ifdef __USE_TIME_BITS64
+#define COBALT_VDSO_GETTIME	"__vdso_clock_gettime64"
+#else
 #define COBALT_VDSO_GETTIME	"__kernel_clock_gettime"
+#endif
 
 #endif /* !_LIB_COBALT_ARM64_TIME_H */
diff --git a/lib/cobalt/arch/x86/include/asm/xenomai/time.h b/lib/cobalt/arch/x86/include/asm/xenomai/time.h
index 693be8736..18eb76697 100644
--- a/lib/cobalt/arch/x86/include/asm/xenomai/time.h
+++ b/lib/cobalt/arch/x86/include/asm/xenomai/time.h
@@ -11,6 +11,11 @@
 #define _LIB_COBALT_X86_TIME_H
 
 #define COBALT_VDSO_VERSION	"LINUX_2.6"
+
+#ifdef __USE_TIME_BITS64
+#define COBALT_VDSO_GETTIME	"__vdso_clock_gettime64"
+#else
 #define COBALT_VDSO_GETTIME	"__vdso_clock_gettime"
+#endif
 
 #endif /* !_LIB_COBALT_X86_TIME_H */

-- 
2.39.2


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH v2 3/9] y2038: testsuite/clocktest: Fix reading of reference clock
  2023-09-27 13:50 [PATCH v2 0/9] y2038: Finalize and enable y2038 support Florian Bezdeka
  2023-09-27 13:50 ` [PATCH v2 1/9] y2038: kernel/drivers: Implement SO_RCVTIMEO_NEW and SO_SNDTIMEO_NEW Florian Bezdeka
  2023-09-27 13:50 ` [PATCH v2 2/9] y2038: lib/cobalt: Switch vdso to gettime64 Florian Bezdeka
@ 2023-09-27 13:50 ` Florian Bezdeka
  2023-09-27 13:50 ` [PATCH v2 4/9] y2038: build: Introduce new build parameter --disable-y2038 Florian Bezdeka
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 17+ messages in thread
From: Florian Bezdeka @ 2023-09-27 13:50 UTC (permalink / raw)
  To: xenomai, jan.kiszka; +Cc: Florian Bezdeka

With y2038 support enabled the wrong syscall was triggered for reading
the reference clock. struct timeval is "auto-converted" to time64_t so
we have to call the time64 based syscall as well.

There is no gettimeofday64 syscall so we have to migrate to
clock_gettime using CLOCK_REALTIME.

Old output:
CPU      ToD offset [us] ToD drift [us/s]      warps max delta [us]
--- -------------------- ---------------- ---------- --------------
  0                  0.0            0.000          0            0.0
  0   1009065219904768.5     -1000000.000          0            0.0
  0    715530549306452.6     -1000000.000          0            0.0

New output:
CPU      ToD offset [us] ToD drift [us/s]      warps max delta [us]
--- -------------------- ---------------- ---------- --------------
  0                  1.8           -5.803          0            0.0
  1                  0.0            0.000          0            0.0

Signed-off-by: Florian Bezdeka <florian.bezdeka@siemens.com>
---
 testsuite/clocktest/clocktest.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/testsuite/clocktest/clocktest.c b/testsuite/clocktest/clocktest.c
index c2b9ee5f4..a611ee889 100644
--- a/testsuite/clocktest/clocktest.c
+++ b/testsuite/clocktest/clocktest.c
@@ -80,14 +80,19 @@ static inline uint64_t read_clock(clockid_t clock_id)
 
 static inline uint64_t read_reference_clock(void)
 {
-	struct timeval tv;
+	struct timespec ts;
 
 	/*
 	 * Make sure we do not pick the vsyscall variant. It won't
 	 * switch us into secondary mode and can easily deadlock.
 	 */
-	syscall(SYS_gettimeofday, &tv, NULL);
-	return tv.tv_usec * 1000ULL + tv.tv_sec * 1000000000ULL;
+#if __USE_TIME_BITS64
+	syscall(SYS_clock_gettime64, CLOCK_REALTIME, &ts);
+#else
+	syscall(SYS_clock_gettime, CLOCK_REALTIME, &ts);
+#endif
+
+	return ts.tv_nsec + ts.tv_sec * 1000000000ULL;
 }
 
 static void check_reference(struct per_cpu_data *per_cpu_data)

-- 
2.39.2


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH v2 4/9] y2038: build: Introduce new build parameter --disable-y2038
  2023-09-27 13:50 [PATCH v2 0/9] y2038: Finalize and enable y2038 support Florian Bezdeka
                   ` (2 preceding siblings ...)
  2023-09-27 13:50 ` [PATCH v2 3/9] y2038: testsuite/clocktest: Fix reading of reference clock Florian Bezdeka
@ 2023-09-27 13:50 ` Florian Bezdeka
  2023-09-27 13:50 ` [PATCH v2 5/9] y2038: lib/cobalt: Split function name and interface in COBALT_DECL() Florian Bezdeka
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 17+ messages in thread
From: Florian Bezdeka @ 2023-09-27 13:50 UTC (permalink / raw)
  To: xenomai, jan.kiszka; +Cc: Florian Bezdeka

The new --disable-y2038 build parameter will be used to disable
additional function wrapping when the architecture we build for is
affected by the y2038 problem.

The default value is "no" so y2038 support is enabled by default.

If --disable-y2038 is given for an architecture that is not affected it
will be ignored.

CONFIG_XENO_LIBS_TIME64 will be set to 1 if the following conditions
are met:
  - y2038 support was requested (default, no --disable-y2038 given)
  - the target platform is affected by the y2038 problem
  - glibc is used as libc
  - glibc has y2038 support (glibc >= 2.34)

CONFIG_XENO_LIBS_TIME64 will be used later to add necessary glibc
wrappers.

If y2038 support was requested and is available in glibc the CFLAGS
-D_TIME_BITS=64 and -D_FILE_OFFSET_BITS=64 will be added to
affect all compile units.

Signed-off-by: Florian Bezdeka <florian.bezdeka@siemens.com>
---
 configure.ac | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

diff --git a/configure.ac b/configure.ac
index 86dd8ba4f..f1734b27a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -138,19 +138,23 @@ case "$build_for" in
 	use_tls=yes
 	target_cpu_arch=x86
 	CONFIG_XENO_DEFAULT_PERIOD=100000
+	y2038_affected=yes
 	;;
  arm*-*)
 	target_cpu_arch=arm
 	CONFIG_XENO_DEFAULT_PERIOD=1000000
+	y2038_affected=yes
 	;;
  aarch64-*)
 	target_cpu_arch=arm64
 	CONFIG_XENO_DEFAULT_PERIOD=1000000
+	y2038_affected=no
 	;;
  x86_64-*|amd64-*)
 	use_tls=yes
 	target_cpu_arch=x86
 	CONFIG_XENO_DEFAULT_PERIOD=100000
+	y2038_affected=no
 	;;
  *)
 	if test $rtcore_type = cobalt; then
@@ -781,6 +785,49 @@ AC_ARG_ENABLE([tls],
 	    [use_tls=$enableval])
 AC_MSG_RESULT($use_tls)
 
+AC_MSG_CHECKING(whether glibc has y2038 support)
+AC_TRY_COMPILE([#include <features.h>],
+	[
+		#if !(__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 34))
+			#error "No y2038 support"
+		#endif
+	],
+	glibc_has_y2038_support=yes,
+	glibc_has_y2038_support=no)
+AC_MSG_RESULT($glibc_has_y2038_support)
+
+AC_MSG_CHECKING(whether to enable y2038 support in Xenomai libraries)
+AC_ARG_ENABLE(y2038,
+	AC_HELP_STRING([--disable-y2038], [Disable y2038 support]),
+	[
+		CONFIG_XENO_LIBS_TIME64=no
+	],
+	[
+		if test "$y2038_affected" = "yes"; then
+			CONFIG_XENO_LIBS_TIME64="$glibc_has_y2038_support"
+		else
+			CONFIG_XENO_LIBS_TIME64=no
+		fi
+	])
+AC_MSG_RESULT(${CONFIG_XENO_LIBS_TIME64})
+
+if test "$CONFIG_XENO_LIBS_TIME64" = "yes"; then
+	AC_DEFINE(CONFIG_XENO_LIBS_TIME64,1,[config])
+	XENO_TIME64_CFLAGS="-D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64"
+	XENO_USER_CFLAGS="$XENO_USER_CFLAGS $XENO_TIME64_CFLAGS"
+	XENO_USER_APP_CFLAGS="$XENO_USER_APP_CFLAGS $XENO_TIME64_CFLAGS"
+	AC_SUBST(CONFIG_XENO_LIBS_TIME64)
+else
+	if test "$y2038_affected" = "yes"; then
+		AC_MSG_WARN([You're affected by the time_t overflow in 2038])
+		if test "$glibc_has_y2038_support" = "yes"; then
+			AC_MSG_WARN([You should consider removing --disable-y2038])
+		fi
+	fi
+fi
+AM_CONDITIONAL(CONFIG_XENO_LIBS_TIME64,[test "$CONFIG_XENO_LIBS_TIME64" = "yes"])
+
+
 dnl Check whether the compiler supports the __thread keyword.
 if test "x$use_tls" != xno; then
 	AC_CACHE_CHECK([for __thread keyword], libc_cv_gcc_tls,

-- 
2.39.2


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH v2 5/9] y2038: lib/cobalt: Split function name and interface in COBALT_DECL()
  2023-09-27 13:50 [PATCH v2 0/9] y2038: Finalize and enable y2038 support Florian Bezdeka
                   ` (3 preceding siblings ...)
  2023-09-27 13:50 ` [PATCH v2 4/9] y2038: build: Introduce new build parameter --disable-y2038 Florian Bezdeka
@ 2023-09-27 13:50 ` Florian Bezdeka
  2023-09-27 13:50 ` [PATCH v2 6/9] y2038: lib/cobalt: Implement necessary wrappers for y2038 support Florian Bezdeka
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 17+ messages in thread
From: Florian Bezdeka @ 2023-09-27 13:50 UTC (permalink / raw)
  To: xenomai, jan.kiszka; +Cc: Florian Bezdeka

This is a preparation step for the following introduction of
COBALT_DECL_TIME64().

We can now re-use the COBALT_DECL() macro when function name (FN) and
the signature / interface (I) are split into different parameters.

Signed-off-by: Florian Bezdeka <florian.bezdeka@siemens.com>
---
 include/cobalt/fcntl.h       | 10 +++---
 include/cobalt/mqueue.h      | 49 +++++++++++-----------------
 include/cobalt/pthread.h     | 77 +++++++++++++++++++++-----------------------
 include/cobalt/sched.h       | 12 +++----
 include/cobalt/semaphore.h   | 24 +++++++-------
 include/cobalt/signal.h      | 16 ++++-----
 include/cobalt/stdio.h       | 33 +++++++++----------
 include/cobalt/stdlib.h      |  4 +--
 include/cobalt/sys/ioctl.h   |  2 +-
 include/cobalt/sys/mman.h    | 10 +++---
 include/cobalt/sys/select.h  |  8 ++---
 include/cobalt/sys/socket.h  | 69 +++++++++++++++++++--------------------
 include/cobalt/sys/time.h    |  3 +-
 include/cobalt/sys/timerfd.h | 10 +++---
 include/cobalt/syslog.h      | 12 +++----
 include/cobalt/time.h        | 46 ++++++++++++--------------
 include/cobalt/unistd.h      | 10 +++---
 include/cobalt/wrappers.h    |  8 ++---
 18 files changed, 188 insertions(+), 215 deletions(-)

diff --git a/include/cobalt/fcntl.h b/include/cobalt/fcntl.h
index f1052c28d..69fd77b0d 100644
--- a/include/cobalt/fcntl.h
+++ b/include/cobalt/fcntl.h
@@ -27,15 +27,15 @@
 extern "C" {
 #endif
 
-COBALT_DECL(int, open(const char *path, int oflag, ...));
+COBALT_DECL(int, open, (const char *path, int oflag, ...));
 
-COBALT_DECL(int, open64(const char *path, int oflag, ...));
+COBALT_DECL(int, open64, (const char *path, int oflag, ...));
 
-COBALT_DECL(int, __open_2(const char *path, int oflag));
+COBALT_DECL(int, __open_2, (const char *path, int oflag));
 
-COBALT_DECL(int, __open64_2(const char *path, int oflag));
+COBALT_DECL(int, __open64_2, (const char *path, int oflag));
 
-COBALT_DECL(int, fcntl(int fd, int cmd, ...));
+COBALT_DECL(int, fcntl, (int fd, int cmd, ...));
 
 #ifdef __cplusplus
 }
diff --git a/include/cobalt/mqueue.h b/include/cobalt/mqueue.h
index 496632dea..c33baf649 100644
--- a/include/cobalt/mqueue.h
+++ b/include/cobalt/mqueue.h
@@ -27,45 +27,34 @@
 extern "C" {
 #endif
 
-COBALT_DECL(mqd_t, mq_open(const char *name,
-			   int oflags,
-			   ...));
+COBALT_DECL(mqd_t, mq_open, (const char *name, int oflags, ...));
 
-COBALT_DECL(int, mq_close(mqd_t qd));
+COBALT_DECL(int, mq_close, (mqd_t qd));
 
-COBALT_DECL(int, mq_unlink(const char *name));
+COBALT_DECL(int, mq_unlink, (const char *name));
 
-COBALT_DECL(int, mq_getattr(mqd_t qd,
-			    struct mq_attr *attr));
+COBALT_DECL(int, mq_getattr, (mqd_t qd, struct mq_attr *attr));
 
-COBALT_DECL(int, mq_setattr(mqd_t qd,
-			    const struct mq_attr *__restrict__ attr,
-			    struct mq_attr *__restrict__ oattr));
+COBALT_DECL(int, mq_setattr,
+	    (mqd_t qd, const struct mq_attr *__restrict__ attr,
+	     struct mq_attr *__restrict__ oattr));
 
-COBALT_DECL(int, mq_send(mqd_t qd,
-			 const char *buffer,
-			 size_t len,
-			 unsigned prio));
+COBALT_DECL(int, mq_send,
+	    (mqd_t qd, const char *buffer, size_t len, unsigned prio));
 
-COBALT_DECL(int, mq_timedsend(mqd_t q,
-			      const char * buffer,
-			      size_t len,
-			      unsigned prio,
-			      const struct timespec *timeout));
+COBALT_DECL(int, mq_timedsend,
+	    (mqd_t q, const char *buffer, size_t len, unsigned prio,
+	     const struct timespec *timeout));
 
-COBALT_DECL(ssize_t, mq_receive(mqd_t q,
-				char *buffer,
-				size_t len,
-				unsigned *prio));
+COBALT_DECL(ssize_t, mq_receive,
+	    (mqd_t q, char *buffer, size_t len, unsigned *prio));
 
-COBALT_DECL(ssize_t, mq_timedreceive(mqd_t q,
-				     char *__restrict__ buffer,
-				     size_t len,
-				     unsigned *__restrict__ prio,
-				     const struct timespec *__restrict__ timeout));
+COBALT_DECL(ssize_t, mq_timedreceive,
+	    (mqd_t q, char *__restrict__ buffer, size_t len,
+	     unsigned *__restrict__ prio,
+	     const struct timespec *__restrict__ timeout));
 
-COBALT_DECL(int, mq_notify(mqd_t q,
-			   const struct sigevent *evp));
+COBALT_DECL(int, mq_notify, (mqd_t q, const struct sigevent *evp));
 
 #ifdef __cplusplus
 }
diff --git a/include/cobalt/pthread.h b/include/cobalt/pthread.h
index 3e9bd4705..4585dd409 100644
--- a/include/cobalt/pthread.h
+++ b/include/cobalt/pthread.h
@@ -38,63 +38,60 @@ typedef struct pthread_attr_ex {
 extern "C" {
 #endif
 
-COBALT_DECL(int, pthread_attr_init(pthread_attr_t *attr));
+COBALT_DECL(int, pthread_attr_init, (pthread_attr_t *attr));
 
-COBALT_DECL(int, pthread_create(pthread_t *ptid_r,
-				const pthread_attr_t *attr,
-				void *(*start) (void *),
-				void *arg));
+COBALT_DECL(int, pthread_create,
+	    (pthread_t *ptid_r, const pthread_attr_t *attr,
+	     void *(*start)(void *), void *arg));
 
-COBALT_DECL(int, pthread_getschedparam(pthread_t thread,
-				       int *policy,
-				       struct sched_param *param));
+COBALT_DECL(int, pthread_getschedparam,
+	    (pthread_t thread, int *policy, struct sched_param *param));
 
-COBALT_DECL(int, pthread_setschedparam(pthread_t thread,
-				       int policy,
-				       const struct sched_param *param));
+COBALT_DECL(int, pthread_setschedparam,
+	    (pthread_t thread, int policy, const struct sched_param *param));
 
-COBALT_DECL(int, pthread_setschedprio(pthread_t thread, int prio));
+COBALT_DECL(int, pthread_setschedprio, (pthread_t thread, int prio));
 
-COBALT_DECL(int, pthread_mutex_init(pthread_mutex_t *mutex,
-				    const pthread_mutexattr_t *attr));
+COBALT_DECL(int, pthread_mutex_init,
+	    (pthread_mutex_t *mutex, const pthread_mutexattr_t *attr));
 
-COBALT_DECL(int, pthread_mutex_destroy(pthread_mutex_t *mutex));
+COBALT_DECL(int, pthread_mutex_destroy, (pthread_mutex_t *mutex));
 
-COBALT_DECL(int, pthread_mutex_lock(pthread_mutex_t *mutex));
+COBALT_DECL(int, pthread_mutex_lock, (pthread_mutex_t *mutex));
 
-COBALT_DECL(int, pthread_mutex_timedlock(pthread_mutex_t *mutex,
-					 const struct timespec *to));
+COBALT_DECL(int, pthread_mutex_timedlock,
+	    (pthread_mutex_t *mutex, const struct timespec *to));
 
-COBALT_DECL(int, pthread_mutex_trylock(pthread_mutex_t *mutex));
+COBALT_DECL(int, pthread_mutex_trylock, (pthread_mutex_t *mutex));
 
-COBALT_DECL(int, pthread_mutex_unlock(pthread_mutex_t *mutex));
+COBALT_DECL(int, pthread_mutex_unlock, (pthread_mutex_t *mutex));
 
-COBALT_DECL(int, pthread_mutex_setprioceiling(pthread_mutex_t *__restrict mutex,
-					      int prioceiling,
-					      int *__restrict old_ceiling));
-  
-COBALT_DECL(int, pthread_mutex_getprioceiling(pthread_mutex_t *__restrict mutex,
-					      int *__restrict old_ceiling));
+COBALT_DECL(int, pthread_mutex_setprioceiling,
+	    (pthread_mutex_t *__restrict mutex, int prioceiling,
+	     int *__restrict old_ceiling));
 
-COBALT_DECL(int, pthread_cond_init (pthread_cond_t *cond,
-				    const pthread_condattr_t *attr));
+COBALT_DECL(int, pthread_mutex_getprioceiling,
+	    (pthread_mutex_t *__restrict mutex, int *__restrict old_ceiling));
 
-COBALT_DECL(int, pthread_cond_destroy(pthread_cond_t *cond));
+COBALT_DECL(int, pthread_cond_init,
+	    (pthread_cond_t *cond, const pthread_condattr_t *attr));
 
-COBALT_DECL(int, pthread_cond_wait(pthread_cond_t *cond,
-				   pthread_mutex_t *mutex));
+COBALT_DECL(int, pthread_cond_destroy, (pthread_cond_t *cond));
 
-COBALT_DECL(int, pthread_cond_timedwait(pthread_cond_t *cond,
-					pthread_mutex_t *mutex,
-					const struct timespec *abstime));
+COBALT_DECL(int, pthread_cond_wait,
+	    (pthread_cond_t *cond, pthread_mutex_t *mutex));
 
-COBALT_DECL(int, pthread_cond_signal(pthread_cond_t *cond));
+COBALT_DECL(int, pthread_cond_timedwait,
+	    (pthread_cond_t *cond, pthread_mutex_t *mutex,
+	     const struct timespec *abstime));
 
-COBALT_DECL(int, pthread_cond_broadcast(pthread_cond_t *cond));
+COBALT_DECL(int, pthread_cond_signal, (pthread_cond_t *cond));
 
-COBALT_DECL(int, pthread_kill(pthread_t ptid, int sig));
+COBALT_DECL(int, pthread_cond_broadcast, (pthread_cond_t *cond));
 
-COBALT_DECL(int, pthread_join(pthread_t ptid, void **retval));
+COBALT_DECL(int, pthread_kill, (pthread_t ptid, int sig));
+
+COBALT_DECL(int, pthread_join, (pthread_t ptid, void **retval));
 
 #ifndef pthread_yield
 /*
@@ -104,13 +101,13 @@ COBALT_DECL(int, pthread_join(pthread_t ptid, void **retval));
  * sched_yield() implementation internally, we can live with this
  * wrapping.
  */
-COBALT_DECL(int, pthread_yield(void));
+COBALT_DECL(int, pthread_yield, (void));
 #endif
 
 int pthread_setmode_np(int clrmask, int setmask,
 		       int *mask_r);
 
-COBALT_DECL(int, pthread_setname_np(pthread_t thread, const char *name));
+COBALT_DECL(int, pthread_setname_np, (pthread_t thread, const char *name));
 
 int pthread_create_ex(pthread_t *ptid_r,
 		      const pthread_attr_ex_t *attr_ex,
diff --git a/include/cobalt/sched.h b/include/cobalt/sched.h
index 7c5b26e77..9889e9aef 100644
--- a/include/cobalt/sched.h
+++ b/include/cobalt/sched.h
@@ -29,16 +29,16 @@
 extern "C" {
 #endif
 
-COBALT_DECL(int, sched_yield(void));
+COBALT_DECL(int, sched_yield, (void));
 
-COBALT_DECL(int, sched_get_priority_min(int policy));
+COBALT_DECL(int, sched_get_priority_min, (int policy));
 
-COBALT_DECL(int, sched_get_priority_max(int policy));
+COBALT_DECL(int, sched_get_priority_max, (int policy));
 
-COBALT_DECL(int, sched_setscheduler(pid_t pid, int policy,
-				    const struct sched_param *param));
+COBALT_DECL(int, sched_setscheduler,
+	    (pid_t pid, int policy, const struct sched_param *param));
 
-COBALT_DECL(int, sched_getscheduler(pid_t pid));
+COBALT_DECL(int, sched_getscheduler, (pid_t pid));
 
 int sched_get_priority_min_ex(int policy);
 
diff --git a/include/cobalt/semaphore.h b/include/cobalt/semaphore.h
index a7714fd34..ed26520ec 100644
--- a/include/cobalt/semaphore.h
+++ b/include/cobalt/semaphore.h
@@ -29,28 +29,26 @@
 extern "C" {
 #endif
 
-COBALT_DECL(int, sem_init(sem_t *sem,
-			  int pshared,
-			  unsigned int value));
+COBALT_DECL(int, sem_init, (sem_t *sem, int pshared, unsigned int value));
 
-COBALT_DECL(int, sem_destroy(sem_t *sem));
+COBALT_DECL(int, sem_destroy, (sem_t *sem));
 
-COBALT_DECL(int, sem_post(sem_t *sem));
+COBALT_DECL(int, sem_post, (sem_t *sem));
 
-COBALT_DECL(int, sem_wait(sem_t *sem));
+COBALT_DECL(int, sem_wait, (sem_t *sem));
 
-COBALT_DECL(int, sem_timedwait(sem_t *sem,
-			       const struct timespec *abs_timeout));
+COBALT_DECL(int, sem_timedwait,
+	    (sem_t *sem, const struct timespec *abs_timeout));
 
-COBALT_DECL(int, sem_trywait(sem_t *sem));
+COBALT_DECL(int, sem_trywait, (sem_t *sem));
 
-COBALT_DECL(int, sem_getvalue(sem_t *sem, int *value));
+COBALT_DECL(int, sem_getvalue, (sem_t *sem, int *value));
 
-COBALT_DECL(sem_t *, sem_open(const char *name, int oflags, ...));
+COBALT_DECL(sem_t *, sem_open, (const char *name, int oflags, ...));
 
-COBALT_DECL(int, sem_close(sem_t *sem));
+COBALT_DECL(int, sem_close, (sem_t *sem));
 
-COBALT_DECL(int, sem_unlink(const char *name));
+COBALT_DECL(int, sem_unlink, (const char *name));
 
 int sem_init_np(sem_t *sem,
 		int flags,
diff --git a/include/cobalt/signal.h b/include/cobalt/signal.h
index 62694f93a..d92ccf2c5 100644
--- a/include/cobalt/signal.h
+++ b/include/cobalt/signal.h
@@ -40,19 +40,19 @@ int cobalt_sigshadow_handler(int sig, siginfo_t *si,
 void cobalt_sigdebug_handler(int sig, siginfo_t *si,
 			     void *context);
 
-COBALT_DECL(int, sigpending(sigset_t *set));
+COBALT_DECL(int, sigpending, (sigset_t *set));
 
-COBALT_DECL(int, sigwait(const sigset_t *set, int *sig));
+COBALT_DECL(int, sigwait, (const sigset_t *set, int *sig));
 
-COBALT_DECL(int, sigwaitinfo(const sigset_t *set, siginfo_t *si));
+COBALT_DECL(int, sigwaitinfo, (const sigset_t *set, siginfo_t *si));
 
-COBALT_DECL(int, sigtimedwait(const sigset_t *set, siginfo_t *si,
-			      const struct timespec *timeout));
+COBALT_DECL(int, sigtimedwait,
+	    (const sigset_t *set, siginfo_t *si,
+	     const struct timespec *timeout));
 
-COBALT_DECL(int, kill(pid_t pid, int sig));
+COBALT_DECL(int, kill, (pid_t pid, int sig));
 
-COBALT_DECL(int, sigqueue(pid_t pid, int sig,
-			  const union sigval value));
+COBALT_DECL(int, sigqueue, (pid_t pid, int sig, const union sigval value));
 
 #ifdef __cplusplus
 }
diff --git a/include/cobalt/stdio.h b/include/cobalt/stdio.h
index 5b9df8006..83121bdbf 100644
--- a/include/cobalt/stdio.h
+++ b/include/cobalt/stdio.h
@@ -31,19 +31,18 @@
 extern "C" {
 #endif /* __cplusplus */
 
-COBALT_DECL(int, vfprintf(FILE *stream, const char *fmt, va_list args));
+COBALT_DECL(int, vfprintf, (FILE *stream, const char *fmt, va_list args));
 
 #ifdef CONFIG_XENO_FORTIFY
 
-COBALT_DECL(int, __vfprintf_chk(FILE *stream, int level,
-				const char *fmt, va_list ap));
+COBALT_DECL(int, __vfprintf_chk,
+	    (FILE *stream, int level, const char *fmt, va_list ap));
 
-COBALT_DECL(int, __vprintf_chk(int flag,
-			       const char *fmt, va_list ap));
+COBALT_DECL(int, __vprintf_chk, (int flag, const char *fmt, va_list ap));
 
-COBALT_DECL(int, __printf_chk(int flag, const char *fmt, ...));
+COBALT_DECL(int, __printf_chk, (int flag, const char *fmt, ...));
 
-COBALT_DECL(int, __fprintf_chk(FILE *fp, int flag, const char *fmt, ...));
+COBALT_DECL(int, __fprintf_chk, (FILE *fp, int flag, const char *fmt, ...));
 
 int __rt_vfprintf_chk(FILE *stream, int level,
 		      const char *fmt, va_list args);
@@ -53,18 +52,18 @@ void __rt_vsyslog_chk(int priority, int level,
 
 #endif	/* CONFIG_XENO_FORTIFY */
 
-COBALT_DECL(int, vprintf(const char *fmt, va_list args));
+COBALT_DECL(int, vprintf, (const char *fmt, va_list args));
 
-COBALT_DECL(int, fprintf(FILE *stream, const char *fmt, ...));
+COBALT_DECL(int, fprintf, (FILE *stream, const char *fmt, ...));
 
-COBALT_DECL(int, printf(const char *fmt, ...));
+COBALT_DECL(int, printf, (const char *fmt, ...));
 
-COBALT_DECL(int, puts(const char *s));
+COBALT_DECL(int, puts, (const char *s));
 
-COBALT_DECL(int, fputs(const char *s, FILE *stream));
+COBALT_DECL(int, fputs, (const char *s, FILE *stream));
 
 #ifndef putchar
-COBALT_DECL(int, putchar(int c));
+COBALT_DECL(int, putchar, (int c));
 #else
 static inline int __real_putchar(int c)
 {
@@ -77,7 +76,7 @@ int __cobalt_putchar(int c);
 #endif
 
 #ifndef fputc
-COBALT_DECL(int, fputc(int c, FILE *stream));
+COBALT_DECL(int, fputc, (int c, FILE *stream));
 #else
 static inline int __real_fputc(int c, FILE *stream)
 {
@@ -89,10 +88,10 @@ int __cobalt_fputc(int c, FILE *stream);
 #define fputc fputc
 #endif
 
-COBALT_DECL(size_t,
-	    fwrite(const void *ptr, size_t sz, size_t nmemb, FILE *stream));
+COBALT_DECL(size_t, fwrite,
+	    (const void *ptr, size_t sz, size_t nmemb, FILE *stream));
 
-COBALT_DECL(int, fclose(FILE *stream));
+COBALT_DECL(int, fclose, (FILE *stream));
 
 int rt_vfprintf(FILE *stream, const char *format, va_list args);
 
diff --git a/include/cobalt/stdlib.h b/include/cobalt/stdlib.h
index 6b664f547..544e383cd 100644
--- a/include/cobalt/stdlib.h
+++ b/include/cobalt/stdlib.h
@@ -29,9 +29,9 @@
 extern "C" {
 #endif /* __cplusplus */
 
-COBALT_DECL(void, free(void *ptr));
+COBALT_DECL(void, free, (void *ptr));
 
-COBALT_DECL(void *, malloc(size_t size));
+COBALT_DECL(void *, malloc, (size_t size));
 
 #ifdef __cplusplus
 }
diff --git a/include/cobalt/sys/ioctl.h b/include/cobalt/sys/ioctl.h
index 553aa566d..ab3189591 100644
--- a/include/cobalt/sys/ioctl.h
+++ b/include/cobalt/sys/ioctl.h
@@ -27,7 +27,7 @@
 extern "C" {
 #endif
 
-COBALT_DECL(int, ioctl(int fildes, unsigned int request, ...));
+COBALT_DECL(int, ioctl, (int fildes, unsigned int request, ...));
 
 #ifdef __cplusplus
 }
diff --git a/include/cobalt/sys/mman.h b/include/cobalt/sys/mman.h
index 75a00da0c..e291f50ef 100644
--- a/include/cobalt/sys/mman.h
+++ b/include/cobalt/sys/mman.h
@@ -28,12 +28,14 @@
 extern "C" {
 #endif
 
-COBALT_DECL(void *, mmap(void *addr, size_t length, int prot, int flags,
-			 int fd, off_t offset));
+COBALT_DECL(void *, mmap,
+	    (void *addr, size_t length, int prot, int flags, int fd,
+	     off_t offset));
 
 #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
-COBALT_DECL(void *, mmap64(void *addr, size_t length, int prot, int flags,
-			   int fd, off64_t offset));
+COBALT_DECL(void *, mmap64,
+	    (void *addr, size_t length, int prot, int flags, int fd,
+	     off64_t offset));
 #endif
 
 #ifdef __cplusplus
diff --git a/include/cobalt/sys/select.h b/include/cobalt/sys/select.h
index 76e8476bb..e823874f8 100644
--- a/include/cobalt/sys/select.h
+++ b/include/cobalt/sys/select.h
@@ -27,10 +27,10 @@
 extern "C" {
 #endif
 
-COBALT_DECL(int, select(int __nfds, fd_set *__restrict __readfds,
-			fd_set *__restrict __writefds,
-			fd_set *__restrict __exceptfds,
-			struct timeval *__restrict __timeout));
+COBALT_DECL(int, select,
+	    (int __nfds, fd_set *__restrict __readfds,
+	     fd_set *__restrict __writefds, fd_set *__restrict __exceptfds,
+	     struct timeval *__restrict __timeout));
 #ifdef __cplusplus
 }
 #endif
diff --git a/include/cobalt/sys/socket.h b/include/cobalt/sys/socket.h
index 156b49356..af7dcc159 100644
--- a/include/cobalt/sys/socket.h
+++ b/include/cobalt/sys/socket.h
@@ -27,59 +27,56 @@
 extern "C" {
 #endif
 
-COBALT_DECL(int, socket(int protocol_family,
-			int socket_type, int protocol));
+COBALT_DECL(int, socket, (int protocol_family, int socket_type, int protocol));
 
-COBALT_DECL(ssize_t, recvmsg(int fd,
-			     struct msghdr *msg, int flags));
+COBALT_DECL(ssize_t, recvmsg, (int fd, struct msghdr *msg, int flags));
 
-COBALT_DECL(int, recvmmsg(int fd,
-			  struct mmsghdr *msgvec, unsigned int vlen,
-			  unsigned int flags, struct timespec *timeout));
+COBALT_DECL(int, recvmmsg,
+	    (int fd, struct mmsghdr *msgvec, unsigned int vlen,
+	     unsigned int flags, struct timespec *timeout));
 
-COBALT_DECL(ssize_t, sendmsg(int fd,
-			     const struct msghdr *msg, int flags));
+COBALT_DECL(ssize_t, sendmsg, (int fd, const struct msghdr *msg, int flags));
 
-COBALT_DECL(int, sendmmsg(int fd,
-			  struct mmsghdr *msgvec, unsigned int vlen,
-			  unsigned int flags));
+COBALT_DECL(int, sendmmsg,
+	    (int fd, struct mmsghdr *msgvec, unsigned int vlen,
+	     unsigned int flags));
 
-COBALT_DECL(ssize_t, recvfrom(int fd, void *buf, size_t len, int flags,
-			      struct sockaddr *from, socklen_t *fromlen));
+COBALT_DECL(ssize_t, recvfrom,
+	    (int fd, void *buf, size_t len, int flags, struct sockaddr *from,
+	     socklen_t *fromlen));
 
-COBALT_DECL(ssize_t, sendto(int fd, const void *buf, size_t len, int flags,
-			    const struct sockaddr *to, socklen_t tolen));
+COBALT_DECL(ssize_t, sendto,
+	    (int fd, const void *buf, size_t len, int flags,
+	     const struct sockaddr *to, socklen_t tolen));
 
-COBALT_DECL(ssize_t, recv(int fd, void *buf,
-			  size_t len, int flags));
+COBALT_DECL(ssize_t, recv, (int fd, void *buf, size_t len, int flags));
 
-COBALT_DECL(ssize_t, send(int fd, const void *buf,
-			  size_t len, int flags));
+COBALT_DECL(ssize_t, send, (int fd, const void *buf, size_t len, int flags));
 
-COBALT_DECL(int, getsockopt(int fd, int level, int optname,
-			    void *optval, socklen_t *optlen));
+COBALT_DECL(int, getsockopt,
+	    (int fd, int level, int optname, void *optval, socklen_t *optlen));
 
-COBALT_DECL(int, setsockopt(int fd, int level, int optname,
-			    const void *optval, socklen_t optlen));
+COBALT_DECL(int, setsockopt,
+	    (int fd, int level, int optname, const void *optval,
+	     socklen_t optlen));
 
-COBALT_DECL(int, bind(int fd, const struct sockaddr *my_addr,
-		      socklen_t addrlen));
+COBALT_DECL(int, bind,
+	    (int fd, const struct sockaddr *my_addr, socklen_t addrlen));
 
-COBALT_DECL(int, connect(int fd, const struct sockaddr *serv_addr,
-			 socklen_t addrlen));
+COBALT_DECL(int, connect,
+	    (int fd, const struct sockaddr *serv_addr, socklen_t addrlen));
 
-COBALT_DECL(int, listen(int fd, int backlog));
+COBALT_DECL(int, listen, (int fd, int backlog));
 
-COBALT_DECL(int, accept(int fd, struct sockaddr *addr,
-			socklen_t *addrlen));
+COBALT_DECL(int, accept, (int fd, struct sockaddr *addr, socklen_t *addrlen));
 
-COBALT_DECL(int, getsockname(int fd, struct sockaddr *name,
-			     socklen_t *namelen));
+COBALT_DECL(int, getsockname,
+	    (int fd, struct sockaddr *name, socklen_t *namelen));
 
-COBALT_DECL(int, getpeername(int fd, struct sockaddr *name,
-			     socklen_t *namelen));
+COBALT_DECL(int, getpeername,
+	    (int fd, struct sockaddr *name, socklen_t *namelen));
 
-COBALT_DECL(int, shutdown(int fd, int how));
+COBALT_DECL(int, shutdown, (int fd, int how));
 
 #ifdef __cplusplus
 }
diff --git a/include/cobalt/sys/time.h b/include/cobalt/sys/time.h
index 38f5a34b6..b27dec815 100644
--- a/include/cobalt/sys/time.h
+++ b/include/cobalt/sys/time.h
@@ -29,8 +29,7 @@ struct timezone;
 extern "C" {
 #endif
 
-COBALT_DECL(int, gettimeofday(struct timeval *tv,
-			      struct timezone *tz));
+COBALT_DECL(int, gettimeofday, (struct timeval *tv, struct timezone *tz));
 
 #ifdef __cplusplus
 }
diff --git a/include/cobalt/sys/timerfd.h b/include/cobalt/sys/timerfd.h
index a7df836e6..6649a19e0 100644
--- a/include/cobalt/sys/timerfd.h
+++ b/include/cobalt/sys/timerfd.h
@@ -27,13 +27,13 @@
 extern "C" {
 #endif /* __cplusplus */
 
-COBALT_DECL(int, timerfd_create(int clockid, int flags));
+COBALT_DECL(int, timerfd_create, (int clockid, int flags));
 
-COBALT_DECL(int, timerfd_settime(int fd, int flags,
-		const struct itimerspec *new_value,
-		struct itimerspec *old_value));
+COBALT_DECL(int, timerfd_settime,
+	    (int fd, int flags, const struct itimerspec *new_value,
+	     struct itimerspec *old_value));
 
-COBALT_DECL(int, timerfd_gettime(int fd, struct itimerspec *curr_value));
+COBALT_DECL(int, timerfd_gettime, (int fd, struct itimerspec *curr_value));
 
 #ifdef __cplusplus
 }
diff --git a/include/cobalt/syslog.h b/include/cobalt/syslog.h
index 236c8a219..c677edec5 100644
--- a/include/cobalt/syslog.h
+++ b/include/cobalt/syslog.h
@@ -29,18 +29,16 @@
 extern "C" {
 #endif /* __cplusplus */
 
-COBALT_DECL(void, syslog(int priority, const char *fmt, ...));
+COBALT_DECL(void, syslog, (int priority, const char *fmt, ...));
 
-COBALT_DECL(void, vsyslog(int priority,
-			  const char *fmt, va_list ap));
+COBALT_DECL(void, vsyslog, (int priority, const char *fmt, va_list ap));
 
 #ifdef CONFIG_XENO_FORTIFY
 
-COBALT_DECL(void, __vsyslog_chk(int priority, int level,
-				const char *fmt, va_list ap));
+COBALT_DECL(void, __vsyslog_chk,
+	    (int priority, int level, const char *fmt, va_list ap));
 
-COBALT_DECL(void, __syslog_chk(int pri, int flag,
-			       const char *fmt, ...));
+COBALT_DECL(void, __syslog_chk, (int pri, int flag, const char *fmt, ...));
 
 #endif /* CONFIG_XENO_FORTIFY */
 
diff --git a/include/cobalt/time.h b/include/cobalt/time.h
index e3f355c61..006a0ae03 100644
--- a/include/cobalt/time.h
+++ b/include/cobalt/time.h
@@ -32,43 +32,37 @@ extern "C" {
 
 struct timex;
 
-COBALT_DECL(int, clock_getres(clockid_t clock_id,
-			      struct timespec *tp));
+COBALT_DECL(int, clock_getres, (clockid_t clock_id, struct timespec *tp));
 
-COBALT_DECL(int, clock_gettime(clockid_t clock_id,
-			       struct timespec *tp));
+COBALT_DECL(int, clock_gettime, (clockid_t clock_id, struct timespec *tp));
 
-COBALT_DECL(int, clock_settime(clockid_t clock_id,
-			       const struct timespec *tp));
+COBALT_DECL(int, clock_settime,
+	    (clockid_t clock_id, const struct timespec *tp));
 
-COBALT_DECL(int, clock_adjtime(clockid_t clock_id,
-			       struct timex *tx));
+COBALT_DECL(int, clock_adjtime, (clockid_t clock_id, struct timex *tx));
 
-COBALT_DECL(int, clock_nanosleep(clockid_t clock_id,
-				 int flags,
-				 const struct timespec *rqtp,
-				 struct timespec *rmtp));
+COBALT_DECL(int, clock_nanosleep,
+	    (clockid_t clock_id, int flags, const struct timespec *rqtp,
+	     struct timespec *rmtp));
 
-COBALT_DECL(time_t, time(time_t *t));
+COBALT_DECL(time_t, time, (time_t *t));
 
-COBALT_DECL(int, nanosleep(const struct timespec *rqtp,
-			   struct timespec *rmtp));
+COBALT_DECL(int, nanosleep,
+	    (const struct timespec *rqtp, struct timespec *rmtp));
 
-COBALT_DECL(int, timer_create(clockid_t clockid,
-			      const struct sigevent *__restrict__ evp,
-			      timer_t * __restrict__ timerid));
+COBALT_DECL(int, timer_create,
+	    (clockid_t clockid, const struct sigevent *__restrict__ evp,
+	     timer_t *__restrict__ timerid));
 
-COBALT_DECL(int, timer_delete(timer_t timerid));
+COBALT_DECL(int, timer_delete, (timer_t timerid));
 
-COBALT_DECL(int, timer_settime(timer_t timerid,
-			       int flags,
-			       const struct itimerspec *value,
-			       struct itimerspec *ovalue));
+COBALT_DECL(int, timer_settime,
+	    (timer_t timerid, int flags, const struct itimerspec *value,
+	     struct itimerspec *ovalue));
 
-COBALT_DECL(int, timer_gettime(timer_t timerid,
-			       struct itimerspec *value));
+COBALT_DECL(int, timer_gettime, (timer_t timerid, struct itimerspec *value));
 
-COBALT_DECL(int, timer_getoverrun(timer_t timerid));
+COBALT_DECL(int, timer_getoverrun, (timer_t timerid));
 
 #ifdef __cplusplus
 }
diff --git a/include/cobalt/unistd.h b/include/cobalt/unistd.h
index fe3992af6..ae3988558 100644
--- a/include/cobalt/unistd.h
+++ b/include/cobalt/unistd.h
@@ -27,15 +27,15 @@
 extern "C" {
 #endif
 
-COBALT_DECL(ssize_t, read(int fd, void *buf, size_t nbyte));
+COBALT_DECL(ssize_t, read, (int fd, void *buf, size_t nbyte));
 
-COBALT_DECL(ssize_t, write(int fd, const void *buf, size_t nbyte));
+COBALT_DECL(ssize_t, write, (int fd, const void *buf, size_t nbyte));
 
-COBALT_DECL(int, close(int fildes));
+COBALT_DECL(int, close, (int fildes));
 
-COBALT_DECL(unsigned int, sleep(unsigned int seconds));
+COBALT_DECL(unsigned int, sleep, (unsigned int seconds));
 
-COBALT_DECL(int, usleep(useconds_t usec));
+COBALT_DECL(int, usleep, (useconds_t usec));
 
 #ifdef __cplusplus
 }
diff --git a/include/cobalt/wrappers.h b/include/cobalt/wrappers.h
index 7e061caf9..aaa581db4 100644
--- a/include/cobalt/wrappers.h
+++ b/include/cobalt/wrappers.h
@@ -27,10 +27,10 @@
 #define __STD(call)		__real_ ## call
 #define __COBALT(call)		__cobalt_ ## call
 #define __RT(call)		__COBALT(call)
-#define COBALT_DECL(T, P)	\
-	__typeof__(T) __RT(P);	\
-	__typeof__(T) __STD(P); \
-	__typeof__(T) __WRAP(P)
+#define COBALT_DECL(T, FN, I)                                                  \
+	__typeof__(T) __RT(FN) I;                                              \
+	__typeof__(T) __STD(FN) I;                                             \
+	__typeof__(T) __WRAP(FN) I
 
 /*
  * 

-- 
2.39.2


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH v2 6/9] y2038: lib/cobalt: Implement necessary wrappers for y2038 support
  2023-09-27 13:50 [PATCH v2 0/9] y2038: Finalize and enable y2038 support Florian Bezdeka
                   ` (4 preceding siblings ...)
  2023-09-27 13:50 ` [PATCH v2 5/9] y2038: lib/cobalt: Split function name and interface in COBALT_DECL() Florian Bezdeka
@ 2023-09-27 13:50 ` Florian Bezdeka
  2023-09-27 13:50 ` [PATCH v2 7/9] y2038: testsuite/smokey: Add some function wrapping tests Florian Bezdeka
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 17+ messages in thread
From: Florian Bezdeka @ 2023-09-27 13:50 UTC (permalink / raw)
  To: xenomai, jan.kiszka; +Cc: Florian Bezdeka

COBALT_IMPL_TIME64():
  This macro is based on COBALT_IMPL() and will add the necessary
  __wrap_ function as weak symbol to the cobalt implementation
  (starting with __cobalt_) when y2038 support has been requested.
  This allows the usage of the __RT() macro in combination with
  y2038/time64 wrappers.

COBALT_DECL_TIME64():
  This macro is based on COBALT_DECL() and allows the usage of __STD()
  in combination with y2038/time64 wrappers.

Both macros will fall back to their basements if y2038 support was
not requested.

Examples, assuming code is located in application code:
  select():       will be redirected by glibc to __select64() when
                  y2038 support is requested. We additionally wrap the
                  __select64() function so __wrap___select64() will be
                  called - which is a weak symbol aliased to
                  __cobalt_select(). That allows users to overwrite
                  __wrap___select64() if they need to.

  __RT(select()): result after preprocessor: __cobalt_select()
                  __cobalt_select() is y2038 safe when y2038 has been
                  requested.

Signed-off-by: Florian Bezdeka <florian.bezdeka@siemens.com>
---
 configure.ac                            | 16 +++++++--
 include/cobalt/mqueue.h                 |  8 ++---
 include/cobalt/pthread.h                | 10 +++---
 include/cobalt/semaphore.h              |  4 +--
 include/cobalt/signal.h                 |  6 ++--
 include/cobalt/sys/ioctl.h              |  3 +-
 include/cobalt/sys/select.h             |  2 +-
 include/cobalt/sys/socket.h             | 11 +++---
 include/cobalt/sys/time.h               |  3 +-
 include/cobalt/sys/timerfd.h            |  9 ++---
 include/cobalt/time.h                   | 34 ++++++++++---------
 include/cobalt/wrappers.h               | 23 +++++++++++--
 lib/cobalt/Makefile.am                  |  2 ++
 lib/cobalt/clock.c                      | 26 ++++++++------
 lib/cobalt/cobalt-glibc-time64.wrappers | 23 +++++++++++++
 lib/cobalt/cond.c                       |  6 ++--
 lib/cobalt/mq.c                         | 16 ++++-----
 lib/cobalt/mutex.c                      |  4 +--
 lib/cobalt/rtdm.c                       | 18 ++++++----
 lib/cobalt/select.c                     | 60 ++++++++++++++++++++++++++++++---
 lib/cobalt/semaphore.c                  |  3 +-
 lib/cobalt/signal.c                     |  5 +--
 lib/cobalt/timer.c                      | 11 +++---
 lib/cobalt/timerfd.c                    |  9 ++---
 scripts/xeno-config-cobalt.in           |  5 +++
 25 files changed, 222 insertions(+), 95 deletions(-)

diff --git a/configure.ac b/configure.ac
index f1734b27a..aa3794a5f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -944,17 +944,27 @@ dnl in-tree executables which require POSIX symbol wrapping.
 
    modechk_wrappers="$topdir/lib/cobalt/modechk.wrappers"
    cobalt_wrappers="$topdir/lib/cobalt/cobalt.wrappers"
+   cobalt_wrappers_glibc_time64="$topdir/lib/cobalt/cobalt-glibc-time64.wrappers"
+   all_wrappers="$modechk_wrappers $cobalt_wrappers"
+
+   linker_flags="-Wl,@$modechk_wrappers -Wl,@$cobalt_wrappers"
+
+   if [[ "$CONFIG_XENO_LIBS_TIME64" = "yes" ]]; then
+      all_wrappers="$all_wrappers $cobalt_wrappers_glibc_time64"
+      linker_flags="$linker_flags -Wl,@$cobalt_wrappers_glibc_time64"
+   fi
+
    if [[ $ac_cv_ld_file_option = yes ]]; then
-	XENO_POSIX_WRAPPERS="-Wl,@$modechk_wrappers -Wl,@$cobalt_wrappers"
+	XENO_POSIX_WRAPPERS="$linker_flags"
    else
-	XENO_POSIX_WRAPPERS=`cat $modechk_wrappers $cobalt_wrappers | \
+	XENO_POSIX_WRAPPERS=`cat $all_wrappers | \
 			while read wrap_option symbol ; do \
 				echo -n "-Wl,$wrap_option,$symbol " ; \
 			done`
    fi
 
    AC_SUBST(XENO_POSIX_WRAPPERS)
-   AC_SUBST([CONFIG_STATUS_DEPENDENCIES], ["$modechk_wrappers $cobalt_wrappers"])
+   AC_SUBST([CONFIG_STATUS_DEPENDENCIES], ["$all_wrappers"])
 fi
 
 dnl Multi-library support.
diff --git a/include/cobalt/mqueue.h b/include/cobalt/mqueue.h
index c33baf649..89d4bff79 100644
--- a/include/cobalt/mqueue.h
+++ b/include/cobalt/mqueue.h
@@ -42,14 +42,14 @@ COBALT_DECL(int, mq_setattr,
 COBALT_DECL(int, mq_send,
 	    (mqd_t qd, const char *buffer, size_t len, unsigned prio));
 
-COBALT_DECL(int, mq_timedsend,
-	    (mqd_t q, const char *buffer, size_t len, unsigned prio,
-	     const struct timespec *timeout));
+COBALT_DECL_TIME64(int, mq_timedsend, __mq_timedsend64,
+		   (mqd_t q, const char *buffer, size_t len, unsigned prio,
+		    const struct timespec *timeout));
 
 COBALT_DECL(ssize_t, mq_receive,
 	    (mqd_t q, char *buffer, size_t len, unsigned *prio));
 
-COBALT_DECL(ssize_t, mq_timedreceive,
+COBALT_DECL_TIME64(ssize_t, mq_timedreceive, __mq_timedsend_time64,
 	    (mqd_t q, char *__restrict__ buffer, size_t len,
 	     unsigned *__restrict__ prio,
 	     const struct timespec *__restrict__ timeout));
diff --git a/include/cobalt/pthread.h b/include/cobalt/pthread.h
index 4585dd409..1a8991f5c 100644
--- a/include/cobalt/pthread.h
+++ b/include/cobalt/pthread.h
@@ -59,8 +59,8 @@ COBALT_DECL(int, pthread_mutex_destroy, (pthread_mutex_t *mutex));
 
 COBALT_DECL(int, pthread_mutex_lock, (pthread_mutex_t *mutex));
 
-COBALT_DECL(int, pthread_mutex_timedlock,
-	    (pthread_mutex_t *mutex, const struct timespec *to));
+COBALT_DECL_TIME64(int, pthread_mutex_timedlock, __pthread_mutex_timedlock64,
+		   (pthread_mutex_t *mutex, const struct timespec *to));
 
 COBALT_DECL(int, pthread_mutex_trylock, (pthread_mutex_t *mutex));
 
@@ -81,9 +81,9 @@ COBALT_DECL(int, pthread_cond_destroy, (pthread_cond_t *cond));
 COBALT_DECL(int, pthread_cond_wait,
 	    (pthread_cond_t *cond, pthread_mutex_t *mutex));
 
-COBALT_DECL(int, pthread_cond_timedwait,
-	    (pthread_cond_t *cond, pthread_mutex_t *mutex,
-	     const struct timespec *abstime));
+COBALT_DECL_TIME64(int, pthread_cond_timedwait, __pthread_cond_timedwait64,
+		   (pthread_cond_t *cond, pthread_mutex_t *mutex,
+		    const struct timespec *abstime));
 
 COBALT_DECL(int, pthread_cond_signal, (pthread_cond_t *cond));
 
diff --git a/include/cobalt/semaphore.h b/include/cobalt/semaphore.h
index ed26520ec..d5e835a8d 100644
--- a/include/cobalt/semaphore.h
+++ b/include/cobalt/semaphore.h
@@ -37,8 +37,8 @@ COBALT_DECL(int, sem_post, (sem_t *sem));
 
 COBALT_DECL(int, sem_wait, (sem_t *sem));
 
-COBALT_DECL(int, sem_timedwait,
-	    (sem_t *sem, const struct timespec *abs_timeout));
+COBALT_DECL_TIME64(int, sem_timedwait, __sem_timedwait64,
+		   (sem_t *sem, const struct timespec *abs_timeout));
 
 COBALT_DECL(int, sem_trywait, (sem_t *sem));
 
diff --git a/include/cobalt/signal.h b/include/cobalt/signal.h
index d92ccf2c5..55cb2baba 100644
--- a/include/cobalt/signal.h
+++ b/include/cobalt/signal.h
@@ -46,9 +46,9 @@ COBALT_DECL(int, sigwait, (const sigset_t *set, int *sig));
 
 COBALT_DECL(int, sigwaitinfo, (const sigset_t *set, siginfo_t *si));
 
-COBALT_DECL(int, sigtimedwait,
-	    (const sigset_t *set, siginfo_t *si,
-	     const struct timespec *timeout));
+COBALT_DECL_TIME64(int, sigtimedwait, __sigtimedwait64,
+		   (const sigset_t *set, siginfo_t *si,
+		    const struct timespec *timeout));
 
 COBALT_DECL(int, kill, (pid_t pid, int sig));
 
diff --git a/include/cobalt/sys/ioctl.h b/include/cobalt/sys/ioctl.h
index ab3189591..1dd06dd09 100644
--- a/include/cobalt/sys/ioctl.h
+++ b/include/cobalt/sys/ioctl.h
@@ -27,7 +27,8 @@
 extern "C" {
 #endif
 
-COBALT_DECL(int, ioctl, (int fildes, unsigned int request, ...));
+COBALT_DECL_TIME64(int, ioctl, __ioctl_time64,
+		   (int fd, unsigned int request, ...));
 
 #ifdef __cplusplus
 }
diff --git a/include/cobalt/sys/select.h b/include/cobalt/sys/select.h
index e823874f8..89062875c 100644
--- a/include/cobalt/sys/select.h
+++ b/include/cobalt/sys/select.h
@@ -27,7 +27,7 @@
 extern "C" {
 #endif
 
-COBALT_DECL(int, select,
+COBALT_DECL_TIME64(int, select, __select64,
 	    (int __nfds, fd_set *__restrict __readfds,
 	     fd_set *__restrict __writefds, fd_set *__restrict __exceptfds,
 	     struct timeval *__restrict __timeout));
diff --git a/include/cobalt/sys/socket.h b/include/cobalt/sys/socket.h
index af7dcc159..d5e81e5bd 100644
--- a/include/cobalt/sys/socket.h
+++ b/include/cobalt/sys/socket.h
@@ -53,12 +53,13 @@ COBALT_DECL(ssize_t, recv, (int fd, void *buf, size_t len, int flags));
 
 COBALT_DECL(ssize_t, send, (int fd, const void *buf, size_t len, int flags));
 
-COBALT_DECL(int, getsockopt,
-	    (int fd, int level, int optname, void *optval, socklen_t *optlen));
+COBALT_DECL_TIME64(int, getsockopt, __getsockopt64,
+		   (int fd, int level, int optname, void *optval,
+		    socklen_t *optlen));
 
-COBALT_DECL(int, setsockopt,
-	    (int fd, int level, int optname, const void *optval,
-	     socklen_t optlen));
+COBALT_DECL_TIME64(int, setsockopt, __setsockopt64,
+		   (int fd, int level, int optname, const void *optval,
+		    socklen_t optlen));
 
 COBALT_DECL(int, bind,
 	    (int fd, const struct sockaddr *my_addr, socklen_t addrlen));
diff --git a/include/cobalt/sys/time.h b/include/cobalt/sys/time.h
index b27dec815..e52f2e162 100644
--- a/include/cobalt/sys/time.h
+++ b/include/cobalt/sys/time.h
@@ -29,7 +29,8 @@ struct timezone;
 extern "C" {
 #endif
 
-COBALT_DECL(int, gettimeofday, (struct timeval *tv, struct timezone *tz));
+COBALT_DECL_TIME64(int, gettimeofday, __gettimeofday64,
+		   (struct timeval *tv, struct timezone *tz));
 
 #ifdef __cplusplus
 }
diff --git a/include/cobalt/sys/timerfd.h b/include/cobalt/sys/timerfd.h
index 6649a19e0..46055d105 100644
--- a/include/cobalt/sys/timerfd.h
+++ b/include/cobalt/sys/timerfd.h
@@ -29,11 +29,12 @@ extern "C" {
 
 COBALT_DECL(int, timerfd_create, (int clockid, int flags));
 
-COBALT_DECL(int, timerfd_settime,
-	    (int fd, int flags, const struct itimerspec *new_value,
-	     struct itimerspec *old_value));
+COBALT_DECL_TIME64(int, timerfd_settime, __timerfd_settime64,
+		   (int fd, int flags, const struct itimerspec *new_value,
+		    struct itimerspec *old_value));
 
-COBALT_DECL(int, timerfd_gettime, (int fd, struct itimerspec *curr_value));
+COBALT_DECL_TIME64(int, timerfd_gettime, __timerfd_gettime64,
+		   (int fd, struct itimerspec *curr_value));
 
 #ifdef __cplusplus
 }
diff --git a/include/cobalt/time.h b/include/cobalt/time.h
index 006a0ae03..65d33e298 100644
--- a/include/cobalt/time.h
+++ b/include/cobalt/time.h
@@ -32,23 +32,26 @@ extern "C" {
 
 struct timex;
 
-COBALT_DECL(int, clock_getres, (clockid_t clock_id, struct timespec *tp));
+COBALT_DECL_TIME64(int, clock_getres, __clock_getres64,
+		   (clockid_t clock_id, struct timespec *tp));
 
-COBALT_DECL(int, clock_gettime, (clockid_t clock_id, struct timespec *tp));
+COBALT_DECL_TIME64(int, clock_gettime, __clock_gettime64,
+		   (clockid_t clock_id, struct timespec *tp));
 
-COBALT_DECL(int, clock_settime,
-	    (clockid_t clock_id, const struct timespec *tp));
+COBALT_DECL_TIME64(int, clock_settime, __clock_settime64,
+		   (clockid_t clock_id, const struct timespec *tp));
 
-COBALT_DECL(int, clock_adjtime, (clockid_t clock_id, struct timex *tx));
+COBALT_DECL_TIME64(int, clock_adjtime, __clock_adjtime64,
+		   (clockid_t clock_id, struct timex *tx));
 
-COBALT_DECL(int, clock_nanosleep,
-	    (clockid_t clock_id, int flags, const struct timespec *rqtp,
-	     struct timespec *rmtp));
+COBALT_DECL_TIME64(int, clock_nanosleep, __clock_nanosleep_time64,
+		   (clockid_t clock_id, int flags, const struct timespec *rqtp,
+		    struct timespec *rmtp));
 
-COBALT_DECL(time_t, time, (time_t *t));
+COBALT_DECL_TIME64(time_t, time, __time64, (time_t *t));
 
-COBALT_DECL(int, nanosleep,
-	    (const struct timespec *rqtp, struct timespec *rmtp));
+COBALT_DECL_TIME64(int, nanosleep, __nanosleep64,
+		   (const struct timespec *rqtp, struct timespec *rmtp));
 
 COBALT_DECL(int, timer_create,
 	    (clockid_t clockid, const struct sigevent *__restrict__ evp,
@@ -56,11 +59,12 @@ COBALT_DECL(int, timer_create,
 
 COBALT_DECL(int, timer_delete, (timer_t timerid));
 
-COBALT_DECL(int, timer_settime,
-	    (timer_t timerid, int flags, const struct itimerspec *value,
-	     struct itimerspec *ovalue));
+COBALT_DECL_TIME64(int, timer_settime, __timer_settime64,
+		   (timer_t timerid, int flags, const struct itimerspec *value,
+		    struct itimerspec *ovalue));
 
-COBALT_DECL(int, timer_gettime, (timer_t timerid, struct itimerspec *value));
+COBALT_DECL_TIME64(int, timer_gettime, __timer_gettime64,
+		   (timer_t timerid, struct itimerspec *value));
 
 COBALT_DECL(int, timer_getoverrun, (timer_t timerid));
 
diff --git a/include/cobalt/wrappers.h b/include/cobalt/wrappers.h
index aaa581db4..21f4ceacb 100644
--- a/include/cobalt/wrappers.h
+++ b/include/cobalt/wrappers.h
@@ -32,6 +32,22 @@
 	__typeof__(T) __STD(FN) I;                                             \
 	__typeof__(T) __WRAP(FN) I
 
+#if __USE_TIME_BITS64
+/*
+ * Make __RT() and __STD() usable in combination with time64_t related services.
+ */
+#define COBALT_IMPL_TIME64(T, FN, FN_64, I)                                    \
+	__typeof__(T) __wrap_##FN_64 I                                         \
+		__attribute__((alias("__cobalt_" __stringify(FN)), weak));     \
+	COBALT_IMPL(T, FN, I)
+#define COBALT_DECL_TIME64(T, FN, A, I)                                        \
+	extern T __REDIRECT_NTH(__STD(FN), I, __real_##A);                     \
+	COBALT_DECL(T, FN, I)
+#else
+#define COBALT_IMPL_TIME64(T, FN, FN_64, I) COBALT_IMPL(T, FN, I)
+#define COBALT_DECL_TIME64(T, FN, FN_64, I) COBALT_DECL(T, FN, I)
+#endif
+
 /*
  * 
  * Each "foo" Cobalt routine shadowing a POSIX service may be
@@ -48,8 +64,9 @@
  * version. The original Cobalt implementation can still be
  * referenced as __COBALT(foo).
  */
-#define COBALT_IMPL(T, I, A)								\
-__typeof__(T) __wrap_ ## I A __attribute__((alias("__cobalt_" __stringify(I)), weak));	\
-__typeof__(T) __cobalt_ ## I A
+#define COBALT_IMPL(T, FN, I)                                                  \
+	__typeof__(T) __wrap_##FN I                                            \
+		__attribute__((alias("__cobalt_" __stringify(FN)), weak));     \
+	__typeof__(T) __cobalt_##FN I
 
 #endif /* !_COBALT_WRAPPERS_H */
diff --git a/lib/cobalt/Makefile.am b/lib/cobalt/Makefile.am
index 3159695b3..4318adf18 100644
--- a/lib/cobalt/Makefile.am
+++ b/lib/cobalt/Makefile.am
@@ -59,10 +59,12 @@ AM_LIBTOOLFLAGS = --silent
 install-data-local:
 	$(mkinstalldirs) $(DESTDIR)$(libdir)
 	$(INSTALL_DATA) $(srcdir)/cobalt.wrappers $(DESTDIR)$(libdir)
+	$(INSTALL_DATA) $(srcdir)/cobalt-glibc-time64.wrappers $(DESTDIR)$(libdir)
 	$(INSTALL_DATA) $(srcdir)/modechk.wrappers $(DESTDIR)$(libdir)
 
 uninstall-local:
 	$(RM) $(DESTDIR)$(libdir)/cobalt.wrappers
+	$(RM) $(DESTDIR)$(libdir)/cobalt-glibc-time64.wrappers
 	$(RM) $(DESTDIR)$(libdir)/modechk.wrappers
 
 EXTRA_DIST = cobalt.wrappers modechk.wrappers
diff --git a/lib/cobalt/clock.c b/lib/cobalt/clock.c
index 377582cf3..9289d8787 100644
--- a/lib/cobalt/clock.c
+++ b/lib/cobalt/clock.c
@@ -96,7 +96,8 @@
  *
  * @apitags{unrestricted}
  */
-COBALT_IMPL(int, clock_getres, (clockid_t clock_id, struct timespec *tp))
+COBALT_IMPL_TIME64(int, clock_getres, __clock_getres64,
+		   (clockid_t clock_id, struct timespec *tp))
 {
 	int ret;
 
@@ -152,7 +153,8 @@ static int __do_clock_gettime(clockid_t clock_id, struct timespec *tp)
  *
  * @apitags{unrestricted}
  */
-COBALT_IMPL(int, clock_gettime, (clockid_t clock_id, struct timespec *tp))
+COBALT_IMPL_TIME64(int, clock_gettime, __clock_gettime64,
+		   (clockid_t clock_id, struct timespec *tp))
 {
 	int ret;
 
@@ -201,7 +203,8 @@ COBALT_IMPL(int, clock_gettime, (clockid_t clock_id, struct timespec *tp))
  *
  * @apitags{unrestricted, switch-secondary}
  */
-COBALT_IMPL(int, clock_settime, (clockid_t clock_id, const struct timespec *tp))
+COBALT_IMPL_TIME64(int, clock_settime, __clock_settime64,
+		   (clockid_t clock_id, const struct timespec *tp))
 {
 	int ret;
 
@@ -223,7 +226,8 @@ COBALT_IMPL(int, clock_settime, (clockid_t clock_id, const struct timespec *tp))
 
 /* @apitags{unrestricted} */
 
-COBALT_IMPL(int, clock_adjtime, (clockid_t clock_id, struct timex *tx))
+COBALT_IMPL_TIME64(int, clock_adjtime, __clock_adjtime64,
+		   (clockid_t clock_id, struct timex *tx))
 {
 	int ret;
 
@@ -281,9 +285,9 @@ COBALT_IMPL(int, clock_adjtime, (clockid_t clock_id, struct timex *tx))
  *
  * @apitags{xthread-only, switch-primary}
  */
-COBALT_IMPL(int, clock_nanosleep, (clockid_t clock_id,
-				   int flags,
-				   const struct timespec *rqtp, struct timespec *rmtp))
+COBALT_IMPL_TIME64(int, clock_nanosleep, __clock_nanosleep_time64,
+		   (clockid_t clock_id, int flags, const struct timespec *rqtp,
+		    struct timespec *rmtp))
 {
 	int ret, oldtype;
 
@@ -332,7 +336,8 @@ COBALT_IMPL(int, clock_nanosleep, (clockid_t clock_id,
  *
  * @apitags{xthread-only, switch-primary}
  */
-COBALT_IMPL(int, nanosleep, (const struct timespec *rqtp, struct timespec *rmtp))
+COBALT_IMPL_TIME64(int, nanosleep, __nanosleep64,
+		   (const struct timespec *rqtp, struct timespec *rmtp))
 {
 	int ret;
 
@@ -380,7 +385,8 @@ COBALT_IMPL(int, usleep, (useconds_t usec))
 
 /* @apitags{unrestricted} */
 
-COBALT_IMPL(int, gettimeofday, (struct timeval *tv, struct timezone *tz))
+COBALT_IMPL_TIME64(int, gettimeofday, __gettimeofday64,
+		   (struct timeval *tv, struct timezone *tz))
 {
 	struct timespec ts;
 	int ret = __WRAP(clock_gettime(CLOCK_REALTIME, &ts));
@@ -393,7 +399,7 @@ COBALT_IMPL(int, gettimeofday, (struct timeval *tv, struct timezone *tz))
 
 /* @apitags{unrestricted} */
 
-COBALT_IMPL(time_t, time, (time_t *t))
+COBALT_IMPL_TIME64(time_t, time, __time64, (time_t *t))
 {
 	struct timespec ts;
 	int ret = __WRAP(clock_gettime(CLOCK_REALTIME, &ts));
diff --git a/lib/cobalt/cobalt-glibc-time64.wrappers b/lib/cobalt/cobalt-glibc-time64.wrappers
new file mode 100644
index 000000000..0bf895ca9
--- /dev/null
+++ b/lib/cobalt/cobalt-glibc-time64.wrappers
@@ -0,0 +1,23 @@
+--wrap __sem_timedwait64
+--wrap __clock_gettime64
+--wrap __clock_settime64
+--wrap __clock_nanosleep_time64
+--wrap __clock_getres64
+--wrap __clock_adjtime64
+--wrap __pthread_mutex_timedlock64
+--wrap __mq_timedsend_time64
+--wrap __mq_timedreceive_time64
+--wrap __sigtimedwait64
+--wrap __recvmmsg64
+--wrap __pthread_cond_timedwait64
+--wrap __timer_settime64
+--wrap __timer_gettime64
+--wrap __timerfd_settime64
+--wrap __timerfd_gettime64
+--wrap __setsockopt64
+--wrap __getsockopt64
+--wrap __select64
+--wrap __ioctl_time64
+--wrap __gettimeofday64
+--wrap __time64
+--wrap __nanosleep64
diff --git a/lib/cobalt/cond.c b/lib/cobalt/cond.c
index 35b367a73..7f1906bf9 100644
--- a/lib/cobalt/cond.c
+++ b/lib/cobalt/cond.c
@@ -375,9 +375,9 @@ COBALT_IMPL(int, pthread_cond_wait, (pthread_cond_t *cond, pthread_mutex_t *mute
  *
  * @apitags{xthread-only, switch-primary}
  */
-COBALT_IMPL(int, pthread_cond_timedwait, (pthread_cond_t *cond,
-					  pthread_mutex_t *mutex,
-					  const struct timespec *abstime))
+COBALT_IMPL_TIME64(int, pthread_cond_timedwait, __pthread_cond_timedwait64,
+		   (pthread_cond_t *cond, pthread_mutex_t *mutex,
+		    const struct timespec *abstime))
 {
 	struct cobalt_cond_shadow *_cnd = &((union cobalt_cond_union *)cond)->shadow_cond;
 	struct cobalt_mutex_shadow *_mx =
diff --git a/lib/cobalt/mq.c b/lib/cobalt/mq.c
index 365a28e7a..117f05d3f 100644
--- a/lib/cobalt/mq.c
+++ b/lib/cobalt/mq.c
@@ -391,10 +391,9 @@ COBALT_IMPL(int, mq_send, (mqd_t q, const char *buffer, size_t len, unsigned pri
  *
  * @apitags{xthread-only, switch-primary}
  */
-COBALT_IMPL(int, mq_timedsend, (mqd_t q,
-				const char *buffer,
-				size_t len,
-				unsigned prio, const struct timespec *timeout))
+COBALT_IMPL_TIME64(int, mq_timedsend, __mq_timedsend_time64,
+		   (mqd_t q, const char *buffer, size_t len, unsigned prio,
+		    const struct timespec *timeout))
 {
 	int err, oldtype;
 
@@ -524,11 +523,10 @@ COBALT_IMPL(ssize_t, mq_receive, (mqd_t q, char *buffer, size_t len, unsigned *p
  *
  * @apitags{xthread-only, switch-primary}
  */
-COBALT_IMPL(ssize_t, mq_timedreceive, (mqd_t q,
-				       char *__restrict__ buffer,
-				       size_t len,
-				       unsigned *__restrict__ prio,
-				       const struct timespec * __restrict__ timeout))
+COBALT_IMPL_TIME64(ssize_t, mq_timedreceive, __mq_timedreceive_time64,
+		   (mqd_t q, char *__restrict__ buffer, size_t len,
+		    unsigned *__restrict__ prio,
+		    const struct timespec *__restrict__ timeout))
 {
 	ssize_t rlen = (ssize_t) len;
 	int err, oldtype;
diff --git a/lib/cobalt/mutex.c b/lib/cobalt/mutex.c
index 73e45a1c4..a578675f3 100644
--- a/lib/cobalt/mutex.c
+++ b/lib/cobalt/mutex.c
@@ -423,8 +423,8 @@ protect:
  *
  * @apitags{xthread-only, switch-primary}
  */
-COBALT_IMPL(int, pthread_mutex_timedlock, (pthread_mutex_t *mutex,
-					   const struct timespec *to))
+COBALT_IMPL_TIME64(int, pthread_mutex_timedlock, __pthread_mutex_timedlock64,
+		   (pthread_mutex_t *mutex, const struct timespec *to))
 {
 	struct cobalt_mutex_shadow *_mutex =
 		&((union cobalt_mutex_union *)mutex)->shadow_mutex;
diff --git a/lib/cobalt/rtdm.c b/lib/cobalt/rtdm.c
index 82323104a..98c8c679a 100644
--- a/lib/cobalt/rtdm.c
+++ b/lib/cobalt/rtdm.c
@@ -192,7 +192,8 @@ COBALT_IMPL(int, fcntl, (int fd, int cmd, ...))
 	return __STD(fcntl(fd, cmd, arg));
 }
 
-COBALT_IMPL(int, ioctl, (int fd, unsigned int request, ...))
+COBALT_IMPL_TIME64(int, ioctl, __ioctl_time64,
+		   (int fd, unsigned int request, ...))
 {
 	va_list ap;
 	void *arg;
@@ -265,8 +266,9 @@ COBALT_IMPL(ssize_t, recvmsg, (int fd, struct msghdr *msg, int flags))
 	return __STD(recvmsg(fd, msg, flags));
 }
 
-COBALT_IMPL(int, recvmmsg, (int fd, struct mmsghdr *msgvec, unsigned int vlen,
-			    unsigned int flags, struct timespec *timeout))
+COBALT_IMPL_TIME64(int, recvmmsg, __recvmmsg64,
+		   (int fd, struct mmsghdr *msgvec, unsigned int vlen,
+		    unsigned int flags, struct timespec *timeout))
 {
 	int ret, oldtype;
 
@@ -429,8 +431,9 @@ COBALT_IMPL(ssize_t, send, (int fd, const void *buf, size_t len, int flags))
 	return __STD(send(fd, buf, len, flags));
 }
 
-COBALT_IMPL(int, getsockopt, (int fd, int level, int optname, void *optval,
-			      socklen_t *optlen))
+COBALT_IMPL_TIME64(int, getsockopt, __getsockopt64,
+		   (int fd, int level, int optname, void *optval,
+		    socklen_t *optlen))
 {
 	struct _rtdm_getsockopt_args args = { level, optname, optval, optlen };
 	int ret;
@@ -442,8 +445,9 @@ COBALT_IMPL(int, getsockopt, (int fd, int level, int optname, void *optval,
 	return __STD(getsockopt(fd, level, optname, optval, optlen));
 }
 
-COBALT_IMPL(int, setsockopt, (int fd, int level, int optname, const void *optval,
-			      socklen_t optlen))
+COBALT_IMPL_TIME64(int, setsockopt, __setsockopt64,
+		   (int fd, int level, int optname, const void *optval,
+		    socklen_t optlen))
 {
 	struct _rtdm_setsockopt_args args = {
 		level, optname, (void *)optval, optlen
diff --git a/lib/cobalt/select.c b/lib/cobalt/select.c
index 7727012c7..9577fa256 100644
--- a/lib/cobalt/select.c
+++ b/lib/cobalt/select.c
@@ -20,12 +20,52 @@
 #include <pthread.h>
 #include <sys/select.h>
 #include <asm/xenomai/syscall.h>
-#include "internal.h"
 
-COBALT_IMPL(int, select, (int __nfds, fd_set *__restrict __readfds,
-			  fd_set *__restrict __writefds,
-			  fd_set *__restrict __exceptfds,
-			  struct timeval *__restrict __timeout))
+#if __USE_TIME_BITS64
+/*
+ * The time64 wrapper for select() is a little different:
+ * There is no y2038 safe syscall for select() itself, but we have pselect()
+ * without signal support.
+ */
+static inline int do_select(int __nfds, fd_set *__restrict __readfds,
+			      fd_set *__restrict __writefds,
+			      fd_set *__restrict __exceptfds,
+			      struct timeval *__restrict __timeout)
+{
+	struct timespec to;
+	int err, oldtype;
+
+	if (__timeout) {
+		to.tv_sec = __timeout->tv_sec;
+		to.tv_nsec = __timeout->tv_usec * 1000;
+	}
+
+	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype);
+
+	/*
+	 * Note: No sigmask here, we already reached the limit of 5
+	 * syscall parameters
+	 */
+	err = XENOMAI_SYSCALL5(sc_cobalt_pselect64, __nfds, __readfds,
+			       __writefds, __exceptfds, __timeout ? &to : NULL);
+
+	pthread_setcanceltype(oldtype, NULL);
+
+	if (err == -EADV || err == -EPERM || err == -ENOSYS)
+		err = __STD(__select64(__nfds, __readfds, __writefds,
+				       __exceptfds, __timeout));
+
+	if (err >= 0)
+		return err;
+
+	errno = -err;
+	return -1;
+}
+#else
+static inline int do_select(int __nfds, fd_set *__restrict __readfds,
+			    fd_set *__restrict __writefds,
+			    fd_set *__restrict __exceptfds,
+			    struct timeval *__restrict __timeout)
 {
 	int err, oldtype;
 
@@ -46,3 +86,13 @@ COBALT_IMPL(int, select, (int __nfds, fd_set *__restrict __readfds,
 	errno = -err;
 	return -1;
 }
+#endif
+
+COBALT_IMPL_TIME64(int, select, __select64,
+		   (int __nfds, fd_set *__restrict __readfds,
+		    fd_set *__restrict __writefds,
+		    fd_set *__restrict __exceptfds,
+		    struct timeval *__restrict __timeout))
+{
+	return do_select(__nfds, __readfds, __writefds, __exceptfds, __timeout);
+}
diff --git a/lib/cobalt/semaphore.c b/lib/cobalt/semaphore.c
index bff005440..b6652b763 100644
--- a/lib/cobalt/semaphore.c
+++ b/lib/cobalt/semaphore.c
@@ -362,7 +362,8 @@ COBALT_IMPL(int, sem_wait, (sem_t *sem))
  *
  * @apitags{xthread-only, switch-primary}
  */
-COBALT_IMPL(int, sem_timedwait, (sem_t *sem, const struct timespec *abs_timeout))
+COBALT_IMPL_TIME64(int, sem_timedwait, __sem_timedwait64,
+		   (sem_t *sem, const struct timespec *abs_timeout))
 {
 	struct cobalt_sem_shadow *_sem = &((union cobalt_sem_union *)sem)->shadow_sem;
 	int ret, oldtype;
diff --git a/lib/cobalt/signal.c b/lib/cobalt/signal.c
index 40d315ebb..d4bc2463d 100644
--- a/lib/cobalt/signal.c
+++ b/lib/cobalt/signal.c
@@ -55,8 +55,9 @@ COBALT_IMPL(int, sigwaitinfo, (const sigset_t *set, siginfo_t *si))
 	return ret;
 }
 
-COBALT_IMPL(int, sigtimedwait, (const sigset_t *set, siginfo_t *si,
-				const struct timespec *timeout))
+COBALT_IMPL_TIME64(int, sigtimedwait, __sigtimedwait64,
+		   (const sigset_t *set, siginfo_t *si,
+		    const struct timespec *timeout))
 {
 	int ret, oldtype;
 
diff --git a/lib/cobalt/timer.c b/lib/cobalt/timer.c
index d86d01417..e20d30e83 100644
--- a/lib/cobalt/timer.c
+++ b/lib/cobalt/timer.c
@@ -159,10 +159,10 @@ COBALT_IMPL(int, timer_delete, (timer_t timerid))
  *
  * @apitags{xcontext, switch-primary}
  */
-COBALT_IMPL(int, timer_settime, (timer_t timerid,
-				 int flags,
-				 const struct itimerspec *__restrict__ value,
-				 struct itimerspec *__restrict__ ovalue))
+COBALT_IMPL_TIME64(int, timer_settime, __timer_settime64,
+		   (timer_t timerid, int flags,
+		    const struct itimerspec *__restrict__ value,
+		    struct itimerspec *__restrict__ ovalue))
 {
 	int ret;
 
@@ -210,7 +210,8 @@ COBALT_IMPL(int, timer_settime, (timer_t timerid,
  *
  * @apitags{unrestricted}
  */
-COBALT_IMPL(int, timer_gettime, (timer_t timerid, struct itimerspec *value))
+COBALT_IMPL_TIME64(int, timer_gettime, __timer_gettime64,
+		   (timer_t timerid, struct itimerspec *value))
 {
 	int ret;
 
diff --git a/lib/cobalt/timerfd.c b/lib/cobalt/timerfd.c
index 5e7db928f..11e0b04e3 100644
--- a/lib/cobalt/timerfd.c
+++ b/lib/cobalt/timerfd.c
@@ -35,9 +35,9 @@ COBALT_IMPL(int, timerfd_create, (int clockid, int flags))
 	return fd;
 }
 
-COBALT_IMPL(int, timerfd_settime,
-	    (int fd, int flags, const struct itimerspec *new_value,
-	     struct itimerspec *old_value))
+COBALT_IMPL_TIME64(int, timerfd_settime, __timerfd_settime64,
+		   (int fd, int flags, const struct itimerspec *new_value,
+		    struct itimerspec *old_value))
 {
 	int ret;
 
@@ -55,7 +55,8 @@ COBALT_IMPL(int, timerfd_settime,
 	return -1;
 }
 
-COBALT_IMPL(int, timerfd_gettime, (int fd, struct itimerspec *curr_value))
+COBALT_IMPL_TIME64(int, timerfd_gettime, __timerfd_gettime64,
+		   (int fd, struct itimerspec *curr_value))
 {
 	int ret;
 
diff --git a/scripts/xeno-config-cobalt.in b/scripts/xeno-config-cobalt.in
index a093779b9..46b6c11b9 100644
--- a/scripts/xeno-config-cobalt.in
+++ b/scripts/xeno-config-cobalt.in
@@ -20,6 +20,7 @@ XENO_COBALT_LDFLAGS="-L${staging}${libdir} -lcobalt"
 XENO_POSIX_LDFLAGS="-lpthread -lrt @XENO_USER_APP_LDFLAGS@"
 XENO_LIBRARY_DIR="${staging}${libdir}"
 LD_FILE_OPTION="@LD_FILE_OPTION@"
+CONFIG_XENO_LIBS_TIME64="@CONFIG_XENO_LIBS_TIME64@"
 
 unset skin_list compat codegen
 
@@ -252,6 +253,10 @@ if test x$do_ldflags = xy; then
 	case "$skin" in
 	    posix|rtdm)
 		ldflags="`dump_wrappers cobalt.wrappers` $ldflags"
+
+		if test "$CONFIG_XENO_LIBS_TIME64" = "yes"; then
+			ldflags="$(dump_wrappers cobalt-glibc-time64.wrappers) $ldflags"
+		fi
 		;;
 	    cobalt)
 		# do NOT wrap POSIX symbols in application code with

-- 
2.39.2


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH v2 7/9] y2038: testsuite/smokey: Add some function wrapping tests
  2023-09-27 13:50 [PATCH v2 0/9] y2038: Finalize and enable y2038 support Florian Bezdeka
                   ` (5 preceding siblings ...)
  2023-09-27 13:50 ` [PATCH v2 6/9] y2038: lib/cobalt: Implement necessary wrappers for y2038 support Florian Bezdeka
@ 2023-09-27 13:50 ` Florian Bezdeka
  2023-09-27 13:50 ` [PATCH v2 8/9] lib/cobalt: Cleanup includes Florian Bezdeka
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 17+ messages in thread
From: Florian Bezdeka @ 2023-09-27 13:50 UTC (permalink / raw)
  To: xenomai, jan.kiszka; +Cc: Florian Bezdeka

Function wrapping in combination with the weak symbols that Xenomai
uses is a complex beast, especially when parts of the wrapping
machinery are allowed to be overwriting by application code.

Let's try to detect basic mistakes by extending the smokey testsuite
a bit.

Signed-off-by: Florian Bezdeka <florian.bezdeka@siemens.com>
---
 testsuite/smokey/y2038/syscall-tests.c | 47 ++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

diff --git a/testsuite/smokey/y2038/syscall-tests.c b/testsuite/smokey/y2038/syscall-tests.c
index 3d4a9106b..91ef5258e 100644
--- a/testsuite/smokey/y2038/syscall-tests.c
+++ b/testsuite/smokey/y2038/syscall-tests.c
@@ -1583,6 +1583,49 @@ out:
 	return test_pselect64_interruption();
 }
 
+static int test_function_wrapping(void)
+{
+#ifndef __USE_TIME_BITS64
+	/*
+	 * We're testing some functions here that are wrapped only for 32 bit
+	 * applications with y2038 support enabled. If that's not the case we
+	 * can simply bail out and simulate success.
+	 */
+	return 0;
+#else
+	struct timespec ts64 = { 0 };
+	int ret;
+
+	/*
+	 * If the nsec part of ts64 is still 0 it's a good indication that our
+	 * function wrapping does not work as expected. We retry up to three
+	 * times to avoid shaky test results.
+	 *
+	 * __STD(clock_gettime()) is replaced with
+	 * __real_clock_gettime() by the preprocessor. If
+	 * __real_clock_gettime() is not properly redirected by the use of
+	 * COBALT_DECL_TIME64() (linker magic) we will end up in the glibc
+	 * implementation with "native" time_t.
+	 */
+	for (int i = 0; i < 3; i++) {
+		ret = smokey_check_errno(
+			__STD(clock_gettime(CLOCK_REALTIME, &ts64)));
+		if (ret)
+			return ret;
+
+		if (ts64.tv_nsec != 0)
+			break;
+
+		if (i == 2) {
+			smokey_warning("Function wrapping seems broken.");
+			return -EINVAL;
+		}
+	}
+
+	return 0;
+#endif
+}
+
 static int check_kernel_version(void)
 {
 	int ret, major, minor;
@@ -1692,5 +1735,9 @@ static int run_y2038(struct smokey_test *t, int argc, char *const argv[])
 	if (ret)
 		return ret;
 
+	ret = test_function_wrapping();
+	if (ret)
+		return ret;
+
 	return 0;
 }

-- 
2.39.2


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH v2 8/9] lib/cobalt: Cleanup includes
  2023-09-27 13:50 [PATCH v2 0/9] y2038: Finalize and enable y2038 support Florian Bezdeka
                   ` (6 preceding siblings ...)
  2023-09-27 13:50 ` [PATCH v2 7/9] y2038: testsuite/smokey: Add some function wrapping tests Florian Bezdeka
@ 2023-09-27 13:50 ` Florian Bezdeka
  2023-09-27 13:50 ` [PATCH v2 9/9] lib/cobalt/wrappers.h: Remove duplicate definition of __stringify() Florian Bezdeka
  2023-09-28 16:25 ` [PATCH v2 0/9] y2038: Finalize and enable y2038 support Jan Kiszka
  9 siblings, 0 replies; 17+ messages in thread
From: Florian Bezdeka @ 2023-09-27 13:50 UTC (permalink / raw)
  To: xenomai, jan.kiszka; +Cc: Florian Bezdeka

- Add an empty line between license information and first include,
  that is what most files already did

- Cleanup unused / unnecessary includes where possible

Signed-off-by: Florian Bezdeka <florian.bezdeka@siemens.com>
---
 lib/cobalt/arch/x86/features.c | 1 -
 lib/cobalt/attr.c              | 4 ----
 lib/cobalt/clock.c             | 7 -------
 lib/cobalt/cond.c              | 1 +
 lib/cobalt/current.c           | 3 +--
 lib/cobalt/init.c              | 2 --
 lib/cobalt/internal.c          | 4 +---
 lib/cobalt/malloc-nowrap.c     | 1 +
 lib/cobalt/malloc.c            | 1 +
 lib/cobalt/mq.c                | 1 -
 lib/cobalt/mutex.c             | 2 +-
 lib/cobalt/parse_vdso.c        | 2 --
 lib/cobalt/rtdm.c              | 1 -
 lib/cobalt/sched.c             | 5 -----
 lib/cobalt/semaphore.c         | 1 -
 lib/cobalt/signal.c            | 4 +---
 lib/cobalt/sigshadow.c         | 1 +
 lib/cobalt/thread.c            | 2 --
 lib/cobalt/ticks.c             | 1 +
 lib/cobalt/timer.c             | 1 +
 lib/cobalt/timerfd.c           | 2 +-
 lib/cobalt/umm.c               | 7 +------
 lib/cobalt/umm.h               | 2 --
 23 files changed, 12 insertions(+), 44 deletions(-)

diff --git a/lib/cobalt/arch/x86/features.c b/lib/cobalt/arch/x86/features.c
index e7e62da39..8c5332b9e 100644
--- a/lib/cobalt/arch/x86/features.c
+++ b/lib/cobalt/arch/x86/features.c
@@ -18,7 +18,6 @@
 
 #include <stdio.h>
 #include <unistd.h>
-#include <stdlib.h>
 #include <string.h>
 #include <boilerplate/atomic.h>
 #include <asm/xenomai/features.h>
diff --git a/lib/cobalt/attr.c b/lib/cobalt/attr.c
index 586de928b..5de2363f7 100644
--- a/lib/cobalt/attr.c
+++ b/lib/cobalt/attr.c
@@ -16,12 +16,8 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
  */
 
-#include <stddef.h>
-#include <errno.h>
 #include <pthread.h>
 #include <memory.h>
-#include <cobalt/uapi/thread.h>
-#include "internal.h"
 
 COBALT_IMPL(int, pthread_attr_init, (pthread_attr_t *attr))
 {
diff --git a/lib/cobalt/clock.c b/lib/cobalt/clock.c
index 9289d8787..65abf5eac 100644
--- a/lib/cobalt/clock.c
+++ b/lib/cobalt/clock.c
@@ -16,20 +16,13 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
  */
 
-#include <sys/types.h>
-#include <stdio.h>
-#include <stdlib.h>
 #include <string.h>
 #include <errno.h>
-#include <stdint.h>
 #include <pthread.h>
 #include <unistd.h>
 #include <time.h>
 #include <sys/time.h>
-#include <cobalt/uapi/time.h>
-#include <cobalt/ticks.h>
 #include <asm/xenomai/syscall.h>
-#include "umm.h"
 #include "internal.h"
 
 /**
diff --git a/lib/cobalt/cond.c b/lib/cobalt/cond.c
index 7f1906bf9..301dabdca 100644
--- a/lib/cobalt/cond.c
+++ b/lib/cobalt/cond.c
@@ -15,6 +15,7 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
  */
+
 #include <errno.h>
 #include <string.h>
 #include <pthread.h>
diff --git a/lib/cobalt/current.c b/lib/cobalt/current.c
index 7d6ee9fd8..1e1535004 100644
--- a/lib/cobalt/current.c
+++ b/lib/cobalt/current.c
@@ -15,8 +15,7 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
  */
-#include <stdlib.h>
-#include <stdio.h>
+
 #include <string.h>
 #include <pthread.h>
 #include <asm/xenomai/syscall.h>
diff --git a/lib/cobalt/init.c b/lib/cobalt/init.c
index 7aa7c48de..84f37999d 100644
--- a/lib/cobalt/init.c
+++ b/lib/cobalt/init.c
@@ -29,8 +29,6 @@
 #include <stdint.h>
 #include <semaphore.h>
 #include <boilerplate/setup.h>
-#include <cobalt/uapi/kernel/heap.h>
-#include <cobalt/ticks.h>
 #include <cobalt/tunables.h>
 #include <asm/xenomai/syscall.h>
 #include <xenomai/init.h>
diff --git a/lib/cobalt/internal.c b/lib/cobalt/internal.c
index b9f518ed1..d721e7ec6 100644
--- a/lib/cobalt/internal.c
+++ b/lib/cobalt/internal.c
@@ -20,10 +20,9 @@
  * Internal Cobalt services. No sanity check will be done with
  * respect to object validity, callers have to take care of this.
  */
+
 #include <sys/types.h>
 #include <stddef.h>
-#include <stdlib.h>
-#include <limits.h>
 #include <stdio.h>
 #include <unistd.h>
 #include <signal.h>
@@ -31,7 +30,6 @@
 #include <stdarg.h>
 #include <pthread.h>
 #include <asm/xenomai/syscall.h>
-#include <cobalt/ticks.h>
 #include <cobalt/sys/cobalt.h>
 #include "internal.h"
 
diff --git a/lib/cobalt/malloc-nowrap.c b/lib/cobalt/malloc-nowrap.c
index 416fbad73..6dda7667d 100644
--- a/lib/cobalt/malloc-nowrap.c
+++ b/lib/cobalt/malloc-nowrap.c
@@ -15,6 +15,7 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
  */
+
 #include <stdlib.h>
 
 __weak
diff --git a/lib/cobalt/malloc.c b/lib/cobalt/malloc.c
index 82f89fd13..c1585586e 100644
--- a/lib/cobalt/malloc.c
+++ b/lib/cobalt/malloc.c
@@ -15,6 +15,7 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
  */
+
 #include <stdlib.h>
 #include <cobalt/sys/cobalt.h>
 
diff --git a/lib/cobalt/mq.c b/lib/cobalt/mq.c
index 117f05d3f..88e6e9fbf 100644
--- a/lib/cobalt/mq.c
+++ b/lib/cobalt/mq.c
@@ -23,7 +23,6 @@
 #include <pthread.h>
 #include <mqueue.h>
 #include <asm/xenomai/syscall.h>
-#include "internal.h"
 
 /**
  * @ingroup cobalt_api
diff --git a/lib/cobalt/mutex.c b/lib/cobalt/mutex.c
index a578675f3..54f6b8461 100644
--- a/lib/cobalt/mutex.c
+++ b/lib/cobalt/mutex.c
@@ -15,9 +15,9 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
  */
+
 #include <errno.h>
 #include <string.h>
-#include <limits.h>
 #include <pthread.h>
 #include <asm/xenomai/syscall.h>
 #include "current.h"
diff --git a/lib/cobalt/parse_vdso.c b/lib/cobalt/parse_vdso.c
index 339e4d564..766f90fad 100644
--- a/lib/cobalt/parse_vdso.c
+++ b/lib/cobalt/parse_vdso.c
@@ -15,10 +15,8 @@
  * architecture that has a vDSO.
  */
 
-#include <sys/types.h>
 #include <sys/auxv.h>
 #include <stdbool.h>
-#include <stdint.h>
 #include <string.h>
 #include <limits.h>
 #include <pthread.h>
diff --git a/lib/cobalt/rtdm.c b/lib/cobalt/rtdm.c
index 98c8c679a..00c1aaf4b 100644
--- a/lib/cobalt/rtdm.c
+++ b/lib/cobalt/rtdm.c
@@ -29,7 +29,6 @@
 #include <rtdm/rtdm.h>
 #include <cobalt/uapi/syscall.h>
 #include <asm/xenomai/syscall.h>
-#include "internal.h"
 
 /* support for very old c libraries not supporting O_TMPFILE */
 #ifndef O_TMPFILE
diff --git a/lib/cobalt/sched.c b/lib/cobalt/sched.c
index bdb8603da..6e61ee407 100644
--- a/lib/cobalt/sched.c
+++ b/lib/cobalt/sched.c
@@ -17,14 +17,9 @@
  */
 
 #include <stddef.h>
-#include <stdlib.h>
-#include <string.h>
 #include <errno.h>
-#include <signal.h>
 #include <unistd.h>
 #include <pthread.h>
-#include <sys/types.h>
-#include <semaphore.h>
 #include <asm/xenomai/syscall.h>
 #include "internal.h"
 
diff --git a/lib/cobalt/semaphore.c b/lib/cobalt/semaphore.c
index b6652b763..0c1a245cd 100644
--- a/lib/cobalt/semaphore.c
+++ b/lib/cobalt/semaphore.c
@@ -23,7 +23,6 @@
 #include <pthread.h>		/* For pthread_setcanceltype. */
 #include <semaphore.h>
 #include <asm/xenomai/syscall.h>
-#include <cobalt/uapi/sem.h>
 #include "internal.h"
 
 /**
diff --git a/lib/cobalt/signal.c b/lib/cobalt/signal.c
index d4bc2463d..6e40a3680 100644
--- a/lib/cobalt/signal.c
+++ b/lib/cobalt/signal.c
@@ -15,15 +15,13 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
  */
+
 #include <stdlib.h>
-#include <stdarg.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <pthread.h>
 #include <signal.h>
-#include <cobalt/uapi/signal.h>
 #include <asm/xenomai/syscall.h>
-#include "internal.h"
 
 COBALT_IMPL(int, sigwait, (const sigset_t *set, int *sig))
 {
diff --git a/lib/cobalt/sigshadow.c b/lib/cobalt/sigshadow.c
index 68d3e6276..b03703526 100644
--- a/lib/cobalt/sigshadow.c
+++ b/lib/cobalt/sigshadow.c
@@ -15,6 +15,7 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
  */
+
 #include <pthread.h>
 #include <signal.h>
 #include <asm/xenomai/syscall.h>
diff --git a/lib/cobalt/thread.c b/lib/cobalt/thread.c
index bb23cdcb9..dee39a8d4 100644
--- a/lib/cobalt/thread.c
+++ b/lib/cobalt/thread.c
@@ -17,10 +17,8 @@
  */
 
 #include <stddef.h>
-#include <stdlib.h>
 #include <string.h>
 #include <errno.h>
-#include <signal.h>
 #include <unistd.h>
 #include <pthread.h>
 #include <sys/types.h>
diff --git a/lib/cobalt/ticks.c b/lib/cobalt/ticks.c
index a6792389c..214f2a1a8 100644
--- a/lib/cobalt/ticks.c
+++ b/lib/cobalt/ticks.c
@@ -15,6 +15,7 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
  */
+
 #include <cobalt/arith.h>
 #include <cobalt/ticks.h>
 #include <asm/xenomai/time.h>
diff --git a/lib/cobalt/timer.c b/lib/cobalt/timer.c
index e20d30e83..a9f91dfc9 100644
--- a/lib/cobalt/timer.c
+++ b/lib/cobalt/timer.c
@@ -15,6 +15,7 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
  */
+
 #include <errno.h>
 #include <time.h>
 #include <asm/xenomai/syscall.h>
diff --git a/lib/cobalt/timerfd.c b/lib/cobalt/timerfd.c
index 11e0b04e3..70e9a4e07 100644
--- a/lib/cobalt/timerfd.c
+++ b/lib/cobalt/timerfd.c
@@ -15,9 +15,9 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
  */
+
 #include <errno.h>
 #include <unistd.h>
-#include <fcntl.h>
 #include <sys/timerfd.h>
 #include <asm/xenomai/syscall.h>
 #include "internal.h"
diff --git a/lib/cobalt/umm.c b/lib/cobalt/umm.c
index 555bee847..c0d4489d3 100644
--- a/lib/cobalt/umm.c
+++ b/lib/cobalt/umm.c
@@ -15,22 +15,17 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
  */
+
 #include <sys/types.h>
-#include <sys/stat.h>
 #include <sys/ioctl.h>
 #include <sys/mman.h>
-#include <stdio.h>
 #include <errno.h>
-#include <stdlib.h>
-#include <stdint.h>
 #include <string.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <pthread.h>
 #include <rtdm/rtdm.h>
 #include <cobalt/uapi/kernel/heap.h>
-#include <asm/xenomai/syscall.h>
-#include "current.h"
 #include "umm.h"
 #include "internal.h"
 
diff --git a/lib/cobalt/umm.h b/lib/cobalt/umm.h
index 7705f9cf9..a298e8369 100644
--- a/lib/cobalt/umm.h
+++ b/lib/cobalt/umm.h
@@ -18,8 +18,6 @@
 #ifndef _LIB_COBALT_UMM_H
 #define _LIB_COBALT_UMM_H
 
-#include <linux/types.h>
-
 void cobalt_init_umm(void);
 
 void cobalt_unmap_umm(void);

-- 
2.39.2


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH v2 9/9] lib/cobalt/wrappers.h: Remove duplicate definition of __stringify()
  2023-09-27 13:50 [PATCH v2 0/9] y2038: Finalize and enable y2038 support Florian Bezdeka
                   ` (7 preceding siblings ...)
  2023-09-27 13:50 ` [PATCH v2 8/9] lib/cobalt: Cleanup includes Florian Bezdeka
@ 2023-09-27 13:50 ` Florian Bezdeka
  2023-09-28 16:25 ` [PATCH v2 0/9] y2038: Finalize and enable y2038 support Jan Kiszka
  9 siblings, 0 replies; 17+ messages in thread
From: Florian Bezdeka @ 2023-09-27 13:50 UTC (permalink / raw)
  To: xenomai, jan.kiszka; +Cc: Florian Bezdeka

__stringify() is already defined in boilerplate/compiler.h which is
included a few lines above.

Signed-off-by: Florian Bezdeka <florian.bezdeka@siemens.com>
---
 include/cobalt/wrappers.h | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/include/cobalt/wrappers.h b/include/cobalt/wrappers.h
index 21f4ceacb..4fcb1c3b9 100644
--- a/include/cobalt/wrappers.h
+++ b/include/cobalt/wrappers.h
@@ -20,9 +20,6 @@
 
 #include <boilerplate/compiler.h>
 
-#define __stringify_1(x...)	#x
-#define __stringify(x...)	__stringify_1(x)
-
 #define __WRAP(call)		__wrap_ ## call
 #define __STD(call)		__real_ ## call
 #define __COBALT(call)		__cobalt_ ## call

-- 
2.39.2


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: [PATCH v2 0/9] y2038: Finalize and enable y2038 support
  2023-09-27 13:50 [PATCH v2 0/9] y2038: Finalize and enable y2038 support Florian Bezdeka
                   ` (8 preceding siblings ...)
  2023-09-27 13:50 ` [PATCH v2 9/9] lib/cobalt/wrappers.h: Remove duplicate definition of __stringify() Florian Bezdeka
@ 2023-09-28 16:25 ` Jan Kiszka
  2023-09-28 17:31   ` Jan Kiszka
  2023-09-29  7:45   ` Florian Bezdeka
  9 siblings, 2 replies; 17+ messages in thread
From: Jan Kiszka @ 2023-09-28 16:25 UTC (permalink / raw)
  To: Florian Bezdeka, xenomai

On 27.09.23 15:50, Florian Bezdeka wrote:
> Hi all,
>     
> this is the final y2038 related patch series. With this series applied
> y2038 support will be enabled by default for all affected
> builds/architectures.
> 
> There is a kill switch (--disable-y2038) available in case unexpected
> problems come up after merge but that is not expected. The y2038 queue
> was regularly tested over the last two years now.
>     
> Short summary:
>   - Implement y2038 safe ioctls around SO_RCVTIMEO and SO_SNDTIMEO
>   - Enable additional function wrapping
>   - Fix some smokey tests (reading of reference clocks)
> 
> Fingers crossed, seems the y2038 issue is solved now.
> 

Thanks, this is sure a major step forward!

How confident are your that all these now possible combinations are
still tested? Our CI will run with y2038 enabled, right? How is the
disabled case tested, at least build-wise? Or the case "unsupported by OS"?

Jan

-- 
Siemens AG, Technology
Linux Expert Center


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v2 1/9] y2038: kernel/drivers: Implement SO_RCVTIMEO_NEW and SO_SNDTIMEO_NEW
  2023-09-27 13:50 ` [PATCH v2 1/9] y2038: kernel/drivers: Implement SO_RCVTIMEO_NEW and SO_SNDTIMEO_NEW Florian Bezdeka
@ 2023-09-28 17:00   ` Jan Kiszka
  0 siblings, 0 replies; 17+ messages in thread
From: Jan Kiszka @ 2023-09-28 17:00 UTC (permalink / raw)
  To: Florian Bezdeka, xenomai

On 27.09.23 15:50, Florian Bezdeka wrote:
> When requesting y2038 support from recent glibc versions SO_RCVTIMEO and
> SO_SNDTIMEO will be auto-converted to the _NEW variants to make clear
> that we have to deal with a different (now y2038 safe) ABI.
> 
> Implementing SO_RCVTIMEO_NEW and SO_SNDTIMEO_NEW where necessary.
> 
> Signed-off-by: Florian Bezdeka <florian.bezdeka@siemens.com>
> ---
>  kernel/drivers/ipc/bufp.c               | 34 +++++++++++++++++++++++++++++++++
>  kernel/drivers/ipc/iddp.c               | 34 +++++++++++++++++++++++++++++++++
>  kernel/drivers/ipc/internal.h           | 27 ++++++++++++++++++++++++++
>  kernel/drivers/ipc/rtipc.c              | 29 ++++++++++++++++++++++++++++
>  kernel/drivers/ipc/xddp.c               | 18 +++++++++++++++++
>  kernel/drivers/net/stack/ipv4/tcp/tcp.c | 31 ++++++++++++++++++++++++++++++
>  6 files changed, 173 insertions(+)
> 
> diff --git a/kernel/drivers/ipc/bufp.c b/kernel/drivers/ipc/bufp.c
> index 565409dd6..f1936d846 100644
> --- a/kernel/drivers/ipc/bufp.c
> +++ b/kernel/drivers/ipc/bufp.c
> @@ -824,6 +824,7 @@ static int __bufp_setsockopt(struct bufp_socket *sk,
>  			     void *arg)
>  {
>  	struct _rtdm_setsockopt_args sopt;
> +	struct __kernel_sock_timeval stv;
>  	struct rtipc_port_label plabel;
>  	struct __kernel_old_timeval tv;
>  	rtdm_lockctx_t s;
> @@ -844,6 +845,14 @@ static int __bufp_setsockopt(struct bufp_socket *sk,
>  			sk->rx_timeout = rtipc_timeval_to_ns(&tv);
>  			break;
>  
> +		case SO_RCVTIMEO_NEW:
> +			ret = rtipc_get_sock_timeval(fd, &stv, sopt.optval,
> +						     sopt.optlen);
> +			if (ret)
> +				return ret;
> +			sk->rx_timeout = rtipc_sock_timeval_to_ns(&stv);
> +			break;
> +
>  		case SO_SNDTIMEO_OLD:
>  			ret = rtipc_get_timeval(fd, &tv, sopt.optval, sopt.optlen);
>  			if (ret)
> @@ -851,6 +860,14 @@ static int __bufp_setsockopt(struct bufp_socket *sk,
>  			sk->tx_timeout = rtipc_timeval_to_ns(&tv);
>  			break;
>  
> +		case SO_SNDTIMEO_NEW:
> +			ret = rtipc_get_sock_timeval(fd, &stv, sopt.optval,
> +						     sopt.optlen);
> +			if (ret)
> +				return ret;
> +			sk->tx_timeout = rtipc_sock_timeval_to_ns(&stv);
> +			break;
> +
>  		default:
>  			ret = -EINVAL;
>  		}
> @@ -913,6 +930,7 @@ static int __bufp_getsockopt(struct bufp_socket *sk,
>  			     void *arg)
>  {
>  	struct _rtdm_getsockopt_args sopt;
> +	struct __kernel_sock_timeval stv;
>  	struct rtipc_port_label plabel;
>  	struct __kernel_old_timeval tv;
>  	rtdm_lockctx_t s;
> @@ -936,6 +954,14 @@ static int __bufp_getsockopt(struct bufp_socket *sk,
>  				return ret;
>  			break;
>  
> +		case SO_RCVTIMEO_NEW:
> +			rtipc_ns_to_sock_timeval(&stv, sk->rx_timeout);
> +			ret = rtipc_put_sock_timeval(fd, sopt.optval, &stv,
> +						     len);
> +			if (ret)
> +				return ret;
> +			break;
> +
>  		case SO_SNDTIMEO_OLD:
>  			rtipc_ns_to_timeval(&tv, sk->tx_timeout);
>  			ret = rtipc_put_timeval(fd, sopt.optval, &tv, len);
> @@ -943,6 +969,14 @@ static int __bufp_getsockopt(struct bufp_socket *sk,
>  				return ret;
>  			break;
>  
> +		case SO_SNDTIMEO_NEW:
> +			rtipc_ns_to_sock_timeval(&stv, sk->tx_timeout);
> +			ret = rtipc_put_sock_timeval(fd, sopt.optval, &stv,
> +						     len);
> +			if (ret)
> +				return ret;
> +			break;
> +
>  		default:
>  			ret = -EINVAL;
>  		}
> diff --git a/kernel/drivers/ipc/iddp.c b/kernel/drivers/ipc/iddp.c
> index 05d019339..e4893a378 100644
> --- a/kernel/drivers/ipc/iddp.c
> +++ b/kernel/drivers/ipc/iddp.c
> @@ -704,6 +704,7 @@ static int __iddp_setsockopt(struct iddp_socket *sk,
>  			     void *arg)
>  {
>  	struct _rtdm_setsockopt_args sopt;
> +	struct __kernel_sock_timeval stv;
>  	struct rtipc_port_label plabel;
>  	struct __kernel_old_timeval tv;
>  	rtdm_lockctx_t s;
> @@ -724,6 +725,14 @@ static int __iddp_setsockopt(struct iddp_socket *sk,
>  			sk->rx_timeout = rtipc_timeval_to_ns(&tv);
>  			break;
>  
> +		case SO_RCVTIMEO_NEW:
> +			ret = rtipc_get_sock_timeval(fd, &stv, sopt.optval,
> +						     sopt.optlen);
> +			if (ret)
> +				return ret;
> +			sk->rx_timeout = rtipc_sock_timeval_to_ns(&stv);
> +			break;
> +
>  		case SO_SNDTIMEO_OLD:
>  			ret = rtipc_get_timeval(fd, &tv, sopt.optval, sopt.optlen);
>  			if (ret)
> @@ -731,6 +740,14 @@ static int __iddp_setsockopt(struct iddp_socket *sk,
>  			sk->tx_timeout = rtipc_timeval_to_ns(&tv);
>  			break;
>  
> +		case SO_SNDTIMEO_NEW:
> +			ret = rtipc_get_sock_timeval(fd, &stv, sopt.optval,
> +						     sopt.optlen);
> +			if (ret)
> +				return ret;
> +			sk->tx_timeout = rtipc_sock_timeval_to_ns(&stv);
> +			break;
> +
>  		default:
>  			ret = -EINVAL;
>  		}
> @@ -793,6 +810,7 @@ static int __iddp_getsockopt(struct iddp_socket *sk,
>  			     void *arg)
>  {
>  	struct _rtdm_getsockopt_args sopt;
> +	struct __kernel_sock_timeval stv;
>  	struct rtipc_port_label plabel;
>  	struct __kernel_old_timeval tv;
>  	rtdm_lockctx_t s;
> @@ -817,6 +835,14 @@ static int __iddp_getsockopt(struct iddp_socket *sk,
>  				return ret;
>  			break;
>  
> +		case SO_RCVTIMEO_NEW:
> +			rtipc_ns_to_sock_timeval(&stv, sk->rx_timeout);
> +			ret = rtipc_put_sock_timeval(fd, sopt.optval, &stv,
> +						     len);
> +			if (ret)
> +				return ret;
> +			break;
> +
>  		case SO_SNDTIMEO_OLD:
>  			rtipc_ns_to_timeval(&tv, sk->tx_timeout);
>  			ret = rtipc_put_timeval(fd, sopt.optval, &tv, len);
> @@ -824,6 +850,14 @@ static int __iddp_getsockopt(struct iddp_socket *sk,
>  				return ret;
>  			break;
>  
> +		case SO_SNDTIMEO_NEW:
> +			rtipc_ns_to_sock_timeval(&stv, sk->tx_timeout);
> +			ret = rtipc_put_sock_timeval(fd, sopt.optval, &stv,
> +						     len);
> +			if (ret)
> +				return ret;
> +			break;
> +
>  		default:
>  			ret = -EINVAL;
>  		}
> diff --git a/kernel/drivers/ipc/internal.h b/kernel/drivers/ipc/internal.h
> index 919a5d978..f29ba2204 100644
> --- a/kernel/drivers/ipc/internal.h
> +++ b/kernel/drivers/ipc/internal.h
> @@ -76,6 +76,17 @@ static inline nanosecs_rel_t rtipc_timeval_to_ns(const struct __kernel_old_timev
>  	return ns;
>  }
>  
> +static inline nanosecs_rel_t
> +rtipc_sock_timeval_to_ns(const struct __kernel_sock_timeval *tv)
> +{
> +	nanosecs_rel_t ns = tv->tv_usec * 1000;
> +
> +	if (tv->tv_sec)
> +		ns += (nanosecs_rel_t)tv->tv_sec * 1000000000UL;
> +
> +	return ns;
> +}
> +
>  static inline void rtipc_ns_to_timeval(struct __kernel_old_timeval *tv, nanosecs_rel_t ns)
>  {
>  	unsigned long nsecs;
> @@ -84,6 +95,15 @@ static inline void rtipc_ns_to_timeval(struct __kernel_old_timeval *tv, nanosecs
>  	tv->tv_usec = nsecs / 1000;
>  }
>  
> +static inline void rtipc_ns_to_sock_timeval(struct __kernel_sock_timeval *tv,
> +					    nanosecs_rel_t ns)
> +{
> +	unsigned long nsecs;
> +
> +	tv->tv_sec = xnclock_divrem_billion(ns, &nsecs);
> +	tv->tv_usec = nsecs / 1000;
> +}
> +
>  int rtipc_get_sockaddr(struct rtdm_fd *fd,
>  		       struct sockaddr_ipc **saddrp,
>  		       const void *arg);
> @@ -105,9 +125,16 @@ int rtipc_get_sockoptin(struct rtdm_fd *fd,
>  int rtipc_get_timeval(struct rtdm_fd *fd, struct __kernel_old_timeval *tv,
>  		      const void *arg, size_t arglen);
>  
> +int rtipc_get_sock_timeval(struct rtdm_fd *fd, struct __kernel_sock_timeval *tv,
> +			   const void *arg, size_t arglen);
> +
>  int rtipc_put_timeval(struct rtdm_fd *fd, void *arg,
>  		      const struct __kernel_old_timeval *tv, size_t arglen);
>  
> +int rtipc_put_sock_timeval(struct rtdm_fd *fd, void *arg,
> +			   const struct __kernel_sock_timeval *tv,
> +			   size_t arglen);
> +
>  int rtipc_get_length(struct rtdm_fd *fd, size_t *lenp,
>  		     const void *arg, size_t arglen);
>  
> diff --git a/kernel/drivers/ipc/rtipc.c b/kernel/drivers/ipc/rtipc.c
> index 211b496ec..66176adad 100644
> --- a/kernel/drivers/ipc/rtipc.c
> +++ b/kernel/drivers/ipc/rtipc.c
> @@ -290,6 +290,20 @@ int rtipc_get_timeval(struct rtdm_fd *fd, struct __kernel_old_timeval *tv,
>  	return rtdm_safe_copy_from_user(fd, tv, arg, sizeof(*tv));
>  }
>  
> +int rtipc_get_sock_timeval(struct rtdm_fd *fd, struct __kernel_sock_timeval *tv,
> +			   const void *arg, size_t arglen)
> +{
> +	if (arglen != sizeof(*tv))
> +		return -EINVAL;
> +
> +	if (!rtdm_fd_is_user(fd)) {
> +		*tv = *(struct __kernel_sock_timeval *)arg;
> +		return 0;
> +	}
> +
> +	return rtdm_safe_copy_from_user(fd, tv, arg, sizeof(*tv));
> +}
> +
>  int rtipc_put_timeval(struct rtdm_fd *fd, void *arg,
>  		      const struct __kernel_old_timeval *tv, size_t arglen)
>  {
> @@ -312,6 +326,21 @@ int rtipc_put_timeval(struct rtdm_fd *fd, void *arg,
>  	return rtdm_safe_copy_to_user(fd, arg, tv, sizeof(*tv));
>  }
>  
> +int rtipc_put_sock_timeval(struct rtdm_fd *fd, void *arg,
> +			   const struct __kernel_sock_timeval *tv,
> +			   size_t arglen)
> +{
> +	if (arglen != sizeof(*tv))
> +		return -EINVAL;
> +
> +	if (!rtdm_fd_is_user(fd)) {
> +		*(struct __kernel_sock_timeval *)arg = *tv;
> +		return 0;
> +	}
> +
> +	return rtdm_safe_copy_to_user(fd, arg, tv, sizeof(*tv));
> +}
> +
>  int rtipc_get_length(struct rtdm_fd *fd, size_t *lenp,
>  		     const void *arg, size_t arglen)
>  {
> diff --git a/kernel/drivers/ipc/xddp.c b/kernel/drivers/ipc/xddp.c
> index 2ca0da5fd..8f1b2ece7 100644
> --- a/kernel/drivers/ipc/xddp.c
> +++ b/kernel/drivers/ipc/xddp.c
> @@ -859,6 +859,7 @@ static int __xddp_setsockopt(struct xddp_socket *sk,
>  {
>  	int (*monitor)(struct rtdm_fd *fd, int event, long arg);
>  	struct _rtdm_setsockopt_args sopt;
> +	struct __kernel_sock_timeval stv;
>  	struct rtipc_port_label plabel;
>  	struct __kernel_old_timeval tv;
>  	rtdm_lockctx_t s;
> @@ -879,6 +880,14 @@ static int __xddp_setsockopt(struct xddp_socket *sk,
>  			sk->timeout = rtipc_timeval_to_ns(&tv);
>  			break;
>  
> +		case SO_RCVTIMEO_NEW:
> +			ret = rtipc_get_sock_timeval(fd, &stv, sopt.optval,
> +						     sopt.optlen);
> +			if (ret)
> +				return ret;
> +
> +			sk->timeout = rtipc_sock_timeval_to_ns(&stv);
> +			break;
>  		default:
>  			ret = -EINVAL;
>  		}
> @@ -965,6 +974,7 @@ static int __xddp_getsockopt(struct xddp_socket *sk,
>  			     void *arg)
>  {
>  	struct _rtdm_getsockopt_args sopt;
> +	struct __kernel_sock_timeval stv;
>  	struct rtipc_port_label plabel;
>  	struct __kernel_old_timeval tv;
>  	rtdm_lockctx_t s;
> @@ -988,6 +998,14 @@ static int __xddp_getsockopt(struct xddp_socket *sk,
>  				return ret;
>  			break;
>  
> +		case SO_RCVTIMEO_NEW:
> +			rtipc_ns_to_sock_timeval(&stv, sk->timeout);
> +			ret = rtipc_put_sock_timeval(fd, sopt.optval, &stv,
> +						     len);
> +			if (ret)
> +				return ret;
> +			break;
> +
>  		default:
>  			ret = -EINVAL;
>  		}
> diff --git a/kernel/drivers/net/stack/ipv4/tcp/tcp.c b/kernel/drivers/net/stack/ipv4/tcp/tcp.c
> index 71628ba03..5bd114530 100644
> --- a/kernel/drivers/net/stack/ipv4/tcp/tcp.c
> +++ b/kernel/drivers/net/stack/ipv4/tcp/tcp.c
> @@ -1743,6 +1743,7 @@ static int rt_tcp_setsockopt(struct rtdm_fd *fd, struct tcp_socket *ts,
>  			     socklen_t optlen)
>  {
>  	/* uint64_t val; */
> +	struct __kernel_sock_timeval stv;
>  	struct __kernel_old_timeval tv;
>  	rtdm_lockctx_t context;
>  
> @@ -1793,6 +1794,36 @@ static int rt_tcp_setsockopt(struct rtdm_fd *fd, struct tcp_socket *ts,
>  
>  		return 0;
>  
> +	case SO_SNDTIMEO_NEW:
> +		if (optlen < sizeof(stv))
> +			return -EINVAL;
> +		if (rtdm_copy_from_user(fd, &stv, optval, sizeof(stv)))
> +			return -EFAULT;
> +		if (stv.tv_usec < 0 || stv.tv_usec >= 1000000)

(u64)tv_usec >= 1000000

But you are using a preexisting pattern, we can optimize on top.

Jan

-- 
Siemens AG, Technology
Linux Expert Center


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v2 0/9] y2038: Finalize and enable y2038 support
  2023-09-28 16:25 ` [PATCH v2 0/9] y2038: Finalize and enable y2038 support Jan Kiszka
@ 2023-09-28 17:31   ` Jan Kiszka
  2023-09-29  7:45   ` Florian Bezdeka
  1 sibling, 0 replies; 17+ messages in thread
From: Jan Kiszka @ 2023-09-28 17:31 UTC (permalink / raw)
  To: Florian Bezdeka, xenomai

On 28.09.23 18:25, Jan Kiszka wrote:
> On 27.09.23 15:50, Florian Bezdeka wrote:
>> Hi all,
>>     
>> this is the final y2038 related patch series. With this series applied
>> y2038 support will be enabled by default for all affected
>> builds/architectures.
>>
>> There is a kill switch (--disable-y2038) available in case unexpected
>> problems come up after merge but that is not expected. The y2038 queue
>> was regularly tested over the last two years now.
>>     
>> Short summary:
>>   - Implement y2038 safe ioctls around SO_RCVTIMEO and SO_SNDTIMEO
>>   - Enable additional function wrapping
>>   - Fix some smokey tests (reading of reference clocks)
>>
>> Fingers crossed, seems the y2038 issue is solved now.
>>
> 
> Thanks, this is sure a major step forward!
> 
> How confident are your that all these now possible combinations are
> still tested? Our CI will run with y2038 enabled, right? How is the
> disabled case tested, at least build-wise? Or the case "unsupported by OS"?
> 

I already applied this to next to let the tests run.

Jan

-- 
Siemens AG, Technology
Linux Expert Center


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v2 0/9] y2038: Finalize and enable y2038 support
  2023-09-28 16:25 ` [PATCH v2 0/9] y2038: Finalize and enable y2038 support Jan Kiszka
  2023-09-28 17:31   ` Jan Kiszka
@ 2023-09-29  7:45   ` Florian Bezdeka
  2023-09-29  8:14     ` Jan Kiszka
  1 sibling, 1 reply; 17+ messages in thread
From: Florian Bezdeka @ 2023-09-29  7:45 UTC (permalink / raw)
  To: Jan Kiszka, xenomai

On Thu, 2023-09-28 at 18:25 +0200, Jan Kiszka wrote:
> Thanks, this is sure a major step forward!
> 
> How confident are your that all these now possible combinations are
> still tested? Our CI will run with y2038 enabled, right? How is the
> disabled case tested, at least build-wise? Or the case "unsupported by OS"?

Per default, y2038 support is enabled if
  - the architecture we build for is affected
  - glibc provides y2038 support as well

All 32 bit targets that we have (bbb, x86-compat) are now built with
y2038 support enabled.

All 64 bit targets are not affected, so y2038 support is disabled (not
required).

The only thing that we do not test right now is the building against
older glibc versions. I'm not sure if it's worth to add more CI jobs to
cover that case.

Florian

> 
> Jan
> 
> -- 
> Siemens AG, Technology
> Linux Expert Center


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v2 0/9] y2038: Finalize and enable y2038 support
  2023-09-29  7:45   ` Florian Bezdeka
@ 2023-09-29  8:14     ` Jan Kiszka
  2023-09-29 11:15       ` Florian Bezdeka
  0 siblings, 1 reply; 17+ messages in thread
From: Jan Kiszka @ 2023-09-29  8:14 UTC (permalink / raw)
  To: Florian Bezdeka, xenomai

On 29.09.23 09:45, Florian Bezdeka wrote:
> On Thu, 2023-09-28 at 18:25 +0200, Jan Kiszka wrote:
>> Thanks, this is sure a major step forward!
>>
>> How confident are your that all these now possible combinations are
>> still tested? Our CI will run with y2038 enabled, right? How is the
>> disabled case tested, at least build-wise? Or the case "unsupported by OS"?
> 
> Per default, y2038 support is enabled if
>   - the architecture we build for is affected
>   - glibc provides y2038 support as well
> 
> All 32 bit targets that we have (bbb, x86-compat) are now built with
> y2038 support enabled.
> 
> All 64 bit targets are not affected, so y2038 support is disabled (not
> required).
> 
> The only thing that we do not test right now is the building against
> older glibc versions. I'm not sure if it's worth to add more CI jobs to
> cover that case.

I think adding one disabled or y2038-incompatible build test with 32-bit
to Xenomai CI (not -images) would be good, at least for now.

Jan

-- 
Siemens AG, Technology
Linux Expert Center


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v2 0/9] y2038: Finalize and enable y2038 support
  2023-09-29  8:14     ` Jan Kiszka
@ 2023-09-29 11:15       ` Florian Bezdeka
  2023-09-29 11:59         ` Jan Kiszka
  0 siblings, 1 reply; 17+ messages in thread
From: Florian Bezdeka @ 2023-09-29 11:15 UTC (permalink / raw)
  To: Jan Kiszka, xenomai

On Fri, 2023-09-29 at 10:14 +0200, Jan Kiszka wrote:
> On 29.09.23 09:45, Florian Bezdeka wrote:
> > On Thu, 2023-09-28 at 18:25 +0200, Jan Kiszka wrote:
> > > Thanks, this is sure a major step forward!
> > > 
> > > How confident are your that all these now possible combinations are
> > > still tested? Our CI will run with y2038 enabled, right? How is the
> > > disabled case tested, at least build-wise? Or the case "unsupported by OS"?
> > 
> > Per default, y2038 support is enabled if
> >   - the architecture we build for is affected
> >   - glibc provides y2038 support as well
> > 
> > All 32 bit targets that we have (bbb, x86-compat) are now built with
> > y2038 support enabled.
> > 
> > All 64 bit targets are not affected, so y2038 support is disabled (not
> > required).
> > 
> > The only thing that we do not test right now is the building against
> > older glibc versions. I'm not sure if it's worth to add more CI jobs to
> > cover that case.
> 
> I think adding one disabled or y2038-incompatible build test with 32-bit
> to Xenomai CI (not -images) would be good, at least for now.

The build jobs of Xenomai (not -images) are still based on Debian
bullseye [1]. So we already test that for now, more or less by accident
[2].

I think we should migrate to Debian bookworm and than add one more job
building on bullseye. Does that make sense?

Florian

[1] https://source.denx.de/Xenomai/xenomai/-/blob/master/.gitlab-ci.yml#L16
[2] https://source.denx.de/Xenomai/xenomai/-/jobs/701101#L1298

> 
> Jan
> 
> -- 
> Siemens AG, Technology
> Linux Expert Center


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v2 0/9] y2038: Finalize and enable y2038 support
  2023-09-29 11:15       ` Florian Bezdeka
@ 2023-09-29 11:59         ` Jan Kiszka
  0 siblings, 0 replies; 17+ messages in thread
From: Jan Kiszka @ 2023-09-29 11:59 UTC (permalink / raw)
  To: Florian Bezdeka, xenomai

On 29.09.23 13:15, Florian Bezdeka wrote:
> On Fri, 2023-09-29 at 10:14 +0200, Jan Kiszka wrote:
>> On 29.09.23 09:45, Florian Bezdeka wrote:
>>> On Thu, 2023-09-28 at 18:25 +0200, Jan Kiszka wrote:
>>>> Thanks, this is sure a major step forward!
>>>>
>>>> How confident are your that all these now possible combinations are
>>>> still tested? Our CI will run with y2038 enabled, right? How is the
>>>> disabled case tested, at least build-wise? Or the case "unsupported by OS"?
>>>
>>> Per default, y2038 support is enabled if
>>>   - the architecture we build for is affected
>>>   - glibc provides y2038 support as well
>>>
>>> All 32 bit targets that we have (bbb, x86-compat) are now built with
>>> y2038 support enabled.
>>>
>>> All 64 bit targets are not affected, so y2038 support is disabled (not
>>> required).
>>>
>>> The only thing that we do not test right now is the building against
>>> older glibc versions. I'm not sure if it's worth to add more CI jobs to
>>> cover that case.
>>
>> I think adding one disabled or y2038-incompatible build test with 32-bit
>> to Xenomai CI (not -images) would be good, at least for now.
> 
> The build jobs of Xenomai (not -images) are still based on Debian
> bullseye [1]. So we already test that for now, more or less by accident
> [2].

Hehe, good point.

> 
> I think we should migrate to Debian bookworm and than add one more job
> building on bullseye. Does that make sense?

Yep, sounds good.

Jan

> 
> Florian
> 
> [1] https://source.denx.de/Xenomai/xenomai/-/blob/master/.gitlab-ci.yml#L16
> [2] https://source.denx.de/Xenomai/xenomai/-/jobs/701101#L1298
> 
>>
>> Jan
>>
>> -- 
>> Siemens AG, Technology
>> Linux Expert Center
> 

-- 
Siemens AG, Technology
Linux Expert Center


^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2023-09-29 11:59 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-27 13:50 [PATCH v2 0/9] y2038: Finalize and enable y2038 support Florian Bezdeka
2023-09-27 13:50 ` [PATCH v2 1/9] y2038: kernel/drivers: Implement SO_RCVTIMEO_NEW and SO_SNDTIMEO_NEW Florian Bezdeka
2023-09-28 17:00   ` Jan Kiszka
2023-09-27 13:50 ` [PATCH v2 2/9] y2038: lib/cobalt: Switch vdso to gettime64 Florian Bezdeka
2023-09-27 13:50 ` [PATCH v2 3/9] y2038: testsuite/clocktest: Fix reading of reference clock Florian Bezdeka
2023-09-27 13:50 ` [PATCH v2 4/9] y2038: build: Introduce new build parameter --disable-y2038 Florian Bezdeka
2023-09-27 13:50 ` [PATCH v2 5/9] y2038: lib/cobalt: Split function name and interface in COBALT_DECL() Florian Bezdeka
2023-09-27 13:50 ` [PATCH v2 6/9] y2038: lib/cobalt: Implement necessary wrappers for y2038 support Florian Bezdeka
2023-09-27 13:50 ` [PATCH v2 7/9] y2038: testsuite/smokey: Add some function wrapping tests Florian Bezdeka
2023-09-27 13:50 ` [PATCH v2 8/9] lib/cobalt: Cleanup includes Florian Bezdeka
2023-09-27 13:50 ` [PATCH v2 9/9] lib/cobalt/wrappers.h: Remove duplicate definition of __stringify() Florian Bezdeka
2023-09-28 16:25 ` [PATCH v2 0/9] y2038: Finalize and enable y2038 support Jan Kiszka
2023-09-28 17:31   ` Jan Kiszka
2023-09-29  7:45   ` Florian Bezdeka
2023-09-29  8:14     ` Jan Kiszka
2023-09-29 11:15       ` Florian Bezdeka
2023-09-29 11:59         ` Jan Kiszka

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 NNTP newsgroup(s).