1 /* Copyright (C) 1995,1997,1998,2000,2004,2006 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, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
26 #include <sys/syscall.h>
27 #include <bp-checks.h>
29 #include <kernel-features.h>
30 #include <shlib-compat.h>
34 struct __old_ipc_perm msg_perm
; /* structure describing operation permission */
35 struct msg
*__unbounded __msg_first
; /* pointer to first message on queue */
36 struct msg
*__unbounded __msg_last
; /* pointer to last message on queue */
37 __time_t msg_stime
; /* time of last msgsnd command */
38 __time_t msg_rtime
; /* time of last msgrcv command */
39 __time_t msg_ctime
; /* time of last change */
40 struct wait_queue
*__unbounded __wwait
; /* ??? */
41 struct wait_queue
*__unbounded __rwait
; /* ??? */
42 unsigned short int __msg_cbytes
; /* current number of bytes on queue */
43 unsigned short int msg_qnum
; /* number of messages currently on queue */
44 unsigned short int msg_qbytes
; /* max number of bytes allowed on queue */
45 __ipc_pid_t msg_lspid
; /* pid of last msgsnd() */
46 __ipc_pid_t msg_lrpid
; /* pid of last msgrcv() */
49 /* Allows to control internal state and destruction of message queue
51 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2)
52 int __old_msgctl (int, int, struct __old_msqid_ds
*);
54 int __new_msgctl (int, int, struct msqid_ds
*);
57 # if __ASSUME_32BITUIDS == 0
58 /* This variable is shared with all files that need to check for 32bit
60 extern int __libc_missing_32bit_uids
;
64 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2)
66 attribute_compat_text_section
67 __old_msgctl (int msqid
, int cmd
, struct __old_msqid_ds
*buf
)
69 return INLINE_SYSCALL (ipc
, 5, IPCOP_msgctl
,
70 msqid
, cmd
, 0, CHECK_1 (buf
));
72 compat_symbol (libc
, __old_msgctl
, msgctl
, GLIBC_2_0
);
76 __new_msgctl (int msqid
, int cmd
, struct msqid_ds
*buf
)
78 #if __ASSUME_32BITUIDS > 0
79 return INLINE_SYSCALL (ipc
, 5, IPCOP_msgctl
,
80 msqid
, cmd
| __IPC_64
, 0, CHECK_1 (buf
));
88 return INLINE_SYSCALL (ipc
, 5, IPCOP_msgctl
,
89 msqid
, cmd
, 0, CHECK_1 (buf
));
94 struct __old_msqid_ds old
;
97 if (__libc_missing_32bit_uids
<= 0)
99 if (__libc_missing_32bit_uids
< 0)
101 int save_errno
= errno
;
103 /* Test presence of new IPC by testing for getuid32 syscall. */
104 result
= INLINE_SYSCALL (getuid32
, 0);
105 if (result
== -1 && errno
== ENOSYS
)
106 __libc_missing_32bit_uids
= 1;
108 __libc_missing_32bit_uids
= 0;
109 __set_errno(save_errno
);
111 if (__libc_missing_32bit_uids
<= 0)
113 result
= INLINE_SYSCALL (ipc
, 5, IPCOP_msgctl
,
114 msqid
, cmd
| __IPC_64
, 0, CHECK_1 (buf
));
121 old
.msg_perm
.uid
= buf
->msg_perm
.uid
;
122 old
.msg_perm
.gid
= buf
->msg_perm
.gid
;
123 old
.msg_perm
.mode
= buf
->msg_perm
.mode
;
124 old
.msg_qbytes
= buf
->msg_qbytes
;
125 if (old
.msg_perm
.uid
!= buf
->msg_perm
.uid
||
126 old
.msg_perm
.gid
!= buf
->msg_perm
.gid
||
127 old
.msg_qbytes
!= buf
->msg_qbytes
)
129 __set_errno (EINVAL
);
133 result
= INLINE_SYSCALL (ipc
, 5, IPCOP_msgctl
,
134 msqid
, cmd
, 0, __ptrvalue (&old
));
135 if (result
!= -1 && cmd
!= IPC_SET
)
137 memset(buf
, 0, sizeof(*buf
));
138 buf
->msg_perm
.__key
= old
.msg_perm
.__key
;
139 buf
->msg_perm
.uid
= old
.msg_perm
.uid
;
140 buf
->msg_perm
.gid
= old
.msg_perm
.gid
;
141 buf
->msg_perm
.cuid
= old
.msg_perm
.cuid
;
142 buf
->msg_perm
.cgid
= old
.msg_perm
.cgid
;
143 buf
->msg_perm
.mode
= old
.msg_perm
.mode
;
144 buf
->msg_perm
.__seq
= old
.msg_perm
.__seq
;
145 buf
->msg_stime
= old
.msg_stime
;
146 buf
->msg_rtime
= old
.msg_rtime
;
147 buf
->msg_ctime
= old
.msg_ctime
;
148 buf
->__msg_cbytes
= old
.__msg_cbytes
;
149 buf
->msg_qnum
= old
.msg_qnum
;
150 buf
->msg_qbytes
= old
.msg_qbytes
;
151 buf
->msg_lspid
= old
.msg_lspid
;
152 buf
->msg_lrpid
= old
.msg_lrpid
;
159 versioned_symbol (libc
, __new_msgctl
, msgctl
, GLIBC_2_2
);