blob: 34e32a37f10672a1516e55c2db3c813a3a4a9dda [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001/*
2 * Copyright (c) 1993 Ulrich Pegelow <pegelow@moorea.uni-muenster.de>
3 * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
4 * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00005 * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00006 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000029 */
30
31#include "defs.h"
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010032#ifdef HAVE_MQUEUE_H
33# include <mqueue.h>
34#endif
Roland McGrath4df13c12004-04-16 21:48:40 +000035#include <fcntl.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000036#include <sys/ipc.h>
37#include <sys/sem.h>
38#include <sys/msg.h>
39#include <sys/shm.h>
40
41#ifndef MSG_STAT
42#define MSG_STAT 11
43#endif
44#ifndef MSG_INFO
45#define MSG_INFO 12
46#endif
47#ifndef SHM_STAT
48#define SHM_STAT 13
49#endif
50#ifndef SHM_INFO
51#define SHM_INFO 14
52#endif
53#ifndef SEM_STAT
54#define SEM_STAT 18
55#endif
56#ifndef SEM_INFO
57#define SEM_INFO 19
58#endif
59
Denys Vlasenko84703742012-02-25 02:38:52 +010060#if !defined IPC_64
Roland McGrath80731792003-01-14 09:46:17 +000061# define IPC_64 0x100
62#endif
63
Roland McGrath4df13c12004-04-16 21:48:40 +000064extern void printsigevent(struct tcb *tcp, long arg);
65
Roland McGrathd9f816f2004-09-04 03:39:20 +000066static const struct xlat msgctl_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000067 { IPC_RMID, "IPC_RMID" },
68 { IPC_SET, "IPC_SET" },
69 { IPC_STAT, "IPC_STAT" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000070 { IPC_INFO, "IPC_INFO" },
71 { MSG_STAT, "MSG_STAT" },
72 { MSG_INFO, "MSG_INFO" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000073 { 0, NULL },
74};
75
Roland McGrathd9f816f2004-09-04 03:39:20 +000076static const struct xlat semctl_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000077 { IPC_RMID, "IPC_RMID" },
78 { IPC_SET, "IPC_SET" },
79 { IPC_STAT, "IPC_STAT" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000080 { IPC_INFO, "IPC_INFO" },
81 { SEM_STAT, "SEM_STAT" },
82 { SEM_INFO, "SEM_INFO" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000083 { GETPID, "GETPID" },
84 { GETVAL, "GETVAL" },
85 { GETALL, "GETALL" },
86 { GETNCNT, "GETNCNT" },
87 { GETZCNT, "GETZCNT" },
88 { SETVAL, "SETVAL" },
89 { SETALL, "SETALL" },
90 { 0, NULL },
91};
92
Roland McGrathd9f816f2004-09-04 03:39:20 +000093static const struct xlat shmctl_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000094 { IPC_RMID, "IPC_RMID" },
95 { IPC_SET, "IPC_SET" },
96 { IPC_STAT, "IPC_STAT" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000097 { IPC_INFO, "IPC_INFO" },
98 { SHM_STAT, "SHM_STAT" },
99 { SHM_INFO, "SHM_INFO" },
Roland McGrath80731792003-01-14 09:46:17 +0000100#ifdef SHM_LOCK
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000101 { SHM_LOCK, "SHM_LOCK" },
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000102#endif
Roland McGrath80731792003-01-14 09:46:17 +0000103#ifdef SHM_UNLOCK
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000104 { SHM_UNLOCK, "SHM_UNLOCK" },
Roland McGrath80731792003-01-14 09:46:17 +0000105#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000106 { 0, NULL },
107};
108
Roland McGrathd9f816f2004-09-04 03:39:20 +0000109static const struct xlat resource_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000110 { IPC_CREAT, "IPC_CREAT" },
111 { IPC_EXCL, "IPC_EXCL" },
112 { IPC_NOWAIT, "IPC_NOWAIT" },
Roland McGrath802b8f42005-05-09 07:40:33 +0000113 { 0, NULL },
114};
115
116static const struct xlat shm_resource_flags[] = {
117 { IPC_CREAT, "IPC_CREAT" },
118 { IPC_EXCL, "IPC_EXCL" },
Roland McGrathe2be9ab2003-07-17 09:03:04 +0000119#ifdef SHM_HUGETLB
120 { SHM_HUGETLB, "SHM_HUGETLB" },
121#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000122 { 0, NULL },
123};
124
Roland McGrathd9f816f2004-09-04 03:39:20 +0000125static const struct xlat shm_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000126 { SHM_REMAP, "SHM_REMAP" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000127 { SHM_RDONLY, "SHM_RDONLY" },
128 { SHM_RND, "SHM_RND" },
129 { 0, NULL },
130};
131
Roland McGrathd9f816f2004-09-04 03:39:20 +0000132static const struct xlat msg_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000133 { MSG_NOERROR, "MSG_NOERROR" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000134 { MSG_EXCEPT, "MSG_EXCEPT" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000135 { IPC_NOWAIT, "IPC_NOWAIT" },
136 { 0, NULL },
137};
138
Jakub Bogusz002e9852009-10-07 22:25:10 +0200139static const struct xlat semop_flags[] = {
140 { SEM_UNDO, "SEM_UNDO" },
141 { IPC_NOWAIT, "IPC_NOWAIT" },
142 { 0, NULL },
143};
144
Denys Vlasenko12014262011-05-30 14:00:14 +0200145int sys_msgget(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000146{
147 if (entering(tcp)) {
148 if (tcp->u_arg[0])
Roland McGrath9f130d52006-08-22 07:36:55 +0000149 tprintf("%#lx", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000150 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200151 tprints("IPC_PRIVATE");
152 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000153 if (printflags(resource_flags, tcp->u_arg[1] & ~0777, NULL) != 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200154 tprints("|");
Roland McGrathe2be9ab2003-07-17 09:03:04 +0000155 tprintf("%#lo", tcp->u_arg[1] & 0777);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000156 }
157 return 0;
158}
159
Roland McGrath80731792003-01-14 09:46:17 +0000160#ifdef IPC_64
161# define PRINTCTL(flagset, arg, dflt) \
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200162 if ((arg) & IPC_64) tprints("IPC_64|"); \
Roland McGrath80731792003-01-14 09:46:17 +0000163 printxval((flagset), (arg) &~ IPC_64, dflt)
164#else
165# define PRINTCTL printxval
166#endif
167
Roland McGrath54b90d72005-12-02 03:57:07 +0000168static int
Denys Vlasenko12014262011-05-30 14:00:14 +0200169indirect_ipccall(struct tcb *tcp)
Roland McGrath54b90d72005-12-02 03:57:07 +0000170{
Roland McGrath54b90d72005-12-02 03:57:07 +0000171#ifdef X86_64
172 return current_personality > 0;
173#endif
Roland McGratha81bf4c2005-12-02 04:18:55 +0000174#if defined IA64
175 return tcp->scno < 1024; /* ia32 emulation syscalls are low */
Roland McGrath54b90d72005-12-02 03:57:07 +0000176#endif
Dmitry V. Levin3d7b11b2012-03-15 21:19:36 +0000177#if defined(ALPHA) || defined(MIPS) || defined(HPPA) || defined(__ARM_EABI__)
Roland McGrath54b90d72005-12-02 03:57:07 +0000178 return 0;
Dmitry V. Levin3d7b11b2012-03-15 21:19:36 +0000179#endif
180 return 1;
Roland McGrath54b90d72005-12-02 03:57:07 +0000181}
182
Denys Vlasenko12014262011-05-30 14:00:14 +0200183int sys_msgctl(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000184{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000185 if (entering(tcp)) {
Roland McGrath80731792003-01-14 09:46:17 +0000186 tprintf("%lu, ", tcp->u_arg[0]);
187 PRINTCTL(msgctl_flags, tcp->u_arg[1], "MSG_???");
Roland McGrath54b90d72005-12-02 03:57:07 +0000188 tprintf(", %#lx", tcp->u_arg[indirect_ipccall(tcp) ? 3 : 2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000189 }
190 return 0;
191}
192
Dmitry V. Levin783f5bc2009-10-08 23:33:15 +0000193static void
Dmitry V. Levin4310a372010-03-31 22:22:01 +0000194tprint_msgsnd(struct tcb *tcp, long addr, unsigned long count,
195 unsigned long flags)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000196{
197 long mtype;
198
Dmitry V. Levin783f5bc2009-10-08 23:33:15 +0000199 if (umove(tcp, addr, &mtype) < 0) {
200 tprintf("%#lx", addr);
201 } else {
202 tprintf("{%lu, ", mtype);
203 printstr(tcp, addr + sizeof(mtype), count);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200204 tprints("}");
Dmitry V. Levin783f5bc2009-10-08 23:33:15 +0000205 }
206 tprintf(", %lu, ", count);
Dmitry V. Levin4310a372010-03-31 22:22:01 +0000207 printflags(msg_flags, flags, "MSG_???");
Dmitry V. Levin783f5bc2009-10-08 23:33:15 +0000208}
209
210int sys_msgsnd(struct tcb *tcp)
211{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000212 if (entering(tcp)) {
Dmitry V. Levin62e05962009-11-03 14:38:44 +0000213 tprintf("%d, ", (int) tcp->u_arg[0]);
Roland McGrath54b90d72005-12-02 03:57:07 +0000214 if (indirect_ipccall(tcp)) {
Dmitry V. Levin4310a372010-03-31 22:22:01 +0000215 tprint_msgsnd(tcp, tcp->u_arg[3], tcp->u_arg[1],
216 tcp->u_arg[2]);
Roland McGrath54b90d72005-12-02 03:57:07 +0000217 } else {
Dmitry V. Levin4310a372010-03-31 22:22:01 +0000218 tprint_msgsnd(tcp, tcp->u_arg[1], tcp->u_arg[2],
219 tcp->u_arg[3]);
Roland McGrath54b90d72005-12-02 03:57:07 +0000220 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000221 }
222 return 0;
223}
224
Dmitry V. Levin62e05962009-11-03 14:38:44 +0000225static void
226tprint_msgrcv(struct tcb *tcp, long addr, unsigned long count, long msgtyp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000227{
228 long mtype;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000229
Dmitry V. Levin62e05962009-11-03 14:38:44 +0000230 if (syserror(tcp) || umove(tcp, addr, &mtype) < 0) {
231 tprintf("%#lx", addr);
Roland McGrathf467c002005-12-02 03:44:12 +0000232 } else {
Dmitry V. Levin62e05962009-11-03 14:38:44 +0000233 tprintf("{%lu, ", mtype);
234 printstr(tcp, addr + sizeof(mtype), count);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200235 tprints("}");
Dmitry V. Levin62e05962009-11-03 14:38:44 +0000236 }
237 tprintf(", %lu, %ld, ", count, msgtyp);
238}
239
240int sys_msgrcv(struct tcb *tcp)
241{
242 if (entering(tcp)) {
243 tprintf("%d, ", (int) tcp->u_arg[0]);
244 } else {
Roland McGrath54b90d72005-12-02 03:57:07 +0000245 if (indirect_ipccall(tcp)) {
246 struct ipc_wrapper {
247 struct msgbuf *msgp;
248 long msgtyp;
249 } tmp;
Dmitry V. Levin62e05962009-11-03 14:38:44 +0000250
251 if (umove(tcp, tcp->u_arg[3], &tmp) < 0) {
252 tprintf("%#lx, %lu, ",
253 tcp->u_arg[3], tcp->u_arg[1]);
254 } else {
255 tprint_msgrcv(tcp, (long) tmp.msgp,
256 tcp->u_arg[1], tmp.msgtyp);
257 }
Roland McGrath54b90d72005-12-02 03:57:07 +0000258 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
259 } else {
Dmitry V. Levin62e05962009-11-03 14:38:44 +0000260 tprint_msgrcv(tcp, tcp->u_arg[1],
261 tcp->u_arg[2], tcp->u_arg[3]);
Roland McGrath54b90d72005-12-02 03:57:07 +0000262 printflags(msg_flags, tcp->u_arg[4], "MSG_???");
263 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000264 }
265 return 0;
266}
267
Dmitry V. Levinef941012009-10-07 22:14:00 +0000268static void
269tprint_sembuf(struct tcb *tcp, long addr, unsigned long count)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000270{
Dmitry V. Levinef941012009-10-07 22:14:00 +0000271 unsigned long i, max_count;
Jakub Bogusz002e9852009-10-07 22:25:10 +0200272
Dmitry V. Levinef941012009-10-07 22:14:00 +0000273 if (abbrev(tcp))
274 max_count = (max_strlen < count) ? max_strlen : count;
275 else
276 max_count = count;
277
278 if (!max_count) {
279 tprintf("%#lx, %lu", addr, count);
280 return;
281 }
282
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200283 for (i = 0; i < max_count; ++i) {
Dmitry V. Levinef941012009-10-07 22:14:00 +0000284 struct sembuf sb;
285 if (i)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200286 tprints(", ");
Dmitry V. Levinef941012009-10-07 22:14:00 +0000287 if (umove(tcp, addr + i * sizeof(struct sembuf), &sb) < 0) {
288 if (i) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200289 tprints("{???}");
Dmitry V. Levinef941012009-10-07 22:14:00 +0000290 break;
291 } else {
292 tprintf("%#lx, %lu", addr, count);
293 return;
Jakub Bogusz002e9852009-10-07 22:25:10 +0200294 }
Roland McGrath54b90d72005-12-02 03:57:07 +0000295 } else {
Dmitry V. Levinef941012009-10-07 22:14:00 +0000296 if (!i)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200297 tprints("{");
Dmitry V. Levinef941012009-10-07 22:14:00 +0000298 tprintf("{%u, %d, ", sb.sem_num, sb.sem_op);
299 printflags(semop_flags, sb.sem_flg, "SEM_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200300 tprints("}");
Dmitry V. Levinef941012009-10-07 22:14:00 +0000301 }
302 }
303
304 if (i < max_count || max_count < count)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200305 tprints(", ...");
Dmitry V. Levinef941012009-10-07 22:14:00 +0000306
307 tprintf("}, %lu", count);
308}
309
310int sys_semop(struct tcb *tcp)
311{
312 if (entering(tcp)) {
313 tprintf("%lu, ", tcp->u_arg[0]);
314 if (indirect_ipccall(tcp)) {
315 tprint_sembuf(tcp, tcp->u_arg[3], tcp->u_arg[1]);
316 } else {
317 tprint_sembuf(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Roland McGrath54b90d72005-12-02 03:57:07 +0000318 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000319 }
320 return 0;
321}
322
Dmitry V. Levinef941012009-10-07 22:14:00 +0000323int sys_semtimedop(struct tcb *tcp)
Roland McGrath84776472003-04-08 01:46:48 +0000324{
325 if (entering(tcp)) {
Dmitry V. Levinef941012009-10-07 22:14:00 +0000326 tprintf("%lu, ", tcp->u_arg[0]);
Roland McGratha079d9f2006-04-25 07:22:01 +0000327 if (indirect_ipccall(tcp)) {
Dmitry V. Levinef941012009-10-07 22:14:00 +0000328 tprint_sembuf(tcp, tcp->u_arg[3], tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200329 tprints(", ");
Heiko Carstense0f5fd82011-11-30 13:16:29 +0100330#if defined(S390)
331 printtv(tcp, tcp->u_arg[2]);
332#else
Roland McGrath54b90d72005-12-02 03:57:07 +0000333 printtv(tcp, tcp->u_arg[5]);
Heiko Carstense0f5fd82011-11-30 13:16:29 +0100334#endif
Roland McGrath54b90d72005-12-02 03:57:07 +0000335 } else {
Dmitry V. Levinef941012009-10-07 22:14:00 +0000336 tprint_sembuf(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200337 tprints(", ");
Roland McGrath54b90d72005-12-02 03:57:07 +0000338 printtv(tcp, tcp->u_arg[3]);
339 }
Roland McGrath84776472003-04-08 01:46:48 +0000340 }
341 return 0;
342}
Roland McGrath84776472003-04-08 01:46:48 +0000343
Denys Vlasenko12014262011-05-30 14:00:14 +0200344int sys_semget(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000345{
346 if (entering(tcp)) {
347 if (tcp->u_arg[0])
Roland McGrath9f130d52006-08-22 07:36:55 +0000348 tprintf("%#lx", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000349 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200350 tprints("IPC_PRIVATE");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000351 tprintf(", %lu", tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200352 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000353 if (printflags(resource_flags, tcp->u_arg[2] & ~0777, NULL) != 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200354 tprints("|");
Roland McGrathe2be9ab2003-07-17 09:03:04 +0000355 tprintf("%#lo", tcp->u_arg[2] & 0777);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000356 }
357 return 0;
358}
359
Denys Vlasenko12014262011-05-30 14:00:14 +0200360int sys_semctl(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000361{
362 if (entering(tcp)) {
363 tprintf("%lu", tcp->u_arg[0]);
364 tprintf(", %lu, ", tcp->u_arg[1]);
Roland McGrath80731792003-01-14 09:46:17 +0000365 PRINTCTL(semctl_flags, tcp->u_arg[2], "SEM_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000366 tprintf(", %#lx", tcp->u_arg[3]);
367 }
368 return 0;
369}
370
Denys Vlasenko12014262011-05-30 14:00:14 +0200371int sys_shmget(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000372{
373 if (entering(tcp)) {
374 if (tcp->u_arg[0])
Roland McGrath9f130d52006-08-22 07:36:55 +0000375 tprintf("%#lx", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000376 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200377 tprints("IPC_PRIVATE");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000378 tprintf(", %lu", tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200379 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000380 if (printflags(shm_resource_flags, tcp->u_arg[2] & ~0777, NULL) != 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200381 tprints("|");
Roland McGrathe2be9ab2003-07-17 09:03:04 +0000382 tprintf("%#lo", tcp->u_arg[2] & 0777);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000383 }
384 return 0;
385}
386
Denys Vlasenko12014262011-05-30 14:00:14 +0200387int sys_shmctl(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000388{
389 if (entering(tcp)) {
390 tprintf("%lu, ", tcp->u_arg[0]);
Roland McGrath80731792003-01-14 09:46:17 +0000391 PRINTCTL(shmctl_flags, tcp->u_arg[1], "SHM_???");
Roland McGrath54b90d72005-12-02 03:57:07 +0000392 if (indirect_ipccall(tcp)) {
393 tprintf(", %#lx", tcp->u_arg[3]);
394 } else {
395 tprintf(", %#lx", tcp->u_arg[2]);
396 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000397 }
398 return 0;
399}
400
Denys Vlasenko12014262011-05-30 14:00:14 +0200401int sys_shmat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000402{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000403 if (exiting(tcp)) {
404 tprintf("%lu", tcp->u_arg[0]);
Roland McGrath54b90d72005-12-02 03:57:07 +0000405 if (indirect_ipccall(tcp)) {
406 tprintf(", %#lx", tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200407 tprints(", ");
Roland McGrath54b90d72005-12-02 03:57:07 +0000408 printflags(shm_flags, tcp->u_arg[1], "SHM_???");
409 } else {
410 tprintf(", %#lx", tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200411 tprints(", ");
Roland McGrath54b90d72005-12-02 03:57:07 +0000412 printflags(shm_flags, tcp->u_arg[2], "SHM_???");
413 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000414 if (syserror(tcp))
415 return 0;
Dmitry V. Levin3d7b11b2012-03-15 21:19:36 +0000416 if (indirect_ipccall(tcp)) {
417 unsigned long raddr;
418 if (umove(tcp, tcp->u_arg[2], &raddr) < 0)
419 return RVAL_NONE;
420 tcp->u_rval = raddr;
421 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000422 return RVAL_HEX;
423 }
424 return 0;
425}
426
Denys Vlasenko12014262011-05-30 14:00:14 +0200427int sys_shmdt(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000428{
Roland McGrath54b90d72005-12-02 03:57:07 +0000429 if (entering(tcp)) {
430 if (indirect_ipccall(tcp)) {
431 tprintf("%#lx", tcp->u_arg[3]);
432 } else {
433 tprintf("%#lx", tcp->u_arg[0]);
434 }
435 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000436 return 0;
437}
438
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000439int
440sys_mq_open(struct tcb *tcp)
Roland McGrath4df13c12004-04-16 21:48:40 +0000441{
442 if (entering(tcp)) {
443 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200444 tprints(", ");
Roland McGrath4df13c12004-04-16 21:48:40 +0000445 /* flags */
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000446 tprint_open_modes(tcp->u_arg[1]);
Roland McGrath4df13c12004-04-16 21:48:40 +0000447 if (tcp->u_arg[1] & O_CREAT) {
448# ifndef HAVE_MQUEUE_H
449 tprintf(", %lx", tcp->u_arg[2]);
450# else
451 struct mq_attr attr;
452 /* mode */
453 tprintf(", %#lo, ", tcp->u_arg[2]);
454 if (umove(tcp, tcp->u_arg[3], &attr) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200455 tprints("{ ??? }");
Roland McGrath4df13c12004-04-16 21:48:40 +0000456 else
457 tprintf("{mq_maxmsg=%ld, mq_msgsize=%ld}",
H.J. Lu0b315b62012-02-03 10:16:03 -0800458 (long) attr.mq_maxmsg,
459 (long) attr.mq_msgsize);
Roland McGrath4df13c12004-04-16 21:48:40 +0000460# endif
461 }
462 }
463 return 0;
464}
465
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000466int
467sys_mq_timedsend(struct tcb *tcp)
Roland McGrath4df13c12004-04-16 21:48:40 +0000468{
469 if (entering(tcp)) {
470 tprintf("%ld, ", tcp->u_arg[0]);
471 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
472 tprintf(", %lu, %ld, ", tcp->u_arg[2], tcp->u_arg[3]);
473 printtv(tcp, tcp->u_arg[4]);
474 }
475 return 0;
476}
477
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000478int
479sys_mq_timedreceive(struct tcb *tcp)
Roland McGrath4df13c12004-04-16 21:48:40 +0000480{
481 if (entering(tcp))
482 tprintf("%ld, ", tcp->u_arg[0]);
483 else {
484 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
485 tprintf(", %lu, %ld, ", tcp->u_arg[2], tcp->u_arg[3]);
486 printtv(tcp, tcp->u_arg[4]);
487 }
488 return 0;
489}
490
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000491int
492sys_mq_notify(struct tcb *tcp)
Roland McGrath4df13c12004-04-16 21:48:40 +0000493{
494 if (entering(tcp)) {
495 tprintf("%ld, ", tcp->u_arg[0]);
496 printsigevent(tcp, tcp->u_arg[1]);
497 }
498 return 0;
499}
500
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000501static void
502printmqattr(struct tcb *tcp, long addr)
Roland McGrath4df13c12004-04-16 21:48:40 +0000503{
504 if (addr == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200505 tprints("NULL");
Roland McGrath4df13c12004-04-16 21:48:40 +0000506 else {
507# ifndef HAVE_MQUEUE_H
508 tprintf("%#lx", addr);
509# else
510 struct mq_attr attr;
511 if (umove(tcp, addr, &attr) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200512 tprints("{...}");
Roland McGrath4df13c12004-04-16 21:48:40 +0000513 return;
514 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200515 tprints("{mq_flags=");
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000516 tprint_open_modes(attr.mq_flags);
Roland McGrath4df13c12004-04-16 21:48:40 +0000517 tprintf(", mq_maxmsg=%ld, mq_msgsize=%ld, mq_curmsg=%ld}",
H.J. Lu0b315b62012-02-03 10:16:03 -0800518 (long) attr.mq_maxmsg, (long) attr.mq_msgsize,
519 (long) attr.mq_curmsgs);
Roland McGrath4df13c12004-04-16 21:48:40 +0000520# endif
521 }
522}
523
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000524int
525sys_mq_getsetattr(struct tcb *tcp)
Roland McGrath4df13c12004-04-16 21:48:40 +0000526{
527 if (entering(tcp)) {
528 tprintf("%ld, ", tcp->u_arg[0]);
529 printmqattr(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200530 tprints(", ");
Roland McGrath4df13c12004-04-16 21:48:40 +0000531 } else
532 printmqattr(tcp, tcp->u_arg[2]);
533 return 0;
534}
Dmitry V. Levinb5e88d42012-02-20 17:02:38 +0000535
536int
537sys_ipc(struct tcb *tcp)
538{
539 return printargs(tcp);
540}