[RFC 6/6] msg: provide glibc local copy of struct msqid_ds

Lukasz Majewski lukma@denx.de
Fri Dec 4 23:36:04 GMT 2020


The rationale for this change is to provide y2038 support for
syscalls which use struct msqid_ds as __USE_TIME64_BITS is only available
in exported headers.

After this commit there is no need to unconditionally
#include <sysvipc/sys/msg.h> header, which prevents from using the
exported struct msqid_ds. The aforementioned header is only included when
_ISOMAC is defined - e.g. when the testsuite is built and executed.

For example the ./sysdeps/unix/sysv/linux/msgctl.c includes <sys/msg.h>:
			(include/sys/msg.h) which has
			#include_next <sys/msg.h>
				    |
				   \|/
			./sysdeps/unix/sysv/linux/include/sys/msg.h
				    |
				   \|/
	(./sysvipc/sys/msg.h) which unconditionally includes
        ./sysdeps/unix/sysv/linux/bits/msq.h
				    |
				   \|/
        ./sysdeps/unix/sysv/linux/bits/types/struct_msqid_ds.h

As a result the externally exported struct msqid_ds.h is used internally
by glibc.

To fix this issue - the internal for glibc copy of struct msqid_ds
has been re-introduced. This will allow clear separation between exported
and internal glibc types.

Build tests:
./src/scripts/build-many-glibcs.py glibcs
---
 sysdeps/unix/sysv/linux/include/sys/msg.h | 66 +++++++++++++++++++++--
 1 file changed, 62 insertions(+), 4 deletions(-)

diff --git a/sysdeps/unix/sysv/linux/include/sys/msg.h b/sysdeps/unix/sysv/linux/include/sys/msg.h
index 522903f818..1057c2e278 100644
--- a/sysdeps/unix/sysv/linux/include/sys/msg.h
+++ b/sysdeps/unix/sysv/linux/include/sys/msg.h
@@ -1,7 +1,63 @@
 #ifndef _SYS_MSG_H
-#include <sysvipc/sys/msg.h>
-
 #ifndef _ISOMAC
+# include <time.h>
+# include <sys/ipc.h>
+
+/* Types used in the MSQID_DS structure definition.  */
+typedef __syscall_ulong_t msgqnum_t;
+typedef __syscall_ulong_t msglen_t;
+
+struct msqid_ds
+{
+  struct ipc_perm msg_perm;	/* structure describing operation permission */
+# if __TIMESIZE == 32
+  __time_t msg_stime;		/* time of last msgsnd command */
+  unsigned long int __msg_stime_high;
+  __time_t msg_rtime;		/* time of last msgsnd command */
+  unsigned long int __msg_rtime_high;
+  __time_t msg_ctime;		/* time of last change */
+  unsigned long int __msg_ctime_high;
+# else
+  __time_t msg_stime;		/* time of last msgsnd command */
+  __time_t msg_rtime;		/* time of last msgsnd command */
+  __time_t msg_ctime;		/* time of last change */
+# endif
+  __syscall_ulong_t __msg_cbytes; /* current number of bytes on queue */
+  msgqnum_t msg_qnum;		/* number of messages currently on queue */
+  msglen_t msg_qbytes;		/* max number of bytes allowed on queue */
+  __pid_t msg_lspid;		/* pid of last msgsnd() */
+  __pid_t msg_lrpid;		/* pid of last msgrcv() */
+  __syscall_ulong_t __glibc_reserved4;
+  __syscall_ulong_t __glibc_reserved5;
+};
+
+# ifdef __USE_MISC
+#  define msg_cbytes	__msg_cbytes
+
+/* ipcs ctl commands */
+#  define MSG_STAT 11
+#  define MSG_INFO 12
+#  define MSG_STAT_ANY 13
+
+/* buffer for msgctl calls IPC_INFO, MSG_INFO */
+struct msginfo
+  {
+    int msgpool;
+    int msgmap;
+    int msgmax;
+    int msgmnb;
+    int msgmni;
+    int msgssz;
+    int msgtql;
+    unsigned short int msgseg;
+  };
+# endif /* __USE_MISC */
+
+# ifndef __ssize_t_defined
+typedef __ssize_t ssize_t;
+#  define __ssize_t_defined
+# endif
+
 extern ssize_t __libc_msgrcv (int msqid, void *msgp, size_t msgsz,
 			      long int msgtyp, int msgflg);
 extern int __libc_msgsnd (int msqid, const void *msgp, size_t msgsz,
@@ -15,7 +71,9 @@ extern int __libc_msgsnd (int msqid, const void *msgp, size_t msgsz,
 extern int __msgctl64 (int msqid, int cmd, struct __msqid64_ds *buf);
 libc_hidden_proto (__msgctl64);
 # endif
-
-#endif
+#else /* _ISOMAC = 1 - e.g. testsuite */
+/* Provide exported sys/msg.h header */
+# include <sysvipc/sys/msg.h>
+#endif /* _ISOMAC */
 
 #endif
-- 
2.20.1



More information about the Libc-alpha mailing list