1 /* Copyright (C) 1995-2022 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
21 #include <shlib-compat.h>
23 #include <linux/posix_types.h> /* For __kernel_mode_t. */
25 /* POSIX states ipc_perm mode should have type of mode_t. */
26 _Static_assert (sizeof ((struct msqid_ds
){0}.msg_perm
.mode
)
28 "sizeof (msqid_ds.msg_perm.mode) != sizeof (mode_t)");
31 typedef struct msqid_ds msgctl_arg_t
;
33 # include <struct_kernel_msqid64_ds.h>
36 msqid64_to_kmsqid64 (const struct __msqid64_ds
*msqid64
,
37 struct kernel_msqid64_ds
*kmsqid
)
39 kmsqid
->msg_perm
= msqid64
->msg_perm
;
40 kmsqid
->msg_stime
= msqid64
->msg_stime
;
41 kmsqid
->msg_stime_high
= msqid64
->msg_stime
>> 32;
42 kmsqid
->msg_rtime
= msqid64
->msg_rtime
;
43 kmsqid
->msg_rtime_high
= msqid64
->msg_rtime
>> 32;
44 kmsqid
->msg_ctime
= msqid64
->msg_ctime
;
45 kmsqid
->msg_ctime_high
= msqid64
->msg_ctime
>> 32;
46 kmsqid
->msg_cbytes
= msqid64
->msg_cbytes
;
47 kmsqid
->msg_qnum
= msqid64
->msg_qnum
;
48 kmsqid
->msg_qbytes
= msqid64
->msg_qbytes
;
49 kmsqid
->msg_lspid
= msqid64
->msg_lspid
;
50 kmsqid
->msg_lrpid
= msqid64
->msg_lrpid
;
54 kmsqid64_to_msqid64 (const struct kernel_msqid64_ds
*kmsqid
,
55 struct __msqid64_ds
*msqid64
)
57 msqid64
->msg_perm
= kmsqid
->msg_perm
;
58 msqid64
->msg_stime
= kmsqid
->msg_stime
59 | ((__time64_t
) kmsqid
->msg_stime_high
<< 32);
60 msqid64
->msg_rtime
= kmsqid
->msg_rtime
61 | ((__time64_t
) kmsqid
->msg_rtime_high
<< 32);
62 msqid64
->msg_ctime
= kmsqid
->msg_ctime
63 | ((__time64_t
) kmsqid
->msg_ctime_high
<< 32);
64 msqid64
->msg_cbytes
= kmsqid
->msg_cbytes
;
65 msqid64
->msg_qnum
= kmsqid
->msg_qnum
;
66 msqid64
->msg_qbytes
= kmsqid
->msg_qbytes
;
67 msqid64
->msg_lspid
= kmsqid
->msg_lspid
;
68 msqid64
->msg_lrpid
= kmsqid
->msg_lrpid
;
71 typedef struct kernel_msqid64_ds msgctl_arg_t
;
75 msgctl_syscall (int msqid
, int cmd
, msgctl_arg_t
*buf
)
77 #ifdef __ASSUME_DIRECT_SYSVIPC_SYSCALLS
78 return INLINE_SYSCALL_CALL (msgctl
, msqid
, cmd
| __IPC_64
, buf
);
80 return INLINE_SYSCALL_CALL (ipc
, IPCOP_msgctl
, msqid
, cmd
| __IPC_64
, 0,
86 __msgctl64 (int msqid
, int cmd
, struct __msqid64_ds
*buf
)
89 struct kernel_msqid64_ds ksemid
, *arg
= NULL
;
107 msqid64_to_kmsqid64 (buf
, &ksemid
);
110 # ifdef __ASSUME_SYSVIPC_BROKEN_MODE_T
112 arg
->msg_perm
.mode
*= 0x10000U
;
121 /* This is a Linux extension where kernel returns a 'struct msginfo'
123 arg
= (__typeof__ (arg
)) buf
;
127 __set_errno (EINVAL
);
131 int ret
= msgctl_syscall (msqid
, cmd
, arg
);
140 #ifdef __ASSUME_SYSVIPC_BROKEN_MODE_T
141 arg
->msg_perm
.mode
>>= 16;
143 /* Old Linux kernel versions might not clear the mode padding. */
144 if (sizeof ((struct msqid_ds
){0}.msg_perm
.mode
)
145 != sizeof (__kernel_mode_t
))
146 arg
->msg_perm
.mode
&= 0xFFFF;
150 kmsqid64_to_msqid64 (arg
, buf
);
157 libc_hidden_def (__msgctl64
)
160 msqid_to_msqid64 (struct __msqid64_ds
*mq64
, const struct msqid_ds
*mq
)
162 mq64
->msg_perm
= mq
->msg_perm
;
163 mq64
->msg_stime
= mq
->msg_stime
164 | ((__time64_t
) mq
->__msg_stime_high
<< 32);
165 mq64
->msg_rtime
= mq
->msg_rtime
166 | ((__time64_t
) mq
->__msg_rtime_high
<< 32);
167 mq64
->msg_ctime
= mq
->msg_ctime
168 | ((__time64_t
) mq
->__msg_ctime_high
<< 32);
169 mq64
->msg_cbytes
= mq
->msg_cbytes
;
170 mq64
->msg_qnum
= mq
->msg_qnum
;
171 mq64
->msg_qbytes
= mq
->msg_qbytes
;
172 mq64
->msg_lspid
= mq
->msg_lspid
;
173 mq64
->msg_lrpid
= mq
->msg_lrpid
;
177 msqid64_to_msqid (struct msqid_ds
*mq
, const struct __msqid64_ds
*mq64
)
179 mq
->msg_perm
= mq64
->msg_perm
;
180 mq
->msg_stime
= mq64
->msg_stime
;
181 mq
->__msg_stime_high
= 0;
182 mq
->msg_rtime
= mq64
->msg_rtime
;
183 mq
->__msg_rtime_high
= 0;
184 mq
->msg_ctime
= mq64
->msg_ctime
;
185 mq
->__msg_ctime_high
= 0;
186 mq
->msg_cbytes
= mq64
->msg_cbytes
;
187 mq
->msg_qnum
= mq64
->msg_qnum
;
188 mq
->msg_qbytes
= mq64
->msg_qbytes
;
189 mq
->msg_lspid
= mq64
->msg_lspid
;
190 mq
->msg_lrpid
= mq64
->msg_lrpid
;
194 __msgctl (int msqid
, int cmd
, struct msqid_ds
*buf
)
196 struct __msqid64_ds msqid64
, *buf64
= NULL
;
199 /* This is a Linux extension where kernel returns a 'struct msginfo'
201 if (cmd
== IPC_INFO
|| cmd
== MSG_INFO
)
202 buf64
= (struct __msqid64_ds
*) buf
;
205 msqid_to_msqid64 (&msqid64
, buf
);
210 int ret
= __msgctl64 (msqid
, cmd
, buf64
);
219 msqid64_to_msqid (buf
, buf64
);
226 #ifndef DEFAULT_VERSION
227 # ifndef __ASSUME_SYSVIPC_BROKEN_MODE_T
228 # define DEFAULT_VERSION GLIBC_2_2
230 # define DEFAULT_VERSION GLIBC_2_31
233 versioned_symbol (libc
, __msgctl
, msgctl
, DEFAULT_VERSION
);
235 #if defined __ASSUME_SYSVIPC_BROKEN_MODE_T \
236 && SHLIB_COMPAT (libc, GLIBC_2_2, GLIBC_2_31)
238 attribute_compat_text_section
239 __msgctl_mode16 (int msqid
, int cmd
, struct msqid_ds
*buf
)
241 return msgctl_syscall (msqid
, cmd
, (msgctl_arg_t
*) buf
);
243 compat_symbol (libc
, __msgctl_mode16
, msgctl
, GLIBC_2_2
);
246 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2)
247 struct __old_msqid_ds
249 struct __old_ipc_perm msg_perm
; /* structure describing operation permission */
250 struct msg
*__msg_first
; /* pointer to first message on queue */
251 struct msg
*__msg_last
; /* pointer to last message on queue */
252 __time_t msg_stime
; /* time of last msgsnd command */
253 __time_t msg_rtime
; /* time of last msgrcv command */
254 __time_t msg_ctime
; /* time of last change */
255 struct wait_queue
*__wwait
; /* ??? */
256 struct wait_queue
*__rwait
; /* ??? */
257 unsigned short int __msg_cbytes
; /* current number of bytes on queue */
258 unsigned short int msg_qnum
; /* number of messages currently on queue */
259 unsigned short int msg_qbytes
; /* max number of bytes allowed on queue */
260 __ipc_pid_t msg_lspid
; /* pid of last msgsnd() */
261 __ipc_pid_t msg_lrpid
; /* pid of last msgrcv() */
265 attribute_compat_text_section
266 __old_msgctl (int msqid
, int cmd
, struct __old_msqid_ds
*buf
)
268 #if defined __ASSUME_DIRECT_SYSVIPC_SYSCALLS \
269 && !defined __ASSUME_SYSVIPC_DEFAULT_IPC_64
270 /* For architecture that have wire-up msgctl but also have __IPC_64 to a
271 value different than default (0x0) it means the compat symbol used the
273 return INLINE_SYSCALL_CALL (msgctl
, msqid
, cmd
, buf
);
275 return INLINE_SYSCALL_CALL (ipc
, IPCOP_msgctl
, msqid
, cmd
, 0, buf
);
278 compat_symbol (libc
, __old_msgctl
, msgctl
, GLIBC_2_0
);