blob: f01a9a911419bfc6254fe2f5ff77d65c4a52fcce [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>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 *
29 * $Id$
30 */
31
32#include "defs.h"
33
34#if defined(LINUX) || defined(SUNOS4)
35
36#include <sys/ipc.h>
37#include <sys/sem.h>
38#include <sys/msg.h>
39#include <sys/shm.h>
40
41#ifndef MSG_STAT
42#define MSG_STAT 11
43#endif
44#ifndef MSG_INFO
45#define MSG_INFO 12
46#endif
47#ifndef SHM_STAT
48#define SHM_STAT 13
49#endif
50#ifndef SHM_INFO
51#define SHM_INFO 14
52#endif
53#ifndef SEM_STAT
54#define SEM_STAT 18
55#endif
56#ifndef SEM_INFO
57#define SEM_INFO 19
58#endif
59
60static struct xlat msgctl_flags[] = {
61 { IPC_RMID, "IPC_RMID" },
62 { IPC_SET, "IPC_SET" },
63 { IPC_STAT, "IPC_STAT" },
64#ifdef LINUX
65 { IPC_INFO, "IPC_INFO" },
66 { MSG_STAT, "MSG_STAT" },
67 { MSG_INFO, "MSG_INFO" },
68#endif /* LINUX */
69 { 0, NULL },
70};
71
72static struct xlat semctl_flags[] = {
73 { IPC_RMID, "IPC_RMID" },
74 { IPC_SET, "IPC_SET" },
75 { IPC_STAT, "IPC_STAT" },
76#ifdef LINUX
77 { IPC_INFO, "IPC_INFO" },
78 { SEM_STAT, "SEM_STAT" },
79 { SEM_INFO, "SEM_INFO" },
80#endif /* LINUX */
81 { GETPID, "GETPID" },
82 { GETVAL, "GETVAL" },
83 { GETALL, "GETALL" },
84 { GETNCNT, "GETNCNT" },
85 { GETZCNT, "GETZCNT" },
86 { SETVAL, "SETVAL" },
87 { SETALL, "SETALL" },
88 { 0, NULL },
89};
90
91static struct xlat shmctl_flags[] = {
92 { IPC_RMID, "IPC_RMID" },
93 { IPC_SET, "IPC_SET" },
94 { IPC_STAT, "IPC_STAT" },
95#ifdef LINUX
96 { IPC_INFO, "IPC_INFO" },
97 { SHM_STAT, "SHM_STAT" },
98 { SHM_INFO, "SHM_INFO" },
99#endif /* LINUX */
100 { SHM_LOCK, "SHM_LOCK" },
101 { SHM_UNLOCK, "SHM_UNLOCK" },
102 { 0, NULL },
103};
104
105static struct xlat resource_flags[] = {
106 { IPC_CREAT, "IPC_CREAT" },
107 { IPC_EXCL, "IPC_EXCL" },
108 { IPC_NOWAIT, "IPC_NOWAIT" },
109 { 0, NULL },
110};
111
112static struct xlat shm_flags[] = {
113#ifdef LINUX
114 { SHM_REMAP, "SHM_REMAP" },
115#endif /* LINUX */
116 { SHM_RDONLY, "SHM_RDONLY" },
117 { SHM_RND, "SHM_RND" },
118 { 0, NULL },
119};
120
121static struct xlat msg_flags[] = {
122 { MSG_NOERROR, "MSG_NOERROR" },
123#ifdef LINUX
124 { MSG_EXCEPT, "MSG_EXCEPT" },
125#endif /* LINUX */
126 { IPC_NOWAIT, "IPC_NOWAIT" },
127 { 0, NULL },
128};
129
130int sys_msgget(tcp)
131struct tcb *tcp;
132{
133 if (entering(tcp)) {
134 if (tcp->u_arg[0])
135 tprintf("%lu", tcp->u_arg[0]);
136 else
137 tprintf("IPC_PRIVATE");
138 tprintf(", ");
139 if (printflags(resource_flags, tcp->u_arg[1]) != 0)
140 tprintf("|");
141 tprintf("%#lo", tcp->u_arg[1] & 0666);
142 }
143 return 0;
144}
145
146int sys_msgctl(tcp)
147struct tcb *tcp;
148{
149 char *cmd = xlookup(msgctl_flags, tcp->u_arg[1]);
150
151 if (entering(tcp)) {
152 tprintf("%lu", tcp->u_arg[0]);
153 tprintf(", %s", cmd == NULL ? "MSG_???" : cmd);
154#ifdef LINUX
155 tprintf(", %#lx", tcp->u_arg[3]);
156#else /* !LINUX */
157 tprintf(", %#lx", tcp->u_arg[2]);
158#endif /* !LINUX */
159 }
160 return 0;
161}
162
163int sys_msgsnd(tcp)
164struct tcb *tcp;
165{
166 long mtype;
167
168 if (entering(tcp)) {
169 tprintf("%lu", tcp->u_arg[0]);
170#ifdef LINUX
171 umove(tcp, tcp->u_arg[3], &mtype);
172 tprintf(", {%lu, ", mtype);
173 printstr(tcp, tcp->u_arg[3] + sizeof(long),
174 tcp->u_arg[1]);
175 tprintf("}, %lu", tcp->u_arg[1]);
176 tprintf(", ");
177 if (printflags(msg_flags, tcp->u_arg[2]) == 0)
178 tprintf("0");
179#else /* !LINUX */
180 umove(tcp, tcp->u_arg[1], &mtype);
181 tprintf(", {%lu, ", mtype);
182 printstr(tcp, tcp->u_arg[1] + sizeof(long),
183 tcp->u_arg[2]);
184 tprintf("}, %lu", tcp->u_arg[2]);
185 tprintf(", ");
186 if (printflags(msg_flags, tcp->u_arg[3]) == 0)
187 tprintf("0");
188#endif /* !LINUX */
189 }
190 return 0;
191}
192
193int sys_msgrcv(tcp)
194struct tcb *tcp;
195{
196 long mtype;
197#ifdef LINUX
198 struct ipc_wrapper {
199 struct msgbuf *msgp;
200 long msgtyp;
201 } tmp;
202#endif
203
204
205 if (exiting(tcp)) {
206 tprintf("%lu", tcp->u_arg[0]);
207#ifdef LINUX
208 umove(tcp, tcp->u_arg[3], &tmp);
209 umove(tcp, (long) tmp.msgp, &mtype);
210 tprintf(", {%lu, ", mtype);
211 printstr(tcp, (long) (tmp.msgp) + sizeof(long),
212 tcp->u_arg[1]);
213 tprintf("}, %lu", tcp->u_arg[1]);
214 tprintf(", %ld", tmp.msgtyp);
215 tprintf(", ");
216 if (printflags(msg_flags, tcp->u_arg[2]) == 0)
217 tprintf("0");
218#else /* !LINUX */
219 umove(tcp, tcp->u_arg[1], &mtype);
220 tprintf(", {%lu, ", mtype);
221 printstr(tcp, tcp->u_arg[1] + sizeof(long),
222 tcp->u_arg[2]);
223 tprintf("}, %lu", tcp->u_arg[2]);
224 tprintf(", %ld", tcp->u_arg[3]);
225 tprintf(", ");
226 if (printflags(msg_flags, tcp->u_arg[4]) == 0)
227 tprintf("0");
228#endif /* !LINUX */
229 }
230 return 0;
231}
232
233int sys_semop(tcp)
234struct tcb *tcp;
235{
236 if (entering(tcp)) {
237 tprintf("%lu", tcp->u_arg[0]);
238#ifdef LINUX
239 tprintf(", %#lx", tcp->u_arg[3]);
240 tprintf(", %lu", tcp->u_arg[1]);
241#else /* !LINUX */
242 tprintf(", %#lx", tcp->u_arg[1]);
243 tprintf(", %lu", tcp->u_arg[2]);
244#endif /* !LINUX */
245 }
246 return 0;
247}
248
249int sys_semget(tcp)
250struct tcb *tcp;
251{
252 if (entering(tcp)) {
253 if (tcp->u_arg[0])
254 tprintf("%lu", tcp->u_arg[0]);
255 else
256 tprintf("IPC_PRIVATE");
257 tprintf(", %lu", tcp->u_arg[1]);
258 tprintf(", ");
259 if (printflags(resource_flags, tcp->u_arg[2]) != 0)
260 tprintf("|");
261 tprintf("%#lo", tcp->u_arg[2] & 0666);
262 }
263 return 0;
264}
265
266int sys_semctl(tcp)
267struct tcb *tcp;
268{
269 if (entering(tcp)) {
270 tprintf("%lu", tcp->u_arg[0]);
271 tprintf(", %lu, ", tcp->u_arg[1]);
272 printxval(semctl_flags, tcp->u_arg[2], "SEM_???");
273 tprintf(", %#lx", tcp->u_arg[3]);
274 }
275 return 0;
276}
277
278int sys_shmget(tcp)
279struct tcb *tcp;
280{
281 if (entering(tcp)) {
282 if (tcp->u_arg[0])
283 tprintf("%lu", tcp->u_arg[0]);
284 else
285 tprintf("IPC_PRIVATE");
286 tprintf(", %lu", tcp->u_arg[1]);
287 tprintf(", ");
288 if (printflags(resource_flags, tcp->u_arg[2]) != 0)
289 tprintf("|");
290 tprintf("%#lo", tcp->u_arg[2] & 0666);
291 }
292 return 0;
293}
294
295int sys_shmctl(tcp)
296struct tcb *tcp;
297{
298 if (entering(tcp)) {
299 tprintf("%lu, ", tcp->u_arg[0]);
300 printxval(shmctl_flags, tcp->u_arg[1], "SHM_???");
301#ifdef LINUX
302 tprintf(", %#lx", tcp->u_arg[3]);
303#else /* !LINUX */
304 tprintf(", %#lx", tcp->u_arg[2]);
305#endif /* !LINUX */
306 }
307 return 0;
308}
309
310int sys_shmat(tcp)
311struct tcb *tcp;
312{
313#ifdef LINUX
314 unsigned long raddr;
315#endif /* LINUX */
316
317 if (exiting(tcp)) {
318 tprintf("%lu", tcp->u_arg[0]);
319#ifdef LINUX
320 tprintf(", %#lx", tcp->u_arg[3]);
321 tprintf(", ");
322 if (printflags(shm_flags, tcp->u_arg[1]) == 0)
323 tprintf("0");
324#else /* !LINUX */
325 tprintf(", %#lx", tcp->u_arg[1]);
326 tprintf(", ");
327 if (printflags(shm_flags, tcp->u_arg[2]) == 0)
328 tprintf("0");
329#endif /* !LINUX */
330 if (syserror(tcp))
331 return 0;
332#ifdef LINUX
333 if (umove(tcp, tcp->u_arg[2], &raddr) < 0)
334 return RVAL_NONE;
335 tcp->u_rval = raddr;
336#endif /* LINUX */
337 return RVAL_HEX;
338 }
339 return 0;
340}
341
342int sys_shmdt(tcp)
343struct tcb *tcp;
344{
345 if (entering(tcp))
346#ifdef LINUX
347 tprintf("%#lx", tcp->u_arg[3]);
348#else /* !LINUX */
349 tprintf("%#lx", tcp->u_arg[0]);
350#endif /* !LINUX */
351 return 0;
352}
353
354#endif /* defined(LINUX) || defined(SUNOS4) */