blob: 5f9a4f79fe5594e8c03c37bf19d1eb4da4e5a62e [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
37#include <sys/ipc.h>
38#include <sys/sem.h>
39#include <sys/msg.h>
40#include <sys/shm.h>
41
42#ifndef MSG_STAT
43#define MSG_STAT 11
44#endif
45#ifndef MSG_INFO
46#define MSG_INFO 12
47#endif
48#ifndef SHM_STAT
49#define SHM_STAT 13
50#endif
51#ifndef SHM_INFO
52#define SHM_INFO 14
53#endif
54#ifndef SEM_STAT
55#define SEM_STAT 18
56#endif
57#ifndef SEM_INFO
58#define SEM_INFO 19
59#endif
60
Roland McGrath80731792003-01-14 09:46:17 +000061#if defined LINUX && !defined IPC_64
62# define IPC_64 0x100
63#endif
64
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000065static struct xlat msgctl_flags[] = {
66 { IPC_RMID, "IPC_RMID" },
67 { IPC_SET, "IPC_SET" },
68 { IPC_STAT, "IPC_STAT" },
69#ifdef LINUX
70 { IPC_INFO, "IPC_INFO" },
71 { MSG_STAT, "MSG_STAT" },
72 { MSG_INFO, "MSG_INFO" },
73#endif /* LINUX */
74 { 0, NULL },
75};
76
77static struct xlat semctl_flags[] = {
78 { IPC_RMID, "IPC_RMID" },
79 { IPC_SET, "IPC_SET" },
80 { IPC_STAT, "IPC_STAT" },
81#ifdef LINUX
82 { IPC_INFO, "IPC_INFO" },
83 { SEM_STAT, "SEM_STAT" },
84 { SEM_INFO, "SEM_INFO" },
85#endif /* LINUX */
86 { GETPID, "GETPID" },
87 { GETVAL, "GETVAL" },
88 { GETALL, "GETALL" },
89 { GETNCNT, "GETNCNT" },
90 { GETZCNT, "GETZCNT" },
91 { SETVAL, "SETVAL" },
92 { SETALL, "SETALL" },
93 { 0, NULL },
94};
95
96static struct xlat shmctl_flags[] = {
97 { IPC_RMID, "IPC_RMID" },
98 { IPC_SET, "IPC_SET" },
99 { IPC_STAT, "IPC_STAT" },
100#ifdef LINUX
101 { IPC_INFO, "IPC_INFO" },
102 { SHM_STAT, "SHM_STAT" },
103 { SHM_INFO, "SHM_INFO" },
104#endif /* LINUX */
Roland McGrath80731792003-01-14 09:46:17 +0000105#ifdef SHM_LOCK
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000106 { SHM_LOCK, "SHM_LOCK" },
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000107#endif
Roland McGrath80731792003-01-14 09:46:17 +0000108#ifdef SHM_UNLOCK
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000109 { SHM_UNLOCK, "SHM_UNLOCK" },
Roland McGrath80731792003-01-14 09:46:17 +0000110#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000111 { 0, NULL },
112};
113
114static struct xlat resource_flags[] = {
115 { IPC_CREAT, "IPC_CREAT" },
116 { IPC_EXCL, "IPC_EXCL" },
117 { IPC_NOWAIT, "IPC_NOWAIT" },
Roland McGrathe2be9ab2003-07-17 09:03:04 +0000118#ifdef SHM_HUGETLB
119 { SHM_HUGETLB, "SHM_HUGETLB" },
120#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000121 { 0, NULL },
122};
123
124static struct xlat shm_flags[] = {
125#ifdef LINUX
126 { SHM_REMAP, "SHM_REMAP" },
127#endif /* LINUX */
128 { SHM_RDONLY, "SHM_RDONLY" },
129 { SHM_RND, "SHM_RND" },
130 { 0, NULL },
131};
132
133static struct xlat msg_flags[] = {
134 { MSG_NOERROR, "MSG_NOERROR" },
135#ifdef LINUX
136 { MSG_EXCEPT, "MSG_EXCEPT" },
137#endif /* LINUX */
138 { IPC_NOWAIT, "IPC_NOWAIT" },
139 { 0, NULL },
140};
141
142int sys_msgget(tcp)
143struct tcb *tcp;
144{
145 if (entering(tcp)) {
146 if (tcp->u_arg[0])
147 tprintf("%lu", tcp->u_arg[0]);
148 else
149 tprintf("IPC_PRIVATE");
150 tprintf(", ");
Roland McGrathe2be9ab2003-07-17 09:03:04 +0000151 if (printflags(resource_flags, tcp->u_arg[1] & ~0777) != 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000152 tprintf("|");
Roland McGrathe2be9ab2003-07-17 09:03:04 +0000153 tprintf("%#lo", tcp->u_arg[1] & 0777);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000154 }
155 return 0;
156}
157
Roland McGrath80731792003-01-14 09:46:17 +0000158#ifdef IPC_64
159# define PRINTCTL(flagset, arg, dflt) \
160 if ((arg) & IPC_64) tprintf("IPC_64|"); \
161 printxval((flagset), (arg) &~ IPC_64, dflt)
162#else
163# define PRINTCTL printxval
164#endif
165
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000166int sys_msgctl(tcp)
167struct tcb *tcp;
168{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000169 if (entering(tcp)) {
Roland McGrath80731792003-01-14 09:46:17 +0000170 tprintf("%lu, ", tcp->u_arg[0]);
171 PRINTCTL(msgctl_flags, tcp->u_arg[1], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000172#ifdef LINUX
173 tprintf(", %#lx", tcp->u_arg[3]);
174#else /* !LINUX */
175 tprintf(", %#lx", tcp->u_arg[2]);
176#endif /* !LINUX */
177 }
178 return 0;
179}
180
181int sys_msgsnd(tcp)
182struct tcb *tcp;
183{
184 long mtype;
185
186 if (entering(tcp)) {
187 tprintf("%lu", tcp->u_arg[0]);
188#ifdef LINUX
189 umove(tcp, tcp->u_arg[3], &mtype);
190 tprintf(", {%lu, ", mtype);
191 printstr(tcp, tcp->u_arg[3] + sizeof(long),
192 tcp->u_arg[1]);
193 tprintf("}, %lu", tcp->u_arg[1]);
194 tprintf(", ");
195 if (printflags(msg_flags, tcp->u_arg[2]) == 0)
196 tprintf("0");
197#else /* !LINUX */
198 umove(tcp, tcp->u_arg[1], &mtype);
199 tprintf(", {%lu, ", mtype);
200 printstr(tcp, tcp->u_arg[1] + sizeof(long),
201 tcp->u_arg[2]);
202 tprintf("}, %lu", tcp->u_arg[2]);
203 tprintf(", ");
204 if (printflags(msg_flags, tcp->u_arg[3]) == 0)
205 tprintf("0");
206#endif /* !LINUX */
207 }
208 return 0;
209}
210
211int sys_msgrcv(tcp)
212struct tcb *tcp;
213{
214 long mtype;
215#ifdef LINUX
216 struct ipc_wrapper {
217 struct msgbuf *msgp;
218 long msgtyp;
219 } tmp;
220#endif
221
222
223 if (exiting(tcp)) {
224 tprintf("%lu", tcp->u_arg[0]);
225#ifdef LINUX
226 umove(tcp, tcp->u_arg[3], &tmp);
227 umove(tcp, (long) tmp.msgp, &mtype);
228 tprintf(", {%lu, ", mtype);
229 printstr(tcp, (long) (tmp.msgp) + sizeof(long),
230 tcp->u_arg[1]);
231 tprintf("}, %lu", tcp->u_arg[1]);
232 tprintf(", %ld", tmp.msgtyp);
233 tprintf(", ");
234 if (printflags(msg_flags, tcp->u_arg[2]) == 0)
235 tprintf("0");
236#else /* !LINUX */
237 umove(tcp, tcp->u_arg[1], &mtype);
238 tprintf(", {%lu, ", mtype);
239 printstr(tcp, tcp->u_arg[1] + sizeof(long),
240 tcp->u_arg[2]);
241 tprintf("}, %lu", tcp->u_arg[2]);
242 tprintf(", %ld", tcp->u_arg[3]);
243 tprintf(", ");
244 if (printflags(msg_flags, tcp->u_arg[4]) == 0)
245 tprintf("0");
246#endif /* !LINUX */
247 }
248 return 0;
249}
250
251int sys_semop(tcp)
252struct tcb *tcp;
253{
254 if (entering(tcp)) {
255 tprintf("%lu", tcp->u_arg[0]);
256#ifdef LINUX
257 tprintf(", %#lx", tcp->u_arg[3]);
258 tprintf(", %lu", tcp->u_arg[1]);
259#else /* !LINUX */
260 tprintf(", %#lx", tcp->u_arg[1]);
261 tprintf(", %lu", tcp->u_arg[2]);
262#endif /* !LINUX */
263 }
264 return 0;
265}
266
Roland McGrath84776472003-04-08 01:46:48 +0000267#ifdef LINUX
268int sys_semtimedop(tcp)
269struct tcb *tcp;
270{
271 if (entering(tcp)) {
272 tprintf("%lu", tcp->u_arg[0]);
273 tprintf(", %#lx", tcp->u_arg[3]);
274 tprintf(", %lu, ", tcp->u_arg[1]);
275 printtv(tcp, tcp->u_arg[5]);
276 }
277 return 0;
278}
279#endif
280
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000281int sys_semget(tcp)
282struct tcb *tcp;
283{
284 if (entering(tcp)) {
285 if (tcp->u_arg[0])
286 tprintf("%lu", tcp->u_arg[0]);
287 else
288 tprintf("IPC_PRIVATE");
289 tprintf(", %lu", tcp->u_arg[1]);
290 tprintf(", ");
Roland McGrathe2be9ab2003-07-17 09:03:04 +0000291 if (printflags(resource_flags, tcp->u_arg[2] & ~0777) != 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000292 tprintf("|");
Roland McGrathe2be9ab2003-07-17 09:03:04 +0000293 tprintf("%#lo", tcp->u_arg[2] & 0777);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000294 }
295 return 0;
296}
297
298int sys_semctl(tcp)
299struct tcb *tcp;
300{
301 if (entering(tcp)) {
302 tprintf("%lu", tcp->u_arg[0]);
303 tprintf(", %lu, ", tcp->u_arg[1]);
Roland McGrath80731792003-01-14 09:46:17 +0000304 PRINTCTL(semctl_flags, tcp->u_arg[2], "SEM_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000305 tprintf(", %#lx", tcp->u_arg[3]);
306 }
307 return 0;
308}
309
310int sys_shmget(tcp)
311struct tcb *tcp;
312{
313 if (entering(tcp)) {
314 if (tcp->u_arg[0])
315 tprintf("%lu", tcp->u_arg[0]);
316 else
317 tprintf("IPC_PRIVATE");
318 tprintf(", %lu", tcp->u_arg[1]);
319 tprintf(", ");
Roland McGrathe2be9ab2003-07-17 09:03:04 +0000320 if (printflags(resource_flags, tcp->u_arg[2] & ~0777) != 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000321 tprintf("|");
Roland McGrathe2be9ab2003-07-17 09:03:04 +0000322 tprintf("%#lo", tcp->u_arg[2] & 0777);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000323 }
324 return 0;
325}
326
327int sys_shmctl(tcp)
328struct tcb *tcp;
329{
330 if (entering(tcp)) {
331 tprintf("%lu, ", tcp->u_arg[0]);
Roland McGrath80731792003-01-14 09:46:17 +0000332 PRINTCTL(shmctl_flags, tcp->u_arg[1], "SHM_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000333#ifdef LINUX
334 tprintf(", %#lx", tcp->u_arg[3]);
335#else /* !LINUX */
336 tprintf(", %#lx", tcp->u_arg[2]);
337#endif /* !LINUX */
338 }
339 return 0;
340}
341
342int sys_shmat(tcp)
343struct tcb *tcp;
344{
345#ifdef LINUX
346 unsigned long raddr;
347#endif /* LINUX */
348
349 if (exiting(tcp)) {
350 tprintf("%lu", tcp->u_arg[0]);
351#ifdef LINUX
352 tprintf(", %#lx", tcp->u_arg[3]);
353 tprintf(", ");
354 if (printflags(shm_flags, tcp->u_arg[1]) == 0)
355 tprintf("0");
356#else /* !LINUX */
357 tprintf(", %#lx", tcp->u_arg[1]);
358 tprintf(", ");
359 if (printflags(shm_flags, tcp->u_arg[2]) == 0)
360 tprintf("0");
361#endif /* !LINUX */
362 if (syserror(tcp))
363 return 0;
364#ifdef LINUX
365 if (umove(tcp, tcp->u_arg[2], &raddr) < 0)
366 return RVAL_NONE;
367 tcp->u_rval = raddr;
368#endif /* LINUX */
369 return RVAL_HEX;
370 }
371 return 0;
372}
373
374int sys_shmdt(tcp)
375struct tcb *tcp;
376{
377 if (entering(tcp))
378#ifdef LINUX
379 tprintf("%#lx", tcp->u_arg[3]);
380#else /* !LINUX */
381 tprintf("%#lx", tcp->u_arg[0]);
382#endif /* !LINUX */
383 return 0;
384}
385
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000386#endif /* defined(LINUX) || defined(SUNOS4) || defined(FREEBSD) */