2 * Check decoding of ipc syscall.
4 * Copyright (c) 2016-2018 Dmitry V. Levin <ldv@altlinux.org>
7 * SPDX-License-Identifier: GPL-2.0-or-later
11 #include <asm/unistd.h>
13 #if defined __NR_ipc && defined HAVE_LINUX_IPC_H
18 # include <linux/ipc.h>
28 ipc_call(const unsigned short version, const unsigned short call,
29 long a1, long a2, long a3, long a4, long a5)
31 const unsigned long val =
32 (unsigned long) 0xfacefeed00000000ULL |
33 (unsigned int) version << 16 |
36 return syscall(__NR_ipc, val, a1, a2, a3, a4, a5);
40 ipc_call0(const unsigned short version, const unsigned short call)
42 int rc = ipc_call(version, call, 0, 0, 0, 0, 0);
43 int saved_errno = errno;
46 printf("%hu<<16|", version);
48 printf("%hu, 0, 0, 0, 0%s) = %d %s (%m)\n", call,
61 void *const efault = tail_alloc(1) + 1;
63 int rc = ipc_call(0, SEMCTL, 0, 0, 0, (long) efault, 0);
64 if (rc != -1 || EFAULT != errno)
65 perror_msg_and_skip("ipc");
66 printf("semctl(0, 0, IPC_RMID, %p) = -1 EFAULT (%m)\n", efault);
69 for (call = 0; call <= 40; call += 10) {
74 rc = ipc_call(42, SEMCTL, 0, 0, 0, (long) efault, 0);
75 int test_version = EFAULT == errno;
77 printf("semctl(0, 0, IPC_RMID, %p) = %d %s (%m)\n",
78 efault, rc, errno2name());
80 printf("ipc(42<<16|SEMCTL, 0, 0, 0, %p) = %d %s (%m)\n",
81 efault, rc, errno2name());
85 const long msgsz = -3;
86 const long msgtyp = 0;
88 rc = ipc_call(1, MSGRCV,
89 msqid, msgsz, IPC_NOWAIT, (long) efault, msgtyp);
90 printf("msgrcv(%d, %p, %lu, %ld, IPC_NOWAIT) = %d %s (%m)\n",
91 msqid, efault, msgsz, msgtyp, rc, errno2name());
94 puts("+++ exited with 0 +++");
100 SKIP_MAIN_UNDEFINED("__NR_ipc && HAVE_LINUX_IPC_H")