blob: d16f70a9a73c0d100db0b553412d5c062b89c9ba [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 McGrathd9f816f2004-09-04 03:39:20 +000070extern const struct xlat openmodes[];
Roland McGrath4df13c12004-04-16 21:48:40 +000071extern void printsigevent(struct tcb *tcp, long arg);
72
Roland McGrathd9f816f2004-09-04 03:39:20 +000073static const struct xlat msgctl_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000074 { IPC_RMID, "IPC_RMID" },
75 { IPC_SET, "IPC_SET" },
76 { IPC_STAT, "IPC_STAT" },
77#ifdef LINUX
78 { IPC_INFO, "IPC_INFO" },
79 { MSG_STAT, "MSG_STAT" },
80 { MSG_INFO, "MSG_INFO" },
81#endif /* LINUX */
82 { 0, NULL },
83};
84
Roland McGrathd9f816f2004-09-04 03:39:20 +000085static const struct xlat semctl_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000086 { IPC_RMID, "IPC_RMID" },
87 { IPC_SET, "IPC_SET" },
88 { IPC_STAT, "IPC_STAT" },
89#ifdef LINUX
90 { IPC_INFO, "IPC_INFO" },
91 { SEM_STAT, "SEM_STAT" },
92 { SEM_INFO, "SEM_INFO" },
93#endif /* LINUX */
94 { GETPID, "GETPID" },
95 { GETVAL, "GETVAL" },
96 { GETALL, "GETALL" },
97 { GETNCNT, "GETNCNT" },
98 { GETZCNT, "GETZCNT" },
99 { SETVAL, "SETVAL" },
100 { SETALL, "SETALL" },
101 { 0, NULL },
102};
103
Roland McGrathd9f816f2004-09-04 03:39:20 +0000104static const struct xlat shmctl_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000105 { IPC_RMID, "IPC_RMID" },
106 { IPC_SET, "IPC_SET" },
107 { IPC_STAT, "IPC_STAT" },
108#ifdef LINUX
109 { IPC_INFO, "IPC_INFO" },
110 { SHM_STAT, "SHM_STAT" },
111 { SHM_INFO, "SHM_INFO" },
112#endif /* LINUX */
Roland McGrath80731792003-01-14 09:46:17 +0000113#ifdef SHM_LOCK
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000114 { SHM_LOCK, "SHM_LOCK" },
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000115#endif
Roland McGrath80731792003-01-14 09:46:17 +0000116#ifdef SHM_UNLOCK
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000117 { SHM_UNLOCK, "SHM_UNLOCK" },
Roland McGrath80731792003-01-14 09:46:17 +0000118#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000119 { 0, NULL },
120};
121
Roland McGrathd9f816f2004-09-04 03:39:20 +0000122static const struct xlat resource_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000123 { IPC_CREAT, "IPC_CREAT" },
124 { IPC_EXCL, "IPC_EXCL" },
125 { IPC_NOWAIT, "IPC_NOWAIT" },
Roland McGrath802b8f42005-05-09 07:40:33 +0000126 { 0, NULL },
127};
128
129static const struct xlat shm_resource_flags[] = {
130 { IPC_CREAT, "IPC_CREAT" },
131 { IPC_EXCL, "IPC_EXCL" },
Roland McGrathe2be9ab2003-07-17 09:03:04 +0000132#ifdef SHM_HUGETLB
133 { SHM_HUGETLB, "SHM_HUGETLB" },
134#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000135 { 0, NULL },
136};
137
Roland McGrathd9f816f2004-09-04 03:39:20 +0000138static const struct xlat shm_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000139#ifdef LINUX
140 { SHM_REMAP, "SHM_REMAP" },
141#endif /* LINUX */
142 { SHM_RDONLY, "SHM_RDONLY" },
143 { SHM_RND, "SHM_RND" },
144 { 0, NULL },
145};
146
Roland McGrathd9f816f2004-09-04 03:39:20 +0000147static const struct xlat msg_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000148 { MSG_NOERROR, "MSG_NOERROR" },
149#ifdef LINUX
150 { MSG_EXCEPT, "MSG_EXCEPT" },
151#endif /* LINUX */
152 { IPC_NOWAIT, "IPC_NOWAIT" },
153 { 0, NULL },
154};
155
156int sys_msgget(tcp)
157struct tcb *tcp;
158{
159 if (entering(tcp)) {
160 if (tcp->u_arg[0])
161 tprintf("%lu", tcp->u_arg[0]);
162 else
163 tprintf("IPC_PRIVATE");
164 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000165 if (printflags(resource_flags, tcp->u_arg[1] & ~0777, NULL) != 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000166 tprintf("|");
Roland McGrathe2be9ab2003-07-17 09:03:04 +0000167 tprintf("%#lo", tcp->u_arg[1] & 0777);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000168 }
169 return 0;
170}
171
Roland McGrath80731792003-01-14 09:46:17 +0000172#ifdef IPC_64
173# define PRINTCTL(flagset, arg, dflt) \
174 if ((arg) & IPC_64) tprintf("IPC_64|"); \
175 printxval((flagset), (arg) &~ IPC_64, dflt)
176#else
177# define PRINTCTL printxval
178#endif
179
Roland McGrath54b90d72005-12-02 03:57:07 +0000180static int
181indirect_ipccall(tcp)
182struct tcb *tcp;
183{
184#ifdef LINUX
185#ifdef X86_64
186 return current_personality > 0;
187#endif
188 return 1;
189#endif
190 return 0;
191}
192
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000193int sys_msgctl(tcp)
194struct tcb *tcp;
195{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000196 if (entering(tcp)) {
Roland McGrath80731792003-01-14 09:46:17 +0000197 tprintf("%lu, ", tcp->u_arg[0]);
198 PRINTCTL(msgctl_flags, tcp->u_arg[1], "MSG_???");
Roland McGrath54b90d72005-12-02 03:57:07 +0000199 tprintf(", %#lx", tcp->u_arg[indirect_ipccall(tcp) ? 3 : 2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000200 }
201 return 0;
202}
203
204int sys_msgsnd(tcp)
205struct tcb *tcp;
206{
207 long mtype;
208
209 if (entering(tcp)) {
210 tprintf("%lu", tcp->u_arg[0]);
Roland McGrath54b90d72005-12-02 03:57:07 +0000211 if (indirect_ipccall(tcp)) {
212 umove(tcp, tcp->u_arg[3], &mtype);
213 tprintf(", {%lu, ", mtype);
214 printstr(tcp, tcp->u_arg[3] + sizeof(long),
215 tcp->u_arg[1]);
216 tprintf("}, %lu", tcp->u_arg[1]);
217 tprintf(", ");
218 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
219 } else {
220 umove(tcp, tcp->u_arg[1], &mtype);
221 tprintf(", {%lu, ", mtype);
222 printstr(tcp, tcp->u_arg[1] + sizeof(long),
223 tcp->u_arg[2]);
224 tprintf("}, %lu", tcp->u_arg[2]);
225 tprintf(", ");
226 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
227 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000228 }
229 return 0;
230}
231
232int sys_msgrcv(tcp)
233struct tcb *tcp;
234{
235 long mtype;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000236
Roland McGrathf467c002005-12-02 03:44:12 +0000237 if (entering(tcp)) {
238 tprintf("%lu, ", tcp->u_arg[0]);
239 } else {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000240 tprintf("%lu", tcp->u_arg[0]);
Roland McGrath54b90d72005-12-02 03:57:07 +0000241 if (indirect_ipccall(tcp)) {
242 struct ipc_wrapper {
243 struct msgbuf *msgp;
244 long msgtyp;
245 } tmp;
246 umove(tcp, tcp->u_arg[3], &tmp);
247 umove(tcp, (long) tmp.msgp, &mtype);
248 tprintf(", {%lu, ", mtype);
249 printstr(tcp, (long) (tmp.msgp) + sizeof(long),
250 tcp->u_arg[1]);
251 tprintf("}, %lu", tcp->u_arg[1]);
252 tprintf(", %ld", tmp.msgtyp);
253 tprintf(", ");
254 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
255 } else {
256 umove(tcp, tcp->u_arg[1], &mtype);
257 tprintf("{%lu, ", mtype);
258 printstr(tcp, tcp->u_arg[1] + sizeof(long),
259 tcp->u_arg[2]);
260 tprintf("}, %lu", tcp->u_arg[2]);
261 tprintf(", %ld", tcp->u_arg[3]);
262 tprintf(", ");
263 printflags(msg_flags, tcp->u_arg[4], "MSG_???");
264 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000265 }
266 return 0;
267}
268
269int sys_semop(tcp)
270struct tcb *tcp;
271{
272 if (entering(tcp)) {
273 tprintf("%lu", tcp->u_arg[0]);
Roland McGrath54b90d72005-12-02 03:57:07 +0000274 if (indirect_ipccall(tcp)) {
275 tprintf(", %#lx", tcp->u_arg[3]);
276 tprintf(", %lu", tcp->u_arg[1]);
277 } else {
278 tprintf(", %#lx", tcp->u_arg[1]);
279 tprintf(", %lu", tcp->u_arg[2]);
280 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000281 }
282 return 0;
283}
284
Roland McGrath84776472003-04-08 01:46:48 +0000285#ifdef LINUX
286int sys_semtimedop(tcp)
287struct tcb *tcp;
288{
289 if (entering(tcp)) {
290 tprintf("%lu", tcp->u_arg[0]);
Roland McGrath54b90d72005-12-02 03:57:07 +0000291 if (!indirect_ipccall(tcp)) {
292 tprintf(", %#lx", tcp->u_arg[3]);
293 tprintf(", %lu, ", tcp->u_arg[1]);
294 printtv(tcp, tcp->u_arg[5]);
295 } else {
296 tprintf(", %#lx", tcp->u_arg[1]);
297 tprintf(", %lu, ", tcp->u_arg[2]);
298 printtv(tcp, tcp->u_arg[3]);
299 }
Roland McGrath84776472003-04-08 01:46:48 +0000300 }
301 return 0;
302}
303#endif
304
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000305int sys_semget(tcp)
306struct tcb *tcp;
307{
308 if (entering(tcp)) {
309 if (tcp->u_arg[0])
310 tprintf("%lu", tcp->u_arg[0]);
311 else
312 tprintf("IPC_PRIVATE");
313 tprintf(", %lu", tcp->u_arg[1]);
314 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000315 if (printflags(resource_flags, tcp->u_arg[2] & ~0777, NULL) != 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000316 tprintf("|");
Roland McGrathe2be9ab2003-07-17 09:03:04 +0000317 tprintf("%#lo", tcp->u_arg[2] & 0777);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000318 }
319 return 0;
320}
321
322int sys_semctl(tcp)
323struct tcb *tcp;
324{
325 if (entering(tcp)) {
326 tprintf("%lu", tcp->u_arg[0]);
327 tprintf(", %lu, ", tcp->u_arg[1]);
Roland McGrath80731792003-01-14 09:46:17 +0000328 PRINTCTL(semctl_flags, tcp->u_arg[2], "SEM_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000329 tprintf(", %#lx", tcp->u_arg[3]);
330 }
331 return 0;
332}
333
334int sys_shmget(tcp)
335struct tcb *tcp;
336{
337 if (entering(tcp)) {
338 if (tcp->u_arg[0])
339 tprintf("%lu", tcp->u_arg[0]);
340 else
341 tprintf("IPC_PRIVATE");
342 tprintf(", %lu", tcp->u_arg[1]);
343 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000344 if (printflags(shm_resource_flags, tcp->u_arg[2] & ~0777, NULL) != 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000345 tprintf("|");
Roland McGrathe2be9ab2003-07-17 09:03:04 +0000346 tprintf("%#lo", tcp->u_arg[2] & 0777);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000347 }
348 return 0;
349}
350
351int sys_shmctl(tcp)
352struct tcb *tcp;
353{
354 if (entering(tcp)) {
355 tprintf("%lu, ", tcp->u_arg[0]);
Roland McGrath80731792003-01-14 09:46:17 +0000356 PRINTCTL(shmctl_flags, tcp->u_arg[1], "SHM_???");
Roland McGrath54b90d72005-12-02 03:57:07 +0000357 if (indirect_ipccall(tcp)) {
358 tprintf(", %#lx", tcp->u_arg[3]);
359 } else {
360 tprintf(", %#lx", tcp->u_arg[2]);
361 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000362 }
363 return 0;
364}
365
366int sys_shmat(tcp)
367struct tcb *tcp;
368{
369#ifdef LINUX
370 unsigned long raddr;
371#endif /* LINUX */
372
373 if (exiting(tcp)) {
374 tprintf("%lu", tcp->u_arg[0]);
Roland McGrath54b90d72005-12-02 03:57:07 +0000375 if (indirect_ipccall(tcp)) {
376 tprintf(", %#lx", tcp->u_arg[3]);
377 tprintf(", ");
378 printflags(shm_flags, tcp->u_arg[1], "SHM_???");
379 } else {
380 tprintf(", %#lx", tcp->u_arg[1]);
381 tprintf(", ");
382 printflags(shm_flags, tcp->u_arg[2], "SHM_???");
383 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000384 if (syserror(tcp))
385 return 0;
386#ifdef LINUX
387 if (umove(tcp, tcp->u_arg[2], &raddr) < 0)
388 return RVAL_NONE;
389 tcp->u_rval = raddr;
390#endif /* LINUX */
391 return RVAL_HEX;
392 }
393 return 0;
394}
395
396int sys_shmdt(tcp)
397struct tcb *tcp;
398{
Roland McGrath54b90d72005-12-02 03:57:07 +0000399 if (entering(tcp)) {
400 if (indirect_ipccall(tcp)) {
401 tprintf("%#lx", tcp->u_arg[3]);
402 } else {
403 tprintf("%#lx", tcp->u_arg[0]);
404 }
405 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000406 return 0;
407}
408
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000409#endif /* defined(LINUX) || defined(SUNOS4) || defined(FREEBSD) */
Roland McGrath4df13c12004-04-16 21:48:40 +0000410
411#ifdef LINUX
412int sys_mq_open(tcp)
413struct tcb *tcp;
414{
415 if (entering(tcp)) {
416 printpath(tcp, tcp->u_arg[0]);
417 tprintf(", ");
418 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000419 printflags(openmodes, tcp->u_arg[1] + 1, "O_???");
Roland McGrath4df13c12004-04-16 21:48:40 +0000420 if (tcp->u_arg[1] & O_CREAT) {
421# ifndef HAVE_MQUEUE_H
422 tprintf(", %lx", tcp->u_arg[2]);
423# else
424 struct mq_attr attr;
425 /* mode */
426 tprintf(", %#lo, ", tcp->u_arg[2]);
427 if (umove(tcp, tcp->u_arg[3], &attr) < 0)
428 tprintf("{ ??? }");
429 else
430 tprintf("{mq_maxmsg=%ld, mq_msgsize=%ld}",
431 attr.mq_maxmsg, attr.mq_msgsize);
432# endif
433 }
434 }
435 return 0;
436}
437
438int sys_mq_timedsend(tcp)
439struct tcb *tcp;
440{
441 if (entering(tcp)) {
442 tprintf("%ld, ", tcp->u_arg[0]);
443 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
444 tprintf(", %lu, %ld, ", tcp->u_arg[2], tcp->u_arg[3]);
445 printtv(tcp, tcp->u_arg[4]);
446 }
447 return 0;
448}
449
450int sys_mq_timedreceive(tcp)
451struct tcb *tcp;
452{
453 if (entering(tcp))
454 tprintf("%ld, ", tcp->u_arg[0]);
455 else {
456 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
457 tprintf(", %lu, %ld, ", tcp->u_arg[2], tcp->u_arg[3]);
458 printtv(tcp, tcp->u_arg[4]);
459 }
460 return 0;
461}
462
463int sys_mq_notify(tcp)
464struct tcb *tcp;
465{
466 if (entering(tcp)) {
467 tprintf("%ld, ", tcp->u_arg[0]);
468 printsigevent(tcp, tcp->u_arg[1]);
469 }
470 return 0;
471}
472
473static void printmqattr(tcp, addr)
474struct tcb *tcp;
475long addr;
476{
477 if (addr == 0)
478 tprintf("NULL");
479 else {
480# ifndef HAVE_MQUEUE_H
481 tprintf("%#lx", addr);
482# else
483 struct mq_attr attr;
484 if (umove(tcp, addr, &attr) < 0) {
485 tprintf("{...}");
486 return;
487 }
488 tprintf("{mq_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +0000489 printflags(openmodes, attr.mq_flags + 1, "O_???");
Roland McGrath4df13c12004-04-16 21:48:40 +0000490 tprintf(", mq_maxmsg=%ld, mq_msgsize=%ld, mq_curmsg=%ld}",
491 attr.mq_maxmsg, attr.mq_msgsize, attr.mq_curmsgs);
492# endif
493 }
494}
495
496int sys_mq_getsetattr(tcp)
497struct tcb *tcp;
498{
499 if (entering(tcp)) {
500 tprintf("%ld, ", tcp->u_arg[0]);
501 printmqattr(tcp, tcp->u_arg[1]);
502 tprintf(", ");
503 } else
504 printmqattr(tcp, tcp->u_arg[2]);
505 return 0;
506}
507#endif