2 * Check decoding of ipc syscall.
4 * Copyright (c) 2016 Dmitry V. Levin <ldv@altlinux.org>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include <sys/syscall.h>
33 #if defined __NR_ipc && defined HAVE_LINUX_IPC_H
38 # include <linux/ipc.h>
48 ipc_call(const unsigned short version, const unsigned short call,
49 long a1, long a2, long a3, long a4, long a5)
51 const unsigned long val =
52 (unsigned long) 0xfacefeed00000000 |
53 (unsigned int) version << 16 |
56 return syscall(__NR_ipc, val, a1, a2, a3, a4, a5);
60 ipc_call0(const unsigned short version, const unsigned short call)
62 int rc = ipc_call(version, call, 0, 0, 0, 0, 0);
63 int saved_errno = errno;
66 printf("%hu<<16|", version);
68 printf("%hu, 0, 0, 0, 0%s) = %d %s (%m)\n", call,
81 void *const efault = tail_alloc(1) + 1;
83 int rc = ipc_call(0, SEMCTL, 0, 0, 0, (long) efault, 0);
84 if (rc != -1 || EFAULT != errno)
85 perror_msg_and_skip("ipc");
86 printf("semctl(0, 0, IPC_RMID, %p) = -1 EFAULT (%m)\n", efault);
89 for (call = 0; call <= 40; call += 10) {
94 rc = ipc_call(42, SEMCTL, 0, 0, 0, (long) efault, 0);
95 int test_version = EFAULT == errno;
97 printf("semctl(0, 0, IPC_RMID, %p) = %d %s (%m)\n",
98 efault, rc, errno2name());
100 printf("ipc(42<<16|SEMCTL, 0, 0, 0, %p) = %d %s (%m)\n",
101 efault, rc, errno2name());
104 const int msqid = -2;
105 const long msgsz = -3;
106 const long msgtyp = 0;
108 rc = ipc_call(1, MSGRCV,
109 msqid, msgsz, IPC_NOWAIT, (long) efault, msgtyp);
110 printf("msgrcv(%d, %p, %lu, %ld, IPC_NOWAIT) = %d %s (%m)\n",
111 msqid, efault, msgsz, msgtyp, rc, errno2name());
114 puts("+++ exited with 0 +++");
120 SKIP_MAIN_UNDEFINED("__NR_ipc && HAVE_LINUX_IPC_H")