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. |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 29 | */ |
| 30 | |
| 31 | #include "defs.h" |
Denys Vlasenko | a6d91de | 2012-03-16 12:02:22 +0100 | [diff] [blame] | 32 | #ifdef HAVE_MQUEUE_H |
| 33 | # include <mqueue.h> |
| 34 | #endif |
Roland McGrath | 4df13c1 | 2004-04-16 21:48:40 +0000 | [diff] [blame] | 35 | #include <fcntl.h> |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 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 | |
Denys Vlasenko | 8470374 | 2012-02-25 02:38:52 +0100 | [diff] [blame] | 60 | #if !defined IPC_64 |
Roland McGrath | 8073179 | 2003-01-14 09:46:17 +0000 | [diff] [blame] | 61 | # define IPC_64 0x100 |
| 62 | #endif |
| 63 | |
Roland McGrath | 4df13c1 | 2004-04-16 21:48:40 +0000 | [diff] [blame] | 64 | extern void printsigevent(struct tcb *tcp, long arg); |
| 65 | |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 66 | static const struct xlat msgctl_flags[] = { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 67 | { IPC_RMID, "IPC_RMID" }, |
| 68 | { IPC_SET, "IPC_SET" }, |
| 69 | { IPC_STAT, "IPC_STAT" }, |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 70 | { IPC_INFO, "IPC_INFO" }, |
| 71 | { MSG_STAT, "MSG_STAT" }, |
| 72 | { MSG_INFO, "MSG_INFO" }, |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 73 | { 0, NULL }, |
| 74 | }; |
| 75 | |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 76 | static const struct xlat semctl_flags[] = { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 77 | { IPC_RMID, "IPC_RMID" }, |
| 78 | { IPC_SET, "IPC_SET" }, |
| 79 | { IPC_STAT, "IPC_STAT" }, |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 80 | { IPC_INFO, "IPC_INFO" }, |
| 81 | { SEM_STAT, "SEM_STAT" }, |
| 82 | { SEM_INFO, "SEM_INFO" }, |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 83 | { GETPID, "GETPID" }, |
| 84 | { GETVAL, "GETVAL" }, |
| 85 | { GETALL, "GETALL" }, |
| 86 | { GETNCNT, "GETNCNT" }, |
| 87 | { GETZCNT, "GETZCNT" }, |
| 88 | { SETVAL, "SETVAL" }, |
| 89 | { SETALL, "SETALL" }, |
| 90 | { 0, NULL }, |
| 91 | }; |
| 92 | |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 93 | static const struct xlat shmctl_flags[] = { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 94 | { IPC_RMID, "IPC_RMID" }, |
| 95 | { IPC_SET, "IPC_SET" }, |
| 96 | { IPC_STAT, "IPC_STAT" }, |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 97 | { IPC_INFO, "IPC_INFO" }, |
| 98 | { SHM_STAT, "SHM_STAT" }, |
| 99 | { SHM_INFO, "SHM_INFO" }, |
Roland McGrath | 8073179 | 2003-01-14 09:46:17 +0000 | [diff] [blame] | 100 | #ifdef SHM_LOCK |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 101 | { SHM_LOCK, "SHM_LOCK" }, |
Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 102 | #endif |
Roland McGrath | 8073179 | 2003-01-14 09:46:17 +0000 | [diff] [blame] | 103 | #ifdef SHM_UNLOCK |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 104 | { SHM_UNLOCK, "SHM_UNLOCK" }, |
Roland McGrath | 8073179 | 2003-01-14 09:46:17 +0000 | [diff] [blame] | 105 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 106 | { 0, NULL }, |
| 107 | }; |
| 108 | |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 109 | static const struct xlat resource_flags[] = { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 110 | { IPC_CREAT, "IPC_CREAT" }, |
| 111 | { IPC_EXCL, "IPC_EXCL" }, |
| 112 | { IPC_NOWAIT, "IPC_NOWAIT" }, |
Roland McGrath | 802b8f4 | 2005-05-09 07:40:33 +0000 | [diff] [blame] | 113 | { 0, NULL }, |
| 114 | }; |
| 115 | |
| 116 | static const struct xlat shm_resource_flags[] = { |
| 117 | { IPC_CREAT, "IPC_CREAT" }, |
| 118 | { IPC_EXCL, "IPC_EXCL" }, |
Roland McGrath | e2be9ab | 2003-07-17 09:03:04 +0000 | [diff] [blame] | 119 | #ifdef SHM_HUGETLB |
| 120 | { SHM_HUGETLB, "SHM_HUGETLB" }, |
| 121 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 122 | { 0, NULL }, |
| 123 | }; |
| 124 | |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 125 | static const struct xlat shm_flags[] = { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 126 | { SHM_REMAP, "SHM_REMAP" }, |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 127 | { SHM_RDONLY, "SHM_RDONLY" }, |
| 128 | { SHM_RND, "SHM_RND" }, |
| 129 | { 0, NULL }, |
| 130 | }; |
| 131 | |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 132 | static const struct xlat msg_flags[] = { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 133 | { MSG_NOERROR, "MSG_NOERROR" }, |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 134 | { MSG_EXCEPT, "MSG_EXCEPT" }, |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 135 | { IPC_NOWAIT, "IPC_NOWAIT" }, |
| 136 | { 0, NULL }, |
| 137 | }; |
| 138 | |
Jakub Bogusz | 002e985 | 2009-10-07 22:25:10 +0200 | [diff] [blame] | 139 | static const struct xlat semop_flags[] = { |
| 140 | { SEM_UNDO, "SEM_UNDO" }, |
| 141 | { IPC_NOWAIT, "IPC_NOWAIT" }, |
| 142 | { 0, NULL }, |
| 143 | }; |
| 144 | |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 145 | int sys_msgget(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 146 | { |
| 147 | if (entering(tcp)) { |
| 148 | if (tcp->u_arg[0]) |
Denys Vlasenko | 859ea8b | 2013-02-23 20:07:44 +0100 | [diff] [blame] | 149 | tprintf("%#lx, ", tcp->u_arg[0]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 150 | else |
Denys Vlasenko | 859ea8b | 2013-02-23 20:07:44 +0100 | [diff] [blame] | 151 | tprints("IPC_PRIVATE, "); |
Roland McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 152 | if (printflags(resource_flags, tcp->u_arg[1] & ~0777, NULL) != 0) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 153 | tprints("|"); |
Roland McGrath | e2be9ab | 2003-07-17 09:03:04 +0000 | [diff] [blame] | 154 | tprintf("%#lo", tcp->u_arg[1] & 0777); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 155 | } |
| 156 | return 0; |
| 157 | } |
| 158 | |
Roland McGrath | 8073179 | 2003-01-14 09:46:17 +0000 | [diff] [blame] | 159 | #ifdef IPC_64 |
| 160 | # define PRINTCTL(flagset, arg, dflt) \ |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 161 | if ((arg) & IPC_64) tprints("IPC_64|"); \ |
Roland McGrath | 8073179 | 2003-01-14 09:46:17 +0000 | [diff] [blame] | 162 | printxval((flagset), (arg) &~ IPC_64, dflt) |
| 163 | #else |
| 164 | # define PRINTCTL printxval |
| 165 | #endif |
| 166 | |
Roland McGrath | 54b90d7 | 2005-12-02 03:57:07 +0000 | [diff] [blame] | 167 | static int |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 168 | indirect_ipccall(struct tcb *tcp) |
Roland McGrath | 54b90d7 | 2005-12-02 03:57:07 +0000 | [diff] [blame] | 169 | { |
Roland McGrath | 54b90d7 | 2005-12-02 03:57:07 +0000 | [diff] [blame] | 170 | #ifdef X86_64 |
H.J. Lu | 35be581 | 2012-04-16 13:00:01 +0200 | [diff] [blame] | 171 | return current_personality == 1; |
Roland McGrath | 54b90d7 | 2005-12-02 03:57:07 +0000 | [diff] [blame] | 172 | #endif |
Roland McGrath | a81bf4c | 2005-12-02 04:18:55 +0000 | [diff] [blame] | 173 | #if defined IA64 |
| 174 | return tcp->scno < 1024; /* ia32 emulation syscalls are low */ |
Roland McGrath | 54b90d7 | 2005-12-02 03:57:07 +0000 | [diff] [blame] | 175 | #endif |
Steve McIntyre | d8d3bd3 | 2012-10-24 17:58:16 +0100 | [diff] [blame] | 176 | #if defined(ALPHA) || defined(MIPS) || defined(HPPA) || defined(__ARM_EABI__) || defined(AARCH64) |
Roland McGrath | 54b90d7 | 2005-12-02 03:57:07 +0000 | [diff] [blame] | 177 | return 0; |
Dmitry V. Levin | 3d7b11b | 2012-03-15 21:19:36 +0000 | [diff] [blame] | 178 | #endif |
| 179 | return 1; |
Roland McGrath | 54b90d7 | 2005-12-02 03:57:07 +0000 | [diff] [blame] | 180 | } |
| 181 | |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 182 | int sys_msgctl(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 183 | { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 184 | if (entering(tcp)) { |
Roland McGrath | 8073179 | 2003-01-14 09:46:17 +0000 | [diff] [blame] | 185 | tprintf("%lu, ", tcp->u_arg[0]); |
| 186 | PRINTCTL(msgctl_flags, tcp->u_arg[1], "MSG_???"); |
Roland McGrath | 54b90d7 | 2005-12-02 03:57:07 +0000 | [diff] [blame] | 187 | tprintf(", %#lx", tcp->u_arg[indirect_ipccall(tcp) ? 3 : 2]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 188 | } |
| 189 | return 0; |
| 190 | } |
| 191 | |
Dmitry V. Levin | 783f5bc | 2009-10-08 23:33:15 +0000 | [diff] [blame] | 192 | static void |
Dmitry V. Levin | 4310a37 | 2010-03-31 22:22:01 +0000 | [diff] [blame] | 193 | tprint_msgsnd(struct tcb *tcp, long addr, unsigned long count, |
| 194 | unsigned long flags) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 195 | { |
| 196 | long mtype; |
| 197 | |
Dmitry V. Levin | 783f5bc | 2009-10-08 23:33:15 +0000 | [diff] [blame] | 198 | if (umove(tcp, addr, &mtype) < 0) { |
| 199 | tprintf("%#lx", addr); |
| 200 | } else { |
| 201 | tprintf("{%lu, ", mtype); |
| 202 | printstr(tcp, addr + sizeof(mtype), count); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 203 | tprints("}"); |
Dmitry V. Levin | 783f5bc | 2009-10-08 23:33:15 +0000 | [diff] [blame] | 204 | } |
| 205 | tprintf(", %lu, ", count); |
Dmitry V. Levin | 4310a37 | 2010-03-31 22:22:01 +0000 | [diff] [blame] | 206 | printflags(msg_flags, flags, "MSG_???"); |
Dmitry V. Levin | 783f5bc | 2009-10-08 23:33:15 +0000 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | int sys_msgsnd(struct tcb *tcp) |
| 210 | { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 211 | if (entering(tcp)) { |
Dmitry V. Levin | 62e0596 | 2009-11-03 14:38:44 +0000 | [diff] [blame] | 212 | tprintf("%d, ", (int) tcp->u_arg[0]); |
Roland McGrath | 54b90d7 | 2005-12-02 03:57:07 +0000 | [diff] [blame] | 213 | if (indirect_ipccall(tcp)) { |
Dmitry V. Levin | 4310a37 | 2010-03-31 22:22:01 +0000 | [diff] [blame] | 214 | tprint_msgsnd(tcp, tcp->u_arg[3], tcp->u_arg[1], |
| 215 | tcp->u_arg[2]); |
Roland McGrath | 54b90d7 | 2005-12-02 03:57:07 +0000 | [diff] [blame] | 216 | } else { |
Dmitry V. Levin | 4310a37 | 2010-03-31 22:22:01 +0000 | [diff] [blame] | 217 | tprint_msgsnd(tcp, tcp->u_arg[1], tcp->u_arg[2], |
| 218 | tcp->u_arg[3]); |
Roland McGrath | 54b90d7 | 2005-12-02 03:57:07 +0000 | [diff] [blame] | 219 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 220 | } |
| 221 | return 0; |
| 222 | } |
| 223 | |
Dmitry V. Levin | 62e0596 | 2009-11-03 14:38:44 +0000 | [diff] [blame] | 224 | static void |
| 225 | tprint_msgrcv(struct tcb *tcp, long addr, unsigned long count, long msgtyp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 226 | { |
| 227 | long mtype; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 228 | |
Dmitry V. Levin | 62e0596 | 2009-11-03 14:38:44 +0000 | [diff] [blame] | 229 | if (syserror(tcp) || umove(tcp, addr, &mtype) < 0) { |
| 230 | tprintf("%#lx", addr); |
Roland McGrath | f467c00 | 2005-12-02 03:44:12 +0000 | [diff] [blame] | 231 | } else { |
Dmitry V. Levin | 62e0596 | 2009-11-03 14:38:44 +0000 | [diff] [blame] | 232 | tprintf("{%lu, ", mtype); |
| 233 | printstr(tcp, addr + sizeof(mtype), count); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 234 | tprints("}"); |
Dmitry V. Levin | 62e0596 | 2009-11-03 14:38:44 +0000 | [diff] [blame] | 235 | } |
| 236 | tprintf(", %lu, %ld, ", count, msgtyp); |
| 237 | } |
| 238 | |
| 239 | int sys_msgrcv(struct tcb *tcp) |
| 240 | { |
| 241 | if (entering(tcp)) { |
| 242 | tprintf("%d, ", (int) tcp->u_arg[0]); |
| 243 | } else { |
Roland McGrath | 54b90d7 | 2005-12-02 03:57:07 +0000 | [diff] [blame] | 244 | if (indirect_ipccall(tcp)) { |
| 245 | struct ipc_wrapper { |
| 246 | struct msgbuf *msgp; |
| 247 | long msgtyp; |
| 248 | } tmp; |
Dmitry V. Levin | 62e0596 | 2009-11-03 14:38:44 +0000 | [diff] [blame] | 249 | |
| 250 | if (umove(tcp, tcp->u_arg[3], &tmp) < 0) { |
| 251 | tprintf("%#lx, %lu, ", |
| 252 | tcp->u_arg[3], tcp->u_arg[1]); |
| 253 | } else { |
| 254 | tprint_msgrcv(tcp, (long) tmp.msgp, |
| 255 | tcp->u_arg[1], tmp.msgtyp); |
| 256 | } |
Roland McGrath | 54b90d7 | 2005-12-02 03:57:07 +0000 | [diff] [blame] | 257 | printflags(msg_flags, tcp->u_arg[2], "MSG_???"); |
| 258 | } else { |
Dmitry V. Levin | 62e0596 | 2009-11-03 14:38:44 +0000 | [diff] [blame] | 259 | tprint_msgrcv(tcp, tcp->u_arg[1], |
| 260 | tcp->u_arg[2], tcp->u_arg[3]); |
Roland McGrath | 54b90d7 | 2005-12-02 03:57:07 +0000 | [diff] [blame] | 261 | printflags(msg_flags, tcp->u_arg[4], "MSG_???"); |
| 262 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 263 | } |
| 264 | return 0; |
| 265 | } |
| 266 | |
Dmitry V. Levin | ef94101 | 2009-10-07 22:14:00 +0000 | [diff] [blame] | 267 | static void |
| 268 | tprint_sembuf(struct tcb *tcp, long addr, unsigned long count) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 269 | { |
Dmitry V. Levin | ef94101 | 2009-10-07 22:14:00 +0000 | [diff] [blame] | 270 | unsigned long i, max_count; |
Jakub Bogusz | 002e985 | 2009-10-07 22:25:10 +0200 | [diff] [blame] | 271 | |
Dmitry V. Levin | ef94101 | 2009-10-07 22:14:00 +0000 | [diff] [blame] | 272 | if (abbrev(tcp)) |
| 273 | max_count = (max_strlen < count) ? max_strlen : count; |
| 274 | else |
| 275 | max_count = count; |
| 276 | |
| 277 | if (!max_count) { |
| 278 | tprintf("%#lx, %lu", addr, count); |
| 279 | return; |
| 280 | } |
| 281 | |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 282 | for (i = 0; i < max_count; ++i) { |
Dmitry V. Levin | ef94101 | 2009-10-07 22:14:00 +0000 | [diff] [blame] | 283 | struct sembuf sb; |
| 284 | if (i) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 285 | tprints(", "); |
Dmitry V. Levin | ef94101 | 2009-10-07 22:14:00 +0000 | [diff] [blame] | 286 | if (umove(tcp, addr + i * sizeof(struct sembuf), &sb) < 0) { |
| 287 | if (i) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 288 | tprints("{???}"); |
Dmitry V. Levin | ef94101 | 2009-10-07 22:14:00 +0000 | [diff] [blame] | 289 | break; |
| 290 | } else { |
| 291 | tprintf("%#lx, %lu", addr, count); |
| 292 | return; |
Jakub Bogusz | 002e985 | 2009-10-07 22:25:10 +0200 | [diff] [blame] | 293 | } |
Roland McGrath | 54b90d7 | 2005-12-02 03:57:07 +0000 | [diff] [blame] | 294 | } else { |
Dmitry V. Levin | ef94101 | 2009-10-07 22:14:00 +0000 | [diff] [blame] | 295 | if (!i) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 296 | tprints("{"); |
Dmitry V. Levin | ef94101 | 2009-10-07 22:14:00 +0000 | [diff] [blame] | 297 | tprintf("{%u, %d, ", sb.sem_num, sb.sem_op); |
| 298 | printflags(semop_flags, sb.sem_flg, "SEM_???"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 299 | tprints("}"); |
Dmitry V. Levin | ef94101 | 2009-10-07 22:14:00 +0000 | [diff] [blame] | 300 | } |
| 301 | } |
| 302 | |
| 303 | if (i < max_count || max_count < count) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 304 | tprints(", ..."); |
Dmitry V. Levin | ef94101 | 2009-10-07 22:14:00 +0000 | [diff] [blame] | 305 | |
| 306 | tprintf("}, %lu", count); |
| 307 | } |
| 308 | |
| 309 | int sys_semop(struct tcb *tcp) |
| 310 | { |
| 311 | if (entering(tcp)) { |
| 312 | tprintf("%lu, ", tcp->u_arg[0]); |
| 313 | if (indirect_ipccall(tcp)) { |
| 314 | tprint_sembuf(tcp, tcp->u_arg[3], tcp->u_arg[1]); |
| 315 | } else { |
| 316 | tprint_sembuf(tcp, tcp->u_arg[1], tcp->u_arg[2]); |
Roland McGrath | 54b90d7 | 2005-12-02 03:57:07 +0000 | [diff] [blame] | 317 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 318 | } |
| 319 | return 0; |
| 320 | } |
| 321 | |
Dmitry V. Levin | ef94101 | 2009-10-07 22:14:00 +0000 | [diff] [blame] | 322 | int sys_semtimedop(struct tcb *tcp) |
Roland McGrath | 8477647 | 2003-04-08 01:46:48 +0000 | [diff] [blame] | 323 | { |
| 324 | if (entering(tcp)) { |
Dmitry V. Levin | ef94101 | 2009-10-07 22:14:00 +0000 | [diff] [blame] | 325 | tprintf("%lu, ", tcp->u_arg[0]); |
Roland McGrath | a079d9f | 2006-04-25 07:22:01 +0000 | [diff] [blame] | 326 | if (indirect_ipccall(tcp)) { |
Dmitry V. Levin | ef94101 | 2009-10-07 22:14:00 +0000 | [diff] [blame] | 327 | tprint_sembuf(tcp, tcp->u_arg[3], tcp->u_arg[1]); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 328 | tprints(", "); |
Stanislav Brabec | beae4c7 | 2012-12-10 20:18:49 +0100 | [diff] [blame] | 329 | #if defined(S390) || defined(S390X) |
Heiko Carstens | e0f5fd8 | 2011-11-30 13:16:29 +0100 | [diff] [blame] | 330 | printtv(tcp, tcp->u_arg[2]); |
| 331 | #else |
Stanislav Brabec | eff5c0e | 2012-12-07 21:30:51 +0100 | [diff] [blame] | 332 | printtv(tcp, tcp->u_arg[4]); |
Heiko Carstens | e0f5fd8 | 2011-11-30 13:16:29 +0100 | [diff] [blame] | 333 | #endif |
Roland McGrath | 54b90d7 | 2005-12-02 03:57:07 +0000 | [diff] [blame] | 334 | } else { |
Dmitry V. Levin | ef94101 | 2009-10-07 22:14:00 +0000 | [diff] [blame] | 335 | tprint_sembuf(tcp, tcp->u_arg[1], tcp->u_arg[2]); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 336 | tprints(", "); |
Roland McGrath | 54b90d7 | 2005-12-02 03:57:07 +0000 | [diff] [blame] | 337 | printtv(tcp, tcp->u_arg[3]); |
| 338 | } |
Roland McGrath | 8477647 | 2003-04-08 01:46:48 +0000 | [diff] [blame] | 339 | } |
| 340 | return 0; |
| 341 | } |
Roland McGrath | 8477647 | 2003-04-08 01:46:48 +0000 | [diff] [blame] | 342 | |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 343 | int sys_semget(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 344 | { |
| 345 | if (entering(tcp)) { |
| 346 | if (tcp->u_arg[0]) |
Roland McGrath | 9f130d5 | 2006-08-22 07:36:55 +0000 | [diff] [blame] | 347 | tprintf("%#lx", tcp->u_arg[0]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 348 | else |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 349 | tprints("IPC_PRIVATE"); |
Denys Vlasenko | 859ea8b | 2013-02-23 20:07:44 +0100 | [diff] [blame] | 350 | tprintf(", %lu, ", tcp->u_arg[1]); |
Roland McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 351 | if (printflags(resource_flags, tcp->u_arg[2] & ~0777, NULL) != 0) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 352 | tprints("|"); |
Roland McGrath | e2be9ab | 2003-07-17 09:03:04 +0000 | [diff] [blame] | 353 | tprintf("%#lo", tcp->u_arg[2] & 0777); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 354 | } |
| 355 | return 0; |
| 356 | } |
| 357 | |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 358 | int sys_semctl(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 359 | { |
| 360 | if (entering(tcp)) { |
Denys Vlasenko | 859ea8b | 2013-02-23 20:07:44 +0100 | [diff] [blame] | 361 | tprintf("%lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1]); |
Roland McGrath | 8073179 | 2003-01-14 09:46:17 +0000 | [diff] [blame] | 362 | PRINTCTL(semctl_flags, tcp->u_arg[2], "SEM_???"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 363 | tprintf(", %#lx", tcp->u_arg[3]); |
| 364 | } |
| 365 | return 0; |
| 366 | } |
| 367 | |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 368 | int sys_shmget(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 369 | { |
| 370 | if (entering(tcp)) { |
| 371 | if (tcp->u_arg[0]) |
Roland McGrath | 9f130d5 | 2006-08-22 07:36:55 +0000 | [diff] [blame] | 372 | tprintf("%#lx", tcp->u_arg[0]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 373 | else |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 374 | tprints("IPC_PRIVATE"); |
Denys Vlasenko | 859ea8b | 2013-02-23 20:07:44 +0100 | [diff] [blame] | 375 | tprintf(", %lu, ", tcp->u_arg[1]); |
Roland McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 376 | if (printflags(shm_resource_flags, tcp->u_arg[2] & ~0777, NULL) != 0) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 377 | tprints("|"); |
Roland McGrath | e2be9ab | 2003-07-17 09:03:04 +0000 | [diff] [blame] | 378 | tprintf("%#lo", tcp->u_arg[2] & 0777); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 379 | } |
| 380 | return 0; |
| 381 | } |
| 382 | |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 383 | int sys_shmctl(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 384 | { |
| 385 | if (entering(tcp)) { |
| 386 | tprintf("%lu, ", tcp->u_arg[0]); |
Roland McGrath | 8073179 | 2003-01-14 09:46:17 +0000 | [diff] [blame] | 387 | PRINTCTL(shmctl_flags, tcp->u_arg[1], "SHM_???"); |
Roland McGrath | 54b90d7 | 2005-12-02 03:57:07 +0000 | [diff] [blame] | 388 | if (indirect_ipccall(tcp)) { |
| 389 | tprintf(", %#lx", tcp->u_arg[3]); |
| 390 | } else { |
| 391 | tprintf(", %#lx", tcp->u_arg[2]); |
| 392 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 393 | } |
| 394 | return 0; |
| 395 | } |
| 396 | |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 397 | int sys_shmat(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 398 | { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 399 | if (exiting(tcp)) { |
| 400 | tprintf("%lu", tcp->u_arg[0]); |
Roland McGrath | 54b90d7 | 2005-12-02 03:57:07 +0000 | [diff] [blame] | 401 | if (indirect_ipccall(tcp)) { |
Denys Vlasenko | 859ea8b | 2013-02-23 20:07:44 +0100 | [diff] [blame] | 402 | tprintf(", %#lx, ", tcp->u_arg[3]); |
Roland McGrath | 54b90d7 | 2005-12-02 03:57:07 +0000 | [diff] [blame] | 403 | printflags(shm_flags, tcp->u_arg[1], "SHM_???"); |
| 404 | } else { |
Denys Vlasenko | 859ea8b | 2013-02-23 20:07:44 +0100 | [diff] [blame] | 405 | tprintf(", %#lx, ", tcp->u_arg[1]); |
Roland McGrath | 54b90d7 | 2005-12-02 03:57:07 +0000 | [diff] [blame] | 406 | printflags(shm_flags, tcp->u_arg[2], "SHM_???"); |
| 407 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 408 | if (syserror(tcp)) |
| 409 | return 0; |
Dmitry V. Levin | 3d7b11b | 2012-03-15 21:19:36 +0000 | [diff] [blame] | 410 | if (indirect_ipccall(tcp)) { |
| 411 | unsigned long raddr; |
| 412 | if (umove(tcp, tcp->u_arg[2], &raddr) < 0) |
| 413 | return RVAL_NONE; |
| 414 | tcp->u_rval = raddr; |
| 415 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 416 | return RVAL_HEX; |
| 417 | } |
| 418 | return 0; |
| 419 | } |
| 420 | |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 421 | int sys_shmdt(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 422 | { |
Roland McGrath | 54b90d7 | 2005-12-02 03:57:07 +0000 | [diff] [blame] | 423 | if (entering(tcp)) { |
| 424 | if (indirect_ipccall(tcp)) { |
| 425 | tprintf("%#lx", tcp->u_arg[3]); |
| 426 | } else { |
| 427 | tprintf("%#lx", tcp->u_arg[0]); |
| 428 | } |
| 429 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 430 | return 0; |
| 431 | } |
| 432 | |
Dmitry V. Levin | 9b5b67e | 2007-01-11 23:19:55 +0000 | [diff] [blame] | 433 | int |
| 434 | sys_mq_open(struct tcb *tcp) |
Roland McGrath | 4df13c1 | 2004-04-16 21:48:40 +0000 | [diff] [blame] | 435 | { |
| 436 | if (entering(tcp)) { |
| 437 | printpath(tcp, tcp->u_arg[0]); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 438 | tprints(", "); |
Roland McGrath | 4df13c1 | 2004-04-16 21:48:40 +0000 | [diff] [blame] | 439 | /* flags */ |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 440 | tprint_open_modes(tcp->u_arg[1]); |
Roland McGrath | 4df13c1 | 2004-04-16 21:48:40 +0000 | [diff] [blame] | 441 | if (tcp->u_arg[1] & O_CREAT) { |
| 442 | # ifndef HAVE_MQUEUE_H |
| 443 | tprintf(", %lx", tcp->u_arg[2]); |
| 444 | # else |
| 445 | struct mq_attr attr; |
| 446 | /* mode */ |
| 447 | tprintf(", %#lo, ", tcp->u_arg[2]); |
| 448 | if (umove(tcp, tcp->u_arg[3], &attr) < 0) |
Denys Vlasenko | 859ea8b | 2013-02-23 20:07:44 +0100 | [diff] [blame] | 449 | tprints("{???}"); |
Roland McGrath | 4df13c1 | 2004-04-16 21:48:40 +0000 | [diff] [blame] | 450 | else |
| 451 | tprintf("{mq_maxmsg=%ld, mq_msgsize=%ld}", |
H.J. Lu | 0b315b6 | 2012-02-03 10:16:03 -0800 | [diff] [blame] | 452 | (long) attr.mq_maxmsg, |
| 453 | (long) attr.mq_msgsize); |
Roland McGrath | 4df13c1 | 2004-04-16 21:48:40 +0000 | [diff] [blame] | 454 | # endif |
| 455 | } |
| 456 | } |
| 457 | return 0; |
| 458 | } |
| 459 | |
Dmitry V. Levin | 9b5b67e | 2007-01-11 23:19:55 +0000 | [diff] [blame] | 460 | int |
| 461 | sys_mq_timedsend(struct tcb *tcp) |
Roland McGrath | 4df13c1 | 2004-04-16 21:48:40 +0000 | [diff] [blame] | 462 | { |
| 463 | if (entering(tcp)) { |
| 464 | tprintf("%ld, ", tcp->u_arg[0]); |
| 465 | printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]); |
| 466 | tprintf(", %lu, %ld, ", tcp->u_arg[2], tcp->u_arg[3]); |
| 467 | printtv(tcp, tcp->u_arg[4]); |
| 468 | } |
| 469 | return 0; |
| 470 | } |
| 471 | |
Dmitry V. Levin | 9b5b67e | 2007-01-11 23:19:55 +0000 | [diff] [blame] | 472 | int |
| 473 | sys_mq_timedreceive(struct tcb *tcp) |
Roland McGrath | 4df13c1 | 2004-04-16 21:48:40 +0000 | [diff] [blame] | 474 | { |
| 475 | if (entering(tcp)) |
| 476 | tprintf("%ld, ", tcp->u_arg[0]); |
| 477 | else { |
| 478 | printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]); |
| 479 | tprintf(", %lu, %ld, ", tcp->u_arg[2], tcp->u_arg[3]); |
| 480 | printtv(tcp, tcp->u_arg[4]); |
| 481 | } |
| 482 | return 0; |
| 483 | } |
| 484 | |
Dmitry V. Levin | 9b5b67e | 2007-01-11 23:19:55 +0000 | [diff] [blame] | 485 | int |
| 486 | sys_mq_notify(struct tcb *tcp) |
Roland McGrath | 4df13c1 | 2004-04-16 21:48:40 +0000 | [diff] [blame] | 487 | { |
| 488 | if (entering(tcp)) { |
| 489 | tprintf("%ld, ", tcp->u_arg[0]); |
| 490 | printsigevent(tcp, tcp->u_arg[1]); |
| 491 | } |
| 492 | return 0; |
| 493 | } |
| 494 | |
Dmitry V. Levin | 9b5b67e | 2007-01-11 23:19:55 +0000 | [diff] [blame] | 495 | static void |
| 496 | printmqattr(struct tcb *tcp, long addr) |
Roland McGrath | 4df13c1 | 2004-04-16 21:48:40 +0000 | [diff] [blame] | 497 | { |
| 498 | if (addr == 0) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 499 | tprints("NULL"); |
Roland McGrath | 4df13c1 | 2004-04-16 21:48:40 +0000 | [diff] [blame] | 500 | else { |
| 501 | # ifndef HAVE_MQUEUE_H |
| 502 | tprintf("%#lx", addr); |
| 503 | # else |
| 504 | struct mq_attr attr; |
| 505 | if (umove(tcp, addr, &attr) < 0) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 506 | tprints("{...}"); |
Roland McGrath | 4df13c1 | 2004-04-16 21:48:40 +0000 | [diff] [blame] | 507 | return; |
| 508 | } |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 509 | tprints("{mq_flags="); |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 510 | tprint_open_modes(attr.mq_flags); |
Roland McGrath | 4df13c1 | 2004-04-16 21:48:40 +0000 | [diff] [blame] | 511 | tprintf(", mq_maxmsg=%ld, mq_msgsize=%ld, mq_curmsg=%ld}", |
H.J. Lu | 0b315b6 | 2012-02-03 10:16:03 -0800 | [diff] [blame] | 512 | (long) attr.mq_maxmsg, (long) attr.mq_msgsize, |
| 513 | (long) attr.mq_curmsgs); |
Roland McGrath | 4df13c1 | 2004-04-16 21:48:40 +0000 | [diff] [blame] | 514 | # endif |
| 515 | } |
| 516 | } |
| 517 | |
Dmitry V. Levin | 9b5b67e | 2007-01-11 23:19:55 +0000 | [diff] [blame] | 518 | int |
| 519 | sys_mq_getsetattr(struct tcb *tcp) |
Roland McGrath | 4df13c1 | 2004-04-16 21:48:40 +0000 | [diff] [blame] | 520 | { |
| 521 | if (entering(tcp)) { |
| 522 | tprintf("%ld, ", tcp->u_arg[0]); |
| 523 | printmqattr(tcp, tcp->u_arg[1]); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 524 | tprints(", "); |
Roland McGrath | 4df13c1 | 2004-04-16 21:48:40 +0000 | [diff] [blame] | 525 | } else |
| 526 | printmqattr(tcp, tcp->u_arg[2]); |
| 527 | return 0; |
| 528 | } |
Dmitry V. Levin | b5e88d4 | 2012-02-20 17:02:38 +0000 | [diff] [blame] | 529 | |
| 530 | int |
| 531 | sys_ipc(struct tcb *tcp) |
| 532 | { |
| 533 | return printargs(tcp); |
| 534 | } |