(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[glibc.git] / sysdeps / unix / sysv / linux / alpha / semctl.c
blob6925c3f0583c8aabb838e6fcf445c76d54f27892
1 /* Copyright (C) 1995, 1997, 1998, 2000, 2003 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
18 02111-1307 USA. */
20 #include <errno.h>
21 #include <stdarg.h>
22 #include <sys/sem.h>
23 #include <ipc_priv.h>
25 #include <sysdep.h>
26 #include <string.h>
27 #include <sys/syscall.h>
29 #include "kernel-features.h"
31 struct __old_semid_ds
33 struct __old_ipc_perm sem_perm; /* operation permission struct */
34 __time_t sem_otime; /* last semop() time */
35 __time_t sem_ctime; /* last time changed by semctl() */
36 struct sem *__sembase; /* ptr to first semaphore in array */
37 struct sem_queue *__sem_pending; /* pending operations */
38 struct sem_queue *__sem_pending_last; /* last pending operation */
39 struct sem_undo *__undo; /* ondo requests on this array */
40 unsigned short int sem_nsems; /* number of semaphores in set */
43 /* Define a `union semun' suitable for Linux here. */
44 union semun
46 int val; /* value for SETVAL */
47 struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */
48 unsigned short int *array; /* array for GETALL & SETALL */
49 struct seminfo *__buf; /* buffer for IPC_INFO */
52 #include <bp-checks.h>
53 #include <bp-semctl.h> /* definition of CHECK_SEMCTL needs union semum */
55 /* Return identifier for array of NSEMS semaphores associated with
56 KEY. */
57 int __new_semctl (int semid, int semnum, int cmd, ...);
59 int
60 __new_semctl (int semid, int semnum, int cmd, ...)
62 union semun arg;
63 va_list ap;
65 va_start (ap, cmd);
67 /* Get the argument. */
68 arg = va_arg (ap, union semun);
70 va_end (ap);
72 #if __ASSUME_32BITUIDS > 0
73 return INLINE_SYSCALL (semctl, 4, semid, semnum, cmd | __IPC_64,
74 CHECK_SEMCTL (&arg, semid, cmd | __IPC_64)->array);
75 #else
76 switch (cmd) {
77 case SEM_STAT:
78 case IPC_STAT:
79 case IPC_SET:
80 break;
81 default:
82 return INLINE_SYSCALL (semctl, 4, semid, semnum, cmd,
83 CHECK_SEMCTL (&arg, semid, cmd)->array);
87 int save_errno = errno, result;
88 struct __old_semid_ds old;
89 struct semid_ds *buf;
91 /* Unfortunately there is no way how to find out for sure whether
92 we should use old or new semctl. */
93 result = INLINE_SYSCALL (semctl, 4, semid, semnum, cmd | __IPC_64,
94 CHECK_SEMCTL (&arg, semid, cmd | __IPC_64)->array);
95 if (result != -1 || errno != EINVAL)
96 return result;
98 __set_errno(save_errno);
99 buf = arg.buf;
100 arg.buf = (void *)&old;
101 if (cmd == IPC_SET)
103 old.sem_perm.uid = buf->sem_perm.uid;
104 old.sem_perm.gid = buf->sem_perm.gid;
105 old.sem_perm.mode = buf->sem_perm.mode;
106 if (old.sem_perm.uid != buf->sem_perm.uid ||
107 old.sem_perm.gid != buf->sem_perm.gid)
109 __set_errno (EINVAL);
110 return -1;
113 result = INLINE_SYSCALL (semctl, 4, semid, semnum, cmd,
114 CHECK_SEMCTL (&arg, semid, cmd)->array);
115 if (result != -1 && cmd != IPC_SET)
117 memset(buf, 0, sizeof(*buf));
118 buf->sem_perm.__key = old.sem_perm.__key;
119 buf->sem_perm.uid = old.sem_perm.uid;
120 buf->sem_perm.gid = old.sem_perm.gid;
121 buf->sem_perm.cuid = old.sem_perm.cuid;
122 buf->sem_perm.cgid = old.sem_perm.cgid;
123 buf->sem_perm.mode = old.sem_perm.mode;
124 buf->sem_perm.__seq = old.sem_perm.__seq;
125 buf->sem_otime = old.sem_otime;
126 buf->sem_ctime = old.sem_ctime;
127 buf->sem_nsems = old.sem_nsems;
129 return result;
131 #endif
134 #include <shlib-compat.h>
135 versioned_symbol (libc, __new_semctl, semctl, GLIBC_2_2);