1 /* Semctl for architectures where word sized unions are passed indirectly
2 Copyright (C) 1995,1997,1998,2000,2002,2003,2004,2006
3 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
5 Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
7 The GNU C Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 The GNU C Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with the GNU C Library; if not, see
19 <http://www.gnu.org/licenses/>. */
28 #include <sys/syscall.h>
30 #include <kernel-features.h>
31 #include <shlib-compat.h>
35 struct __old_ipc_perm sem_perm
; /* operation permission struct */
36 __time_t sem_otime
; /* last semop() time */
37 __time_t sem_ctime
; /* last time changed by semctl() */
38 struct sem
*__sembase
; /* ptr to first semaphore in array */
39 struct sem_queue
*__sem_pending
; /* pending operations */
40 struct sem_queue
*__sem_pending_last
; /* last pending operation */
41 struct sem_undo
*__undo
; /* ondo requests on this array */
42 unsigned short int sem_nsems
; /* number of semaphores in set */
45 /* Define a `union semun' suitable for Linux here. */
48 int val
; /* value for SETVAL */
49 struct semid_ds
*buf
; /* buffer for IPC_STAT & IPC_SET */
50 unsigned short int *array
; /* array for GETALL & SETALL */
51 struct seminfo
*__buf
; /* buffer for IPC_INFO */
52 struct __old_semid_ds
*__old_buf
;
55 #include <bp-checks.h>
56 #include <bp-semctl.h> /* definition of CHECK_SEMCTL needs union semum */
59 # if __ASSUME_32BITUIDS == 0
60 /* This variable is shared with all files that need to check for 32bit
62 extern int __libc_missing_32bit_uids
;
66 /* Return identifier for array of NSEMS semaphores associated with
68 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2)
69 int __old_semctl (int semid
, int semnum
, int cmd
, ...);
71 int __new_semctl (int semid
, int semnum
, int cmd
, ...);
73 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2)
75 attribute_compat_text_section
76 __old_semctl (int semid
, int semnum
, int cmd
, ...)
81 /* Get the argument only if required. */
85 case SETVAL
: /* arg.val */
86 case GETALL
: /* arg.array */
88 case IPC_STAT
: /* arg.buf */
91 case IPC_INFO
: /* arg.__buf */
94 arg
= va_arg (ap
, union semun
);
99 return INLINE_SYSCALL (ipc
, 5, IPCOP_semctl
, semid
, semnum
, cmd
,
100 CHECK_SEMCTL (&arg
, semid
, cmd
));
102 compat_symbol (libc
, __old_semctl
, semctl
, GLIBC_2_0
);
106 __new_semctl (int semid
, int semnum
, int cmd
, ...)
111 /* Get the argument only if required. */
115 case SETVAL
: /* arg.val */
116 case GETALL
: /* arg.array */
118 case IPC_STAT
: /* arg.buf */
121 case IPC_INFO
: /* arg.__buf */
124 arg
= va_arg (ap
, union semun
);
129 #if __ASSUME_32BITUIDS > 0
130 return INLINE_SYSCALL (ipc
, 5, IPCOP_semctl
, semid
, semnum
, cmd
| __IPC_64
,
131 CHECK_SEMCTL (&arg
, semid
, cmd
| __IPC_64
));
139 return INLINE_SYSCALL (ipc
, 5, IPCOP_semctl
, semid
, semnum
, cmd
,
140 CHECK_SEMCTL (&arg
, semid
, cmd
));
145 struct __old_semid_ds old
;
146 struct semid_ds
*buf
;
149 if (__libc_missing_32bit_uids
<= 0)
151 if (__libc_missing_32bit_uids
< 0)
153 int save_errno
= errno
;
155 /* Test presence of new IPC by testing for getuid32 syscall. */
156 result
= INLINE_SYSCALL (getuid32
, 0);
157 if (result
== -1 && errno
== ENOSYS
)
158 __libc_missing_32bit_uids
= 1;
160 __libc_missing_32bit_uids
= 0;
161 __set_errno(save_errno
);
163 if (__libc_missing_32bit_uids
<= 0)
165 result
= INLINE_SYSCALL (ipc
, 5, IPCOP_semctl
, semid
, semnum
, cmd
| __IPC_64
,
166 CHECK_SEMCTL (&arg
, semid
, cmd
| __IPC_64
));
173 arg
.__old_buf
= &old
;
176 old
.sem_perm
.uid
= buf
->sem_perm
.uid
;
177 old
.sem_perm
.gid
= buf
->sem_perm
.gid
;
178 old
.sem_perm
.mode
= buf
->sem_perm
.mode
;
179 if (old
.sem_perm
.uid
!= buf
->sem_perm
.uid
||
180 old
.sem_perm
.gid
!= buf
->sem_perm
.gid
)
182 __set_errno (EINVAL
);
186 result
= INLINE_SYSCALL (ipc
, 5, IPCOP_semctl
, semid
, semnum
, cmd
,
187 CHECK_SEMCTL (&arg
, semid
, cmd
));
188 if (result
!= -1 && cmd
!= IPC_SET
)
190 memset(buf
, 0, sizeof(*buf
));
191 buf
->sem_perm
.__key
= old
.sem_perm
.__key
;
192 buf
->sem_perm
.uid
= old
.sem_perm
.uid
;
193 buf
->sem_perm
.gid
= old
.sem_perm
.gid
;
194 buf
->sem_perm
.cuid
= old
.sem_perm
.cuid
;
195 buf
->sem_perm
.cgid
= old
.sem_perm
.cgid
;
196 buf
->sem_perm
.mode
= old
.sem_perm
.mode
;
197 buf
->sem_perm
.__seq
= old
.sem_perm
.__seq
;
198 buf
->sem_otime
= old
.sem_otime
;
199 buf
->sem_ctime
= old
.sem_ctime
;
200 buf
->sem_nsems
= old
.sem_nsems
;
207 versioned_symbol (libc
, __new_semctl
, semctl
, GLIBC_2_2
);