blob: c956b19a33f20b7f56b9e865b24a943afd83a262 [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
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +000035#if defined(LINUX) || defined(SUNOS4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000036
Roland McGrath4df13c12004-04-16 21:48:40 +000037# ifdef HAVE_MQUEUE_H
38# include <mqueue.h>
39# endif
40
41#include <fcntl.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000042#include <sys/ipc.h>
43#include <sys/sem.h>
44#include <sys/msg.h>
45#include <sys/shm.h>
46
47#ifndef MSG_STAT
48#define MSG_STAT 11
49#endif
50#ifndef MSG_INFO
51#define MSG_INFO 12
52#endif
53#ifndef SHM_STAT
54#define SHM_STAT 13
55#endif
56#ifndef SHM_INFO
57#define SHM_INFO 14
58#endif
59#ifndef SEM_STAT
60#define SEM_STAT 18
61#endif
62#ifndef SEM_INFO
63#define SEM_INFO 19
64#endif
65
Roland McGrath80731792003-01-14 09:46:17 +000066#if defined LINUX && !defined IPC_64
67# define IPC_64 0x100
68#endif
69
Roland McGrath4df13c12004-04-16 21:48:40 +000070extern void printsigevent(struct tcb *tcp, long arg);
71
Roland McGrathd9f816f2004-09-04 03:39:20 +000072static const struct xlat msgctl_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000073 { IPC_RMID, "IPC_RMID" },
74 { IPC_SET, "IPC_SET" },
75 { IPC_STAT, "IPC_STAT" },
76#ifdef LINUX
77 { IPC_INFO, "IPC_INFO" },
78 { MSG_STAT, "MSG_STAT" },
79 { MSG_INFO, "MSG_INFO" },
80#endif /* LINUX */
81 { 0, NULL },
82};
83
Roland McGrathd9f816f2004-09-04 03:39:20 +000084static const struct xlat semctl_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000085 { IPC_RMID, "IPC_RMID" },
86 { IPC_SET, "IPC_SET" },
87 { IPC_STAT, "IPC_STAT" },
88#ifdef LINUX
89 { IPC_INFO, "IPC_INFO" },
90 { SEM_STAT, "SEM_STAT" },
91 { SEM_INFO, "SEM_INFO" },
92#endif /* LINUX */
93 { GETPID, "GETPID" },
94 { GETVAL, "GETVAL" },
95 { GETALL, "GETALL" },
96 { GETNCNT, "GETNCNT" },
97 { GETZCNT, "GETZCNT" },
98 { SETVAL, "SETVAL" },
99 { SETALL, "SETALL" },
100 { 0, NULL },
101};
102
Roland McGrathd9f816f2004-09-04 03:39:20 +0000103static const struct xlat shmctl_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000104 { IPC_RMID, "IPC_RMID" },
105 { IPC_SET, "IPC_SET" },
106 { IPC_STAT, "IPC_STAT" },
107#ifdef LINUX
108 { IPC_INFO, "IPC_INFO" },
109 { SHM_STAT, "SHM_STAT" },
110 { SHM_INFO, "SHM_INFO" },
111#endif /* LINUX */
Roland McGrath80731792003-01-14 09:46:17 +0000112#ifdef SHM_LOCK
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000113 { SHM_LOCK, "SHM_LOCK" },
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000114#endif
Roland McGrath80731792003-01-14 09:46:17 +0000115#ifdef SHM_UNLOCK
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000116 { SHM_UNLOCK, "SHM_UNLOCK" },
Roland McGrath80731792003-01-14 09:46:17 +0000117#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000118 { 0, NULL },
119};
120
Roland McGrathd9f816f2004-09-04 03:39:20 +0000121static const struct xlat resource_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000122 { IPC_CREAT, "IPC_CREAT" },
123 { IPC_EXCL, "IPC_EXCL" },
124 { IPC_NOWAIT, "IPC_NOWAIT" },
Roland McGrath802b8f42005-05-09 07:40:33 +0000125 { 0, NULL },
126};
127
128static const struct xlat shm_resource_flags[] = {
129 { IPC_CREAT, "IPC_CREAT" },
130 { IPC_EXCL, "IPC_EXCL" },
Roland McGrathe2be9ab2003-07-17 09:03:04 +0000131#ifdef SHM_HUGETLB
132 { SHM_HUGETLB, "SHM_HUGETLB" },
133#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000134 { 0, NULL },
135};
136
Roland McGrathd9f816f2004-09-04 03:39:20 +0000137static const struct xlat shm_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000138#ifdef LINUX
139 { SHM_REMAP, "SHM_REMAP" },
140#endif /* LINUX */
141 { SHM_RDONLY, "SHM_RDONLY" },
142 { SHM_RND, "SHM_RND" },
143 { 0, NULL },
144};
145
Roland McGrathd9f816f2004-09-04 03:39:20 +0000146static const struct xlat msg_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000147 { MSG_NOERROR, "MSG_NOERROR" },
148#ifdef LINUX
149 { MSG_EXCEPT, "MSG_EXCEPT" },
150#endif /* LINUX */
151 { IPC_NOWAIT, "IPC_NOWAIT" },
152 { 0, NULL },
153};
154
Jakub Bogusz002e9852009-10-07 22:25:10 +0200155static const struct xlat semop_flags[] = {
156 { SEM_UNDO, "SEM_UNDO" },
157 { IPC_NOWAIT, "IPC_NOWAIT" },
158 { 0, NULL },
159};
160
Denys Vlasenko12014262011-05-30 14:00:14 +0200161int sys_msgget(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000162{
163 if (entering(tcp)) {
164 if (tcp->u_arg[0])
Roland McGrath9f130d52006-08-22 07:36:55 +0000165 tprintf("%#lx", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000166 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200167 tprints("IPC_PRIVATE");
168 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000169 if (printflags(resource_flags, tcp->u_arg[1] & ~0777, NULL) != 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200170 tprints("|");
Roland McGrathe2be9ab2003-07-17 09:03:04 +0000171 tprintf("%#lo", tcp->u_arg[1] & 0777);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000172 }
173 return 0;
174}
175
Roland McGrath80731792003-01-14 09:46:17 +0000176#ifdef IPC_64
177# define PRINTCTL(flagset, arg, dflt) \
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200178 if ((arg) & IPC_64) tprints("IPC_64|"); \
Roland McGrath80731792003-01-14 09:46:17 +0000179 printxval((flagset), (arg) &~ IPC_64, dflt)
180#else
181# define PRINTCTL printxval
182#endif
183
Roland McGrath54b90d72005-12-02 03:57:07 +0000184static int
Denys Vlasenko12014262011-05-30 14:00:14 +0200185indirect_ipccall(struct tcb *tcp)
Roland McGrath54b90d72005-12-02 03:57:07 +0000186{
187#ifdef LINUX
188#ifdef X86_64
189 return current_personality > 0;
190#endif
Roland McGratha81bf4c2005-12-02 04:18:55 +0000191#if defined IA64
192 return tcp->scno < 1024; /* ia32 emulation syscalls are low */
Roland McGrath54b90d72005-12-02 03:57:07 +0000193#endif
Roland McGrathe1ebaab2005-12-02 04:34:09 +0000194#if !defined MIPS && !defined HPPA
195 return 1;
196#endif
197#endif /* LINUX */
Roland McGrath54b90d72005-12-02 03:57:07 +0000198 return 0;
199}
200
Denys Vlasenko12014262011-05-30 14:00:14 +0200201int sys_msgctl(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000202{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000203 if (entering(tcp)) {
Roland McGrath80731792003-01-14 09:46:17 +0000204 tprintf("%lu, ", tcp->u_arg[0]);
205 PRINTCTL(msgctl_flags, tcp->u_arg[1], "MSG_???");
Roland McGrath54b90d72005-12-02 03:57:07 +0000206 tprintf(", %#lx", tcp->u_arg[indirect_ipccall(tcp) ? 3 : 2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000207 }
208 return 0;
209}
210
Dmitry V. Levin783f5bc2009-10-08 23:33:15 +0000211static void
Dmitry V. Levin4310a372010-03-31 22:22:01 +0000212tprint_msgsnd(struct tcb *tcp, long addr, unsigned long count,
213 unsigned long flags)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000214{
215 long mtype;
216
Dmitry V. Levin783f5bc2009-10-08 23:33:15 +0000217 if (umove(tcp, addr, &mtype) < 0) {
218 tprintf("%#lx", addr);
219 } else {
220 tprintf("{%lu, ", mtype);
221 printstr(tcp, addr + sizeof(mtype), count);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200222 tprints("}");
Dmitry V. Levin783f5bc2009-10-08 23:33:15 +0000223 }
224 tprintf(", %lu, ", count);
Dmitry V. Levin4310a372010-03-31 22:22:01 +0000225 printflags(msg_flags, flags, "MSG_???");
Dmitry V. Levin783f5bc2009-10-08 23:33:15 +0000226}
227
228int sys_msgsnd(struct tcb *tcp)
229{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000230 if (entering(tcp)) {
Dmitry V. Levin62e05962009-11-03 14:38:44 +0000231 tprintf("%d, ", (int) tcp->u_arg[0]);
Roland McGrath54b90d72005-12-02 03:57:07 +0000232 if (indirect_ipccall(tcp)) {
Dmitry V. Levin4310a372010-03-31 22:22:01 +0000233 tprint_msgsnd(tcp, tcp->u_arg[3], tcp->u_arg[1],
234 tcp->u_arg[2]);
Roland McGrath54b90d72005-12-02 03:57:07 +0000235 } else {
Dmitry V. Levin4310a372010-03-31 22:22:01 +0000236 tprint_msgsnd(tcp, tcp->u_arg[1], tcp->u_arg[2],
237 tcp->u_arg[3]);
Roland McGrath54b90d72005-12-02 03:57:07 +0000238 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000239 }
240 return 0;
241}
242
Dmitry V. Levin62e05962009-11-03 14:38:44 +0000243static void
244tprint_msgrcv(struct tcb *tcp, long addr, unsigned long count, long msgtyp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000245{
246 long mtype;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000247
Dmitry V. Levin62e05962009-11-03 14:38:44 +0000248 if (syserror(tcp) || umove(tcp, addr, &mtype) < 0) {
249 tprintf("%#lx", addr);
Roland McGrathf467c002005-12-02 03:44:12 +0000250 } else {
Dmitry V. Levin62e05962009-11-03 14:38:44 +0000251 tprintf("{%lu, ", mtype);
252 printstr(tcp, addr + sizeof(mtype), count);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200253 tprints("}");
Dmitry V. Levin62e05962009-11-03 14:38:44 +0000254 }
255 tprintf(", %lu, %ld, ", count, msgtyp);
256}
257
258int sys_msgrcv(struct tcb *tcp)
259{
260 if (entering(tcp)) {
261 tprintf("%d, ", (int) tcp->u_arg[0]);
262 } else {
Roland McGrath54b90d72005-12-02 03:57:07 +0000263 if (indirect_ipccall(tcp)) {
264 struct ipc_wrapper {
265 struct msgbuf *msgp;
266 long msgtyp;
267 } tmp;
Dmitry V. Levin62e05962009-11-03 14:38:44 +0000268
269 if (umove(tcp, tcp->u_arg[3], &tmp) < 0) {
270 tprintf("%#lx, %lu, ",
271 tcp->u_arg[3], tcp->u_arg[1]);
272 } else {
273 tprint_msgrcv(tcp, (long) tmp.msgp,
274 tcp->u_arg[1], tmp.msgtyp);
275 }
Roland McGrath54b90d72005-12-02 03:57:07 +0000276 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
277 } else {
Dmitry V. Levin62e05962009-11-03 14:38:44 +0000278 tprint_msgrcv(tcp, tcp->u_arg[1],
279 tcp->u_arg[2], tcp->u_arg[3]);
Roland McGrath54b90d72005-12-02 03:57:07 +0000280 printflags(msg_flags, tcp->u_arg[4], "MSG_???");
281 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000282 }
283 return 0;
284}
285
Dmitry V. Levinef941012009-10-07 22:14:00 +0000286static void
287tprint_sembuf(struct tcb *tcp, long addr, unsigned long count)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000288{
Dmitry V. Levinef941012009-10-07 22:14:00 +0000289 unsigned long i, max_count;
Jakub Bogusz002e9852009-10-07 22:25:10 +0200290
Dmitry V. Levinef941012009-10-07 22:14:00 +0000291 if (abbrev(tcp))
292 max_count = (max_strlen < count) ? max_strlen : count;
293 else
294 max_count = count;
295
296 if (!max_count) {
297 tprintf("%#lx, %lu", addr, count);
298 return;
299 }
300
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200301 for (i = 0; i < max_count; ++i) {
Dmitry V. Levinef941012009-10-07 22:14:00 +0000302 struct sembuf sb;
303 if (i)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200304 tprints(", ");
Dmitry V. Levinef941012009-10-07 22:14:00 +0000305 if (umove(tcp, addr + i * sizeof(struct sembuf), &sb) < 0) {
306 if (i) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200307 tprints("{???}");
Dmitry V. Levinef941012009-10-07 22:14:00 +0000308 break;
309 } else {
310 tprintf("%#lx, %lu", addr, count);
311 return;
Jakub Bogusz002e9852009-10-07 22:25:10 +0200312 }
Roland McGrath54b90d72005-12-02 03:57:07 +0000313 } else {
Dmitry V. Levinef941012009-10-07 22:14:00 +0000314 if (!i)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200315 tprints("{");
Dmitry V. Levinef941012009-10-07 22:14:00 +0000316 tprintf("{%u, %d, ", sb.sem_num, sb.sem_op);
317 printflags(semop_flags, sb.sem_flg, "SEM_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200318 tprints("}");
Dmitry V. Levinef941012009-10-07 22:14:00 +0000319 }
320 }
321
322 if (i < max_count || max_count < count)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200323 tprints(", ...");
Dmitry V. Levinef941012009-10-07 22:14:00 +0000324
325 tprintf("}, %lu", count);
326}
327
328int sys_semop(struct tcb *tcp)
329{
330 if (entering(tcp)) {
331 tprintf("%lu, ", tcp->u_arg[0]);
332 if (indirect_ipccall(tcp)) {
333 tprint_sembuf(tcp, tcp->u_arg[3], tcp->u_arg[1]);
334 } else {
335 tprint_sembuf(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Roland McGrath54b90d72005-12-02 03:57:07 +0000336 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000337 }
338 return 0;
339}
340
Roland McGrath84776472003-04-08 01:46:48 +0000341#ifdef LINUX
Dmitry V. Levinef941012009-10-07 22:14:00 +0000342int sys_semtimedop(struct tcb *tcp)
Roland McGrath84776472003-04-08 01:46:48 +0000343{
344 if (entering(tcp)) {
Dmitry V. Levinef941012009-10-07 22:14:00 +0000345 tprintf("%lu, ", tcp->u_arg[0]);
Roland McGratha079d9f2006-04-25 07:22:01 +0000346 if (indirect_ipccall(tcp)) {
Dmitry V. Levinef941012009-10-07 22:14:00 +0000347 tprint_sembuf(tcp, tcp->u_arg[3], tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200348 tprints(", ");
Heiko Carstense0f5fd82011-11-30 13:16:29 +0100349#if defined(S390)
350 printtv(tcp, tcp->u_arg[2]);
351#else
Roland McGrath54b90d72005-12-02 03:57:07 +0000352 printtv(tcp, tcp->u_arg[5]);
Heiko Carstense0f5fd82011-11-30 13:16:29 +0100353#endif
Roland McGrath54b90d72005-12-02 03:57:07 +0000354 } else {
Dmitry V. Levinef941012009-10-07 22:14:00 +0000355 tprint_sembuf(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200356 tprints(", ");
Roland McGrath54b90d72005-12-02 03:57:07 +0000357 printtv(tcp, tcp->u_arg[3]);
358 }
Roland McGrath84776472003-04-08 01:46:48 +0000359 }
360 return 0;
361}
362#endif
363
Denys Vlasenko12014262011-05-30 14:00:14 +0200364int sys_semget(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000365{
366 if (entering(tcp)) {
367 if (tcp->u_arg[0])
Roland McGrath9f130d52006-08-22 07:36:55 +0000368 tprintf("%#lx", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000369 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200370 tprints("IPC_PRIVATE");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000371 tprintf(", %lu", tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200372 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000373 if (printflags(resource_flags, tcp->u_arg[2] & ~0777, NULL) != 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200374 tprints("|");
Roland McGrathe2be9ab2003-07-17 09:03:04 +0000375 tprintf("%#lo", tcp->u_arg[2] & 0777);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000376 }
377 return 0;
378}
379
Denys Vlasenko12014262011-05-30 14:00:14 +0200380int sys_semctl(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000381{
382 if (entering(tcp)) {
383 tprintf("%lu", tcp->u_arg[0]);
384 tprintf(", %lu, ", tcp->u_arg[1]);
Roland McGrath80731792003-01-14 09:46:17 +0000385 PRINTCTL(semctl_flags, tcp->u_arg[2], "SEM_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000386 tprintf(", %#lx", tcp->u_arg[3]);
387 }
388 return 0;
389}
390
Denys Vlasenko12014262011-05-30 14:00:14 +0200391int sys_shmget(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000392{
393 if (entering(tcp)) {
394 if (tcp->u_arg[0])
Roland McGrath9f130d52006-08-22 07:36:55 +0000395 tprintf("%#lx", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000396 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200397 tprints("IPC_PRIVATE");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000398 tprintf(", %lu", tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200399 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000400 if (printflags(shm_resource_flags, tcp->u_arg[2] & ~0777, NULL) != 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200401 tprints("|");
Roland McGrathe2be9ab2003-07-17 09:03:04 +0000402 tprintf("%#lo", tcp->u_arg[2] & 0777);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000403 }
404 return 0;
405}
406
Denys Vlasenko12014262011-05-30 14:00:14 +0200407int sys_shmctl(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000408{
409 if (entering(tcp)) {
410 tprintf("%lu, ", tcp->u_arg[0]);
Roland McGrath80731792003-01-14 09:46:17 +0000411 PRINTCTL(shmctl_flags, tcp->u_arg[1], "SHM_???");
Roland McGrath54b90d72005-12-02 03:57:07 +0000412 if (indirect_ipccall(tcp)) {
413 tprintf(", %#lx", tcp->u_arg[3]);
414 } else {
415 tprintf(", %#lx", tcp->u_arg[2]);
416 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000417 }
418 return 0;
419}
420
Denys Vlasenko12014262011-05-30 14:00:14 +0200421int sys_shmat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000422{
423#ifdef LINUX
424 unsigned long raddr;
425#endif /* LINUX */
426
427 if (exiting(tcp)) {
428 tprintf("%lu", tcp->u_arg[0]);
Roland McGrath54b90d72005-12-02 03:57:07 +0000429 if (indirect_ipccall(tcp)) {
430 tprintf(", %#lx", tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200431 tprints(", ");
Roland McGrath54b90d72005-12-02 03:57:07 +0000432 printflags(shm_flags, tcp->u_arg[1], "SHM_???");
433 } else {
434 tprintf(", %#lx", tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200435 tprints(", ");
Roland McGrath54b90d72005-12-02 03:57:07 +0000436 printflags(shm_flags, tcp->u_arg[2], "SHM_???");
437 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000438 if (syserror(tcp))
439 return 0;
Dmitry V. Levinc0124e62009-10-05 23:31:54 +0000440/* HPPA does not use an IPC multiplexer on Linux. */
441#if defined(LINUX) && !defined(HPPA)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000442 if (umove(tcp, tcp->u_arg[2], &raddr) < 0)
443 return RVAL_NONE;
444 tcp->u_rval = raddr;
445#endif /* LINUX */
446 return RVAL_HEX;
447 }
448 return 0;
449}
450
Denys Vlasenko12014262011-05-30 14:00:14 +0200451int sys_shmdt(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000452{
Roland McGrath54b90d72005-12-02 03:57:07 +0000453 if (entering(tcp)) {
454 if (indirect_ipccall(tcp)) {
455 tprintf("%#lx", tcp->u_arg[3]);
456 } else {
457 tprintf("%#lx", tcp->u_arg[0]);
458 }
459 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000460 return 0;
461}
462
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000463#endif /* defined(LINUX) || defined(SUNOS4) || defined(FREEBSD) */
Roland McGrath4df13c12004-04-16 21:48:40 +0000464
465#ifdef LINUX
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000466int
467sys_mq_open(struct tcb *tcp)
Roland McGrath4df13c12004-04-16 21:48:40 +0000468{
469 if (entering(tcp)) {
470 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200471 tprints(", ");
Roland McGrath4df13c12004-04-16 21:48:40 +0000472 /* flags */
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000473 tprint_open_modes(tcp->u_arg[1]);
Roland McGrath4df13c12004-04-16 21:48:40 +0000474 if (tcp->u_arg[1] & O_CREAT) {
475# ifndef HAVE_MQUEUE_H
476 tprintf(", %lx", tcp->u_arg[2]);
477# else
478 struct mq_attr attr;
479 /* mode */
480 tprintf(", %#lo, ", tcp->u_arg[2]);
481 if (umove(tcp, tcp->u_arg[3], &attr) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200482 tprints("{ ??? }");
Roland McGrath4df13c12004-04-16 21:48:40 +0000483 else
484 tprintf("{mq_maxmsg=%ld, mq_msgsize=%ld}",
H.J. Lu0b315b62012-02-03 10:16:03 -0800485 (long) attr.mq_maxmsg,
486 (long) attr.mq_msgsize);
Roland McGrath4df13c12004-04-16 21:48:40 +0000487# endif
488 }
489 }
490 return 0;
491}
492
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000493int
494sys_mq_timedsend(struct tcb *tcp)
Roland McGrath4df13c12004-04-16 21:48:40 +0000495{
496 if (entering(tcp)) {
497 tprintf("%ld, ", tcp->u_arg[0]);
498 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
499 tprintf(", %lu, %ld, ", tcp->u_arg[2], tcp->u_arg[3]);
500 printtv(tcp, tcp->u_arg[4]);
501 }
502 return 0;
503}
504
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000505int
506sys_mq_timedreceive(struct tcb *tcp)
Roland McGrath4df13c12004-04-16 21:48:40 +0000507{
508 if (entering(tcp))
509 tprintf("%ld, ", tcp->u_arg[0]);
510 else {
511 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
512 tprintf(", %lu, %ld, ", tcp->u_arg[2], tcp->u_arg[3]);
513 printtv(tcp, tcp->u_arg[4]);
514 }
515 return 0;
516}
517
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000518int
519sys_mq_notify(struct tcb *tcp)
Roland McGrath4df13c12004-04-16 21:48:40 +0000520{
521 if (entering(tcp)) {
522 tprintf("%ld, ", tcp->u_arg[0]);
523 printsigevent(tcp, tcp->u_arg[1]);
524 }
525 return 0;
526}
527
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000528static void
529printmqattr(struct tcb *tcp, long addr)
Roland McGrath4df13c12004-04-16 21:48:40 +0000530{
531 if (addr == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200532 tprints("NULL");
Roland McGrath4df13c12004-04-16 21:48:40 +0000533 else {
534# ifndef HAVE_MQUEUE_H
535 tprintf("%#lx", addr);
536# else
537 struct mq_attr attr;
538 if (umove(tcp, addr, &attr) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200539 tprints("{...}");
Roland McGrath4df13c12004-04-16 21:48:40 +0000540 return;
541 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200542 tprints("{mq_flags=");
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000543 tprint_open_modes(attr.mq_flags);
Roland McGrath4df13c12004-04-16 21:48:40 +0000544 tprintf(", mq_maxmsg=%ld, mq_msgsize=%ld, mq_curmsg=%ld}",
H.J. Lu0b315b62012-02-03 10:16:03 -0800545 (long) attr.mq_maxmsg, (long) attr.mq_msgsize,
546 (long) attr.mq_curmsgs);
Roland McGrath4df13c12004-04-16 21:48:40 +0000547# endif
548 }
549}
550
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000551int
552sys_mq_getsetattr(struct tcb *tcp)
Roland McGrath4df13c12004-04-16 21:48:40 +0000553{
554 if (entering(tcp)) {
555 tprintf("%ld, ", tcp->u_arg[0]);
556 printmqattr(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200557 tprints(", ");
Roland McGrath4df13c12004-04-16 21:48:40 +0000558 } else
559 printmqattr(tcp, tcp->u_arg[2]);
560 return 0;
561}
562#endif
Dmitry V. Levinb5e88d42012-02-20 17:02:38 +0000563
564int
565sys_ipc(struct tcb *tcp)
566{
567 return printargs(tcp);
568}