Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl> |
| 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" |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 32 | #include <fcntl.h> |
| 33 | #include <sys/file.h> |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 34 | #ifdef HAVE_SYS_EPOLL_H |
Denys Vlasenko | a6d91de | 2012-03-16 12:02:22 +0100 | [diff] [blame] | 35 | # include <sys/epoll.h> |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 36 | #endif |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 37 | #ifdef HAVE_LIBAIO_H |
Denys Vlasenko | a6d91de | 2012-03-16 12:02:22 +0100 | [diff] [blame] | 38 | # include <libaio.h> |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 39 | #endif |
Ben Noordhuis | 88eafd8 | 2013-02-04 00:04:57 +0100 | [diff] [blame] | 40 | #ifdef HAVE_LINUX_PERF_EVENT_H |
| 41 | # include <linux/perf_event.h> |
| 42 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 43 | |
John Hughes | 70623be | 2001-03-08 13:59:00 +0000 | [diff] [blame] | 44 | #if HAVE_LONG_LONG_OFF_T |
| 45 | /* |
| 46 | * Hacks for systems that have a long long off_t |
| 47 | */ |
Denys Vlasenko | a6d91de | 2012-03-16 12:02:22 +0100 | [diff] [blame] | 48 | # define flock64 flock /* Horrid hack */ |
| 49 | # define printflock printflock64 /* Horrider hack */ |
John Hughes | b8c9f77 | 2001-03-07 16:53:07 +0000 | [diff] [blame] | 50 | #endif |
| 51 | |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 52 | static const struct xlat fcntlcmds[] = { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 53 | { F_DUPFD, "F_DUPFD" }, |
| 54 | { F_GETFD, "F_GETFD" }, |
| 55 | { F_SETFD, "F_SETFD" }, |
| 56 | { F_GETFL, "F_GETFL" }, |
| 57 | { F_SETFL, "F_SETFL" }, |
| 58 | { F_GETLK, "F_GETLK" }, |
| 59 | { F_SETLK, "F_SETLK" }, |
| 60 | { F_SETLKW, "F_SETLKW" }, |
| 61 | { F_GETOWN, "F_GETOWN" }, |
| 62 | { F_SETOWN, "F_SETOWN" }, |
| 63 | #ifdef F_RSETLK |
| 64 | { F_RSETLK, "F_RSETLK" }, |
| 65 | #endif |
| 66 | #ifdef F_RSETLKW |
| 67 | { F_RSETLKW, "F_RSETLKW" }, |
| 68 | #endif |
| 69 | #ifdef F_RGETLK |
| 70 | { F_RGETLK, "F_RGETLK" }, |
| 71 | #endif |
| 72 | #ifdef F_CNVT |
| 73 | { F_CNVT, "F_CNVT" }, |
| 74 | #endif |
Wichert Akkerman | 5ae21ea | 2000-05-01 01:53:59 +0000 | [diff] [blame] | 75 | #ifdef F_SETSIG |
| 76 | { F_SETSIG, "F_SETSIG" }, |
| 77 | #endif |
| 78 | #ifdef F_GETSIG |
| 79 | { F_GETSIG, "F_GETSIG" }, |
| 80 | #endif |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 81 | #ifdef F_CHKFL |
| 82 | { F_CHKFL, "F_CHKFL" }, |
| 83 | #endif |
| 84 | #ifdef F_DUP2FD |
| 85 | { F_DUP2FD, "F_DUP2FD" }, |
| 86 | #endif |
| 87 | #ifdef F_ALLOCSP |
| 88 | { F_ALLOCSP, "F_ALLOCSP" }, |
| 89 | #endif |
| 90 | #ifdef F_ISSTREAM |
| 91 | { F_ISSTREAM, "F_ISSTREAM" }, |
| 92 | #endif |
| 93 | #ifdef F_PRIV |
| 94 | { F_PRIV, "F_PRIV" }, |
| 95 | #endif |
| 96 | #ifdef F_NPRIV |
| 97 | { F_NPRIV, "F_NPRIV" }, |
| 98 | #endif |
| 99 | #ifdef F_QUOTACL |
| 100 | { F_QUOTACL, "F_QUOTACL" }, |
| 101 | #endif |
| 102 | #ifdef F_BLOCKS |
| 103 | { F_BLOCKS, "F_BLOCKS" }, |
| 104 | #endif |
| 105 | #ifdef F_BLKSIZE |
| 106 | { F_BLKSIZE, "F_BLKSIZE" }, |
| 107 | #endif |
| 108 | #ifdef F_GETOWN |
| 109 | { F_GETOWN, "F_GETOWN" }, |
| 110 | #endif |
| 111 | #ifdef F_SETOWN |
| 112 | { F_SETOWN, "F_SETOWN" }, |
| 113 | #endif |
| 114 | #ifdef F_REVOKE |
| 115 | { F_REVOKE, "F_REVOKE" }, |
| 116 | #endif |
| 117 | #ifdef F_SETLK |
| 118 | { F_SETLK, "F_SETLK" }, |
| 119 | #endif |
| 120 | #ifdef F_SETLKW |
| 121 | { F_SETLKW, "F_SETLKW" }, |
| 122 | #endif |
| 123 | #ifdef F_FREESP |
| 124 | { F_FREESP, "F_FREESP" }, |
| 125 | #endif |
| 126 | #ifdef F_GETLK |
| 127 | { F_GETLK, "F_GETLK" }, |
| 128 | #endif |
| 129 | #ifdef F_SETLK64 |
| 130 | { F_SETLK64, "F_SETLK64" }, |
| 131 | #endif |
| 132 | #ifdef F_SETLKW64 |
| 133 | { F_SETLKW64, "F_SETLKW64" }, |
| 134 | #endif |
| 135 | #ifdef F_FREESP64 |
| 136 | { F_FREESP64, "F_FREESP64" }, |
| 137 | #endif |
| 138 | #ifdef F_GETLK64 |
| 139 | { F_GETLK64, "F_GETLK64" }, |
| 140 | #endif |
| 141 | #ifdef F_SHARE |
| 142 | { F_SHARE, "F_SHARE" }, |
| 143 | #endif |
| 144 | #ifdef F_UNSHARE |
| 145 | { F_UNSHARE, "F_UNSHARE" }, |
| 146 | #endif |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 147 | #ifdef F_SETLEASE |
| 148 | { F_SETLEASE, "F_SETLEASE" }, |
| 149 | #endif |
| 150 | #ifdef F_GETLEASE |
| 151 | { F_GETLEASE, "F_GETLEASE" }, |
| 152 | #endif |
| 153 | #ifdef F_NOTIFY |
| 154 | { F_NOTIFY, "F_NOTIFY" }, |
| 155 | #endif |
| 156 | #ifdef F_DUPFD_CLOEXEC |
| 157 | { F_DUPFD_CLOEXEC,"F_DUPFD_CLOEXEC"}, |
| 158 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 159 | { 0, NULL }, |
| 160 | }; |
| 161 | |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 162 | static const struct xlat fdflags[] = { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 163 | #ifdef FD_CLOEXEC |
| 164 | { FD_CLOEXEC, "FD_CLOEXEC" }, |
| 165 | #endif |
| 166 | { 0, NULL }, |
| 167 | }; |
| 168 | |
| 169 | #ifdef LOCK_SH |
| 170 | |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 171 | static const struct xlat flockcmds[] = { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 172 | { LOCK_SH, "LOCK_SH" }, |
| 173 | { LOCK_EX, "LOCK_EX" }, |
| 174 | { LOCK_NB, "LOCK_NB" }, |
| 175 | { LOCK_UN, "LOCK_UN" }, |
| 176 | { 0, NULL }, |
| 177 | }; |
| 178 | |
| 179 | #endif /* LOCK_SH */ |
| 180 | |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 181 | static const struct xlat lockfcmds[] = { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 182 | { F_RDLCK, "F_RDLCK" }, |
| 183 | { F_WRLCK, "F_WRLCK" }, |
| 184 | { F_UNLCK, "F_UNLCK" }, |
| 185 | #ifdef F_EXLCK |
| 186 | { F_EXLCK, "F_EXLCK" }, |
| 187 | #endif |
| 188 | #ifdef F_SHLCK |
| 189 | { F_SHLCK, "F_SHLCK" }, |
| 190 | #endif |
| 191 | { 0, NULL }, |
| 192 | }; |
| 193 | |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 194 | #ifdef F_NOTIFY |
| 195 | static const struct xlat notifyflags[] = { |
| 196 | #ifdef DN_ACCESS |
| 197 | { DN_ACCESS, "DN_ACCESS" }, |
| 198 | #endif |
| 199 | #ifdef DN_MODIFY |
| 200 | { DN_MODIFY, "DN_MODIFY" }, |
| 201 | #endif |
| 202 | #ifdef DN_CREATE |
| 203 | { DN_CREATE, "DN_CREATE" }, |
| 204 | #endif |
| 205 | #ifdef DN_DELETE |
| 206 | { DN_DELETE, "DN_DELETE" }, |
| 207 | #endif |
| 208 | #ifdef DN_RENAME |
| 209 | { DN_RENAME, "DN_RENAME" }, |
| 210 | #endif |
| 211 | #ifdef DN_ATTRIB |
| 212 | { DN_ATTRIB, "DN_ATTRIB" }, |
| 213 | #endif |
| 214 | #ifdef DN_MULTISHOT |
| 215 | { DN_MULTISHOT, "DN_MULTISHOT" }, |
| 216 | #endif |
| 217 | { 0, NULL }, |
| 218 | }; |
| 219 | #endif |
| 220 | |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 221 | static const struct xlat whence[] = { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 222 | { SEEK_SET, "SEEK_SET" }, |
| 223 | { SEEK_CUR, "SEEK_CUR" }, |
| 224 | { SEEK_END, "SEEK_END" }, |
| 225 | { 0, NULL }, |
| 226 | }; |
| 227 | |
Ben Noordhuis | 88eafd8 | 2013-02-04 00:04:57 +0100 | [diff] [blame] | 228 | static const struct xlat perf_event_open_flags[] = { |
| 229 | #ifdef PERF_FLAG_FD_NO_GROUP |
| 230 | { PERF_FLAG_FD_NO_GROUP, "PERF_FLAG_FD_NO_GROUP" }, |
| 231 | #endif |
| 232 | #ifdef PERF_FLAG_FD_OUTPUT |
| 233 | { PERF_FLAG_FD_OUTPUT, "PERF_FLAG_FD_OUTPUT" }, |
| 234 | #endif |
| 235 | #ifdef PERF_FLAG_PID_CGROUP |
| 236 | { PERF_FLAG_PID_CGROUP, "PERF_FLAG_PID_CGROUP" }, |
| 237 | #endif |
| 238 | { 0, NULL }, |
| 239 | }; |
| 240 | |
John Hughes | 70623be | 2001-03-08 13:59:00 +0000 | [diff] [blame] | 241 | #ifndef HAVE_LONG_LONG_OFF_T |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 242 | /* fcntl/lockf */ |
| 243 | static void |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 244 | printflock(struct tcb *tcp, long addr, int getlk) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 245 | { |
| 246 | struct flock fl; |
| 247 | |
Denys Vlasenko | 7a862d7 | 2009-04-15 13:22:59 +0000 | [diff] [blame] | 248 | #if SUPPORTED_PERSONALITIES > 1 |
Denys Vlasenko | 9fd4f96 | 2012-03-19 09:36:42 +0100 | [diff] [blame] | 249 | if (current_wordsize != sizeof(fl.l_start)) { |
| 250 | if (current_wordsize == 4) { |
Denys Vlasenko | 7a862d7 | 2009-04-15 13:22:59 +0000 | [diff] [blame] | 251 | /* 32-bit x86 app on x86_64 and similar cases */ |
| 252 | struct { |
| 253 | short int l_type; |
| 254 | short int l_whence; |
| 255 | int32_t l_start; /* off_t */ |
| 256 | int32_t l_len; /* off_t */ |
| 257 | int32_t l_pid; /* pid_t */ |
| 258 | } fl32; |
| 259 | if (umove(tcp, addr, &fl32) < 0) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 260 | tprints("{...}"); |
Denys Vlasenko | 7a862d7 | 2009-04-15 13:22:59 +0000 | [diff] [blame] | 261 | return; |
| 262 | } |
| 263 | fl.l_type = fl32.l_type; |
| 264 | fl.l_whence = fl32.l_whence; |
| 265 | fl.l_start = fl32.l_start; |
| 266 | fl.l_len = fl32.l_len; |
| 267 | fl.l_pid = fl32.l_pid; |
| 268 | } else { |
| 269 | /* let people know we have a problem here */ |
Denys Vlasenko | 751acb3 | 2013-02-08 15:34:46 +0100 | [diff] [blame] | 270 | tprintf("<decode error: unsupported wordsize %d>", |
Denys Vlasenko | 9fd4f96 | 2012-03-19 09:36:42 +0100 | [diff] [blame] | 271 | current_wordsize); |
Denys Vlasenko | 7a862d7 | 2009-04-15 13:22:59 +0000 | [diff] [blame] | 272 | return; |
| 273 | } |
| 274 | } else |
| 275 | #endif |
| 276 | { |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 277 | if (umove(tcp, addr, &fl) < 0) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 278 | tprints("{...}"); |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 279 | return; |
| 280 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 281 | } |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 282 | tprints("{type="); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 283 | printxval(lockfcmds, fl.l_type, "F_???"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 284 | tprints(", whence="); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 285 | printxval(whence, fl.l_whence, "SEEK_???"); |
| 286 | tprintf(", start=%ld, len=%ld", fl.l_start, fl.l_len); |
| 287 | if (getlk) |
| 288 | tprintf(", pid=%lu}", (unsigned long) fl.l_pid); |
| 289 | else |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 290 | tprints("}"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 291 | } |
John Hughes | b8c9f77 | 2001-03-07 16:53:07 +0000 | [diff] [blame] | 292 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 293 | |
John Hughes | 70623be | 2001-03-08 13:59:00 +0000 | [diff] [blame] | 294 | #if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 295 | /* fcntl/lockf */ |
| 296 | static void |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 297 | printflock64(struct tcb *tcp, long addr, int getlk) |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 298 | { |
| 299 | struct flock64 fl; |
| 300 | |
| 301 | if (umove(tcp, addr, &fl) < 0) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 302 | tprints("{...}"); |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 303 | return; |
| 304 | } |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 305 | tprints("{type="); |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 306 | printxval(lockfcmds, fl.l_type, "F_???"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 307 | tprints(", whence="); |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 308 | printxval(whence, fl.l_whence, "SEEK_???"); |
Wichert Akkerman | 7b3346b | 2001-10-09 23:47:38 +0000 | [diff] [blame] | 309 | tprintf(", start=%lld, len=%lld", (long long) fl.l_start, (long long) fl.l_len); |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 310 | if (getlk) |
| 311 | tprintf(", pid=%lu}", (unsigned long) fl.l_pid); |
| 312 | else |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 313 | tprints("}"); |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 314 | } |
| 315 | #endif |
| 316 | |
Dmitry V. Levin | 9b5b67e | 2007-01-11 23:19:55 +0000 | [diff] [blame] | 317 | int |
| 318 | sys_fcntl(struct tcb *tcp) |
| 319 | { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 320 | if (entering(tcp)) { |
Dmitry V. Levin | 3138213 | 2011-03-04 05:08:02 +0300 | [diff] [blame] | 321 | printfd(tcp, tcp->u_arg[0]); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 322 | tprints(", "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 323 | printxval(fcntlcmds, tcp->u_arg[1], "F_???"); |
| 324 | switch (tcp->u_arg[1]) { |
| 325 | case F_SETFD: |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 326 | tprints(", "); |
Roland McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 327 | printflags(fdflags, tcp->u_arg[2], "FD_???"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 328 | break; |
| 329 | case F_SETOWN: case F_DUPFD: |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 330 | #ifdef F_DUPFD_CLOEXEC |
| 331 | case F_DUPFD_CLOEXEC: |
| 332 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 333 | tprintf(", %ld", tcp->u_arg[2]); |
| 334 | break; |
| 335 | case F_SETFL: |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 336 | tprints(", "); |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 337 | tprint_open_modes(tcp->u_arg[2]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 338 | break; |
| 339 | case F_SETLK: case F_SETLKW: |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 340 | #ifdef F_FREESP |
| 341 | case F_FREESP: |
| 342 | #endif |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 343 | tprints(", "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 344 | printflock(tcp, tcp->u_arg[2], 0); |
| 345 | break; |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 346 | #if _LFS64_LARGEFILE |
| 347 | #ifdef F_FREESP64 |
| 348 | case F_FREESP64: |
| 349 | #endif |
Roland McGrath | e948faf | 2002-12-15 23:58:18 +0000 | [diff] [blame] | 350 | /* Linux glibc defines SETLK64 as SETLK, |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 351 | even though the kernel has different values - as does Solaris. */ |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 352 | #if defined(F_SETLK64) && F_SETLK64 + 0 != F_SETLK |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 353 | case F_SETLK64: |
| 354 | #endif |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 355 | #if defined(F_SETLKW64) && F_SETLKW64 + 0 != F_SETLKW |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 356 | case F_SETLKW64: |
| 357 | #endif |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 358 | tprints(", "); |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 359 | printflock64(tcp, tcp->u_arg[2], 0); |
| 360 | break; |
| 361 | #endif |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 362 | #ifdef F_NOTIFY |
| 363 | case F_NOTIFY: |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 364 | tprints(", "); |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 365 | printflags(notifyflags, tcp->u_arg[2], "DN_???"); |
| 366 | break; |
| 367 | #endif |
| 368 | #ifdef F_SETLEASE |
| 369 | case F_SETLEASE: |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 370 | tprints(", "); |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 371 | printxval(lockfcmds, tcp->u_arg[2], "F_???"); |
| 372 | break; |
| 373 | #endif |
Denys Vlasenko | 5ae2b7c | 2009-02-27 20:32:52 +0000 | [diff] [blame] | 374 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 375 | } |
| 376 | else { |
| 377 | switch (tcp->u_arg[1]) { |
| 378 | case F_DUPFD: |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 379 | #ifdef F_DUPFD_CLOEXEC |
| 380 | case F_DUPFD_CLOEXEC: |
| 381 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 382 | case F_SETFD: case F_SETFL: |
| 383 | case F_SETLK: case F_SETLKW: |
| 384 | case F_SETOWN: case F_GETOWN: |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 385 | #ifdef F_NOTIFY |
| 386 | case F_NOTIFY: |
| 387 | #endif |
| 388 | #ifdef F_SETLEASE |
| 389 | case F_SETLEASE: |
| 390 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 391 | break; |
| 392 | case F_GETFD: |
Dmitry V. Levin | 21a7534 | 2008-09-03 01:22:18 +0000 | [diff] [blame] | 393 | if (syserror(tcp) || tcp->u_rval == 0) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 394 | return 0; |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 395 | tcp->auxstr = sprintflags("flags ", fdflags, tcp->u_rval); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 396 | return RVAL_HEX|RVAL_STR; |
| 397 | case F_GETFL: |
Dmitry V. Levin | 21a7534 | 2008-09-03 01:22:18 +0000 | [diff] [blame] | 398 | if (syserror(tcp)) |
| 399 | return 0; |
Dmitry V. Levin | 9b5b67e | 2007-01-11 23:19:55 +0000 | [diff] [blame] | 400 | tcp->auxstr = sprint_open_modes(tcp->u_rval); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 401 | return RVAL_HEX|RVAL_STR; |
| 402 | case F_GETLK: |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 403 | tprints(", "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 404 | printflock(tcp, tcp->u_arg[2], 1); |
| 405 | break; |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 406 | #if _LFS64_LARGEFILE |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 407 | #if defined(F_GETLK64) && F_GETLK64+0 != F_GETLK |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 408 | case F_GETLK64: |
| 409 | #endif |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 410 | tprints(", "); |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 411 | printflock64(tcp, tcp->u_arg[2], 1); |
| 412 | break; |
| 413 | #endif |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 414 | #ifdef F_GETLEASE |
| 415 | case F_GETLEASE: |
| 416 | if (syserror(tcp)) |
| 417 | return 0; |
| 418 | tcp->auxstr = xlookup(lockfcmds, tcp->u_rval); |
| 419 | return RVAL_HEX|RVAL_STR; |
| 420 | #endif |
Denys Vlasenko | 5ae2b7c | 2009-02-27 20:32:52 +0000 | [diff] [blame] | 421 | default: |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 422 | tprintf(", %#lx", tcp->u_arg[2]); |
| 423 | break; |
| 424 | } |
| 425 | } |
| 426 | return 0; |
| 427 | } |
| 428 | |
| 429 | #ifdef LOCK_SH |
| 430 | |
| 431 | int |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 432 | sys_flock(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 433 | { |
| 434 | if (entering(tcp)) { |
Dmitry V. Levin | 3138213 | 2011-03-04 05:08:02 +0300 | [diff] [blame] | 435 | printfd(tcp, tcp->u_arg[0]); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 436 | tprints(", "); |
Roland McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 437 | printflags(flockcmds, tcp->u_arg[1], "LOCK_???"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 438 | } |
| 439 | return 0; |
| 440 | } |
| 441 | #endif /* LOCK_SH */ |
| 442 | |
| 443 | int |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 444 | sys_close(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 445 | { |
| 446 | if (entering(tcp)) { |
Dmitry V. Levin | 3138213 | 2011-03-04 05:08:02 +0300 | [diff] [blame] | 447 | printfd(tcp, tcp->u_arg[0]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 448 | } |
| 449 | return 0; |
| 450 | } |
| 451 | |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 452 | static int |
| 453 | do_dup2(struct tcb *tcp, int flags_arg) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 454 | { |
| 455 | if (entering(tcp)) { |
Dmitry V. Levin | 3138213 | 2011-03-04 05:08:02 +0300 | [diff] [blame] | 456 | printfd(tcp, tcp->u_arg[0]); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 457 | tprints(", "); |
Dmitry V. Levin | 3138213 | 2011-03-04 05:08:02 +0300 | [diff] [blame] | 458 | printfd(tcp, tcp->u_arg[1]); |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 459 | if (flags_arg >= 0) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 460 | tprints(", "); |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 461 | printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???"); |
| 462 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 463 | } |
| 464 | return 0; |
| 465 | } |
| 466 | |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 467 | int |
| 468 | sys_dup2(struct tcb *tcp) |
| 469 | { |
| 470 | return do_dup2(tcp, -1); |
| 471 | } |
| 472 | |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 473 | int |
| 474 | sys_dup3(struct tcb *tcp) |
| 475 | { |
| 476 | return do_dup2(tcp, 2); |
| 477 | } |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 478 | |
Denys Vlasenko | 8470374 | 2012-02-25 02:38:52 +0100 | [diff] [blame] | 479 | #if defined(ALPHA) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 480 | int |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 481 | sys_getdtablesize(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 482 | { |
| 483 | return 0; |
| 484 | } |
Denys Vlasenko | 8470374 | 2012-02-25 02:38:52 +0100 | [diff] [blame] | 485 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 486 | |
| 487 | static int |
Dmitry V. Levin | a7945a3 | 2006-12-13 17:10:11 +0000 | [diff] [blame] | 488 | decode_select(struct tcb *tcp, long *args, enum bitness_t bitness) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 489 | { |
Denys Vlasenko | ad5155a | 2011-09-01 18:18:04 +0200 | [diff] [blame] | 490 | int i, j; |
Denys Vlasenko | 79a79ea | 2011-09-01 16:35:44 +0200 | [diff] [blame] | 491 | unsigned nfds, fdsize; |
Roland McGrath | e85aaa4 | 2005-02-06 01:55:12 +0000 | [diff] [blame] | 492 | fd_set *fds; |
Dmitry V. Levin | 30145dd | 2010-09-06 22:08:24 +0000 | [diff] [blame] | 493 | const char *sep; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 494 | long arg; |
| 495 | |
Denys Vlasenko | 79a79ea | 2011-09-01 16:35:44 +0200 | [diff] [blame] | 496 | fdsize = args[0]; |
| 497 | /* Beware of select(2^31-1, NULL, NULL, NULL) and similar... */ |
| 498 | if (args[0] > 1024*1024) |
| 499 | fdsize = 1024*1024; |
| 500 | if (args[0] < 0) |
| 501 | fdsize = 0; |
| 502 | fdsize = (((fdsize + 7) / 8) + sizeof(long)-1) & -sizeof(long); |
| 503 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 504 | if (entering(tcp)) { |
Denys Vlasenko | 1d46ba5 | 2011-08-31 14:00:02 +0200 | [diff] [blame] | 505 | fds = malloc(fdsize); |
| 506 | if (!fds) |
| 507 | die_out_of_memory(); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 508 | nfds = args[0]; |
| 509 | tprintf("%d", nfds); |
| 510 | for (i = 0; i < 3; i++) { |
| 511 | arg = args[i+1]; |
| 512 | if (arg == 0) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 513 | tprints(", NULL"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 514 | continue; |
| 515 | } |
Denys Vlasenko | 1d46ba5 | 2011-08-31 14:00:02 +0200 | [diff] [blame] | 516 | if (!verbose(tcp)) { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 517 | tprintf(", %#lx", arg); |
| 518 | continue; |
| 519 | } |
Roland McGrath | e85aaa4 | 2005-02-06 01:55:12 +0000 | [diff] [blame] | 520 | if (umoven(tcp, arg, fdsize, (char *) fds) < 0) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 521 | tprints(", [?]"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 522 | continue; |
| 523 | } |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 524 | tprints(", ["); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 525 | for (j = 0, sep = ""; j < nfds; j++) { |
Roland McGrath | e85aaa4 | 2005-02-06 01:55:12 +0000 | [diff] [blame] | 526 | if (FD_ISSET(j, fds)) { |
Denys Vlasenko | 5940e65 | 2011-09-01 09:55:05 +0200 | [diff] [blame] | 527 | tprints(sep); |
Dmitry V. Levin | 3138213 | 2011-03-04 05:08:02 +0300 | [diff] [blame] | 528 | printfd(tcp, j); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 529 | sep = " "; |
| 530 | } |
| 531 | } |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 532 | tprints("]"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 533 | } |
Roland McGrath | e85aaa4 | 2005-02-06 01:55:12 +0000 | [diff] [blame] | 534 | free(fds); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 535 | tprints(", "); |
Roland McGrath | 6afc565 | 2007-07-24 01:57:11 +0000 | [diff] [blame] | 536 | printtv_bitness(tcp, args[4], bitness, 0); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 537 | } |
Denys Vlasenko | 7b609d5 | 2011-06-22 14:32:43 +0200 | [diff] [blame] | 538 | else { |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 539 | static char outstr[1024]; |
| 540 | char *outptr; |
| 541 | #define end_outstr (outstr + sizeof(outstr)) |
| 542 | const char *sep; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 543 | |
| 544 | if (syserror(tcp)) |
| 545 | return 0; |
| 546 | |
Denys Vlasenko | 5d64581 | 2011-08-20 12:48:18 +0200 | [diff] [blame] | 547 | nfds = tcp->u_rval; |
| 548 | if (nfds == 0) { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 549 | tcp->auxstr = "Timeout"; |
| 550 | return RVAL_STR; |
| 551 | } |
Roland McGrath | e85aaa4 | 2005-02-06 01:55:12 +0000 | [diff] [blame] | 552 | |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 553 | fds = malloc(fdsize); |
Denys Vlasenko | 1d46ba5 | 2011-08-31 14:00:02 +0200 | [diff] [blame] | 554 | if (!fds) |
| 555 | die_out_of_memory(); |
Roland McGrath | e85aaa4 | 2005-02-06 01:55:12 +0000 | [diff] [blame] | 556 | |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 557 | outptr = outstr; |
| 558 | sep = ""; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 559 | for (i = 0; i < 3; i++) { |
| 560 | int first = 1; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 561 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 562 | arg = args[i+1]; |
Denys Vlasenko | 1d46ba5 | 2011-08-31 14:00:02 +0200 | [diff] [blame] | 563 | if (!arg || umoven(tcp, arg, fdsize, (char *) fds) < 0) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 564 | continue; |
| 565 | for (j = 0; j < args[0]; j++) { |
Roland McGrath | e85aaa4 | 2005-02-06 01:55:12 +0000 | [diff] [blame] | 566 | if (FD_ISSET(j, fds)) { |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 567 | /* +2 chars needed at the end: ']',NUL */ |
| 568 | if (outptr < end_outstr - (sizeof(", except [") + sizeof(int)*3 + 2)) { |
| 569 | if (first) { |
| 570 | outptr += sprintf(outptr, "%s%s [%u", |
| 571 | sep, |
| 572 | i == 0 ? "in" : i == 1 ? "out" : "except", |
| 573 | j |
| 574 | ); |
| 575 | first = 0; |
| 576 | sep = ", "; |
| 577 | } |
| 578 | else { |
| 579 | outptr += sprintf(outptr, " %u", j); |
| 580 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 581 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 582 | nfds--; |
| 583 | } |
| 584 | } |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 585 | if (outptr != outstr) |
| 586 | *outptr++ = ']'; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 587 | if (nfds == 0) |
| 588 | break; |
| 589 | } |
Roland McGrath | e85aaa4 | 2005-02-06 01:55:12 +0000 | [diff] [blame] | 590 | free(fds); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 591 | /* This contains no useful information on SunOS. */ |
| 592 | if (args[4]) { |
Denys Vlasenko | a1d541e | 2012-01-20 11:04:04 +0100 | [diff] [blame] | 593 | if (outptr < end_outstr - (10 + TIMEVAL_TEXT_BUFSIZE)) { |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 594 | outptr += sprintf(outptr, "%sleft ", sep); |
Denys Vlasenko | a1d541e | 2012-01-20 11:04:04 +0100 | [diff] [blame] | 595 | outptr = sprinttv(outptr, tcp, args[4], bitness, /*special:*/ 0); |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 596 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 597 | } |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 598 | *outptr = '\0'; |
Denys Vlasenko | 1161725 | 2011-09-01 11:27:37 +0200 | [diff] [blame] | 599 | tcp->auxstr = outstr; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 600 | return RVAL_STR; |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 601 | #undef end_outstr |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 602 | } |
| 603 | return 0; |
| 604 | } |
| 605 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 606 | int |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 607 | sys_oldselect(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 608 | { |
| 609 | long args[5]; |
| 610 | |
| 611 | if (umoven(tcp, tcp->u_arg[0], sizeof args, (char *) args) < 0) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 612 | tprints("[...]"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 613 | return 0; |
| 614 | } |
Dmitry V. Levin | a7945a3 | 2006-12-13 17:10:11 +0000 | [diff] [blame] | 615 | return decode_select(tcp, args, BITNESS_CURRENT); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 616 | } |
| 617 | |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 618 | #ifdef ALPHA |
Roland McGrath | e948faf | 2002-12-15 23:58:18 +0000 | [diff] [blame] | 619 | int |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 620 | sys_osf_select(struct tcb *tcp) |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 621 | { |
| 622 | long *args = tcp->u_arg; |
Dmitry V. Levin | a7945a3 | 2006-12-13 17:10:11 +0000 | [diff] [blame] | 623 | return decode_select(tcp, args, BITNESS_32); |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 624 | } |
| 625 | #endif |
| 626 | |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 627 | static const struct xlat epollctls[] = { |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 628 | #ifdef EPOLL_CTL_ADD |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 629 | { EPOLL_CTL_ADD, "EPOLL_CTL_ADD" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 630 | #endif |
| 631 | #ifdef EPOLL_CTL_MOD |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 632 | { EPOLL_CTL_MOD, "EPOLL_CTL_MOD" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 633 | #endif |
| 634 | #ifdef EPOLL_CTL_DEL |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 635 | { EPOLL_CTL_DEL, "EPOLL_CTL_DEL" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 636 | #endif |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 637 | { 0, NULL } |
| 638 | }; |
| 639 | |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 640 | static const struct xlat epollevents[] = { |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 641 | #ifdef EPOLLIN |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 642 | { EPOLLIN, "EPOLLIN" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 643 | #endif |
| 644 | #ifdef EPOLLPRI |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 645 | { EPOLLPRI, "EPOLLPRI" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 646 | #endif |
| 647 | #ifdef EPOLLOUT |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 648 | { EPOLLOUT, "EPOLLOUT" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 649 | #endif |
| 650 | #ifdef EPOLLRDNORM |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 651 | { EPOLLRDNORM, "EPOLLRDNORM" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 652 | #endif |
| 653 | #ifdef EPOLLRDBAND |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 654 | { EPOLLRDBAND, "EPOLLRDBAND" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 655 | #endif |
| 656 | #ifdef EPOLLWRNORM |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 657 | { EPOLLWRNORM, "EPOLLWRNORM" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 658 | #endif |
| 659 | #ifdef EPOLLWRBAND |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 660 | { EPOLLWRBAND, "EPOLLWRBAND" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 661 | #endif |
| 662 | #ifdef EPOLLMSG |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 663 | { EPOLLMSG, "EPOLLMSG" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 664 | #endif |
| 665 | #ifdef EPOLLERR |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 666 | { EPOLLERR, "EPOLLERR" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 667 | #endif |
| 668 | #ifdef EPOLLHUP |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 669 | { EPOLLHUP, "EPOLLHUP" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 670 | #endif |
Dmitry V. Levin | 5967c1a | 2011-10-11 15:55:40 +0000 | [diff] [blame] | 671 | #ifdef EPOLLRDHUP |
| 672 | { EPOLLRDHUP, "EPOLLRDHUP" }, |
| 673 | #endif |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 674 | #ifdef EPOLLONESHOT |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 675 | { EPOLLONESHOT, "EPOLLONESHOT" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 676 | #endif |
| 677 | #ifdef EPOLLET |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 678 | { EPOLLET, "EPOLLET" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 679 | #endif |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 680 | { 0, NULL } |
| 681 | }; |
| 682 | |
Denys Vlasenko | 72879c6 | 2012-02-27 14:18:02 +0100 | [diff] [blame] | 683 | /* Not aliased to printargs_ld: we want it to have a distinct address */ |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 684 | int |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 685 | sys_epoll_create(struct tcb *tcp) |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 686 | { |
Denys Vlasenko | 72879c6 | 2012-02-27 14:18:02 +0100 | [diff] [blame] | 687 | return printargs_ld(tcp); |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 688 | } |
| 689 | |
Mike Frysinger | aed334c | 2011-10-13 22:33:45 -0400 | [diff] [blame] | 690 | static const struct xlat epollflags[] = { |
| 691 | #ifdef EPOLL_CLOEXEC |
| 692 | { EPOLL_CLOEXEC, "EPOLL_CLOEXEC" }, |
| 693 | #endif |
| 694 | #ifdef EPOLL_NONBLOCK |
| 695 | { EPOLL_NONBLOCK, "EPOLL_NONBLOCK" }, |
| 696 | #endif |
| 697 | { 0, NULL } |
| 698 | }; |
| 699 | |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 700 | int |
| 701 | sys_epoll_create1(struct tcb *tcp) |
| 702 | { |
| 703 | if (entering(tcp)) |
Mike Frysinger | aed334c | 2011-10-13 22:33:45 -0400 | [diff] [blame] | 704 | printflags(epollflags, tcp->u_arg[0], "EPOLL_???"); |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 705 | return 0; |
| 706 | } |
| 707 | |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 708 | #ifdef HAVE_SYS_EPOLL_H |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 709 | static void |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 710 | print_epoll_event(struct epoll_event *ev) |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 711 | { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 712 | tprints("{"); |
Roland McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 713 | printflags(epollevents, ev->events, "EPOLL???"); |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 714 | /* We cannot know what format the program uses, so print u32 and u64 |
| 715 | which will cover every value. */ |
| 716 | tprintf(", {u32=%" PRIu32 ", u64=%" PRIu64 "}}", |
| 717 | ev->data.u32, ev->data.u64); |
| 718 | } |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 719 | #endif |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 720 | |
| 721 | int |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 722 | sys_epoll_ctl(struct tcb *tcp) |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 723 | { |
| 724 | if (entering(tcp)) { |
Dmitry V. Levin | 3138213 | 2011-03-04 05:08:02 +0300 | [diff] [blame] | 725 | printfd(tcp, tcp->u_arg[0]); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 726 | tprints(", "); |
Denys Vlasenko | adedb51 | 2008-12-30 18:47:55 +0000 | [diff] [blame] | 727 | printxval(epollctls, tcp->u_arg[1], "EPOLL_CTL_???"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 728 | tprints(", "); |
Dmitry V. Levin | 3138213 | 2011-03-04 05:08:02 +0300 | [diff] [blame] | 729 | printfd(tcp, tcp->u_arg[2]); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 730 | tprints(", "); |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 731 | if (tcp->u_arg[3] == 0) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 732 | tprints("NULL"); |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 733 | else { |
| 734 | #ifdef HAVE_SYS_EPOLL_H |
| 735 | struct epoll_event ev; |
Roland McGrath | 6e52d23 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 736 | if (umove(tcp, tcp->u_arg[3], &ev) == 0) |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 737 | print_epoll_event(&ev); |
| 738 | else |
| 739 | #endif |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 740 | tprints("{...}"); |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 741 | } |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 742 | } |
| 743 | return 0; |
| 744 | } |
| 745 | |
Roland McGrath | f240005 | 2007-08-02 01:13:26 +0000 | [diff] [blame] | 746 | static void |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 747 | epoll_wait_common(struct tcb *tcp) |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 748 | { |
Dmitry V. Levin | 3138213 | 2011-03-04 05:08:02 +0300 | [diff] [blame] | 749 | if (entering(tcp)) { |
| 750 | printfd(tcp, tcp->u_arg[0]); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 751 | tprints(", "); |
Dmitry V. Levin | 3138213 | 2011-03-04 05:08:02 +0300 | [diff] [blame] | 752 | } else { |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 753 | if (syserror(tcp)) |
| 754 | tprintf("%lx", tcp->u_arg[1]); |
| 755 | else if (tcp->u_rval == 0) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 756 | tprints("{}"); |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 757 | else { |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 758 | #ifdef HAVE_SYS_EPOLL_H |
Roland McGrath | aa524c8 | 2005-06-01 19:22:06 +0000 | [diff] [blame] | 759 | struct epoll_event ev, *start, *cur, *end; |
| 760 | int failed = 0; |
| 761 | |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 762 | tprints("{"); |
Roland McGrath | aa524c8 | 2005-06-01 19:22:06 +0000 | [diff] [blame] | 763 | start = (struct epoll_event *) tcp->u_arg[1]; |
| 764 | end = start + tcp->u_rval; |
| 765 | for (cur = start; cur < end; ++cur) { |
| 766 | if (cur > start) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 767 | tprints(", "); |
Roland McGrath | aa524c8 | 2005-06-01 19:22:06 +0000 | [diff] [blame] | 768 | if (umove(tcp, (long) cur, &ev) == 0) |
| 769 | print_epoll_event(&ev); |
| 770 | else { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 771 | tprints("?"); |
Roland McGrath | aa524c8 | 2005-06-01 19:22:06 +0000 | [diff] [blame] | 772 | failed = 1; |
| 773 | break; |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 774 | } |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 775 | } |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 776 | tprints("}"); |
Roland McGrath | aa524c8 | 2005-06-01 19:22:06 +0000 | [diff] [blame] | 777 | if (failed) |
| 778 | tprintf(" %#lx", (long) start); |
| 779 | #else |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 780 | tprints("{...}"); |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 781 | #endif |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 782 | } |
Dmitry V. Levin | c327d71 | 2011-10-11 16:05:57 +0000 | [diff] [blame] | 783 | tprintf(", %d, %d", (int) tcp->u_arg[2], (int) tcp->u_arg[3]); |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 784 | } |
Roland McGrath | f240005 | 2007-08-02 01:13:26 +0000 | [diff] [blame] | 785 | } |
| 786 | |
| 787 | int |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 788 | sys_epoll_wait(struct tcb *tcp) |
Roland McGrath | f240005 | 2007-08-02 01:13:26 +0000 | [diff] [blame] | 789 | { |
| 790 | epoll_wait_common(tcp); |
| 791 | return 0; |
| 792 | } |
| 793 | |
| 794 | int |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 795 | sys_epoll_pwait(struct tcb *tcp) |
Roland McGrath | f240005 | 2007-08-02 01:13:26 +0000 | [diff] [blame] | 796 | { |
| 797 | epoll_wait_common(tcp); |
Dmitry V. Levin | 9676499 | 2010-04-06 23:54:18 +0000 | [diff] [blame] | 798 | if (exiting(tcp)) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 799 | tprints(", "); |
Roland McGrath | f240005 | 2007-08-02 01:13:26 +0000 | [diff] [blame] | 800 | print_sigset(tcp, tcp->u_arg[4], 0); |
Dmitry V. Levin | 9676499 | 2010-04-06 23:54:18 +0000 | [diff] [blame] | 801 | } |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 802 | return 0; |
| 803 | } |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 804 | |
| 805 | int |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 806 | sys_io_setup(struct tcb *tcp) |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 807 | { |
| 808 | if (entering(tcp)) |
| 809 | tprintf("%ld, ", tcp->u_arg[0]); |
| 810 | else { |
| 811 | if (syserror(tcp)) |
| 812 | tprintf("0x%0lx", tcp->u_arg[1]); |
| 813 | else { |
| 814 | unsigned long user_id; |
| 815 | if (umove(tcp, tcp->u_arg[1], &user_id) == 0) |
| 816 | tprintf("{%lu}", user_id); |
| 817 | else |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 818 | tprints("{...}"); |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 819 | } |
| 820 | } |
| 821 | return 0; |
| 822 | } |
| 823 | |
| 824 | int |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 825 | sys_io_destroy(struct tcb *tcp) |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 826 | { |
| 827 | if (entering(tcp)) |
| 828 | tprintf("%lu", tcp->u_arg[0]); |
| 829 | return 0; |
| 830 | } |
| 831 | |
Dmitry V. Levin | 081e72f | 2011-06-21 15:11:57 +0000 | [diff] [blame] | 832 | #ifdef HAVE_LIBAIO_H |
| 833 | |
Andi Kleen | dfcd741 | 2011-06-13 22:05:44 +0000 | [diff] [blame] | 834 | enum iocb_sub { |
| 835 | SUB_NONE, SUB_COMMON, SUB_POLL, SUB_VECTOR |
| 836 | }; |
| 837 | |
| 838 | static const char * |
| 839 | iocb_cmd_lookup(unsigned cmd, enum iocb_sub *sub) |
| 840 | { |
Denys Vlasenko | 7999262 | 2011-08-19 19:44:17 +0200 | [diff] [blame] | 841 | static char buf[sizeof("%u /* SUB_??? */") + sizeof(int)*3]; |
| 842 | static const struct { |
Andi Kleen | dfcd741 | 2011-06-13 22:05:44 +0000 | [diff] [blame] | 843 | const char *name; |
| 844 | enum iocb_sub sub; |
| 845 | } cmds[] = { |
| 846 | { "pread", SUB_COMMON }, |
| 847 | { "pwrite", SUB_COMMON }, |
| 848 | { "fsync", SUB_NONE }, |
| 849 | { "fdsync", SUB_NONE }, |
| 850 | { "op4", SUB_NONE }, |
| 851 | { "poll", SUB_POLL }, |
| 852 | { "noop", SUB_NONE }, |
| 853 | { "preadv", SUB_VECTOR }, |
| 854 | { "pwritev", SUB_VECTOR }, |
| 855 | }; |
| 856 | |
| 857 | if (cmd < ARRAY_SIZE(cmds)) { |
| 858 | *sub = cmds[cmd].sub; |
| 859 | return cmds[cmd].name; |
| 860 | } |
| 861 | *sub = SUB_NONE; |
Denys Vlasenko | 7999262 | 2011-08-19 19:44:17 +0200 | [diff] [blame] | 862 | sprintf(buf, "%u /* SUB_??? */", cmd); |
Andi Kleen | dfcd741 | 2011-06-13 22:05:44 +0000 | [diff] [blame] | 863 | return buf; |
| 864 | } |
| 865 | |
| 866 | /* Not defined in libaio.h */ |
| 867 | #ifndef IOCB_RESFD |
| 868 | # define IOCB_RESFD (1 << 0) |
| 869 | #endif |
| 870 | |
| 871 | static void |
| 872 | print_common_flags(struct iocb *iocb) |
| 873 | { |
| 874 | if (iocb->u.c.flags & IOCB_RESFD) |
| 875 | tprintf("resfd=%d, ", iocb->u.c.resfd); |
| 876 | if (iocb->u.c.flags & ~IOCB_RESFD) |
| 877 | tprintf("flags=%x, ", iocb->u.c.flags); |
| 878 | } |
Dmitry V. Levin | 081e72f | 2011-06-21 15:11:57 +0000 | [diff] [blame] | 879 | |
| 880 | #endif /* HAVE_LIBAIO_H */ |
| 881 | |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 882 | int |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 883 | sys_io_submit(struct tcb *tcp) |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 884 | { |
| 885 | long nr; |
| 886 | if (entering(tcp)) { |
| 887 | tprintf("%lu, %ld, ", tcp->u_arg[0], tcp->u_arg[1]); |
| 888 | nr = tcp->u_arg[1]; |
| 889 | /* and if nr is negative? */ |
| 890 | if (nr == 0) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 891 | tprints("{}"); |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 892 | else { |
| 893 | #ifdef HAVE_LIBAIO_H |
| 894 | long i; |
| 895 | struct iocb *iocbp, **iocbs = (void *)tcp->u_arg[2]; |
| 896 | |
| 897 | for (i = 0; i < nr; i++, iocbs++) { |
Andi Kleen | dfcd741 | 2011-06-13 22:05:44 +0000 | [diff] [blame] | 898 | enum iocb_sub sub; |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 899 | struct iocb iocb; |
| 900 | if (i == 0) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 901 | tprints("{"); |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 902 | else |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 903 | tprints(", "); |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 904 | |
| 905 | if (umove(tcp, (unsigned long)iocbs, &iocbp) || |
| 906 | umove(tcp, (unsigned long)iocbp, &iocb)) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 907 | tprints("{...}"); |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 908 | continue; |
| 909 | } |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 910 | tprints("{"); |
Andi Kleen | dfcd741 | 2011-06-13 22:05:44 +0000 | [diff] [blame] | 911 | if (iocb.data) |
| 912 | tprintf("data:%p, ", iocb.data); |
| 913 | if (iocb.key) |
| 914 | tprintf("key:%u, ", iocb.key); |
| 915 | tprintf("%s, ", iocb_cmd_lookup(iocb.aio_lio_opcode, &sub)); |
| 916 | if (iocb.aio_reqprio) |
| 917 | tprintf("reqprio:%d, ", iocb.aio_reqprio); |
| 918 | tprintf("filedes:%d", iocb.aio_fildes); |
| 919 | switch (sub) { |
| 920 | case SUB_COMMON: |
| 921 | if (iocb.aio_lio_opcode == IO_CMD_PWRITE) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 922 | tprints(", str:"); |
Andi Kleen | dfcd741 | 2011-06-13 22:05:44 +0000 | [diff] [blame] | 923 | printstr(tcp, (unsigned long)iocb.u.c.buf, |
| 924 | iocb.u.c.nbytes); |
| 925 | } else { |
| 926 | tprintf(", buf:%p", iocb.u.c.buf); |
| 927 | } |
| 928 | tprintf(", nbytes:%lu, offset:%llx", |
| 929 | iocb.u.c.nbytes, |
| 930 | iocb.u.c.offset); |
| 931 | print_common_flags(&iocb); |
| 932 | break; |
| 933 | case SUB_VECTOR: |
| 934 | tprintf(", %llx, ", iocb.u.v.offset); |
| 935 | print_common_flags(&iocb); |
| 936 | tprint_iov(tcp, iocb.u.v.nr, |
| 937 | (unsigned long)iocb.u.v.vec, |
| 938 | iocb.aio_lio_opcode == IO_CMD_PWRITEV); |
| 939 | break; |
| 940 | case SUB_POLL: |
| 941 | tprintf(", %x", iocb.u.poll.events); |
| 942 | break; |
| 943 | case SUB_NONE: |
| 944 | break; |
| 945 | } |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 946 | tprints("}"); |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 947 | } |
| 948 | if (i) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 949 | tprints("}"); |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 950 | #else |
Andi Kleen | dfcd741 | 2011-06-13 22:05:44 +0000 | [diff] [blame] | 951 | #warning "libaio-devel is not available => no io_submit decoding" |
| 952 | tprintf("%#lx", tcp->u_arg[2]); |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 953 | #endif |
| 954 | } |
| 955 | } |
| 956 | return 0; |
| 957 | } |
| 958 | |
| 959 | int |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 960 | sys_io_cancel(struct tcb *tcp) |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 961 | { |
| 962 | if (entering(tcp)) { |
| 963 | #ifdef HAVE_LIBAIO_H |
| 964 | struct iocb iocb; |
| 965 | #endif |
| 966 | tprintf("%lu, ", tcp->u_arg[0]); |
| 967 | #ifdef HAVE_LIBAIO_H |
| 968 | if (umove(tcp, tcp->u_arg[1], &iocb) == 0) { |
Denys Vlasenko | 61d62cf | 2012-04-16 18:12:27 +0200 | [diff] [blame] | 969 | tprintf("{%p, %u, %u, %u, %d}, ", |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 970 | iocb.data, iocb.key, |
Denys Vlasenko | 61d62cf | 2012-04-16 18:12:27 +0200 | [diff] [blame] | 971 | (unsigned)iocb.aio_lio_opcode, |
| 972 | (unsigned)iocb.aio_reqprio, iocb.aio_fildes); |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 973 | } else |
| 974 | #endif |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 975 | tprints("{...}, "); |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 976 | } else { |
| 977 | if (tcp->u_rval < 0) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 978 | tprints("{...}"); |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 979 | else { |
| 980 | #ifdef HAVE_LIBAIO_H |
| 981 | struct io_event event; |
| 982 | if (umove(tcp, tcp->u_arg[2], &event) == 0) |
| 983 | tprintf("{%p, %p, %ld, %ld}", |
| 984 | event.data, event.obj, |
| 985 | event.res, event.res2); |
Dmitry V. Levin | 414fe7d | 2009-07-08 11:21:17 +0000 | [diff] [blame] | 986 | else |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 987 | #endif |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 988 | tprints("{...}"); |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 989 | } |
| 990 | } |
| 991 | return 0; |
| 992 | } |
| 993 | |
| 994 | int |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 995 | sys_io_getevents(struct tcb *tcp) |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 996 | { |
| 997 | if (entering(tcp)) { |
| 998 | tprintf("%ld, %ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1], |
| 999 | tcp->u_arg[2]); |
| 1000 | } else { |
| 1001 | if (tcp->u_rval == 0) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 1002 | tprints("{}"); |
Denys Vlasenko | 3e3490a | 2012-03-17 01:27:37 +0100 | [diff] [blame] | 1003 | } else { |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 1004 | #ifdef HAVE_LIBAIO_H |
| 1005 | struct io_event *events = (void *)tcp->u_arg[3]; |
| 1006 | long i, nr = tcp->u_rval; |
| 1007 | |
| 1008 | for (i = 0; i < nr; i++, events++) { |
| 1009 | struct io_event event; |
| 1010 | |
| 1011 | if (i == 0) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 1012 | tprints("{"); |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 1013 | else |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 1014 | tprints(", "); |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 1015 | |
| 1016 | if (umove(tcp, (unsigned long)events, &event) != 0) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 1017 | tprints("{...}"); |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 1018 | continue; |
| 1019 | } |
| 1020 | tprintf("{%p, %p, %ld, %ld}", event.data, |
| 1021 | event.obj, event.res, event.res2); |
| 1022 | } |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 1023 | tprints("}, "); |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 1024 | #else |
Denys Vlasenko | b237b1b | 2012-02-27 13:56:59 +0100 | [diff] [blame] | 1025 | tprints("{...}"); |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 1026 | #endif |
| 1027 | } |
| 1028 | |
Roland McGrath | 6bc09da | 2007-11-01 21:50:54 +0000 | [diff] [blame] | 1029 | print_timespec(tcp, tcp->u_arg[4]); |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 1030 | } |
| 1031 | return 0; |
| 1032 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1033 | |
| 1034 | int |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 1035 | sys_select(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1036 | { |
Dmitry V. Levin | a7945a3 | 2006-12-13 17:10:11 +0000 | [diff] [blame] | 1037 | return decode_select(tcp, tcp->u_arg, BITNESS_CURRENT); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1038 | } |
Dmitry V. Levin | 95ebf5a | 2006-10-13 20:25:12 +0000 | [diff] [blame] | 1039 | |
Dmitry V. Levin | 95ebf5a | 2006-10-13 20:25:12 +0000 | [diff] [blame] | 1040 | int |
| 1041 | sys_pselect6(struct tcb *tcp) |
| 1042 | { |
Dmitry V. Levin | a7945a3 | 2006-12-13 17:10:11 +0000 | [diff] [blame] | 1043 | int rc = decode_select(tcp, tcp->u_arg, BITNESS_CURRENT); |
Roland McGrath | fe10aa7 | 2007-11-01 21:52:20 +0000 | [diff] [blame] | 1044 | if (entering(tcp)) { |
Dmitry V. Levin | 95ebf5a | 2006-10-13 20:25:12 +0000 | [diff] [blame] | 1045 | struct { |
| 1046 | void *ss; |
| 1047 | unsigned long len; |
| 1048 | } data; |
| 1049 | if (umove(tcp, tcp->u_arg[5], &data) < 0) |
| 1050 | tprintf(", %#lx", tcp->u_arg[5]); |
| 1051 | else { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 1052 | tprints(", {"); |
Roland McGrath | fe10aa7 | 2007-11-01 21:52:20 +0000 | [diff] [blame] | 1053 | if (data.len < sizeof(long)) |
Dmitry V. Levin | 95ebf5a | 2006-10-13 20:25:12 +0000 | [diff] [blame] | 1054 | tprintf("%#lx", (long)data.ss); |
| 1055 | else |
| 1056 | print_sigset(tcp, (long)data.ss, 0); |
| 1057 | tprintf(", %lu}", data.len); |
| 1058 | } |
| 1059 | } |
| 1060 | return rc; |
| 1061 | } |
Roland McGrath | e7c3967 | 2007-08-02 01:32:17 +0000 | [diff] [blame] | 1062 | |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 1063 | static int |
| 1064 | do_eventfd(struct tcb *tcp, int flags_arg) |
Roland McGrath | e7c3967 | 2007-08-02 01:32:17 +0000 | [diff] [blame] | 1065 | { |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 1066 | if (entering(tcp)) { |
Roland McGrath | e7c3967 | 2007-08-02 01:32:17 +0000 | [diff] [blame] | 1067 | tprintf("%lu", tcp->u_arg[0]); |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 1068 | if (flags_arg >= 0) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 1069 | tprints(", "); |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 1070 | printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???"); |
| 1071 | } |
| 1072 | } |
Roland McGrath | e7c3967 | 2007-08-02 01:32:17 +0000 | [diff] [blame] | 1073 | return 0; |
| 1074 | } |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 1075 | |
| 1076 | int |
| 1077 | sys_eventfd(struct tcb *tcp) |
| 1078 | { |
| 1079 | return do_eventfd(tcp, -1); |
| 1080 | } |
| 1081 | |
| 1082 | int |
| 1083 | sys_eventfd2(struct tcb *tcp) |
| 1084 | { |
| 1085 | return do_eventfd(tcp, 1); |
| 1086 | } |
Ben Noordhuis | 88eafd8 | 2013-02-04 00:04:57 +0100 | [diff] [blame] | 1087 | |
| 1088 | int |
| 1089 | sys_perf_event_open(struct tcb *tcp) |
| 1090 | { |
| 1091 | if (entering(tcp)) { |
| 1092 | tprintf("%#lx, %d, %d, %d, ", |
| 1093 | tcp->u_arg[0], |
| 1094 | (int) tcp->u_arg[1], |
| 1095 | (int) tcp->u_arg[2], |
| 1096 | (int) tcp->u_arg[3]); |
| 1097 | printflags(perf_event_open_flags, tcp->u_arg[4], |
| 1098 | "PERF_FLAG_???"); |
| 1099 | } |
| 1100 | return 0; |
| 1101 | } |