1 /* Copyright (C) 1995-2020 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
22 #include <shlib-compat.h>
25 #ifndef DEFAULT_VERSION
26 # ifndef __ASSUME_SYSVIPC_BROKEN_MODE_T
27 # define DEFAULT_VERSION GLIBC_2_2
29 # define DEFAULT_VERSION GLIBC_2_31
34 msgctl_syscall (int msqid
, int cmd
, struct msqid_ds
*buf
)
36 #ifdef __ASSUME_DIRECT_SYSVIPC_SYSCALLS
37 return INLINE_SYSCALL_CALL (msgctl
, msqid
, cmd
| __IPC_64
, buf
);
39 return INLINE_SYSCALL_CALL (ipc
, IPCOP_msgctl
, msqid
, cmd
| __IPC_64
, 0,
45 __new_msgctl (int msqid
, int cmd
, struct msqid_ds
*buf
)
47 /* POSIX states ipc_perm mode should have type of mode_t. */
48 _Static_assert (sizeof ((struct msqid_ds
){0}.msg_perm
.mode
)
50 "sizeof (msqid_ds.msg_perm.mode) != sizeof (mode_t)");
52 #ifdef __ASSUME_SYSVIPC_BROKEN_MODE_T
53 struct msqid_ds tmpds
;
57 tmpds
.msg_perm
.mode
*= 0x10000U
;
62 int ret
= msgctl_syscall (msqid
, cmd
, buf
);
71 #ifdef __ASSUME_SYSVIPC_BROKEN_MODE_T
72 buf
->msg_perm
.mode
>>= 16;
74 /* Old Linux kernel versions might not clear the mode padding. */
75 if (sizeof ((struct msqid_ds
){0}.msg_perm
.mode
)
76 != sizeof (__kernel_mode_t
))
77 buf
->msg_perm
.mode
&= 0xFFFF;
84 versioned_symbol (libc
, __new_msgctl
, msgctl
, DEFAULT_VERSION
);
86 #if defined __ASSUME_SYSVIPC_BROKEN_MODE_T \
87 && SHLIB_COMPAT (libc, GLIBC_2_2, GLIBC_2_31)
89 attribute_compat_text_section
90 __msgctl_mode16 (int msqid
, int cmd
, struct msqid_ds
*buf
)
92 return msgctl_syscall (msqid
, cmd
, buf
);
94 compat_symbol (libc
, __msgctl_mode16
, msgctl
, GLIBC_2_2
);
97 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2)
100 struct __old_ipc_perm msg_perm
; /* structure describing operation permission */
101 struct msg
*__msg_first
; /* pointer to first message on queue */
102 struct msg
*__msg_last
; /* pointer to last message on queue */
103 __time_t msg_stime
; /* time of last msgsnd command */
104 __time_t msg_rtime
; /* time of last msgrcv command */
105 __time_t msg_ctime
; /* time of last change */
106 struct wait_queue
*__wwait
; /* ??? */
107 struct wait_queue
*__rwait
; /* ??? */
108 unsigned short int __msg_cbytes
; /* current number of bytes on queue */
109 unsigned short int msg_qnum
; /* number of messages currently on queue */
110 unsigned short int msg_qbytes
; /* max number of bytes allowed on queue */
111 __ipc_pid_t msg_lspid
; /* pid of last msgsnd() */
112 __ipc_pid_t msg_lrpid
; /* pid of last msgrcv() */
116 attribute_compat_text_section
117 __old_msgctl (int msqid
, int cmd
, struct __old_msqid_ds
*buf
)
119 #if defined __ASSUME_DIRECT_SYSVIPC_SYSCALLS \
120 && !defined __ASSUME_SYSVIPC_DEFAULT_IPC_64
121 /* For architecture that have wire-up msgctl but also have __IPC_64 to a
122 value different than default (0x0) it means the compat symbol used the
124 return INLINE_SYSCALL_CALL (msgctl
, msqid
, cmd
, buf
);
126 return INLINE_SYSCALL_CALL (ipc
, IPCOP_msgctl
, msqid
, cmd
, 0, buf
);
129 compat_symbol (libc
, __old_msgctl
, msgctl
, GLIBC_2_0
);