blob: e1746cba05375170824a3955c572f353731747e7 [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.
29 *
30 * $Id$
31 */
32
33#include "defs.h"
34
Roland McGrath4df13c12004-04-16 21:48:40 +000035# ifdef HAVE_MQUEUE_H
36# include <mqueue.h>
37# endif
38
39#include <fcntl.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000040#include <sys/ipc.h>
41#include <sys/sem.h>
42#include <sys/msg.h>
43#include <sys/shm.h>
44
45#ifndef MSG_STAT
46#define MSG_STAT 11
47#endif
48#ifndef MSG_INFO
49#define MSG_INFO 12
50#endif
51#ifndef SHM_STAT
52#define SHM_STAT 13
53#endif
54#ifndef SHM_INFO
55#define SHM_INFO 14
56#endif
57#ifndef SEM_STAT
58#define SEM_STAT 18
59#endif
60#ifndef SEM_INFO
61#define SEM_INFO 19
62#endif
63
Denys Vlasenko84703742012-02-25 02:38:52 +010064#if !defined IPC_64
Roland McGrath80731792003-01-14 09:46:17 +000065# define IPC_64 0x100
66#endif
67
Roland McGrath4df13c12004-04-16 21:48:40 +000068extern void printsigevent(struct tcb *tcp, long arg);
69
Roland McGrathd9f816f2004-09-04 03:39:20 +000070static const struct xlat msgctl_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000071 { IPC_RMID, "IPC_RMID" },
72 { IPC_SET, "IPC_SET" },
73 { IPC_STAT, "IPC_STAT" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000074 { IPC_INFO, "IPC_INFO" },
75 { MSG_STAT, "MSG_STAT" },
76 { MSG_INFO, "MSG_INFO" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000077 { 0, NULL },
78};
79
Roland McGrathd9f816f2004-09-04 03:39:20 +000080static const struct xlat semctl_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000081 { IPC_RMID, "IPC_RMID" },
82 { IPC_SET, "IPC_SET" },
83 { IPC_STAT, "IPC_STAT" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000084 { IPC_INFO, "IPC_INFO" },
85 { SEM_STAT, "SEM_STAT" },
86 { SEM_INFO, "SEM_INFO" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000087 { GETPID, "GETPID" },
88 { GETVAL, "GETVAL" },
89 { GETALL, "GETALL" },
90 { GETNCNT, "GETNCNT" },
91 { GETZCNT, "GETZCNT" },
92 { SETVAL, "SETVAL" },
93 { SETALL, "SETALL" },
94 { 0, NULL },
95};
96
Roland McGrathd9f816f2004-09-04 03:39:20 +000097static const struct xlat shmctl_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000098 { IPC_RMID, "IPC_RMID" },
99 { IPC_SET, "IPC_SET" },
100 { IPC_STAT, "IPC_STAT" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000101 { IPC_INFO, "IPC_INFO" },
102 { SHM_STAT, "SHM_STAT" },
103 { SHM_INFO, "SHM_INFO" },
Roland McGrath80731792003-01-14 09:46:17 +0000104#ifdef SHM_LOCK
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000105 { SHM_LOCK, "SHM_LOCK" },
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000106#endif
Roland McGrath80731792003-01-14 09:46:17 +0000107#ifdef SHM_UNLOCK
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000108 { SHM_UNLOCK, "SHM_UNLOCK" },
Roland McGrath80731792003-01-14 09:46:17 +0000109#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000110 { 0, NULL },
111};
112
Roland McGrathd9f816f2004-09-04 03:39:20 +0000113static const struct xlat resource_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000114 { IPC_CREAT, "IPC_CREAT" },
115 { IPC_EXCL, "IPC_EXCL" },
116 { IPC_NOWAIT, "IPC_NOWAIT" },
Roland McGrath802b8f42005-05-09 07:40:33 +0000117 { 0, NULL },
118};
119
120static const struct xlat shm_resource_flags[] = {
121 { IPC_CREAT, "IPC_CREAT" },
122 { IPC_EXCL, "IPC_EXCL" },
Roland McGrathe2be9ab2003-07-17 09:03:04 +0000123#ifdef SHM_HUGETLB
124 { SHM_HUGETLB, "SHM_HUGETLB" },
125#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000126 { 0, NULL },
127};
128
Roland McGrathd9f816f2004-09-04 03:39:20 +0000129static const struct xlat shm_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000130 { SHM_REMAP, "SHM_REMAP" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000131 { SHM_RDONLY, "SHM_RDONLY" },
132 { SHM_RND, "SHM_RND" },
133 { 0, NULL },
134};
135
Roland McGrathd9f816f2004-09-04 03:39:20 +0000136static const struct xlat msg_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000137 { MSG_NOERROR, "MSG_NOERROR" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000138 { MSG_EXCEPT, "MSG_EXCEPT" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000139 { IPC_NOWAIT, "IPC_NOWAIT" },
140 { 0, NULL },
141};
142
Jakub Bogusz002e9852009-10-07 22:25:10 +0200143static const struct xlat semop_flags[] = {
144 { SEM_UNDO, "SEM_UNDO" },
145 { IPC_NOWAIT, "IPC_NOWAIT" },
146 { 0, NULL },
147};
148
Denys Vlasenko12014262011-05-30 14:00:14 +0200149int sys_msgget(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000150{
151 if (entering(tcp)) {
152 if (tcp->u_arg[0])
Roland McGrath9f130d52006-08-22 07:36:55 +0000153 tprintf("%#lx", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000154 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200155 tprints("IPC_PRIVATE");
156 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000157 if (printflags(resource_flags, tcp->u_arg[1] & ~0777, NULL) != 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200158 tprints("|");
Roland McGrathe2be9ab2003-07-17 09:03:04 +0000159 tprintf("%#lo", tcp->u_arg[1] & 0777);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000160 }
161 return 0;
162}
163
Roland McGrath80731792003-01-14 09:46:17 +0000164#ifdef IPC_64
165# define PRINTCTL(flagset, arg, dflt) \
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200166 if ((arg) & IPC_64) tprints("IPC_64|"); \
Roland McGrath80731792003-01-14 09:46:17 +0000167 printxval((flagset), (arg) &~ IPC_64, dflt)
168#else
169# define PRINTCTL printxval
170#endif
171
Roland McGrath54b90d72005-12-02 03:57:07 +0000172static int
Denys Vlasenko12014262011-05-30 14:00:14 +0200173indirect_ipccall(struct tcb *tcp)
Roland McGrath54b90d72005-12-02 03:57:07 +0000174{
Roland McGrath54b90d72005-12-02 03:57:07 +0000175#ifdef X86_64
176 return current_personality > 0;
177#endif
Roland McGratha81bf4c2005-12-02 04:18:55 +0000178#if defined IA64
179 return tcp->scno < 1024; /* ia32 emulation syscalls are low */
Roland McGrath54b90d72005-12-02 03:57:07 +0000180#endif
Roland McGrathe1ebaab2005-12-02 04:34:09 +0000181#if !defined MIPS && !defined HPPA
182 return 1;
183#endif
Roland McGrath54b90d72005-12-02 03:57:07 +0000184 return 0;
185}
186
Denys Vlasenko12014262011-05-30 14:00:14 +0200187int sys_msgctl(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000188{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000189 if (entering(tcp)) {
Roland McGrath80731792003-01-14 09:46:17 +0000190 tprintf("%lu, ", tcp->u_arg[0]);
191 PRINTCTL(msgctl_flags, tcp->u_arg[1], "MSG_???");
Roland McGrath54b90d72005-12-02 03:57:07 +0000192 tprintf(", %#lx", tcp->u_arg[indirect_ipccall(tcp) ? 3 : 2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000193 }
194 return 0;
195}
196
Dmitry V. Levin783f5bc2009-10-08 23:33:15 +0000197static void
Dmitry V. Levin4310a372010-03-31 22:22:01 +0000198tprint_msgsnd(struct tcb *tcp, long addr, unsigned long count,
199 unsigned long flags)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000200{
201 long mtype;
202
Dmitry V. Levin783f5bc2009-10-08 23:33:15 +0000203 if (umove(tcp, addr, &mtype) < 0) {
204 tprintf("%#lx", addr);
205 } else {
206 tprintf("{%lu, ", mtype);
207 printstr(tcp, addr + sizeof(mtype), count);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200208 tprints("}");
Dmitry V. Levin783f5bc2009-10-08 23:33:15 +0000209 }
210 tprintf(", %lu, ", count);
Dmitry V. Levin4310a372010-03-31 22:22:01 +0000211 printflags(msg_flags, flags, "MSG_???");
Dmitry V. Levin783f5bc2009-10-08 23:33:15 +0000212}
213
214int sys_msgsnd(struct tcb *tcp)
215{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000216 if (entering(tcp)) {
Dmitry V. Levin62e05962009-11-03 14:38:44 +0000217 tprintf("%d, ", (int) tcp->u_arg[0]);
Roland McGrath54b90d72005-12-02 03:57:07 +0000218 if (indirect_ipccall(tcp)) {
Dmitry V. Levin4310a372010-03-31 22:22:01 +0000219 tprint_msgsnd(tcp, tcp->u_arg[3], tcp->u_arg[1],
220 tcp->u_arg[2]);
Roland McGrath54b90d72005-12-02 03:57:07 +0000221 } else {
Dmitry V. Levin4310a372010-03-31 22:22:01 +0000222 tprint_msgsnd(tcp, tcp->u_arg[1], tcp->u_arg[2],
223 tcp->u_arg[3]);
Roland McGrath54b90d72005-12-02 03:57:07 +0000224 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000225 }
226 return 0;
227}
228
Dmitry V. Levin62e05962009-11-03 14:38:44 +0000229static void
230tprint_msgrcv(struct tcb *tcp, long addr, unsigned long count, long msgtyp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000231{
232 long mtype;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000233
Dmitry V. Levin62e05962009-11-03 14:38:44 +0000234 if (syserror(tcp) || umove(tcp, addr, &mtype) < 0) {
235 tprintf("%#lx", addr);
Roland McGrathf467c002005-12-02 03:44:12 +0000236 } else {
Dmitry V. Levin62e05962009-11-03 14:38:44 +0000237 tprintf("{%lu, ", mtype);
238 printstr(tcp, addr + sizeof(mtype), count);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200239 tprints("}");
Dmitry V. Levin62e05962009-11-03 14:38:44 +0000240 }
241 tprintf(", %lu, %ld, ", count, msgtyp);
242}
243
244int sys_msgrcv(struct tcb *tcp)
245{
246 if (entering(tcp)) {
247 tprintf("%d, ", (int) tcp->u_arg[0]);
248 } else {
Roland McGrath54b90d72005-12-02 03:57:07 +0000249 if (indirect_ipccall(tcp)) {
250 struct ipc_wrapper {
251 struct msgbuf *msgp;
252 long msgtyp;
253 } tmp;
Dmitry V. Levin62e05962009-11-03 14:38:44 +0000254
255 if (umove(tcp, tcp->u_arg[3], &tmp) < 0) {
256 tprintf("%#lx, %lu, ",
257 tcp->u_arg[3], tcp->u_arg[1]);
258 } else {
259 tprint_msgrcv(tcp, (long) tmp.msgp,
260 tcp->u_arg[1], tmp.msgtyp);
261 }
Roland McGrath54b90d72005-12-02 03:57:07 +0000262 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
263 } else {
Dmitry V. Levin62e05962009-11-03 14:38:44 +0000264 tprint_msgrcv(tcp, tcp->u_arg[1],
265 tcp->u_arg[2], tcp->u_arg[3]);
Roland McGrath54b90d72005-12-02 03:57:07 +0000266 printflags(msg_flags, tcp->u_arg[4], "MSG_???");
267 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000268 }
269 return 0;
270}
271
Dmitry V. Levinef941012009-10-07 22:14:00 +0000272static void
273tprint_sembuf(struct tcb *tcp, long addr, unsigned long count)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000274{
Dmitry V. Levinef941012009-10-07 22:14:00 +0000275 unsigned long i, max_count;
Jakub Bogusz002e9852009-10-07 22:25:10 +0200276
Dmitry V. Levinef941012009-10-07 22:14:00 +0000277 if (abbrev(tcp))
278 max_count = (max_strlen < count) ? max_strlen : count;
279 else
280 max_count = count;
281
282 if (!max_count) {
283 tprintf("%#lx, %lu", addr, count);
284 return;
285 }
286
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200287 for (i = 0; i < max_count; ++i) {
Dmitry V. Levinef941012009-10-07 22:14:00 +0000288 struct sembuf sb;
289 if (i)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200290 tprints(", ");
Dmitry V. Levinef941012009-10-07 22:14:00 +0000291 if (umove(tcp, addr + i * sizeof(struct sembuf), &sb) < 0) {
292 if (i) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200293 tprints("{???}");
Dmitry V. Levinef941012009-10-07 22:14:00 +0000294 break;
295 } else {
296 tprintf("%#lx, %lu", addr, count);
297 return;
Jakub Bogusz002e9852009-10-07 22:25:10 +0200298 }
Roland McGrath54b90d72005-12-02 03:57:07 +0000299 } else {
Dmitry V. Levinef941012009-10-07 22:14:00 +0000300 if (!i)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200301 tprints("{");
Dmitry V. Levinef941012009-10-07 22:14:00 +0000302 tprintf("{%u, %d, ", sb.sem_num, sb.sem_op);
303 printflags(semop_flags, sb.sem_flg, "SEM_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200304 tprints("}");
Dmitry V. Levinef941012009-10-07 22:14:00 +0000305 }
306 }
307
308 if (i < max_count || max_count < count)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200309 tprints(", ...");
Dmitry V. Levinef941012009-10-07 22:14:00 +0000310
311 tprintf("}, %lu", count);
312}
313
314int sys_semop(struct tcb *tcp)
315{
316 if (entering(tcp)) {
317 tprintf("%lu, ", tcp->u_arg[0]);
318 if (indirect_ipccall(tcp)) {
319 tprint_sembuf(tcp, tcp->u_arg[3], tcp->u_arg[1]);
320 } else {
321 tprint_sembuf(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Roland McGrath54b90d72005-12-02 03:57:07 +0000322 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000323 }
324 return 0;
325}
326
Dmitry V. Levinef941012009-10-07 22:14:00 +0000327int sys_semtimedop(struct tcb *tcp)
Roland McGrath84776472003-04-08 01:46:48 +0000328{
329 if (entering(tcp)) {
Dmitry V. Levinef941012009-10-07 22:14:00 +0000330 tprintf("%lu, ", tcp->u_arg[0]);
Roland McGratha079d9f2006-04-25 07:22:01 +0000331 if (indirect_ipccall(tcp)) {
Dmitry V. Levinef941012009-10-07 22:14:00 +0000332 tprint_sembuf(tcp, tcp->u_arg[3], tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200333 tprints(", ");
Heiko Carstense0f5fd82011-11-30 13:16:29 +0100334#if defined(S390)
335 printtv(tcp, tcp->u_arg[2]);
336#else
Roland McGrath54b90d72005-12-02 03:57:07 +0000337 printtv(tcp, tcp->u_arg[5]);
Heiko Carstense0f5fd82011-11-30 13:16:29 +0100338#endif
Roland McGrath54b90d72005-12-02 03:57:07 +0000339 } else {
Dmitry V. Levinef941012009-10-07 22:14:00 +0000340 tprint_sembuf(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200341 tprints(", ");
Roland McGrath54b90d72005-12-02 03:57:07 +0000342 printtv(tcp, tcp->u_arg[3]);
343 }
Roland McGrath84776472003-04-08 01:46:48 +0000344 }
345 return 0;
346}
Roland McGrath84776472003-04-08 01:46:48 +0000347
Denys Vlasenko12014262011-05-30 14:00:14 +0200348int sys_semget(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000349{
350 if (entering(tcp)) {
351 if (tcp->u_arg[0])
Roland McGrath9f130d52006-08-22 07:36:55 +0000352 tprintf("%#lx", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000353 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200354 tprints("IPC_PRIVATE");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000355 tprintf(", %lu", tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200356 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000357 if (printflags(resource_flags, tcp->u_arg[2] & ~0777, NULL) != 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200358 tprints("|");
Roland McGrathe2be9ab2003-07-17 09:03:04 +0000359 tprintf("%#lo", tcp->u_arg[2] & 0777);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000360 }
361 return 0;
362}
363
Denys Vlasenko12014262011-05-30 14:00:14 +0200364int sys_semctl(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000365{
366 if (entering(tcp)) {
367 tprintf("%lu", tcp->u_arg[0]);
368 tprintf(", %lu, ", tcp->u_arg[1]);
Roland McGrath80731792003-01-14 09:46:17 +0000369 PRINTCTL(semctl_flags, tcp->u_arg[2], "SEM_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000370 tprintf(", %#lx", tcp->u_arg[3]);
371 }
372 return 0;
373}
374
Denys Vlasenko12014262011-05-30 14:00:14 +0200375int sys_shmget(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000376{
377 if (entering(tcp)) {
378 if (tcp->u_arg[0])
Roland McGrath9f130d52006-08-22 07:36:55 +0000379 tprintf("%#lx", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000380 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200381 tprints("IPC_PRIVATE");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000382 tprintf(", %lu", tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200383 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000384 if (printflags(shm_resource_flags, tcp->u_arg[2] & ~0777, NULL) != 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200385 tprints("|");
Roland McGrathe2be9ab2003-07-17 09:03:04 +0000386 tprintf("%#lo", tcp->u_arg[2] & 0777);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000387 }
388 return 0;
389}
390
Denys Vlasenko12014262011-05-30 14:00:14 +0200391int sys_shmctl(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000392{
393 if (entering(tcp)) {
394 tprintf("%lu, ", tcp->u_arg[0]);
Roland McGrath80731792003-01-14 09:46:17 +0000395 PRINTCTL(shmctl_flags, tcp->u_arg[1], "SHM_???");
Roland McGrath54b90d72005-12-02 03:57:07 +0000396 if (indirect_ipccall(tcp)) {
397 tprintf(", %#lx", tcp->u_arg[3]);
398 } else {
399 tprintf(", %#lx", tcp->u_arg[2]);
400 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000401 }
402 return 0;
403}
404
Denys Vlasenko12014262011-05-30 14:00:14 +0200405int sys_shmat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000406{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000407 unsigned long raddr;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000408
409 if (exiting(tcp)) {
410 tprintf("%lu", tcp->u_arg[0]);
Roland McGrath54b90d72005-12-02 03:57:07 +0000411 if (indirect_ipccall(tcp)) {
412 tprintf(", %#lx", tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200413 tprints(", ");
Roland McGrath54b90d72005-12-02 03:57:07 +0000414 printflags(shm_flags, tcp->u_arg[1], "SHM_???");
415 } else {
416 tprintf(", %#lx", tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200417 tprints(", ");
Roland McGrath54b90d72005-12-02 03:57:07 +0000418 printflags(shm_flags, tcp->u_arg[2], "SHM_???");
419 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000420 if (syserror(tcp))
421 return 0;
Dmitry V. Levinc0124e62009-10-05 23:31:54 +0000422/* HPPA does not use an IPC multiplexer on Linux. */
Denys Vlasenko84703742012-02-25 02:38:52 +0100423#if !defined(HPPA)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000424 if (umove(tcp, tcp->u_arg[2], &raddr) < 0)
425 return RVAL_NONE;
426 tcp->u_rval = raddr;
Denys Vlasenko84703742012-02-25 02:38:52 +0100427#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000428 return RVAL_HEX;
429 }
430 return 0;
431}
432
Denys Vlasenko12014262011-05-30 14:00:14 +0200433int sys_shmdt(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000434{
Roland McGrath54b90d72005-12-02 03:57:07 +0000435 if (entering(tcp)) {
436 if (indirect_ipccall(tcp)) {
437 tprintf("%#lx", tcp->u_arg[3]);
438 } else {
439 tprintf("%#lx", tcp->u_arg[0]);
440 }
441 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000442 return 0;
443}
444
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000445int
446sys_mq_open(struct tcb *tcp)
Roland McGrath4df13c12004-04-16 21:48:40 +0000447{
448 if (entering(tcp)) {
449 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200450 tprints(", ");
Roland McGrath4df13c12004-04-16 21:48:40 +0000451 /* flags */
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000452 tprint_open_modes(tcp->u_arg[1]);
Roland McGrath4df13c12004-04-16 21:48:40 +0000453 if (tcp->u_arg[1] & O_CREAT) {
454# ifndef HAVE_MQUEUE_H
455 tprintf(", %lx", tcp->u_arg[2]);
456# else
457 struct mq_attr attr;
458 /* mode */
459 tprintf(", %#lo, ", tcp->u_arg[2]);
460 if (umove(tcp, tcp->u_arg[3], &attr) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200461 tprints("{ ??? }");
Roland McGrath4df13c12004-04-16 21:48:40 +0000462 else
463 tprintf("{mq_maxmsg=%ld, mq_msgsize=%ld}",
H.J. Lu0b315b62012-02-03 10:16:03 -0800464 (long) attr.mq_maxmsg,
465 (long) attr.mq_msgsize);
Roland McGrath4df13c12004-04-16 21:48:40 +0000466# endif
467 }
468 }
469 return 0;
470}
471
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000472int
473sys_mq_timedsend(struct tcb *tcp)
Roland McGrath4df13c12004-04-16 21:48:40 +0000474{
475 if (entering(tcp)) {
476 tprintf("%ld, ", tcp->u_arg[0]);
477 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
478 tprintf(", %lu, %ld, ", tcp->u_arg[2], tcp->u_arg[3]);
479 printtv(tcp, tcp->u_arg[4]);
480 }
481 return 0;
482}
483
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000484int
485sys_mq_timedreceive(struct tcb *tcp)
Roland McGrath4df13c12004-04-16 21:48:40 +0000486{
487 if (entering(tcp))
488 tprintf("%ld, ", tcp->u_arg[0]);
489 else {
490 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
491 tprintf(", %lu, %ld, ", tcp->u_arg[2], tcp->u_arg[3]);
492 printtv(tcp, tcp->u_arg[4]);
493 }
494 return 0;
495}
496
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000497int
498sys_mq_notify(struct tcb *tcp)
Roland McGrath4df13c12004-04-16 21:48:40 +0000499{
500 if (entering(tcp)) {
501 tprintf("%ld, ", tcp->u_arg[0]);
502 printsigevent(tcp, tcp->u_arg[1]);
503 }
504 return 0;
505}
506
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000507static void
508printmqattr(struct tcb *tcp, long addr)
Roland McGrath4df13c12004-04-16 21:48:40 +0000509{
510 if (addr == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200511 tprints("NULL");
Roland McGrath4df13c12004-04-16 21:48:40 +0000512 else {
513# ifndef HAVE_MQUEUE_H
514 tprintf("%#lx", addr);
515# else
516 struct mq_attr attr;
517 if (umove(tcp, addr, &attr) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200518 tprints("{...}");
Roland McGrath4df13c12004-04-16 21:48:40 +0000519 return;
520 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200521 tprints("{mq_flags=");
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000522 tprint_open_modes(attr.mq_flags);
Roland McGrath4df13c12004-04-16 21:48:40 +0000523 tprintf(", mq_maxmsg=%ld, mq_msgsize=%ld, mq_curmsg=%ld}",
H.J. Lu0b315b62012-02-03 10:16:03 -0800524 (long) attr.mq_maxmsg, (long) attr.mq_msgsize,
525 (long) attr.mq_curmsgs);
Roland McGrath4df13c12004-04-16 21:48:40 +0000526# endif
527 }
528}
529
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000530int
531sys_mq_getsetattr(struct tcb *tcp)
Roland McGrath4df13c12004-04-16 21:48:40 +0000532{
533 if (entering(tcp)) {
534 tprintf("%ld, ", tcp->u_arg[0]);
535 printmqattr(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200536 tprints(", ");
Roland McGrath4df13c12004-04-16 21:48:40 +0000537 } else
538 printmqattr(tcp, tcp->u_arg[2]);
539 return 0;
540}
Dmitry V. Levinb5e88d42012-02-20 17:02:38 +0000541
542int
543sys_ipc(struct tcb *tcp)
544{
545 return printargs(tcp);
546}