blob: 0b91a526ad9a05e039bb666b56acf6bc73bc5add [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])
Denys Vlasenko859ea8b2013-02-23 20:07:44 +0100149 tprintf("%#lx, ", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000150 else
Denys Vlasenko859ea8b2013-02-23 20:07:44 +0100151 tprints("IPC_PRIVATE, ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000152 if (printflags(resource_flags, tcp->u_arg[1] & ~0777, NULL) != 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200153 tprints("|");
Roland McGrathe2be9ab2003-07-17 09:03:04 +0000154 tprintf("%#lo", tcp->u_arg[1] & 0777);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000155 }
156 return 0;
157}
158
Roland McGrath80731792003-01-14 09:46:17 +0000159#ifdef IPC_64
160# define PRINTCTL(flagset, arg, dflt) \
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200161 if ((arg) & IPC_64) tprints("IPC_64|"); \
Roland McGrath80731792003-01-14 09:46:17 +0000162 printxval((flagset), (arg) &~ IPC_64, dflt)
163#else
164# define PRINTCTL printxval
165#endif
166
Roland McGrath54b90d72005-12-02 03:57:07 +0000167static int
Denys Vlasenko12014262011-05-30 14:00:14 +0200168indirect_ipccall(struct tcb *tcp)
Roland McGrath54b90d72005-12-02 03:57:07 +0000169{
Roland McGrath54b90d72005-12-02 03:57:07 +0000170#ifdef X86_64
H.J. Lu35be5812012-04-16 13:00:01 +0200171 return current_personality == 1;
Roland McGrath54b90d72005-12-02 03:57:07 +0000172#endif
Roland McGratha81bf4c2005-12-02 04:18:55 +0000173#if defined IA64
174 return tcp->scno < 1024; /* ia32 emulation syscalls are low */
Roland McGrath54b90d72005-12-02 03:57:07 +0000175#endif
Steve McIntyred8d3bd32012-10-24 17:58:16 +0100176#if defined(ALPHA) || defined(MIPS) || defined(HPPA) || defined(__ARM_EABI__) || defined(AARCH64)
Roland McGrath54b90d72005-12-02 03:57:07 +0000177 return 0;
Dmitry V. Levin3d7b11b2012-03-15 21:19:36 +0000178#endif
179 return 1;
Roland McGrath54b90d72005-12-02 03:57:07 +0000180}
181
Denys Vlasenko12014262011-05-30 14:00:14 +0200182int sys_msgctl(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000183{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000184 if (entering(tcp)) {
Roland McGrath80731792003-01-14 09:46:17 +0000185 tprintf("%lu, ", tcp->u_arg[0]);
186 PRINTCTL(msgctl_flags, tcp->u_arg[1], "MSG_???");
Roland McGrath54b90d72005-12-02 03:57:07 +0000187 tprintf(", %#lx", tcp->u_arg[indirect_ipccall(tcp) ? 3 : 2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000188 }
189 return 0;
190}
191
Dmitry V. Levin783f5bc2009-10-08 23:33:15 +0000192static void
Dmitry V. Levin4310a372010-03-31 22:22:01 +0000193tprint_msgsnd(struct tcb *tcp, long addr, unsigned long count,
194 unsigned long flags)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000195{
196 long mtype;
197
Dmitry V. Levin783f5bc2009-10-08 23:33:15 +0000198 if (umove(tcp, addr, &mtype) < 0) {
199 tprintf("%#lx", addr);
200 } else {
201 tprintf("{%lu, ", mtype);
202 printstr(tcp, addr + sizeof(mtype), count);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200203 tprints("}");
Dmitry V. Levin783f5bc2009-10-08 23:33:15 +0000204 }
205 tprintf(", %lu, ", count);
Dmitry V. Levin4310a372010-03-31 22:22:01 +0000206 printflags(msg_flags, flags, "MSG_???");
Dmitry V. Levin783f5bc2009-10-08 23:33:15 +0000207}
208
209int sys_msgsnd(struct tcb *tcp)
210{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000211 if (entering(tcp)) {
Dmitry V. Levin62e05962009-11-03 14:38:44 +0000212 tprintf("%d, ", (int) tcp->u_arg[0]);
Roland McGrath54b90d72005-12-02 03:57:07 +0000213 if (indirect_ipccall(tcp)) {
Dmitry V. Levin4310a372010-03-31 22:22:01 +0000214 tprint_msgsnd(tcp, tcp->u_arg[3], tcp->u_arg[1],
215 tcp->u_arg[2]);
Roland McGrath54b90d72005-12-02 03:57:07 +0000216 } else {
Dmitry V. Levin4310a372010-03-31 22:22:01 +0000217 tprint_msgsnd(tcp, tcp->u_arg[1], tcp->u_arg[2],
218 tcp->u_arg[3]);
Roland McGrath54b90d72005-12-02 03:57:07 +0000219 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000220 }
221 return 0;
222}
223
Dmitry V. Levin62e05962009-11-03 14:38:44 +0000224static void
225tprint_msgrcv(struct tcb *tcp, long addr, unsigned long count, long msgtyp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000226{
227 long mtype;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000228
Dmitry V. Levin62e05962009-11-03 14:38:44 +0000229 if (syserror(tcp) || umove(tcp, addr, &mtype) < 0) {
230 tprintf("%#lx", addr);
Roland McGrathf467c002005-12-02 03:44:12 +0000231 } else {
Dmitry V. Levin62e05962009-11-03 14:38:44 +0000232 tprintf("{%lu, ", mtype);
233 printstr(tcp, addr + sizeof(mtype), count);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200234 tprints("}");
Dmitry V. Levin62e05962009-11-03 14:38:44 +0000235 }
236 tprintf(", %lu, %ld, ", count, msgtyp);
237}
238
239int sys_msgrcv(struct tcb *tcp)
240{
241 if (entering(tcp)) {
242 tprintf("%d, ", (int) tcp->u_arg[0]);
243 } else {
Roland McGrath54b90d72005-12-02 03:57:07 +0000244 if (indirect_ipccall(tcp)) {
245 struct ipc_wrapper {
246 struct msgbuf *msgp;
247 long msgtyp;
248 } tmp;
Dmitry V. Levin62e05962009-11-03 14:38:44 +0000249
250 if (umove(tcp, tcp->u_arg[3], &tmp) < 0) {
251 tprintf("%#lx, %lu, ",
252 tcp->u_arg[3], tcp->u_arg[1]);
253 } else {
254 tprint_msgrcv(tcp, (long) tmp.msgp,
255 tcp->u_arg[1], tmp.msgtyp);
256 }
Roland McGrath54b90d72005-12-02 03:57:07 +0000257 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
258 } else {
Dmitry V. Levin62e05962009-11-03 14:38:44 +0000259 tprint_msgrcv(tcp, tcp->u_arg[1],
260 tcp->u_arg[2], tcp->u_arg[3]);
Roland McGrath54b90d72005-12-02 03:57:07 +0000261 printflags(msg_flags, tcp->u_arg[4], "MSG_???");
262 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000263 }
264 return 0;
265}
266
Dmitry V. Levinef941012009-10-07 22:14:00 +0000267static void
268tprint_sembuf(struct tcb *tcp, long addr, unsigned long count)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000269{
Dmitry V. Levinef941012009-10-07 22:14:00 +0000270 unsigned long i, max_count;
Jakub Bogusz002e9852009-10-07 22:25:10 +0200271
Dmitry V. Levinef941012009-10-07 22:14:00 +0000272 if (abbrev(tcp))
273 max_count = (max_strlen < count) ? max_strlen : count;
274 else
275 max_count = count;
276
277 if (!max_count) {
278 tprintf("%#lx, %lu", addr, count);
279 return;
280 }
281
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200282 for (i = 0; i < max_count; ++i) {
Dmitry V. Levinef941012009-10-07 22:14:00 +0000283 struct sembuf sb;
284 if (i)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200285 tprints(", ");
Dmitry V. Levinef941012009-10-07 22:14:00 +0000286 if (umove(tcp, addr + i * sizeof(struct sembuf), &sb) < 0) {
287 if (i) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200288 tprints("{???}");
Dmitry V. Levinef941012009-10-07 22:14:00 +0000289 break;
290 } else {
291 tprintf("%#lx, %lu", addr, count);
292 return;
Jakub Bogusz002e9852009-10-07 22:25:10 +0200293 }
Roland McGrath54b90d72005-12-02 03:57:07 +0000294 } else {
Dmitry V. Levinef941012009-10-07 22:14:00 +0000295 if (!i)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200296 tprints("{");
Dmitry V. Levinef941012009-10-07 22:14:00 +0000297 tprintf("{%u, %d, ", sb.sem_num, sb.sem_op);
298 printflags(semop_flags, sb.sem_flg, "SEM_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200299 tprints("}");
Dmitry V. Levinef941012009-10-07 22:14:00 +0000300 }
301 }
302
303 if (i < max_count || max_count < count)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200304 tprints(", ...");
Dmitry V. Levinef941012009-10-07 22:14:00 +0000305
306 tprintf("}, %lu", count);
307}
308
309int sys_semop(struct tcb *tcp)
310{
311 if (entering(tcp)) {
312 tprintf("%lu, ", tcp->u_arg[0]);
313 if (indirect_ipccall(tcp)) {
314 tprint_sembuf(tcp, tcp->u_arg[3], tcp->u_arg[1]);
315 } else {
316 tprint_sembuf(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Roland McGrath54b90d72005-12-02 03:57:07 +0000317 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000318 }
319 return 0;
320}
321
Dmitry V. Levinef941012009-10-07 22:14:00 +0000322int sys_semtimedop(struct tcb *tcp)
Roland McGrath84776472003-04-08 01:46:48 +0000323{
324 if (entering(tcp)) {
Dmitry V. Levinef941012009-10-07 22:14:00 +0000325 tprintf("%lu, ", tcp->u_arg[0]);
Roland McGratha079d9f2006-04-25 07:22:01 +0000326 if (indirect_ipccall(tcp)) {
Dmitry V. Levinef941012009-10-07 22:14:00 +0000327 tprint_sembuf(tcp, tcp->u_arg[3], tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200328 tprints(", ");
Stanislav Brabecbeae4c72012-12-10 20:18:49 +0100329#if defined(S390) || defined(S390X)
Heiko Carstense0f5fd82011-11-30 13:16:29 +0100330 printtv(tcp, tcp->u_arg[2]);
331#else
Stanislav Brabeceff5c0e2012-12-07 21:30:51 +0100332 printtv(tcp, tcp->u_arg[4]);
Heiko Carstense0f5fd82011-11-30 13:16:29 +0100333#endif
Roland McGrath54b90d72005-12-02 03:57:07 +0000334 } else {
Dmitry V. Levinef941012009-10-07 22:14:00 +0000335 tprint_sembuf(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200336 tprints(", ");
Roland McGrath54b90d72005-12-02 03:57:07 +0000337 printtv(tcp, tcp->u_arg[3]);
338 }
Roland McGrath84776472003-04-08 01:46:48 +0000339 }
340 return 0;
341}
Roland McGrath84776472003-04-08 01:46:48 +0000342
Denys Vlasenko12014262011-05-30 14:00:14 +0200343int sys_semget(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000344{
345 if (entering(tcp)) {
346 if (tcp->u_arg[0])
Roland McGrath9f130d52006-08-22 07:36:55 +0000347 tprintf("%#lx", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000348 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200349 tprints("IPC_PRIVATE");
Denys Vlasenko859ea8b2013-02-23 20:07:44 +0100350 tprintf(", %lu, ", tcp->u_arg[1]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000351 if (printflags(resource_flags, tcp->u_arg[2] & ~0777, NULL) != 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200352 tprints("|");
Roland McGrathe2be9ab2003-07-17 09:03:04 +0000353 tprintf("%#lo", tcp->u_arg[2] & 0777);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000354 }
355 return 0;
356}
357
Denys Vlasenko12014262011-05-30 14:00:14 +0200358int sys_semctl(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000359{
360 if (entering(tcp)) {
Denys Vlasenko859ea8b2013-02-23 20:07:44 +0100361 tprintf("%lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrath80731792003-01-14 09:46:17 +0000362 PRINTCTL(semctl_flags, tcp->u_arg[2], "SEM_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000363 tprintf(", %#lx", tcp->u_arg[3]);
364 }
365 return 0;
366}
367
Denys Vlasenko12014262011-05-30 14:00:14 +0200368int sys_shmget(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000369{
370 if (entering(tcp)) {
371 if (tcp->u_arg[0])
Roland McGrath9f130d52006-08-22 07:36:55 +0000372 tprintf("%#lx", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000373 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200374 tprints("IPC_PRIVATE");
Denys Vlasenko859ea8b2013-02-23 20:07:44 +0100375 tprintf(", %lu, ", tcp->u_arg[1]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000376 if (printflags(shm_resource_flags, tcp->u_arg[2] & ~0777, NULL) != 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200377 tprints("|");
Roland McGrathe2be9ab2003-07-17 09:03:04 +0000378 tprintf("%#lo", tcp->u_arg[2] & 0777);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000379 }
380 return 0;
381}
382
Denys Vlasenko12014262011-05-30 14:00:14 +0200383int sys_shmctl(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000384{
385 if (entering(tcp)) {
386 tprintf("%lu, ", tcp->u_arg[0]);
Roland McGrath80731792003-01-14 09:46:17 +0000387 PRINTCTL(shmctl_flags, tcp->u_arg[1], "SHM_???");
Roland McGrath54b90d72005-12-02 03:57:07 +0000388 if (indirect_ipccall(tcp)) {
389 tprintf(", %#lx", tcp->u_arg[3]);
390 } else {
391 tprintf(", %#lx", tcp->u_arg[2]);
392 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000393 }
394 return 0;
395}
396
Denys Vlasenko12014262011-05-30 14:00:14 +0200397int sys_shmat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000398{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000399 if (exiting(tcp)) {
400 tprintf("%lu", tcp->u_arg[0]);
Roland McGrath54b90d72005-12-02 03:57:07 +0000401 if (indirect_ipccall(tcp)) {
Denys Vlasenko859ea8b2013-02-23 20:07:44 +0100402 tprintf(", %#lx, ", tcp->u_arg[3]);
Roland McGrath54b90d72005-12-02 03:57:07 +0000403 printflags(shm_flags, tcp->u_arg[1], "SHM_???");
404 } else {
Denys Vlasenko859ea8b2013-02-23 20:07:44 +0100405 tprintf(", %#lx, ", tcp->u_arg[1]);
Roland McGrath54b90d72005-12-02 03:57:07 +0000406 printflags(shm_flags, tcp->u_arg[2], "SHM_???");
407 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000408 if (syserror(tcp))
409 return 0;
Dmitry V. Levin3d7b11b2012-03-15 21:19:36 +0000410 if (indirect_ipccall(tcp)) {
411 unsigned long raddr;
412 if (umove(tcp, tcp->u_arg[2], &raddr) < 0)
413 return RVAL_NONE;
414 tcp->u_rval = raddr;
415 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000416 return RVAL_HEX;
417 }
418 return 0;
419}
420
Denys Vlasenko12014262011-05-30 14:00:14 +0200421int sys_shmdt(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000422{
Roland McGrath54b90d72005-12-02 03:57:07 +0000423 if (entering(tcp)) {
424 if (indirect_ipccall(tcp)) {
425 tprintf("%#lx", tcp->u_arg[3]);
426 } else {
427 tprintf("%#lx", tcp->u_arg[0]);
428 }
429 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000430 return 0;
431}
432
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000433int
434sys_mq_open(struct tcb *tcp)
Roland McGrath4df13c12004-04-16 21:48:40 +0000435{
436 if (entering(tcp)) {
437 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200438 tprints(", ");
Roland McGrath4df13c12004-04-16 21:48:40 +0000439 /* flags */
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000440 tprint_open_modes(tcp->u_arg[1]);
Roland McGrath4df13c12004-04-16 21:48:40 +0000441 if (tcp->u_arg[1] & O_CREAT) {
442# ifndef HAVE_MQUEUE_H
443 tprintf(", %lx", tcp->u_arg[2]);
444# else
445 struct mq_attr attr;
446 /* mode */
447 tprintf(", %#lo, ", tcp->u_arg[2]);
448 if (umove(tcp, tcp->u_arg[3], &attr) < 0)
Denys Vlasenko859ea8b2013-02-23 20:07:44 +0100449 tprints("{???}");
Roland McGrath4df13c12004-04-16 21:48:40 +0000450 else
451 tprintf("{mq_maxmsg=%ld, mq_msgsize=%ld}",
H.J. Lu0b315b62012-02-03 10:16:03 -0800452 (long) attr.mq_maxmsg,
453 (long) attr.mq_msgsize);
Roland McGrath4df13c12004-04-16 21:48:40 +0000454# endif
455 }
456 }
457 return 0;
458}
459
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000460int
461sys_mq_timedsend(struct tcb *tcp)
Roland McGrath4df13c12004-04-16 21:48:40 +0000462{
463 if (entering(tcp)) {
464 tprintf("%ld, ", tcp->u_arg[0]);
465 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
466 tprintf(", %lu, %ld, ", tcp->u_arg[2], tcp->u_arg[3]);
467 printtv(tcp, tcp->u_arg[4]);
468 }
469 return 0;
470}
471
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000472int
473sys_mq_timedreceive(struct tcb *tcp)
Roland McGrath4df13c12004-04-16 21:48:40 +0000474{
475 if (entering(tcp))
476 tprintf("%ld, ", tcp->u_arg[0]);
477 else {
478 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
479 tprintf(", %lu, %ld, ", tcp->u_arg[2], tcp->u_arg[3]);
480 printtv(tcp, tcp->u_arg[4]);
481 }
482 return 0;
483}
484
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000485int
486sys_mq_notify(struct tcb *tcp)
Roland McGrath4df13c12004-04-16 21:48:40 +0000487{
488 if (entering(tcp)) {
489 tprintf("%ld, ", tcp->u_arg[0]);
490 printsigevent(tcp, tcp->u_arg[1]);
491 }
492 return 0;
493}
494
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000495static void
496printmqattr(struct tcb *tcp, long addr)
Roland McGrath4df13c12004-04-16 21:48:40 +0000497{
498 if (addr == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200499 tprints("NULL");
Roland McGrath4df13c12004-04-16 21:48:40 +0000500 else {
501# ifndef HAVE_MQUEUE_H
502 tprintf("%#lx", addr);
503# else
504 struct mq_attr attr;
505 if (umove(tcp, addr, &attr) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200506 tprints("{...}");
Roland McGrath4df13c12004-04-16 21:48:40 +0000507 return;
508 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200509 tprints("{mq_flags=");
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000510 tprint_open_modes(attr.mq_flags);
Roland McGrath4df13c12004-04-16 21:48:40 +0000511 tprintf(", mq_maxmsg=%ld, mq_msgsize=%ld, mq_curmsg=%ld}",
H.J. Lu0b315b62012-02-03 10:16:03 -0800512 (long) attr.mq_maxmsg, (long) attr.mq_msgsize,
513 (long) attr.mq_curmsgs);
Roland McGrath4df13c12004-04-16 21:48:40 +0000514# endif
515 }
516}
517
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000518int
519sys_mq_getsetattr(struct tcb *tcp)
Roland McGrath4df13c12004-04-16 21:48:40 +0000520{
521 if (entering(tcp)) {
522 tprintf("%ld, ", tcp->u_arg[0]);
523 printmqattr(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200524 tprints(", ");
Roland McGrath4df13c12004-04-16 21:48:40 +0000525 } else
526 printmqattr(tcp, tcp->u_arg[2]);
527 return 0;
528}
Dmitry V. Levinb5e88d42012-02-20 17:02:38 +0000529
530int
531sys_ipc(struct tcb *tcp)
532{
533 return printargs(tcp);
534}