1 /* Semctl for architectures where word sized unions are passed indirectly
2 Copyright (C) 1995, 1997, 1998, 2000, 2002, 2003, 2004
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, write to the Free
19 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
29 #include <sys/syscall.h>
31 #include "kernel-features.h"
32 #include <shlib-compat.h>
36 struct __old_ipc_perm sem_perm
; /* operation permission struct */
37 __time_t sem_otime
; /* last semop() time */
38 __time_t sem_ctime
; /* last time changed by semctl() */
39 struct sem
*__sembase
; /* ptr to first semaphore in array */
40 struct sem_queue
*__sem_pending
; /* pending operations */
41 struct sem_queue
*__sem_pending_last
; /* last pending operation */
42 struct sem_undo
*__undo
; /* ondo requests on this array */
43 unsigned short int sem_nsems
; /* number of semaphores in set */
46 /* Define a `union semun' suitable for Linux here. */
49 int val
; /* value for SETVAL */
50 struct semid_ds
*buf
; /* buffer for IPC_STAT & IPC_SET */
51 unsigned short int *array
; /* array for GETALL & SETALL */
52 struct seminfo
*__buf
; /* buffer for IPC_INFO */
53 struct __old_semid_ds
*__old_buf
;
56 #include <bp-checks.h>
57 #include <bp-semctl.h> /* definition of CHECK_SEMCTL needs union semum */
60 # if __ASSUME_32BITUIDS == 0
61 /* This variable is shared with all files that need to check for 32bit
63 extern int __libc_missing_32bit_uids
;
67 /* Return identifier for array of NSEMS semaphores associated with
69 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2)
70 int __old_semctl (int semid
, int semnum
, int cmd
, ...);
72 int __new_semctl (int semid
, int semnum
, int cmd
, ...);
74 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2)
76 attribute_compat_text_section
77 __old_semctl (int semid
, int semnum
, int cmd
, ...)
82 /* Get the argument only if required. */
86 case SETVAL
: /* arg.val */
87 case GETALL
: /* arg.array */
89 case IPC_STAT
: /* arg.buf */
92 case IPC_INFO
: /* arg.__buf */
95 arg
= va_arg (ap
, union semun
);
100 return INLINE_SYSCALL (ipc
, 5, IPCOP_semctl
, semid
, semnum
, cmd
,
101 CHECK_SEMCTL (&arg
, semid
, cmd
));
103 compat_symbol (libc
, __old_semctl
, semctl
, GLIBC_2_0
);
107 __new_semctl (int semid
, int semnum
, int cmd
, ...)
112 /* Get the argument only if required. */
116 case SETVAL
: /* arg.val */
117 case GETALL
: /* arg.array */
119 case IPC_STAT
: /* arg.buf */
122 case IPC_INFO
: /* arg.__buf */
125 arg
= va_arg (ap
, union semun
);
130 #if __ASSUME_32BITUIDS > 0
131 return INLINE_SYSCALL (ipc
, 5, IPCOP_semctl
, semid
, semnum
, cmd
| __IPC_64
,
132 CHECK_SEMCTL (&arg
, semid
, cmd
| __IPC_64
));
140 return INLINE_SYSCALL (ipc
, 5, IPCOP_semctl
, semid
, semnum
, cmd
,
141 CHECK_SEMCTL (&arg
, semid
, cmd
));
146 struct __old_semid_ds old
;
147 struct semid_ds
*buf
;
150 if (__libc_missing_32bit_uids
<= 0)
152 if (__libc_missing_32bit_uids
< 0)
154 int save_errno
= errno
;
156 /* Test presence of new IPC by testing for getuid32 syscall. */
157 result
= INLINE_SYSCALL (getuid32
, 0);
158 if (result
== -1 && errno
== ENOSYS
)
159 __libc_missing_32bit_uids
= 1;
161 __libc_missing_32bit_uids
= 0;
162 __set_errno(save_errno
);
164 if (__libc_missing_32bit_uids
<= 0)
166 result
= INLINE_SYSCALL (ipc
, 5, IPCOP_semctl
, semid
, semnum
, cmd
| __IPC_64
,
167 CHECK_SEMCTL (&arg
, semid
, cmd
| __IPC_64
));
174 arg
.__old_buf
= &old
;
177 old
.sem_perm
.uid
= buf
->sem_perm
.uid
;
178 old
.sem_perm
.gid
= buf
->sem_perm
.gid
;
179 old
.sem_perm
.mode
= buf
->sem_perm
.mode
;
180 if (old
.sem_perm
.uid
!= buf
->sem_perm
.uid
||
181 old
.sem_perm
.gid
!= buf
->sem_perm
.gid
)
183 __set_errno (EINVAL
);
187 result
= INLINE_SYSCALL (ipc
, 5, IPCOP_semctl
, semid
, semnum
, cmd
,
188 CHECK_SEMCTL (&arg
, semid
, cmd
));
189 if (result
!= -1 && cmd
!= IPC_SET
)
191 memset(buf
, 0, sizeof(*buf
));
192 buf
->sem_perm
.__key
= old
.sem_perm
.__key
;
193 buf
->sem_perm
.uid
= old
.sem_perm
.uid
;
194 buf
->sem_perm
.gid
= old
.sem_perm
.gid
;
195 buf
->sem_perm
.cuid
= old
.sem_perm
.cuid
;
196 buf
->sem_perm
.cgid
= old
.sem_perm
.cgid
;
197 buf
->sem_perm
.mode
= old
.sem_perm
.mode
;
198 buf
->sem_perm
.__seq
= old
.sem_perm
.__seq
;
199 buf
->sem_otime
= old
.sem_otime
;
200 buf
->sem_ctime
= old
.sem_ctime
;
201 buf
->sem_nsems
= old
.sem_nsems
;
208 versioned_symbol (libc
, __new_semctl
, semctl
, GLIBC_2_2
);