blob: 60fece0d82b7bad826625ecc0edc42eec33e0a15 [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 McGrathe2be9ab2003-07-17 09:03:04 +0000165 if (printflags(resource_flags, tcp->u_arg[1] & ~0777) != 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
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000180int sys_msgctl(tcp)
181struct tcb *tcp;
182{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000183 if (entering(tcp)) {
Roland McGrath80731792003-01-14 09:46:17 +0000184 tprintf("%lu, ", tcp->u_arg[0]);
185 PRINTCTL(msgctl_flags, tcp->u_arg[1], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000186#ifdef LINUX
187 tprintf(", %#lx", tcp->u_arg[3]);
188#else /* !LINUX */
189 tprintf(", %#lx", tcp->u_arg[2]);
190#endif /* !LINUX */
191 }
192 return 0;
193}
194
195int sys_msgsnd(tcp)
196struct tcb *tcp;
197{
198 long mtype;
199
200 if (entering(tcp)) {
201 tprintf("%lu", tcp->u_arg[0]);
202#ifdef LINUX
203 umove(tcp, tcp->u_arg[3], &mtype);
204 tprintf(", {%lu, ", mtype);
205 printstr(tcp, tcp->u_arg[3] + sizeof(long),
206 tcp->u_arg[1]);
207 tprintf("}, %lu", tcp->u_arg[1]);
208 tprintf(", ");
209 if (printflags(msg_flags, tcp->u_arg[2]) == 0)
210 tprintf("0");
211#else /* !LINUX */
212 umove(tcp, tcp->u_arg[1], &mtype);
213 tprintf(", {%lu, ", mtype);
214 printstr(tcp, tcp->u_arg[1] + sizeof(long),
215 tcp->u_arg[2]);
216 tprintf("}, %lu", tcp->u_arg[2]);
217 tprintf(", ");
218 if (printflags(msg_flags, tcp->u_arg[3]) == 0)
219 tprintf("0");
220#endif /* !LINUX */
221 }
222 return 0;
223}
224
225int sys_msgrcv(tcp)
226struct tcb *tcp;
227{
228 long mtype;
229#ifdef LINUX
230 struct ipc_wrapper {
231 struct msgbuf *msgp;
232 long msgtyp;
233 } tmp;
234#endif
235
236
237 if (exiting(tcp)) {
238 tprintf("%lu", tcp->u_arg[0]);
239#ifdef LINUX
240 umove(tcp, tcp->u_arg[3], &tmp);
241 umove(tcp, (long) tmp.msgp, &mtype);
242 tprintf(", {%lu, ", mtype);
243 printstr(tcp, (long) (tmp.msgp) + sizeof(long),
244 tcp->u_arg[1]);
245 tprintf("}, %lu", tcp->u_arg[1]);
246 tprintf(", %ld", tmp.msgtyp);
247 tprintf(", ");
248 if (printflags(msg_flags, tcp->u_arg[2]) == 0)
249 tprintf("0");
250#else /* !LINUX */
251 umove(tcp, tcp->u_arg[1], &mtype);
252 tprintf(", {%lu, ", mtype);
253 printstr(tcp, tcp->u_arg[1] + sizeof(long),
254 tcp->u_arg[2]);
255 tprintf("}, %lu", tcp->u_arg[2]);
256 tprintf(", %ld", tcp->u_arg[3]);
257 tprintf(", ");
258 if (printflags(msg_flags, tcp->u_arg[4]) == 0)
259 tprintf("0");
260#endif /* !LINUX */
261 }
262 return 0;
263}
264
265int sys_semop(tcp)
266struct tcb *tcp;
267{
268 if (entering(tcp)) {
269 tprintf("%lu", tcp->u_arg[0]);
270#ifdef LINUX
271 tprintf(", %#lx", tcp->u_arg[3]);
272 tprintf(", %lu", tcp->u_arg[1]);
273#else /* !LINUX */
274 tprintf(", %#lx", tcp->u_arg[1]);
275 tprintf(", %lu", tcp->u_arg[2]);
276#endif /* !LINUX */
277 }
278 return 0;
279}
280
Roland McGrath84776472003-04-08 01:46:48 +0000281#ifdef LINUX
282int sys_semtimedop(tcp)
283struct tcb *tcp;
284{
285 if (entering(tcp)) {
286 tprintf("%lu", tcp->u_arg[0]);
287 tprintf(", %#lx", tcp->u_arg[3]);
288 tprintf(", %lu, ", tcp->u_arg[1]);
289 printtv(tcp, tcp->u_arg[5]);
290 }
291 return 0;
292}
293#endif
294
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000295int sys_semget(tcp)
296struct tcb *tcp;
297{
298 if (entering(tcp)) {
299 if (tcp->u_arg[0])
300 tprintf("%lu", tcp->u_arg[0]);
301 else
302 tprintf("IPC_PRIVATE");
303 tprintf(", %lu", tcp->u_arg[1]);
304 tprintf(", ");
Roland McGrathe2be9ab2003-07-17 09:03:04 +0000305 if (printflags(resource_flags, tcp->u_arg[2] & ~0777) != 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000306 tprintf("|");
Roland McGrathe2be9ab2003-07-17 09:03:04 +0000307 tprintf("%#lo", tcp->u_arg[2] & 0777);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000308 }
309 return 0;
310}
311
312int sys_semctl(tcp)
313struct tcb *tcp;
314{
315 if (entering(tcp)) {
316 tprintf("%lu", tcp->u_arg[0]);
317 tprintf(", %lu, ", tcp->u_arg[1]);
Roland McGrath80731792003-01-14 09:46:17 +0000318 PRINTCTL(semctl_flags, tcp->u_arg[2], "SEM_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000319 tprintf(", %#lx", tcp->u_arg[3]);
320 }
321 return 0;
322}
323
324int sys_shmget(tcp)
325struct tcb *tcp;
326{
327 if (entering(tcp)) {
328 if (tcp->u_arg[0])
329 tprintf("%lu", tcp->u_arg[0]);
330 else
331 tprintf("IPC_PRIVATE");
332 tprintf(", %lu", tcp->u_arg[1]);
333 tprintf(", ");
Roland McGrath802b8f42005-05-09 07:40:33 +0000334 if (printflags(shm_resource_flags, tcp->u_arg[2] & ~0777) != 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000335 tprintf("|");
Roland McGrathe2be9ab2003-07-17 09:03:04 +0000336 tprintf("%#lo", tcp->u_arg[2] & 0777);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000337 }
338 return 0;
339}
340
341int sys_shmctl(tcp)
342struct tcb *tcp;
343{
344 if (entering(tcp)) {
345 tprintf("%lu, ", tcp->u_arg[0]);
Roland McGrath80731792003-01-14 09:46:17 +0000346 PRINTCTL(shmctl_flags, tcp->u_arg[1], "SHM_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000347#ifdef LINUX
348 tprintf(", %#lx", tcp->u_arg[3]);
349#else /* !LINUX */
350 tprintf(", %#lx", tcp->u_arg[2]);
351#endif /* !LINUX */
352 }
353 return 0;
354}
355
356int sys_shmat(tcp)
357struct tcb *tcp;
358{
359#ifdef LINUX
360 unsigned long raddr;
361#endif /* LINUX */
362
363 if (exiting(tcp)) {
364 tprintf("%lu", tcp->u_arg[0]);
365#ifdef LINUX
366 tprintf(", %#lx", tcp->u_arg[3]);
367 tprintf(", ");
368 if (printflags(shm_flags, tcp->u_arg[1]) == 0)
369 tprintf("0");
370#else /* !LINUX */
371 tprintf(", %#lx", tcp->u_arg[1]);
372 tprintf(", ");
373 if (printflags(shm_flags, tcp->u_arg[2]) == 0)
374 tprintf("0");
375#endif /* !LINUX */
376 if (syserror(tcp))
377 return 0;
378#ifdef LINUX
379 if (umove(tcp, tcp->u_arg[2], &raddr) < 0)
380 return RVAL_NONE;
381 tcp->u_rval = raddr;
382#endif /* LINUX */
383 return RVAL_HEX;
384 }
385 return 0;
386}
387
388int sys_shmdt(tcp)
389struct tcb *tcp;
390{
391 if (entering(tcp))
392#ifdef LINUX
393 tprintf("%#lx", tcp->u_arg[3]);
394#else /* !LINUX */
395 tprintf("%#lx", tcp->u_arg[0]);
396#endif /* !LINUX */
397 return 0;
398}
399
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000400#endif /* defined(LINUX) || defined(SUNOS4) || defined(FREEBSD) */
Roland McGrath4df13c12004-04-16 21:48:40 +0000401
402#ifdef LINUX
403int sys_mq_open(tcp)
404struct tcb *tcp;
405{
406 if (entering(tcp)) {
407 printpath(tcp, tcp->u_arg[0]);
408 tprintf(", ");
409 /* flags */
410 printflags(openmodes, tcp->u_arg[1] + 1);
411 if (tcp->u_arg[1] & O_CREAT) {
412# ifndef HAVE_MQUEUE_H
413 tprintf(", %lx", tcp->u_arg[2]);
414# else
415 struct mq_attr attr;
416 /* mode */
417 tprintf(", %#lo, ", tcp->u_arg[2]);
418 if (umove(tcp, tcp->u_arg[3], &attr) < 0)
419 tprintf("{ ??? }");
420 else
421 tprintf("{mq_maxmsg=%ld, mq_msgsize=%ld}",
422 attr.mq_maxmsg, attr.mq_msgsize);
423# endif
424 }
425 }
426 return 0;
427}
428
429int sys_mq_timedsend(tcp)
430struct tcb *tcp;
431{
432 if (entering(tcp)) {
433 tprintf("%ld, ", tcp->u_arg[0]);
434 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
435 tprintf(", %lu, %ld, ", tcp->u_arg[2], tcp->u_arg[3]);
436 printtv(tcp, tcp->u_arg[4]);
437 }
438 return 0;
439}
440
441int sys_mq_timedreceive(tcp)
442struct tcb *tcp;
443{
444 if (entering(tcp))
445 tprintf("%ld, ", tcp->u_arg[0]);
446 else {
447 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
448 tprintf(", %lu, %ld, ", tcp->u_arg[2], tcp->u_arg[3]);
449 printtv(tcp, tcp->u_arg[4]);
450 }
451 return 0;
452}
453
454int sys_mq_notify(tcp)
455struct tcb *tcp;
456{
457 if (entering(tcp)) {
458 tprintf("%ld, ", tcp->u_arg[0]);
459 printsigevent(tcp, tcp->u_arg[1]);
460 }
461 return 0;
462}
463
464static void printmqattr(tcp, addr)
465struct tcb *tcp;
466long addr;
467{
468 if (addr == 0)
469 tprintf("NULL");
470 else {
471# ifndef HAVE_MQUEUE_H
472 tprintf("%#lx", addr);
473# else
474 struct mq_attr attr;
475 if (umove(tcp, addr, &attr) < 0) {
476 tprintf("{...}");
477 return;
478 }
479 tprintf("{mq_flags=");
480 printflags(openmodes, attr.mq_flags + 1);
481 tprintf(", mq_maxmsg=%ld, mq_msgsize=%ld, mq_curmsg=%ld}",
482 attr.mq_maxmsg, attr.mq_msgsize, attr.mq_curmsgs);
483# endif
484 }
485}
486
487int sys_mq_getsetattr(tcp)
488struct tcb *tcp;
489{
490 if (entering(tcp)) {
491 tprintf("%ld, ", tcp->u_arg[0]);
492 printmqattr(tcp, tcp->u_arg[1]);
493 tprintf(", ");
494 } else
495 printmqattr(tcp, tcp->u_arg[2]);
496 return 0;
497}
498#endif