1/* Copyright (C) 1995-2019 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.
4
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.
9
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.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
18
19#include <sys/sem.h>
20#include <stdarg.h>
21#include <ipc_priv.h>
22#include <sysdep.h>
23#include <shlib-compat.h>
24#include <errno.h>
25
26/* Define a `union semun' suitable for Linux here. */
27union semun
28{
29 int val; /* value for SETVAL */
30 struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */
31 unsigned short int *array; /* array for GETALL & SETALL */
32 struct seminfo *__buf; /* buffer for IPC_INFO */
33};
34
35#ifndef DEFAULT_VERSION
36# define DEFAULT_VERSION GLIBC_2_2
37#endif
38
39int
40__new_semctl (int semid, int semnum, int cmd, ...)
41{
42 union semun arg = { 0 };
43 va_list ap;
44
45 /* Get the argument only if required. */
46 switch (cmd)
47 {
48 case SETVAL: /* arg.val */
49 case GETALL: /* arg.array */
50 case SETALL:
51 case IPC_STAT: /* arg.buf */
52 case IPC_SET:
53 case SEM_STAT:
54 case IPC_INFO: /* arg.__buf */
55 case SEM_INFO:
56 va_start (ap, cmd);
57 arg = va_arg (ap, union semun);
58 va_end (ap);
59 break;
60 }
61
62#ifdef __ASSUME_DIRECT_SYSVIPC_SYSCALLS
63 return INLINE_SYSCALL_CALL (semctl, semid, semnum, cmd | __IPC_64,
64 arg.array);
65#else
66 return INLINE_SYSCALL_CALL (ipc, IPCOP_semctl, semid, semnum, cmd | __IPC_64,
67 SEMCTL_ARG_ADDRESS (arg));
68#endif
69}
70versioned_symbol (libc, __new_semctl, semctl, DEFAULT_VERSION);
71
72
73#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2)
74/* Since semctl use a variadic argument for semid_ds there is not need to
75 define and tie the compatibility symbol to the old 'union semun'
76 definition. */
77int
78attribute_compat_text_section
79__old_semctl (int semid, int semnum, int cmd, ...)
80{
81 union semun arg = { 0 };
82 va_list ap;
83
84 /* Get the argument only if required. */
85 switch (cmd)
86 {
87 case SETVAL: /* arg.val */
88 case GETALL: /* arg.array */
89 case SETALL:
90 case IPC_STAT: /* arg.buf */
91 case IPC_SET:
92 case SEM_STAT:
93 case IPC_INFO: /* arg.__buf */
94 case SEM_INFO:
95 va_start (ap, cmd);
96 arg = va_arg (ap, union semun);
97 va_end (ap);
98 break;
99 }
100
101# ifdef __ASSUME_DIRECT_SYSVIPC_SYSCALLS
102 return INLINE_SYSCALL_CALL (semctl, semid, semnum, cmd, arg.array);
103# else
104 return INLINE_SYSCALL_CALL (ipc, IPCOP_semctl, semid, semnum, cmd,
105 SEMCTL_ARG_ADDRESS (arg));
106# endif
107}
108compat_symbol (libc, __old_semctl, semctl, GLIBC_2_0);
109#endif
110