Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1 | /* |
| 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 Akkerman | 4dc8a2a | 1999-12-23 14:20:14 +0000 | [diff] [blame] | 5 | * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl> |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 6 | * 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 Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 35 | #if defined(LINUX) || defined(SUNOS4) || defined(FREEBSD) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 36 | |
| 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 McGrath | 8073179 | 2003-01-14 09:46:17 +0000 | [diff] [blame] | 61 | #if defined LINUX && !defined IPC_64 |
| 62 | # define IPC_64 0x100 |
| 63 | #endif |
| 64 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 65 | static 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 | |
| 77 | static 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 | |
| 96 | static 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 McGrath | 8073179 | 2003-01-14 09:46:17 +0000 | [diff] [blame] | 105 | #ifdef SHM_LOCK |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 106 | { SHM_LOCK, "SHM_LOCK" }, |
Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 107 | #endif |
Roland McGrath | 8073179 | 2003-01-14 09:46:17 +0000 | [diff] [blame] | 108 | #ifdef SHM_UNLOCK |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 109 | { SHM_UNLOCK, "SHM_UNLOCK" }, |
Roland McGrath | 8073179 | 2003-01-14 09:46:17 +0000 | [diff] [blame] | 110 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 111 | { 0, NULL }, |
| 112 | }; |
| 113 | |
| 114 | static struct xlat resource_flags[] = { |
| 115 | { IPC_CREAT, "IPC_CREAT" }, |
| 116 | { IPC_EXCL, "IPC_EXCL" }, |
| 117 | { IPC_NOWAIT, "IPC_NOWAIT" }, |
Roland McGrath | e2be9ab | 2003-07-17 09:03:04 +0000 | [diff] [blame] | 118 | #ifdef SHM_HUGETLB |
| 119 | { SHM_HUGETLB, "SHM_HUGETLB" }, |
| 120 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 121 | { 0, NULL }, |
| 122 | }; |
| 123 | |
| 124 | static 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 | |
| 133 | static 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 | |
| 142 | int sys_msgget(tcp) |
| 143 | struct 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 McGrath | e2be9ab | 2003-07-17 09:03:04 +0000 | [diff] [blame] | 151 | if (printflags(resource_flags, tcp->u_arg[1] & ~0777) != 0) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 152 | tprintf("|"); |
Roland McGrath | e2be9ab | 2003-07-17 09:03:04 +0000 | [diff] [blame] | 153 | tprintf("%#lo", tcp->u_arg[1] & 0777); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 154 | } |
| 155 | return 0; |
| 156 | } |
| 157 | |
Roland McGrath | 8073179 | 2003-01-14 09:46:17 +0000 | [diff] [blame] | 158 | #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 Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 166 | int sys_msgctl(tcp) |
| 167 | struct tcb *tcp; |
| 168 | { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 169 | if (entering(tcp)) { |
Roland McGrath | 8073179 | 2003-01-14 09:46:17 +0000 | [diff] [blame] | 170 | tprintf("%lu, ", tcp->u_arg[0]); |
| 171 | PRINTCTL(msgctl_flags, tcp->u_arg[1], "MSG_???"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 172 | #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 | |
| 181 | int sys_msgsnd(tcp) |
| 182 | struct 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 | |
| 211 | int sys_msgrcv(tcp) |
| 212 | struct 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 | |
| 251 | int sys_semop(tcp) |
| 252 | struct 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 McGrath | 8477647 | 2003-04-08 01:46:48 +0000 | [diff] [blame] | 267 | #ifdef LINUX |
| 268 | int sys_semtimedop(tcp) |
| 269 | struct 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 Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 281 | int sys_semget(tcp) |
| 282 | struct 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 McGrath | e2be9ab | 2003-07-17 09:03:04 +0000 | [diff] [blame] | 291 | if (printflags(resource_flags, tcp->u_arg[2] & ~0777) != 0) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 292 | tprintf("|"); |
Roland McGrath | e2be9ab | 2003-07-17 09:03:04 +0000 | [diff] [blame] | 293 | tprintf("%#lo", tcp->u_arg[2] & 0777); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 294 | } |
| 295 | return 0; |
| 296 | } |
| 297 | |
| 298 | int sys_semctl(tcp) |
| 299 | struct tcb *tcp; |
| 300 | { |
| 301 | if (entering(tcp)) { |
| 302 | tprintf("%lu", tcp->u_arg[0]); |
| 303 | tprintf(", %lu, ", tcp->u_arg[1]); |
Roland McGrath | 8073179 | 2003-01-14 09:46:17 +0000 | [diff] [blame] | 304 | PRINTCTL(semctl_flags, tcp->u_arg[2], "SEM_???"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 305 | tprintf(", %#lx", tcp->u_arg[3]); |
| 306 | } |
| 307 | return 0; |
| 308 | } |
| 309 | |
| 310 | int sys_shmget(tcp) |
| 311 | struct 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 McGrath | e2be9ab | 2003-07-17 09:03:04 +0000 | [diff] [blame] | 320 | if (printflags(resource_flags, tcp->u_arg[2] & ~0777) != 0) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 321 | tprintf("|"); |
Roland McGrath | e2be9ab | 2003-07-17 09:03:04 +0000 | [diff] [blame] | 322 | tprintf("%#lo", tcp->u_arg[2] & 0777); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 323 | } |
| 324 | return 0; |
| 325 | } |
| 326 | |
| 327 | int sys_shmctl(tcp) |
| 328 | struct tcb *tcp; |
| 329 | { |
| 330 | if (entering(tcp)) { |
| 331 | tprintf("%lu, ", tcp->u_arg[0]); |
Roland McGrath | 8073179 | 2003-01-14 09:46:17 +0000 | [diff] [blame] | 332 | PRINTCTL(shmctl_flags, tcp->u_arg[1], "SHM_???"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 333 | #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 | |
| 342 | int sys_shmat(tcp) |
| 343 | struct 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 | |
| 374 | int sys_shmdt(tcp) |
| 375 | struct 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 Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 386 | #endif /* defined(LINUX) || defined(SUNOS4) || defined(FREEBSD) */ |