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